mirror of
https://github.com/tabler/tabler.git
synced 2026-08-29 13:21:29 +04:00
`Render Modal as real markup` (#2742) reformatted ~140 files back to tabs/semicolons, breaking the Prettier config added by the Astro quality gates (#2749). Re-run prettier --write to restore it, and fix the type errors it had been masking: HTMLElement casts and `this` typing in ChangePasswordModalContent/ConfirmDeleteModalContent scripts, plain-JS syntax in the inline-injected progress.astro script, narrowed prop unions in Button/Check/Spinner, nullable icon svg casts in Icons/Rating, and a duplicate firstLetters/invalid `placeholder` attribute in Select.astro. Also fix shared/vitest.config.mts's stale `astro/lib/**/*.test.ts` include glob left over from the shared source restructure, which made `pnpm test` report zero test files.
68 lines
2.2 KiB
Plaintext
68 lines
2.2 KiB
Plaintext
---
|
|
// Dropdown menu item, optionally with a nested dropend.
|
|
import Icon from '@ui/Icon.astro'
|
|
|
|
interface Level3 {
|
|
title: string
|
|
url?: string
|
|
badge?: string
|
|
}
|
|
|
|
interface Level2 extends Level3 {
|
|
icon?: string
|
|
color?: string
|
|
children?: Record<string, Level3>
|
|
}
|
|
|
|
interface Props {
|
|
level1Key: string
|
|
itemKey: string
|
|
item: Level2
|
|
currentPage: string[]
|
|
keepOpen?: boolean
|
|
}
|
|
|
|
const { level1Key, itemKey, item, currentPage, keepOpen = false } = Astro.props
|
|
|
|
const hasChildren = !!item.children
|
|
const isExternal = (url?: string) => !!url && (url.includes('http://') || url.includes('https://'))
|
|
const relative = (url?: string) => (isExternal(url) ? url : `./${url}`)
|
|
|
|
const active = level1Key === currentPage[0] && itemKey === currentPage[1] && currentPage.length === 2
|
|
|
|
const itemClasses = ['dropdown-item', hasChildren && 'dropdown-toggle', active && 'active', item.color && `text-${item.color}`]
|
|
---
|
|
|
|
<!-- BEGIN NAVBAR ITEM -->{
|
|
hasChildren ? (
|
|
<div class="dropend">
|
|
<a class:list={itemClasses} href={`#sidebar-${itemKey}`} data-bs-toggle="dropdown" data-bs-auto-close={keepOpen ? 'false' : 'outside'} role="button" aria-haspopup="true" aria-expanded="false" aria-current={active ? 'page' : undefined}>
|
|
{item.icon && <Icon name={item.icon} class="icon-inline me-1" />}
|
|
|
|
{item.title}
|
|
|
|
{item.badge && <span class="badge badge-sm bg-green-lt text-uppercase ms-auto">{item.badge}</span>}
|
|
</a>
|
|
|
|
<div class="dropdown-menu">
|
|
{Object.entries(item.children!).map(([, child]) => (
|
|
<a href={relative(child.url)} class="dropdown-item">
|
|
{child.title}
|
|
|
|
{child.badge && <span class="badge badge-sm bg-green-lt text-uppercase ms-auto">{child.badge}</span>}
|
|
</a>
|
|
))}
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<a class:list={itemClasses} href={relative(item.url)} target={isExternal(item.url) ? '_blank' : undefined} rel={isExternal(item.url) ? 'noopener' : undefined} aria-current={active ? 'page' : undefined}>
|
|
{item.icon && <Icon name={item.icon} class="icon-inline me-1" />}
|
|
|
|
{item.title}
|
|
|
|
{item.badge && <span class="badge badge-sm bg-green-lt text-uppercase ms-auto">{item.badge}</span>}
|
|
</a>
|
|
)
|
|
}
|
|
<!-- END NAVBAR ITEM -->
|