mirror of
https://github.com/tabler/tabler.git
synced 2026-08-07 03:42:27 +04:00
f27c70ad38
`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.
57 lines
2.3 KiB
Plaintext
57 lines
2.3 KiB
Plaintext
---
|
|
import Icon from './Icon.astro'
|
|
import { includeArgCount } from '@shared/lib/include-args'
|
|
|
|
interface Props {
|
|
items?: string[]
|
|
icons?: string[]
|
|
disabled?: number[]
|
|
hover?: string
|
|
default?: number
|
|
vertical?: boolean
|
|
size?: string
|
|
fullWidth?: boolean
|
|
name?: string
|
|
class?: string
|
|
}
|
|
|
|
const { items, icons, disabled, hover = '', default: defaultIndex = 1, vertical, size, fullWidth, name, class: className } = Astro.props
|
|
|
|
// When `size` is omitted, append `nav-{argCount}` (e.g. nav-1, nav-2). An explicit size uses nav-sm/nav-lg.
|
|
const includeArgKeys = ['items', 'icons', 'disabled', 'hover', 'default', 'vertical', 'size', 'fullWidth', 'class', 'name'] as const
|
|
const argCount = includeArgCount(Astro.props as Record<string, unknown>, includeArgKeys)
|
|
const sizeToken = size ? `nav-${size}` : `nav-${argCount}`
|
|
|
|
const itemsArr = items ?? []
|
|
const iconsArr = icons ?? []
|
|
const count = Math.max(itemsArr.length, iconsArr.length)
|
|
|
|
const navClasses = ['nav', 'nav-segmented', vertical && 'nav-segmented-vertical', sizeToken, fullWidth && 'w-100', className]
|
|
|
|
const rows = Array.from({ length: count }, (_, i) => {
|
|
const forloopIndex = i + 1
|
|
const index = String(forloopIndex)
|
|
const isDisabled = disabled?.includes(forloopIndex) ?? false
|
|
const isDefault = forloopIndex === defaultIndex
|
|
const linkClasses = ['nav-link', isDisabled && 'disabled', isDefault && !name && 'active', hover === index && 'hover']
|
|
return { forloopIndex, index, isDisabled, isDefault, linkClasses, icon: iconsArr[i], item: itemsArr[i] }
|
|
})
|
|
---
|
|
|
|
<nav class:list={navClasses} role="tablist" aria-orientation={vertical ? 'vertical' : undefined}>
|
|
{
|
|
rows.map((row) => {
|
|
const Element = name ? 'label' : 'button'
|
|
return (
|
|
<Fragment>
|
|
{name && <input type="radio" class="nav-link-input" name={name} id={`segmented-${name}-${row.index}`} checked={row.isDefault} />}
|
|
<Element for={name ? `segmented-${name}-${row.index}` : undefined} class:list={row.linkClasses} role="tab" data-bs-toggle={name ? undefined : 'tab'} aria-selected={row.isDefault ? 'true' : 'false'} aria-disabled={row.isDisabled ? 'true' : undefined} aria-current={row.isDefault ? 'page' : undefined}>
|
|
{row.icon && <Icon name={row.icon} class="nav-link-icon" />}
|
|
{row.item && row.item}
|
|
</Element>
|
|
</Fragment>
|
|
)
|
|
})
|
|
}
|
|
</nav>
|