Basic Striped Table
A data-driven table with zebra striping, wrapped in a horizontal scroller that keeps it usable at 320px.
3 个框架初级
Row checkboxes with a tri-state select-all header and a live-updating selection count.
<!--
Two accessibility jobs here. The header checkbox is TRI-STATE: checked when all
rows are, indeterminate when some are - and `indeterminate` is a DOM property
with no HTML attribute, so it must be set from JS (see React/TS). Each row
checkbox has an aria-label naming its row, because a bare checkbox in a grid is
otherwise announced as just "checkbox". The selected row gets a tinted bg so the
selection is not carried by the checkmark alone.
-->
<div class="w-full overflow-x-auto">
<table class="w-full min-w-[34rem] border-collapse text-left text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-800">
<th scope="col" class="w-10 px-3 py-2.5">
<input type="checkbox" aria-label="Select all rows" class="h-4 w-4 accent-blue-600 dark:accent-blue-500" />
</th>
<th scope="col" class="px-3 py-2.5 font-medium text-gray-700 dark:text-gray-300">Name</th>
<th scope="col" class="px-3 py-2.5 font-medium text-gray-700 dark:text-gray-300">Role</th>
</tr>
</thead>
<tbody>
<tr class="border-b border-gray-100 bg-blue-50/60 dark:border-gray-800 dark:bg-blue-500/10">
<td class="px-3 py-2.5"><input type="checkbox" checked aria-label="Select Dana Lee" class="h-4 w-4 accent-blue-600 dark:accent-blue-500" /></td>
<td class="px-3 py-2.5 text-gray-700 dark:text-gray-300">Dana Lee</td>
<td class="px-3 py-2.5 text-gray-700 dark:text-gray-300">Admin</td>
</tr>
<tr class="border-b border-gray-100 dark:border-gray-800">
<td class="px-3 py-2.5"><input type="checkbox" aria-label="Select Sam Ford" class="h-4 w-4 accent-blue-600 dark:accent-blue-500" /></td>
<td class="px-3 py-2.5 text-gray-700 dark:text-gray-300">Sam Ford</td>
<td class="px-3 py-2.5 text-gray-700 dark:text-gray-300">Editor</td>
</tr>
</tbody>
</table>
</div>| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
columns必填 | DataColumn[] | - | 参与比较的列,按显示顺序排列。 |
rows必填 | DataRow[] | - | 图文交替排列的行,按顺序显示。 |
className | string | - | 合并到根元素上的额外类名。 |
The header checkbox is genuinely tri-state - `indeterminate` is a DOM property with no attribute, so it is set via a ref in an effect. Each row checkbox gets an `aria-label` naming its row, and the selected row is tinted so selection is not carried by the checkmark alone.