--- import Icon from '@ui/Icon.astro' import NavbarMenuItem, { type Level2 } from './NavbarMenuItem.astro' import menu from '@data/menu.json' import menuSample from '@data/menu-sample.json' interface Level1 { 'title': string 'title-long'?: string 'icon'?: string 'url'?: string 'badge'?: string 'active'?: boolean 'disabled'?: boolean 'right'?: boolean 'columns'?: number /** section label rendered before this item (sidebar only, needs the `sections` prop) */ 'section'?: string 'children'?: Record } interface Props { /** active menu entry, e.g. "dashboards.default" */ pageMenu?: string | undefined sample?: boolean hideIcons?: boolean longTitles?: boolean keepOpen?: boolean autoOpen?: boolean /** renders `section` fields from the menu data as group labels */ sections?: boolean class?: string } const { pageMenu = '', sample = false, hideIcons = false, longTitles = false, keepOpen = false, autoOpen = false, sections = false, class: className } = Astro.props const currentPage = pageMenu.split('.') const items = Object.entries((sample ? menuSample : menu) as Record) // per-column = ceil(size / columns), break every per-column. const chunk = (arr: T[], size: number): T[][] => { const out: T[][] = [] for (let i = 0; i < arr.length; i += size) out.push(arr.slice(i, i + size)) return out } ---
    { items.map(([key, item]) => { const active = key === currentPage[0] || item.active const hasChildren = !!item.children const children = Object.entries(item.children ?? {}) const columns = item.columns ? chunk(children, Math.ceil(children.length / item.columns)) : null const title = longTitles ? (item['title-long'] ?? item.title) : item.title return ( {sections && item.section && } '} />
  • {!hideIcons && {item.icon && }} {title} {item.badge && {item.badge}} {hasChildren && (
    {columns ? ( ) : ( children.map(([childKey, child]) => ) )}
    )}
  • '} /> ) }) }