mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
feat(component): add DataTableSkeleton
This commit is contained in:
parent
5c1237f2e4
commit
b95fd1ac55
5 changed files with 84 additions and 0 deletions
52
src/components/DataTableSkeleton/DataTableSkeleton.svelte
Normal file
52
src/components/DataTableSkeleton/DataTableSkeleton.svelte
Normal file
|
@ -0,0 +1,52 @@
|
|||
<script>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let zebra = false;
|
||||
export let compact = false;
|
||||
export let rowCount = 5;
|
||||
export let columnCount = 5;
|
||||
export let headers = [];
|
||||
export let props = {};
|
||||
|
||||
import { cx } from '../../lib';
|
||||
|
||||
const rows = Array.from({ length: rowCount - 1 }, (_, i) => i);
|
||||
const columns = Array.from({ length: columnCount }, (_, i) => i);
|
||||
const _headers =
|
||||
headers[0] === Object(headers[0]) && !Array.isArray(headers[0])
|
||||
? headers.map(({ header }) => header)
|
||||
: headers;
|
||||
const _class = cx(
|
||||
'--skeleton',
|
||||
'--data-table',
|
||||
zebra && '--data-table--zebra',
|
||||
compact && '--data-table--compact',
|
||||
className
|
||||
);
|
||||
</script>
|
||||
|
||||
<table {...props} on:click on:mouseover on:mouseenter on:mouseleave class={_class}>
|
||||
<thead>
|
||||
<tr>
|
||||
{#each columns as column, i (column)}
|
||||
<th>{_headers[column]}</th>
|
||||
{/each}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
{#each columns as column, i (column)}
|
||||
<td>
|
||||
<span />
|
||||
</td>
|
||||
{/each}
|
||||
</tr>
|
||||
{#each rows as row, i (row)}
|
||||
<tr>
|
||||
{#each columns as column, j (column)}
|
||||
<td />
|
||||
{/each}
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
Loading…
Add table
Add a link
Reference in a new issue