From 348c75f3e525d4c7ef4bd6288e41409c4c873c31 Mon Sep 17 00:00:00 2001 From: Margarida Silva <--list> Date: Thu, 18 Jan 2024 17:01:17 +0000 Subject: [PATCH] [feat](@svelteui/core): add new props to table and improve/fix styling --- .../src/components/Table/Table.d.ts | 8 ++- .../src/components/Table/Table.stories.svelte | 43 ++++++++++++++- .../src/components/Table/Table.styles.ts | 53 +++++++++++++++---- .../src/components/Table/Table.svelte | 19 ++++--- 4 files changed, 103 insertions(+), 20 deletions(-) diff --git a/packages/svelteui-core/src/components/Table/Table.d.ts b/packages/svelteui-core/src/components/Table/Table.d.ts index 13ab01fd..9ddb9ff4 100644 --- a/packages/svelteui-core/src/components/Table/Table.d.ts +++ b/packages/svelteui-core/src/components/Table/Table.d.ts @@ -1,10 +1,14 @@ import { HTMLAttributes } from 'svelte/elements'; import { DefaultProps, SvelteUINumberSize } from '$lib/styles'; -export interface TableProps extends DefaultProps, HTMLAttributes { - withBorder?: boolean; +export interface TableProps + extends DefaultProps, + HTMLAttributes { striped?: boolean; highlightOnHover?: boolean; cellPadding?: SvelteUINumberSize; textAlign?: 'center' | 'right' | 'left'; + withRowBorder?: boolean; + withColumnBorder?: boolean; + withTableBorder?: boolean; } diff --git a/packages/svelteui-core/src/components/Table/Table.stories.svelte b/packages/svelteui-core/src/components/Table/Table.stories.svelte index 5500c9be..f5cce2e6 100644 --- a/packages/svelteui-core/src/components/Table/Table.stories.svelte +++ b/packages/svelteui-core/src/components/Table/Table.stories.svelte @@ -6,7 +6,48 @@ diff --git a/packages/svelteui-core/src/components/Table/Table.styles.ts b/packages/svelteui-core/src/components/Table/Table.styles.ts index bc68f4f0..7912c565 100644 --- a/packages/svelteui-core/src/components/Table/Table.styles.ts +++ b/packages/svelteui-core/src/components/Table/Table.styles.ts @@ -2,11 +2,13 @@ import { createStyles } from '$lib/styles'; import type { SvelteUINumberSize } from '$lib/styles'; export interface TableStyleParams { - withBorder: boolean; striped: boolean; highlightOnHover: boolean; cellPadding: SvelteUINumberSize; textAlign: 'center' | 'left' | 'right'; + withRowBorder: boolean; + withColumnBorder: boolean; + withTableBorder: boolean; } export const padding = { @@ -16,25 +18,56 @@ export const padding = { }; export default createStyles( - (theme, { withBorder, highlightOnHover, striped, cellPadding, textAlign }: TableStyleParams) => { + ( + theme, + { + highlightOnHover, + striped, + cellPadding, + textAlign, + withRowBorder, + withColumnBorder, + withTableBorder + }: TableStyleParams + ) => { const { themeColor } = theme.fn; return { root: { + tableLayout: 'auto', borderCollapse: 'collapse', cursor: highlightOnHover ? 'pointer' : 'default', - border: withBorder ? `1px solid ${themeColor('gray', 6)}` : '', - borderStyle: withBorder ? '' : 'hidden', - '& > * > th, & > * > td': { + border: withTableBorder ? `1px solid ${themeColor('gray', 3)}` : '', + '& > thead > tr > th, & > tbody > tr > td': { padding: typeof cellPadding === 'number' ? `${cellPadding}px` : `${padding[`${cellPadding}`]}px`, - border: `1px solid ${themeColor('gray', 6)}`, textAlign }, - '& > tr:nth-child(even)': { - backgroundColor: striped ? themeColor('gray', 9) : '' + '& tr': { + borderBottom: withRowBorder ? `1px solid ${themeColor('gray', 3)}` : 'none' }, - '& > tr:hover': { - backgroundColor: highlightOnHover ? themeColor('gray', 9) : '' + '& td, & th': { + borderRight: withColumnBorder ? `1px solid ${themeColor('gray', 3)}` : 'none' + }, + '& tbody tr:last-of-type': { + borderBottom: 'none' + }, + '& td:last-of-type': { + borderRight: 'none' + }, + '& tr:nth-child(even)': { + backgroundColor: striped ? themeColor('gray', 1) : '', + darkMode: { + backgroundColor: striped ? themeColor('dark', 6) : '' + } + }, + '& > tbody > tr:hover': { + backgroundColor: highlightOnHover ? themeColor('gray', 2) : '', + darkMode: { + backgroundColor: highlightOnHover ? themeColor('dark', 5) : '' + } + }, + darkMode: { + borderColor: themeColor('dark', 4) } } }; diff --git a/packages/svelteui-core/src/components/Table/Table.svelte b/packages/svelteui-core/src/components/Table/Table.svelte index 4df58e68..29efc1c9 100644 --- a/packages/svelteui-core/src/components/Table/Table.svelte +++ b/packages/svelteui-core/src/components/Table/Table.svelte @@ -1,28 +1,33 @@ - + -
+