1
0
mirror of https://github.com/tabler/tabler.git synced 2026-08-07 03:42:27 +04:00
Files
tabler/shared/ui/DropdownMenu.astro
codecalm f27c70ad38 Fix Prettier formatting regression and Astro type-check errors
`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.
2026-08-03 01:26:19 +02:00

135 lines
3.9 KiB
Plaintext

---
import Icon from './Icon.astro'
import Avatar from './Avatar.astro'
import Flag from './Flag.astro'
import people from '@data/people.json'
import countries from '@data/countries.json'
interface Props {
right?: boolean
show?: boolean
arrow?: boolean
dark?: boolean
class?: string
menu?: string[]
check?: boolean
radio?: boolean
people?: boolean
flag?: boolean
type?: string
header?: boolean
icons?: boolean
badge?: boolean
active?: boolean
disabled?: boolean
separated?: boolean
}
const { right, show, arrow, dark, class: className, menu, check, radio, people: showPeople, flag: showFlags, type, header, icons, badge, active, disabled, separated } = Astro.props
const classes = ['dropdown-menu', right && 'dropdown-menu-end', show && 'dropdown-menu-demo', arrow && 'dropdown-menu-arrow', className]
const menuItems = menu
const peopleItems = (people as { id: string; full_name: string }[]).slice(0, 5)
const countryItems = (countries as { name: string; flag: string }[]).slice(0, 5)
---
<div class:list={classes} data-bs-theme={dark ? 'dark' : undefined}>
{
menuItems ? (
menuItems.map((item) =>
item === '|' ? (
<div class="dropdown-divider" />
) : item.includes('h:') ? (
<h3 class="dropdown-header">{item.split('h:').join('')}</h3>
) : item.includes('a:') ? (
<a href="#" class="dropdown-item active">
{item.split('a:').join('')}
</a>
) : item.includes('d:') ? (
<a href="#" class="dropdown-item text-danger">
{item.split('d:').join('')}
</a>
) : (
<a href="#" class="dropdown-item">
{item}
</a>
),
)
) : check || radio ? (
[1, 2, 3].map((i) => (
<label class="dropdown-item">
<input class="form-check-input m-0 me-2" type={radio ? 'radio' : 'checkbox'} /> Option {i}
</label>
))
) : showPeople ? (
peopleItems.map((person) => (
<a href="#" class="dropdown-item">
<Avatar personId={Number(person.id)} size="xs" /> {person.full_name}
</a>
))
) : showFlags ? (
countryItems.map((country) => (
<a href="#" class="dropdown-item">
<Flag flag={country.flag} size="xs" /> {country.name}
</a>
))
) : type === 'text' ? null : (
<>
{header && <span class="dropdown-header">Dropdown header</span>}
<a class="dropdown-item" href="#">
{icons && (
<>
<Icon name="settings" class="dropdown-item-icon" />{' '}
</>
)}
Action
{badge && <span class="badge bg-primary text-primary-fg ms-auto">12</span>}
</a>
<a class="dropdown-item" href="#">
{icons && (
<>
<Icon name="edit" class="dropdown-item-icon" />{' '}
</>
)}
Another action
{badge && <span class="badge bg-green ms-auto" />}
</a>
{active && (
<a class="dropdown-item active" href="#">
{icons && (
<>
<Icon name="activity" class="dropdown-item-icon" />{' '}
</>
)}
Active action
</a>
)}
{disabled && (
<a class="dropdown-item disabled" href="#">
{icons && (
<>
<Icon name="user-x" class="dropdown-item-icon" />{' '}
</>
)}
Disabled action
</a>
)}
{separated && (
<>
<div class="dropdown-divider" />
<a class="dropdown-item" href="#">
{icons && (
<>
<Icon name="plus" class="dropdown-item-icon" />{' '}
</>
)}
Separated link
</a>
</>
)}
</>
)
}
</div>