/* * The MIT License (MIT) * * Copyright (c) 2015 - present Instructure, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import { Drilldown } from '@instructure/ui-drilldown/v11_6' import { IconQuestionLine, IconAlertsLine, IconConfigureLine, IconSearchLine, IconDiscussionLine, IconDashboardLine } from '@instructure/ui-icons' import type { TopNavBarBrandProps } from '../TopNavBarBrand/props' import type { TopNavBarActionItemsProps } from '../TopNavBarActionItems/props' import type { TopNavBarMenuItemsProps } from '../TopNavBarMenuItems/props' import type { TopNavBarUserProps } from '../TopNavBarUser/props' import type { TopNavBarItemProps, ItemChild } from '../TopNavBarItem/props' import type { TopNavBarLayoutProps } from '../TopNavBarLayout/props' import { TopNavBarContext } from '../TopNavBarContext' import type { TopNavBarContextType } from '../TopNavBarContext' import { TopNavBar } from '../index' import { elevateIcon } from './exampleSvgFiles' import { Breadcrumb } from '@instructure/ui-breadcrumb/v11_6' type ChildrenFuncProps = { currentLayout: TopNavBarContextType['layout'] inverseColor: TopNavBarContextType['inverseColor'] } type VariantConfig = Partial & { hasAlternativeTitle?: boolean hasRenderInPlaceDialogConfig?: boolean brandProps?: Partial hasRenderBreadcrumb?: boolean currentPageId?: string menuItemsWithSubmenu?: boolean menuItemsCustomIdList?: string[] menuItemsProps?: Partial menuItemsItemProps?: | Partial | ((id: string, idx: number) => Partial) menuItemsCount?: 0 | 1 | 2 | 3 | 4 | 5 | 6 actionItemsCount?: 0 | 1 | 2 | 3 | 4 | 5 | 6 actionItemsProps?: Partial actionItemsItemProps?: | Partial | ((id: string, idx: number) => Partial) userVariant?: 'avatar' | 'default' | 'button' | 'forceIconWithLabel' userWithAvatar?: boolean userWithSubmenu?: boolean userId?: string userProps?: Partial userItemProps?: Partial } const avatarExample = { avatarName: 'User Name', avatarSrc: 'https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1' } const itemSubmenuExample = ( Link One Link Two Link Three ) const getCustomPopoverConfig = ( inverseColor?: ChildrenFuncProps['inverseColor'], extraProps: Partial = {} ): TopNavBarItemProps['customPopoverConfig'] => ({ children: getCustomPopoverContent(!inverseColor), color: inverseColor ? 'primary-inverse' : 'primary', isShowingContent: true, placement: 'bottom center', ...extraProps }) const getCustomPopoverContent = ( inverseColor?: ChildrenFuncProps['inverseColor'] ) => (
dialog content
) const getInPlaceDialogConfig = ( inverseColor?: ChildrenFuncProps['inverseColor'], extraProps: Partial< TopNavBarLayoutProps['smallViewportConfig']['renderInPlaceDialogConfig'] > = {} ) => ({ open: true, onClose: () => {}, closeButtonLabel: 'Close Search and return to Navigation', returnFocusElement: () => document.getElementById('Search'), shouldCloseOnEscape: true, shouldCloseOnDocumentClick: false, shouldContainFocus: false, content: () => getCustomPopoverContent(inverseColor), ...extraProps }) const SmallViewportModeWrapper = ( props: { children: React.ReactNode } & TopNavBarContextType ) => { return ( {props.children} ) } SmallViewportModeWrapper.defaultProps = { layout: 'smallViewport', inverseColor: false } const getBrand = (config: VariantConfig = {}) => { return ( ) } const getMenuItems = (config: VariantConfig = {}) => { const items = config.menuItemsCustomIdList || [ 'Overview', 'Admin', 'Settings', 'Maps', 'Assessments', 'Community' ] const count = typeof config.menuItemsCount !== 'undefined' ? config.menuItemsCount : 6 const itemsSubset = items.slice(0, count) return ( `${hiddenChildrenCount} More` } {...config.menuItemsProps} > {itemsSubset.map((item, idx) => { const itemProps = typeof config.menuItemsItemProps === 'function' ? config.menuItemsItemProps(item, idx) : config.menuItemsItemProps return ( {itemProps?.children || item} ) })} ) } const getActionItems = (config: VariantConfig = {}) => { const items = [ { label: 'Search', icon: IconSearchLine }, { label: 'Info', icon: IconQuestionLine }, { label: 'Alerts', icon: IconAlertsLine }, { label: 'Discussions', icon: IconDiscussionLine }, { label: 'Dashboard', icon: IconDashboardLine }, { label: 'Settings', icon: IconConfigureLine } ] const count = typeof config.actionItemsCount !== 'undefined' ? config.actionItemsCount : 3 const itemsSubset = items.slice(0, count) return ( `${hiddenChildrenCount} more actions`) } > {itemsSubset.map((item, idx) => { const itemProps = typeof config.actionItemsItemProps === 'function' ? config.actionItemsItemProps(item.label, idx) : config.actionItemsItemProps return ( {itemProps?.children || item.label} ) })} ) } const getUser = (config: VariantConfig = {}) => { return ( {config.userProps && 'children' in config.userProps ? ( (config.userProps?.children as ItemChild) ) : ( {config.userItemProps?.children || (config.userVariant === 'button' ? 'Log In/Register' : 'User Name')} )} ) } const getBreadcrumb = (_config: VariantConfig = {}) => { return ( Course page 1 Course page 2 Course page 3 ) } const getLayoutProps = ( props: ChildrenFuncProps, config: VariantConfig = {} ): TopNavBarLayoutProps => { return { smallViewportConfig: { dropdownMenuToggleButtonLabel: 'Toggle Menu', dropdownMenuLabel: 'Main Menu', alternativeTitle: config.hasAlternativeTitle ? 'Page title' : undefined, renderInPlaceDialogConfig: config.hasRenderInPlaceDialogConfig ? getInPlaceDialogConfig(props.inverseColor) : undefined }, renderBrand: config.hasRenderBreadcrumb ? undefined : getBrand({ ...props, ...config }), renderMenuItems: config.hasRenderBreadcrumb ? undefined : getMenuItems({ ...props, ...config }), renderActionItems: getActionItems({ ...props, ...config }), renderUser: getUser({ ...props, ...config }), renderBreadcrumb: config.hasRenderBreadcrumb ? getBreadcrumb({ ...props, ...config }) : undefined } } export { avatarExample, itemSubmenuExample, SmallViewportModeWrapper, getCustomPopoverConfig, getCustomPopoverContent, getInPlaceDialogConfig, getBrand, getMenuItems, getActionItems, getUser, getLayoutProps, getBreadcrumb } export type { VariantConfig, ChildrenFuncProps }