68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
import { isObject, isOptionalOf, isString, isNullOrUndefined, isOptionalArrayOf, isInArray } from 'common/utils';
|
|
|
|
export enum MenuPosition {
|
|
LEFT = 'left',
|
|
RIGHT = 'right',
|
|
CENTER = 'none',
|
|
}
|
|
|
|
export function isMenuPosition(data: any): data is MenuPosition {
|
|
return isInArray(data, ['left', 'right', 'none']);
|
|
}
|
|
|
|
export interface MenuItem {
|
|
// Position of the menue element
|
|
position: MenuPosition;
|
|
// Hover help
|
|
hover?: string;
|
|
// Icon of the menue (need to be a meterial-icon name
|
|
icon?: string;
|
|
// Displayed Title
|
|
image?: string;
|
|
// Displayed Title
|
|
title: string;
|
|
// Model of the display:
|
|
model?: string;
|
|
// Jump Link (If undefined: it is considered as text and not a button)
|
|
navigateTo?: string;
|
|
// Menu model For a subList of elements
|
|
callback?: boolean;
|
|
// Other data that want to be set by the user
|
|
otherData?: any;
|
|
// Menu model For a subList of elements
|
|
enable?: boolean;
|
|
// Menu model For a subList of elements
|
|
subMenu?: MenuItem[];
|
|
}
|
|
|
|
export function isMenuItem(data: any): data is MenuItem {
|
|
if (isNullOrUndefined(data)) {
|
|
return false;
|
|
}
|
|
if (!isObject(data)) {
|
|
return false;
|
|
}
|
|
if (!isMenuPosition(data.position)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalOf(data.hover, isString)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalOf(data.icon, isString)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalOf(data.image, isString)) {
|
|
return false;
|
|
}
|
|
if (!isString(data.title)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalOf(data.navigateTo, isString)) {
|
|
return false;
|
|
}
|
|
if (!isOptionalArrayOf(data.subMenu, isMenuItem)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|