diff --git a/src/components/Table/Table.stories.svelte b/src/components/Table/Table.stories.svelte
index e6978261..ddeb45f7 100644
--- a/src/components/Table/Table.stories.svelte
+++ b/src/components/Table/Table.stories.svelte
@@ -20,6 +20,8 @@
import sortDocs from './stories/docs/sort.md?raw';
// @ts-ignore
import formatDocs from './stories/docs/format.md?raw';
+ // @ts-ignore
+ import styleDocs from './stories/docs/style.md?raw';
import Table from './Table.svelte';
@@ -151,11 +153,22 @@
args="{{
data: richestWomen,
title: 'The Richest Women in the World',
- source:
- "Source: Forbes",
+ source: 'Source: Forbes',
sortable: true,
sortField: 'Net worth (in billions)',
sortDirection: 'descending',
fieldFormatters: { 'Net worth (in billions)': (v) => '$' + v.toFixed(1) },
}}"
/>
+
+
diff --git a/src/components/Table/Table.svelte b/src/components/Table/Table.svelte
index f50b5892..d731e7f3 100644
--- a/src/components/Table/Table.svelte
+++ b/src/components/Table/Table.svelte
@@ -138,12 +138,7 @@
import Search from './Search.svelte';
import Select from './Select.svelte';
import SortArrow from './SortArrow.svelte';
- import {
- filterArray,
- paginateArray,
- getOptions,
- isNumeric,
- } from './utils.js';
+ import { filterArray, paginateArray, getOptions } from './utils.js';
/** Set truncate, filtering and pagination configuration */
let showAll = false;
@@ -161,15 +156,6 @@
? paginateArray(sortedData, pageSize, pageNumber)
: sortedData;
- // Estimate the text alignment of our fields. Strings go left. Numbers go right.
- function getAlignment(value) {
- return isNumeric(value) ? 'right' : 'left';
- }
- const fieldAlignments = includedFields.reduce((acc, cur) => {
- acc[cur] = getAlignment(data[0][cur]);
- return acc;
- }, {});
-
//* * Handle show all, search, filter, sort and pagination events */
function toggleTruncate(event) {
showAll = !showAll;
@@ -282,7 +268,6 @@
sortDirection === 'descending'}"
data-field="{field}"
on:click="{handleSort}"
- style="text-align: {fieldAlignments[field]}"
>
{field}
{#if sortable && sortableFields.includes(field)}
@@ -305,7 +290,6 @@
data-row-index="{idx}"
data-field="{field}"
data-value="{item[field]}"
- style="text-align: {fieldAlignments[field]}"
>
{@html formatValue(item, field)}
@@ -402,9 +386,6 @@
.table--thead--sortarrow {
display: inline-block;
margin: 0 0 0 0.125rem;
- &.invisible {
- display: none;
- }
}
}
}
diff --git a/src/components/Table/stories/docs/format.md b/src/components/Table/stories/docs/format.md
index 5c4aa792..42037e1a 100644
--- a/src/components/Table/stories/docs/format.md
+++ b/src/components/Table/stories/docs/format.md
@@ -1,4 +1,4 @@
-Format columns by supplying functions keyed to field names with the `fieldFormatters` option. Columns are still sorted using the raw, underlying values.
+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.
diff --git a/src/components/Table/stories/docs/style.md b/src/components/Table/stories/docs/style.md
new file mode 100644
index 00000000..9f441bcb
--- /dev/null
+++ b/src/components/Table/stories/docs/style.md
@@ -0,0 +1,24 @@
+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 can allow you to make broad changes that remain limited to your element.
+
+Each column has `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/utils.js b/src/components/Table/utils.js
index 9f4abaf2..4f88513c 100644
--- a/src/components/Table/utils.js
+++ b/src/components/Table/utils.js
@@ -34,13 +34,3 @@ export function getOptions(data, attr) {
// Convert the list into Option typed objects ready for our Select component
return attrList.map((a) => ({ text: a, value: a }));
}
-
-export function isNumeric(value) {
- return (
- typeof value === 'number' ||
- value instanceof Number ||
- typeof value === 'bigint' ||
- value instanceof BigInt ||
- (typeof value === 'string' && !isNaN(value))
- );
-}
diff --git a/src/docs/docStyles.scss b/src/docs/docStyles.scss
index 2e777cd9..451f89a2 100644
--- a/src/docs/docStyles.scss
+++ b/src/docs/docStyles.scss
@@ -1,6 +1,11 @@
-
img.feature {
max-width: 100%;
margin: 0 auto;
display: block;
-}
\ No newline at end of file
+}
+
+#custom-table {
+ [data-field='Net worth (in billions)'] {
+ text-align: right;
+ }
+}
diff --git a/src/index.js b/src/index.js
index 3c53fce6..11a2ab17 100644
--- a/src/index.js
+++ b/src/index.js
@@ -28,6 +28,7 @@ export { default as SiteFooter } from './components/SiteFooter/SiteFooter.svelte
export { default as SiteHeader } from './components/SiteHeader/SiteHeader.svelte';
export { default as SiteHeadline } from './components/SiteHeadline/SiteHeadline.svelte';
export { default as Spinner } from './components/Spinner/Spinner.svelte';
+export { default as Table } from './components/Table/Table.svelte';
export {
default as Theme,
// @ts-ignore