/************************************************************************* * Copyright 2020 Adobe * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in * accordance with the terms of the Adobe license agreement accompanying * it. If you have received this file from a source other than Adobe, * then your use, modification, or distribution of it requires the prior * written permission of Adobe. **************************************************************************/ /** * APIs that let solutions interact with the Sidenav nav. * * ***Import:*** * * ```typescript * import sidenav from '@adobe/exc-app/sidenav'; * ``` * * ***Default export:*** * * [SidenavApi](../interfaces/sidenav.sidenavapi.md#interface-sidenavapi) * * ***Usage:*** * * ```typescript * sidenav.config = { * menu: [ * {absolutePath: true, id: 'home', name: 'Home', url: '/home'}, * {id: 'example', name: 'Example', url: '/'}, * {id: 'journeys', name: 'Journeys', url: '/journeys'}, * { * heading: 'STORAGE', * items: [ * {id: 'external', name: 'External', target: '_blank', url: 'https://adobe.com'} * ] * }, * { * heading: 'DOCUMENTS', * items: [ * {id: '2', name: 'Item 2'} * ] * } * ], * settings: { * id: 'mySideNav', * typeToSelect: true, * variant: 'default' * } * }; * * sidenav.visible = false; * sidenav.collapsed = true; * * console.log(sidenav.visible); * console.log(sidenav.collapsed); * ``` * * ### Receiving updates * * You can also listen for updates on the requested data by listening to specific change events. * * These change events are emitted from the api that the data is requested from. For example, if a * user calls `await sidenav.get('shellSideNavCollapsed');` they must listen for the change event on * `user.on('change:shellSideNavCollapsed')`. Here is a more detailed example of how the promise * api and change events can be used to keep track of specific values from the config: * * ```typescript * import sidenav from '@adobe/exc-app/sidenav'; * * constructor() { * this.state = {shellSideNavCollapsed: false}; * * sidenav.on('change:shellSideNavCollapsed', (shellSideNavCollapsed) => { * this.setState({shellSideNavCollapsed}); * }); * } * * async componentDidMount() { * const shellSideNavCollapsed = await user.get('shellSideNavCollapsed'); * this.setState({shellSideNavCollapsed}); * } * ``` * @packageDocumentation * @module sidenav */ import EventEmitter from './src/EventEmitter'; export interface NavHeading { /** * Display name of the nav category heading. */ heading: string; /** * A list of NavItems that go under the nav category heading. */ items: NavItem[]; } export declare enum NAV_POSITIONS { FOOTER = "FOOTER" } export interface NavItem { /** * Whether the path is absolute or relative to the base path. */ absolutePath?: boolean; /** * Nested nav items. */ children?: NavItem[]; /** * Whether or not to disable the nav item. */ disabled?: boolean; /** * The section of the sidenav to display the item in. If unset, item will appear in the main nav */ displayInSection?: NAV_POSITIONS; /** * A string icon (from @react/react-spectrum/Icon) to be shown on the left side of the nav item. */ icon?: string; /** * ID of the Sidenav nav item. */ id: string; /** * The label and display name of the Sidenav nav item. */ name: string; /** * Paths on which to select the nav item. */ selectOn?: string[]; /** * Where to open external URL e.g., '_self' or '_blank' for same tab or new tab. */ target?: string; /** * A string url the user is taken to when this item is clicked. */ url?: string; } export interface NavSettings { /** * ID of the Sidenav nav. * */ id: string; /** * Whether or not to enable type to select. */ typeToSelect?: boolean; /** * Type and style of Sidenav nav. */ variant?: 'default' | 'multiLevel'; } export interface NavConfig { /** * List of nav item objects. */ menu: (NavItem | NavHeading)[]; /** * Extra Sidenav nav options and configurations. */ settings?: NavSettings; } export interface SidenavInfo { shellSideNavCollapsed: boolean; } interface SidenavInfoEvent { 'change:shellSideNavCollapsed': boolean; } export interface LeftNavConfig { /** * Function called when the left nav state is changed * @param isOpen Is the left nav open? */ callback: (isOpen: boolean) => void; /** * Should the left nav close when a side nav item is selected */ closeOnSelection: boolean; } /** * APIs that let solutions interact with Sidenav nav. */ export interface SidenavApi extends EventEmitter { /** * Configuration to add headings, items, and other settings to the Sidenav nav. * * ***Example:*** * * ```typescript * sidenav.config = { * menu: [ * {absolutePath: true, id: 'home', name: 'Home', url: '/home'}, * {id: 'example', name: 'Example', url: '/'}, * {id: 'journeys', name: 'Journeys', url: '/journeys'}, * { * heading: 'STORAGE', * items: [ * {id: 'external', name: 'External', target: '_blank', url: 'https://adobe.com'} * ] * }, * { * heading: 'DOCUMENTS', * items: [ * {id: '2', name: 'Item 2'} * ] * } * ], * settings: { * id: 'mySideNav', * typeToSelect: true, * variant: 'default' * } * }; * ``` * * Options: * * menu: List of nav items and headers and their nav items and headings to add to the Sidenav nav. There are two types: * * Heading Nav Item * * heading: The heading name. This string needs to be translated using the locale shell provides. * * items: The list of nav items that belong under the heading. Each nav items should have the below properties * * Regular Nav Item * * id: Unique id and value of the nav item. * * name: The nav item's label and display name. This string needs to be translated using the locale shell provides. * * disabled: (optional) Whether or not this item is disabled. * * target: (optional) Where to open external URL e.g., '_self' or '_blank' for same tab or new tab. * * url: A string url the user is taken to when this item is clicked. * * absolutePath: Whether the path is absolute or relative to the base path. * * settings: Optional object of additional settings for the Sidenav nav. * * id: Unique id and value of the sidenav nav. * * typeToSelect: Whether to enable typing to select an item. * * variant: Can be one of two values: default or multiLevel. Currently, we only support default. */ config?: NavConfig; /** * Boolean representing whether the sidenav drawer is presently open or closed. * * ***Example:*** * * ```typescript * sidenav.collapsed = true; * ``` */ collapsed?: boolean; /** * Gets the specified type of information about the sidenav. * @param type The type of information to get. */ get(type: T): Promise; /** * Adds a callback function to be called when a Sidenav nav item is clicked. * This is separate from the config property so that it can work seamlessly * with WorkHub provided rails. This callback only receives an event if the * nav item clicked does not have a url. * * ***Example:*** * * ```typescript * sidenav.onNavItemClick(item => console.log('nav item clicked', item)); * ``` */ onNavItemClick: (callback: (item: NavItem) => void) => void; /** * Adds the left nav button to shell to control an application's internal left nav. * The callback function will recieve the state of the left nav every time the shell left nav button is clicked, * either open or closed, and the application can use that value to control their left nav. * * ***Example:*** * * ```typescript * sidenav.useLeftNavButton({ * callback: isOpen => console.log('side nav is ', isOpen ? 'open' : 'closed'), * closeOnSelection: false * }); * ``` */ useLeftNavButton(config: LeftNavConfig): void; /** * Boolean representing whether Sidenav and its button should be rendered at all. * * ***Example:*** * * ```typescript * sidenav.visible = false; * ``` */ visible?: boolean; } declare const sidenav: SidenavApi; export default sidenav;