/* * 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 { ComponentElement, Component } from 'react' import { withStyle } from '@instructure/emotion' import { callRenderProp, omitProps } from '@instructure/ui-react-utils' import { View } from '@instructure/ui-view/latest' import { Menu } from '@instructure/ui-menu/latest' import { Item } from './Item' import generateStyle from './styles' import type { AppNavProps } from './props' import { allowedProps } from './props' import { AppNavItemProps } from './Item/props' import { TruncateList } from '@instructure/ui-truncate-list' /** --- category: components --- **/ @withStyle(generateStyle) class AppNav extends Component { static readonly componentId = 'AppNav' static allowedProps = allowedProps static defaultProps = { children: null, debounce: 300, margin: '0', renderTruncateLabel: () => 'More', visibleItemsCount: 0 } static Item = Item state = { isMeasuring: false } ref: Element | null = null componentDidMount() { this.props.makeStyles?.() } componentDidUpdate() { this.props.makeStyles?.() } handleRef = (el: Element | null) => { const { elementRef } = this.props this.ref = el if (typeof elementRef === 'function') { elementRef(el) } } renderMenu(items: ComponentElement[]) { return ( } > {(items as ComponentElement[]).map( (item, index) => { return ( {callRenderProp(item.props.renderLabel)} ) } )} ) } render() { const { visibleItemsCount, screenReaderLabel, margin, debounce, styles } = this.props const passthroughProps = View.omitViewProps( omitProps(this.props, AppNav.allowedProps), AppNav ) const renderBeforeItems = callRenderProp(this.props.renderBeforeItems) const renderAfterItems = callRenderProp(this.props.renderAfterItems) const hasRenderedContent = renderBeforeItems || renderAfterItems return ( {renderBeforeItems && {renderBeforeItems}} this.renderMenu( hiddenChildren as ComponentElement[] ) } itemSpacing={styles?.horizontalMargin} fixMenuTriggerWidth={styles?.menuTriggerWidth} css={styles?.list} aria-label={callRenderProp(screenReaderLabel)} > {this.props.children} {renderAfterItems && {renderAfterItems}} ) } } export { AppNav } export default AppNav