mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
feat(component): add DataTableSkeleton
This commit is contained in:
parent
5c1237f2e4
commit
b95fd1ac55
5 changed files with 84 additions and 0 deletions
17
src/components/DataTableSkeleton/DataTable.stories.js
Normal file
17
src/components/DataTableSkeleton/DataTable.stories.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { withKnobs, array, boolean } from '@storybook/addon-knobs';
|
||||
import Component from './DataTableSkeleton.Story.svelte';
|
||||
|
||||
export default { title: 'DataTableSkeleton', decorators: [withKnobs] };
|
||||
|
||||
export const Default = () => ({
|
||||
Component,
|
||||
props: {
|
||||
headers: array(
|
||||
'Optional table headers (headers)',
|
||||
['Name', 'Protocol', 'Port', 'Rule', 'Attached Groups'],
|
||||
','
|
||||
),
|
||||
zebra: boolean('Use zebra stripe (zebra)', false),
|
||||
compact: boolean('Compact variant (compact)', false)
|
||||
}
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
<script>
|
||||
import Layout from '../../internal/ui/Layout.svelte';
|
||||
import DataTableSkeleton from './DataTableSkeleton.svelte';
|
||||
</script>
|
||||
|
||||
<Layout>
|
||||
<div style="width: 800px">
|
||||
<DataTableSkeleton {...$$props} />
|
||||
</div>
|
||||
</Layout>
|
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>
|
3
src/components/DataTableSkeleton/index.js
Normal file
3
src/components/DataTableSkeleton/index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import DataTableSkeleton from './DataTableSkeleton.svelte';
|
||||
|
||||
export default DataTableSkeleton;
|
|
@ -5,6 +5,7 @@ import Checkbox, { CheckboxSkeleton } from './components/Checkbox';
|
|||
import Copy from './components/Copy';
|
||||
import CopyButton from './components/CopyButton';
|
||||
import CodeSnippet, { CodeSnippetSkeleton } from './components/CodeSnippet';
|
||||
import DataTableSkeleton from './components/DataTableSkeleton';
|
||||
import InlineLoading from './components/InlineLoading';
|
||||
import Loading from './components/Loading';
|
||||
import Link from './components/Link';
|
||||
|
@ -38,6 +39,7 @@ export {
|
|||
CodeSnippetSkeleton,
|
||||
Copy,
|
||||
CopyButton,
|
||||
DataTableSkeleton,
|
||||
InlineLoading,
|
||||
Loading,
|
||||
Link,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue