From 7cfd93f9012358d7ccde13d1c37f49a7bc52f369 Mon Sep 17 00:00:00 2001 From: MinamiFunakoshiTR Date: Tue, 25 Mar 2025 10:55:23 -0700 Subject: [PATCH 1/7] setting up table --- src/components/Table/Table.mdx | 19 ++ src/components/Table/Table.stories.svelte | 98 ++----- src/components/Table/Table.svelte | 251 +++++++----------- .../Table/{stories => demo}/docs/both.md | 0 .../Table/{stories => demo}/docs/component.md | 0 .../Table/{stories => demo}/docs/filter.md | 0 .../Table/{stories => demo}/docs/format.md | 0 .../Table/{stories => demo}/docs/metadata.md | 0 .../Table/{stories => demo}/docs/paginate.md | 0 .../Table/{stories => demo}/docs/search.md | 0 .../Table/{stories => demo}/docs/sort.md | 0 .../Table/{stories => demo}/docs/style.md | 0 .../Table/{stories => demo}/docs/truncate.md | 0 .../Table/{stories => demo}/homeRuns.json | 0 .../Table/{stories => demo}/pressFreedom.json | 0 .../Table/{stories => demo}/richestWomen.json | 0 src/components/Table/{utils.js => utils.ts} | 0 17 files changed, 143 insertions(+), 225 deletions(-) create mode 100644 src/components/Table/Table.mdx rename src/components/Table/{stories => demo}/docs/both.md (100%) rename src/components/Table/{stories => demo}/docs/component.md (100%) rename src/components/Table/{stories => demo}/docs/filter.md (100%) rename src/components/Table/{stories => demo}/docs/format.md (100%) rename src/components/Table/{stories => demo}/docs/metadata.md (100%) rename src/components/Table/{stories => demo}/docs/paginate.md (100%) rename src/components/Table/{stories => demo}/docs/search.md (100%) rename src/components/Table/{stories => demo}/docs/sort.md (100%) rename src/components/Table/{stories => demo}/docs/style.md (100%) rename src/components/Table/{stories => demo}/docs/truncate.md (100%) rename src/components/Table/{stories => demo}/homeRuns.json (100%) rename src/components/Table/{stories => demo}/pressFreedom.json (100%) rename src/components/Table/{stories => demo}/richestWomen.json (100%) rename src/components/Table/{utils.js => utils.ts} (100%) diff --git a/src/components/Table/Table.mdx b/src/components/Table/Table.mdx new file mode 100644 index 00000000..aa15c7c4 --- /dev/null +++ b/src/components/Table/Table.mdx @@ -0,0 +1,19 @@ +import { Meta, Canvas } from '@storybook/blocks'; + +import * as TableTextStories from './Table.stories.svelte'; + + + +# Table + +The `Table` component TKTK + +```svelte + + + +``` + + diff --git a/src/components/Table/Table.stories.svelte b/src/components/Table/Table.stories.svelte index d7777f23..d7f74e9b 100644 --- a/src/components/Table/Table.stories.svelte +++ b/src/components/Table/Table.stories.svelte @@ -1,128 +1,91 @@ - - - + }} +/> --> diff --git a/src/components/Table/Table.svelte b/src/components/Table/Table.svelte index efb621e1..fa241e52 100644 --- a/src/components/Table/Table.svelte +++ b/src/components/Table/Table.svelte @@ -1,138 +1,79 @@ - -
+
{#if title || dek || searchable || filterList} -
+
{#if title}

{@html title}

{/if} @@ -187,9 +228,9 @@ {/if} {/if} -
+
{/if} -
+
- {#each includedFields as field} + {#each includedFieldsDerived as field} @@ -227,7 +266,7 @@ {#each currentPageData as item, idx} - {#each includedFields as field} + {#each includedFieldsDerived as field} @@ -251,7 +290,7 @@ {#if notes} - - {/if}
{field} - {#if sortable && sortableFields.includes(field)} + {#if sortable && sortableFieldsDerived.includes(field)}
- +
{/if}
- + No results found for "{searchText}"
+
{@html notes}
@@ -260,7 +299,7 @@ {/if} {#if source}
+
{@html source}
@@ -270,16 +309,20 @@
- + {#if truncated && data.length > truncateLength} {/if} {#if paginated} @@ -289,7 +332,7 @@ bind:pageLength={currentPageData.length} bind:n={sortedData.length} />{/if} - + \ No newline at end of file + diff --git a/src/components/Table/Table.svelte b/src/components/Table/Table.svelte index 600a53e2..e961a7f4 100644 --- a/src/components/Table/Table.svelte +++ b/src/components/Table/Table.svelte @@ -1,5 +1,5 @@ - @@ -212,10 +219,7 @@ {/if} {#if searchable} {/if} diff --git a/src/components/Table/utils.ts b/src/components/Table/utils.ts index 5892ab6d..be9357e5 100644 --- a/src/components/Table/utils.ts +++ b/src/components/Table/utils.ts @@ -1,8 +1,12 @@ -export function filterArray( - data: T[], +type FilterableDatum> = T & { + searchStr: string; +}; + +export function filterArray>( + data: FilterableDatum[], searchText: string, - filterField: keyof T, - filterValue: T[keyof T] + filterField: keyof FilterableDatum, + filterValue: FilterableDatum[keyof FilterableDatum] ) { if (searchText) { data = data.filter((item) => { @@ -12,13 +16,14 @@ export function filterArray( if (filterValue) { data = data.filter((item) => { + if (!filterField) return true; // or handle the undefined case as appropriate + return item[filterField] === filterValue; }); } return data; } - export function paginateArray( array: T[], pageSize: number, From 0645c636fae4a919598f848d1d311315ed022d4b Mon Sep 17 00:00:00 2001 From: MinamiFunakoshiTR Date: Mon, 31 Mar 2025 16:33:14 -0700 Subject: [PATCH 7/7] deletes old docs --- src/components/Table/demo/docs/both.md | 13 ------------ src/components/Table/demo/docs/component.md | 14 ------------- src/components/Table/demo/docs/filter.md | 11 ---------- src/components/Table/demo/docs/format.md | 21 ------------------- src/components/Table/demo/docs/metadata.md | 14 ------------- src/components/Table/demo/docs/paginate.md | 14 ------------- src/components/Table/demo/docs/search.md | 11 ---------- src/components/Table/demo/docs/sort.md | 14 ------------- src/components/Table/demo/docs/style.md | 23 --------------------- src/components/Table/demo/docs/truncate.md | 11 ---------- 10 files changed, 146 deletions(-) delete mode 100644 src/components/Table/demo/docs/both.md delete mode 100644 src/components/Table/demo/docs/component.md delete mode 100644 src/components/Table/demo/docs/filter.md delete mode 100644 src/components/Table/demo/docs/format.md delete mode 100644 src/components/Table/demo/docs/metadata.md delete mode 100644 src/components/Table/demo/docs/paginate.md delete mode 100644 src/components/Table/demo/docs/search.md delete mode 100644 src/components/Table/demo/docs/sort.md delete mode 100644 src/components/Table/demo/docs/style.md delete mode 100644 src/components/Table/demo/docs/truncate.md diff --git a/src/components/Table/demo/docs/both.md b/src/components/Table/demo/docs/both.md deleted file mode 100644 index 150557d4..00000000 --- a/src/components/Table/demo/docs/both.md +++ /dev/null @@ -1,13 +0,0 @@ -Feel free to both search and filter. - -```svelte -
-``` diff --git a/src/components/Table/demo/docs/component.md b/src/components/Table/demo/docs/component.md deleted file mode 100644 index 31646f1e..00000000 --- a/src/components/Table/demo/docs/component.md +++ /dev/null @@ -1,14 +0,0 @@ -Present structured data in a table. Consider making it interactive. - ---- - -```svelte - - -
-``` diff --git a/src/components/Table/demo/docs/filter.md b/src/components/Table/demo/docs/filter.md deleted file mode 100644 index ba9f3ba2..00000000 --- a/src/components/Table/demo/docs/filter.md +++ /dev/null @@ -1,11 +0,0 @@ -Allow users to filter the table by providing one of the attributes as the `filterField`. This works best with categorical columns. - -```svelte -
-``` diff --git a/src/components/Table/demo/docs/format.md b/src/components/Table/demo/docs/format.md deleted file mode 100644 index b53d7ba0..00000000 --- a/src/components/Table/demo/docs/format.md +++ /dev/null @@ -1,21 +0,0 @@ -Format column values by supplying functions keyed to field names with the `fieldFormatters` option. Columns are still sorted using the raw, underlying values. - -Among other things, this feature can be used to provide a unit of measurement with numeric fields. - -```svelte - - -
-``` diff --git a/src/components/Table/demo/docs/metadata.md b/src/components/Table/demo/docs/metadata.md deleted file mode 100644 index 9db84c7a..00000000 --- a/src/components/Table/demo/docs/metadata.md +++ /dev/null @@ -1,14 +0,0 @@ -Set the `title`, `dek`, `notes` and `source` options to add supporting metadata above and below the table. - -```svelte - -``` diff --git a/src/components/Table/demo/docs/paginate.md b/src/components/Table/demo/docs/paginate.md deleted file mode 100644 index d18646bf..00000000 --- a/src/components/Table/demo/docs/paginate.md +++ /dev/null @@ -1,14 +0,0 @@ -When your table has lots of rows you should consider breaking it up into pages. This can be done by setting the `paginated` option. - -When it is enabled, readers can leaf through the data using a set of buttons below the table. By default there are 25 records per page. You can change the number by adjusting the `pageSize` option. - -This is a good option when publishing large tables for readers to explore. It works well with interactive features like searching and filters. - -```svelte -
-``` diff --git a/src/components/Table/demo/docs/search.md b/src/components/Table/demo/docs/search.md deleted file mode 100644 index e81b05c8..00000000 --- a/src/components/Table/demo/docs/search.md +++ /dev/null @@ -1,11 +0,0 @@ -Allow users to search the table by setting the optional `searchable` variable. Modify the default text that appears in the box by supplying the `searchPlaceholder` option. - -```svelte -
-``` diff --git a/src/components/Table/demo/docs/sort.md b/src/components/Table/demo/docs/sort.md deleted file mode 100644 index 7ed003cd..00000000 --- a/src/components/Table/demo/docs/sort.md +++ /dev/null @@ -1,14 +0,0 @@ -Allow users to sort the table by setting the `sortable` input. Specify the starting order by setting `sortField` to a column name and `sortDirection` to `ascending` or `descending`. - -By default, all fields are sortable. If you'd like to limit the columns where sorting is allowed, provide a list to the `sortableFields` option. - -```svelte -
-``` diff --git a/src/components/Table/demo/docs/style.md b/src/components/Table/demo/docs/style.md deleted file mode 100644 index 42c89e28..00000000 --- a/src/components/Table/demo/docs/style.md +++ /dev/null @@ -1,23 +0,0 @@ -You can tailor the table's appearance by crafting CSS that targets specific elements. - -Like other components, you can apply labels by providing the `id` of `cls` options, which allow you to make broad changes that remain limited to your element. - -Each column has a `data-field` attribute that contains the field's name. Use it to apply different styles to different fields. One common use is setting different text alignments on different columns. - -```svelte -
- - -``` diff --git a/src/components/Table/demo/docs/truncate.md b/src/components/Table/demo/docs/truncate.md deleted file mode 100644 index d36a230f..00000000 --- a/src/components/Table/demo/docs/truncate.md +++ /dev/null @@ -1,11 +0,0 @@ -When your table has 10 or more rows, consider clipping it by setting the `truncated` option. When it is enabled, the table is clipped and readers must request to see all rows by clicking a button below the table. By default this configuration will limit the table to five records. You can change the cutoff point by adjusting the `truncateLength` option. - -This is a good option for simple tables with row counts between 10 and 30. It works best when the table doesn't require interactivity. - -```svelte -
-```