Menu service

Live provides an API to register new menu items at navigation bar.

Standard API

Since Live @ 2

The menuService is a javascript module that allows registering custom menu items to Live navigation bar or an item that already exists at the navigation bar. Every menu item must have a unique name and alias to represent itself.

How to import

import MenuService from 'live/services/menu'

Methods

register(menu: MenuItem, type: MenuType): void

Register a new menu item.

unregister(menu: MenuItem, type: MenuType): void

Unregister an already existing menu item.

getAll(): MenuItems

Obtain all registered menu items.

withMenuItems(Component: React.ComponentType<{ menus: MenuItems }>): React.FC

Allow a React component to receive all listed menus.

The base properties that are commom between all types of menu are explained in more detail in the table below:

The 'right' type menu has the component property instead of the Component described before. It also have the same properties, with an extra described as follows:

The preferences menu has some extra properties that are described down below:

The console menu has the same component, name, url, onClick, icon and description described above, but have its own particularities. See the table below to know about the extra properties of it:

Examples

Regular menu example:

const Test = (): JSX.Element => <h1 style={{ padding: '50px 0 0 20px' }}>Test</h1>

Router.route('test', Test, 'test')

MenuService.register(
    {
        alias: 'test',
        name: 'Test Menu',
        url: '/#/test/'
    },
    'regular'
)

Regular menu with selectedAliases:

const Test = (): JSX.Element => <h1 style={{ padding: '50px 0 0 20px' }}>Test</h1>

Router.route('test-url', Test, 'test-route-alias')

MenuService.register(
    {
        alias: 'test',
        name: 'Test Menu',
        url: '/#/test-url/',
        selectedAliases: ['test-route-alias'],
    },
    'regular'
)

Regular menu with replaces:

const Test = (): JSX.Element => <h1 style={{ padding: '50px 20px'}}>Test</h1>

Router.route('test', Test, 'test')

MenuService.register(
    {
        alias: 'test',
        name: 'Test Menu',
        url: '/#/test',
        replaces: 'dashboards'
    },
    'regular'
)

Right menu example:

const Test = (): JSX.Element => <h1 style={{ padding: '50px 20px'}}>Test</h1>

Router.route('test', Test, 'test')

MenuService.register(
    {
        alias: 'test',
        name: 'Test Menu',
        url: '/#/test/',
        config: { iconCls: 'fa-info-circle' }
    },
    'right'
)

Preferences menu example:

const Test = (): JSX.Element => <h1 style={{ padding: '50px 20px'}}>Test</h1>

Router.route('test', Test, 'test')

MenuService.register(
    {
        alias: 'test',
        name: 'Test Menu',
        url: '/#/test/',
        icon: 'far fa-info-circle',
        description: 'This is a test menu'
    },
    'preferences'
)

Console menu example:

const Test = (): JSX.Element => <h1 style={{ padding: '50px 20px'}}>Test</h1>

Router.route('test', Test, 'test')

MenuService.register(
    {
        alias: 'test',
        name: 'Test Menu',
        url: '#/test',
        icon: 'far fa-info-circle'
    },
    'console'
)

Last updated