1
0
mirror of https://github.com/tabler/tabler.git synced 2026-08-07 03:42:27 +04:00
Files
tabler/shared/ui/Table.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

117 lines
3.7 KiB
Plaintext

---
import Avatar from './Avatar.astro'
import Button from './Button.astro'
import ButtonList from './ButtonList.astro'
import DropdownMenu from './DropdownMenu.astro'
import people from '@data/people.json'
import { randomNumber } from '@shared/lib/pseudo-random'
interface Props {
card?: boolean
limit?: number
stripped?: boolean
offset?: number
avatars?: boolean
mobile?: boolean
buttons?: boolean
nowrap?: boolean
}
const { card, limit = 5, stripped, offset, avatars, mobile, buttons, nowrap } = Astro.props
const roles = ['User', 'Admin', 'Owner']
const start = offset ?? 0
const rows = (people as Record<string, any>[]).slice(start, start + limit)
const tableClasses = ['table', 'table-vcenter', mobile && 'table-mobile-md', card && 'card-table', stripped && 'table-striped', nowrap && 'table-nowrap']
---
<div class="table-responsive">
<table class:list={tableClasses}>
<thead>
<tr>
<th>Name</th>
<th>Title</th>
{!avatars && <th>Email</th>}
<th>Role</th>
{nowrap && <th />}
<th class="w-1"></th>
</tr>
</thead>
<tbody>
{
rows.map((person, i) => {
const role = roles[randomNumber(i + 1, 0, 2)]
return (
<tr>
{avatars ? (
<td data-label={mobile ? 'Name' : undefined}>
<div class="d-flex py-1 align-items-center">
<Avatar personId={person.id} class="me-2" />
<div class="flex-fill">
<div class="fw-medium">{person.full_name}</div>
<div class="text-secondary">
<a href="#" class="text-reset">
{person.email}
</a>
</div>
</div>
</div>
</td>
) : (
<td data-label={mobile ? 'Name' : undefined}>{person.full_name}</td>
)}
{avatars ? (
<td data-label={mobile ? 'Title' : undefined}>
<div>{person.job_title}</div>
<div class="text-secondary">{person.department}</div>
</td>
) : (
<td class="text-secondary" data-label={mobile ? 'Title' : undefined}>
{person.job_title}, {person.department}
</td>
)}
{!avatars && (
<td class="text-secondary" data-label={mobile ? 'Email' : undefined}>
<a href="#" class="text-reset">
{person.email}
</a>
</td>
)}
<td class="text-secondary" data-label={mobile ? 'Role' : undefined}>
{role}
</td>
{nowrap && <td>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, commodi cupiditate debitis deserunt expedita hic incidunt iste modi molestiae nesciunt non nostrum perferendis perspiciatis placeat praesentium quaerat quo repellendus, voluptates.</td>}
<td>
{buttons ? (
<ButtonList class="flex-nowrap">
<Button text="Edit" />
<div class="dropdown">
<button class="btn dropdown-toggle align-text-top" data-bs-toggle="dropdown">
Actions
</button>
<DropdownMenu right={true} />
</div>
</ButtonList>
) : (
<a href="#">Edit</a>
)}
</td>
</tr>
)
})
}
</tbody>
</table>
</div>