diff --git a/src/lib/ui/core/Checkbox/Checkbox.svelte b/src/lib/ui/core/Checkbox/Checkbox.svelte index a39bbd61b..45f2201e1 100644 --- a/src/lib/ui/core/Checkbox/Checkbox.svelte +++ b/src/lib/ui/core/Checkbox/Checkbox.svelte @@ -35,7 +35,7 @@ bind:checked={isActive} bind:indeterminate class={cn( - 'flex size-4 min-w-4 items-center justify-center rounded border border-mystic bg-[inherit] fill-athens-day transition-colors', + 'flex size-4 min-w-4 items-center justify-center rounded border border-mystic bg-[inherit] fill-athens-day', 'hover:border-casper hover:bg-athens group-hover/label:border-casper group-hover/label:bg-[inherit]', error && 'relative border-red hover:border-red-hover group-hover/label:border-red-hover', selected && diff --git a/src/lib/ui/core/Table/DataTable/DataTable.svelte b/src/lib/ui/core/Table/DataTable/DataTable.svelte index e29c7142f..9615ab3b9 100644 --- a/src/lib/ui/core/Table/DataTable/DataTable.svelte +++ b/src/lib/ui/core/Table/DataTable/DataTable.svelte @@ -1,8 +1,8 @@ - - - - - {#each columns as { title, Head, class: className }} - {#if Head} - - {:else} - {title} - {/if} - {/each} - - - - {#each items as item, i} - +
+
+ + {#each columns as column} - {#if column.Cell} - + {@const { id, title, Head, class: className, getHeadProps, isSortable } = column} + {@const isSorted = sortColumn?.id === column.id} + + {#if Head} + {:else} - - {column.format(item, i)} - + setSort(column)} + sortDirection={isSorted ? sortDirection : undefined} + {isSortable} + > + {title || id} + {/if} {/each} - {/each} - -
+ + + {#each pagedItems as item, i} + + {#each columns as column} + {@const { id, Cell, format, class: className, getCellProps } = column} + + {#if Cell} + + {:else if format} + + {format(item, i, column)} + + {:else} + +
Declare Cell or format for column {id}
+
+ {/if} + {/each} +
+ {/each} + + {#each { length: padRowsAmount } as _} + + {#each columns as _} + + {/each} + + {/each} +
+ + + {#if pagination} + {@const { page, pageSize, rows, onPageChange } = pagination} + + + {/if} + diff --git a/src/lib/ui/core/Table/DataTable/types.ts b/src/lib/ui/core/Table/DataTable/types.ts index 786a2cafe..18c281af7 100644 --- a/src/lib/ui/core/Table/DataTable/types.ts +++ b/src/lib/ui/core/Table/DataTable/types.ts @@ -1,25 +1,41 @@ -import type { Component } from 'svelte' +import type { Component, ComponentProps } from 'svelte' -// TODO: Maybe it's not worth it to use union for format/Cell and title/Head options -export type BaseTableColumn> = { +type BaseHeadProps = { + column: ColumnDef +} + +type BaseCellProps = { + item: GItem + column: ColumnDef +} + +export type ComponentExtraProps> = Omit< + ComponentProps, + keyof BaseCellProps +> + +export type ColumnDef = { + id: string class?: string -} & ( - | { - Cell: Component<{ item: GItem }> - format?: undefined - } - | { - Cell?: undefined - format: (item: GItem, index: number) => string | number - } -) & - ( - | { - title: string - Head?: undefined - } - | { - title?: undefined - Head: Component - } - ) + + title?: string + Head?: Component & GHeaderExtra> + getHeadProps?: () => GHeaderExtra + + format?: ( + item: GItem, + index: number, + column: ColumnDef, + ) => string | number + Cell?: Component & GCellExtra> + getCellProps?: (item: GItem) => GCellExtra + + isSortable?: boolean + sortAccessor?: (item: GItem) => number +} + +export const defineColumn = ( + col: ColumnDef, +) => col + +export type SortDirection = 'DESC' | 'ASC' diff --git a/src/lib/ui/core/Table/Pagination.svelte b/src/lib/ui/core/Table/Pagination.svelte new file mode 100644 index 000000000..54f273afa --- /dev/null +++ b/src/lib/ui/core/Table/Pagination.svelte @@ -0,0 +1,147 @@ + + +
+ {#if rows.length > 1} + + {#snippet children({ props })} + + {/snippet} + + {#snippet content()} +
+ {#each rows as option} + + {/each} +
+ {/snippet} +
+ {/if} + +
+ Page + + + +
+ of {pagesAmount} +
+
+ +
+ + + +
+
diff --git a/src/lib/ui/core/Table/Table.svelte b/src/lib/ui/core/Table/Table.svelte index a7a1a347c..0cc419228 100644 --- a/src/lib/ui/core/Table/Table.svelte +++ b/src/lib/ui/core/Table/Table.svelte @@ -12,6 +12,9 @@ const { class: className, children, ...props }: TProps = $props() - +
{@render children()}
diff --git a/src/lib/ui/core/Table/TableCell.svelte b/src/lib/ui/core/Table/TableCell.svelte index 6147b892a..4eeec844c 100644 --- a/src/lib/ui/core/Table/TableCell.svelte +++ b/src/lib/ui/core/Table/TableCell.svelte @@ -6,18 +6,19 @@ type TProps = { class?: string - children: Snippet + children?: Snippet + noStyles?: boolean } & HTMLTdAttributes - const { class: className, children, ...props }: TProps = $props() + const { class: className, children, noStyles = false, ...props }: TProps = $props() - {@render children()} + {@render children?.()} diff --git a/src/lib/ui/core/Table/TableHead.svelte b/src/lib/ui/core/Table/TableHead.svelte index 12f7f8b24..97ab91467 100644 --- a/src/lib/ui/core/Table/TableHead.svelte +++ b/src/lib/ui/core/Table/TableHead.svelte @@ -1,23 +1,50 @@ {@render children()} + + {#if isSortable} + + {/if} diff --git a/src/lib/ui/core/Table/TableRow.svelte b/src/lib/ui/core/Table/TableRow.svelte index c90af7fe4..2cba001c3 100644 --- a/src/lib/ui/core/Table/TableRow.svelte +++ b/src/lib/ui/core/Table/TableRow.svelte @@ -5,13 +5,14 @@ import { cn } from '$ui/utils/index.js' type TProps = { + height?: number class?: string children: Snippet } & HTMLAttributes - const { class: className, children, ...props }: TProps = $props() + let { class: className, height = $bindable(), children, ...props }: TProps = $props() - + {@render children()} diff --git a/src/lib/ui/core/Table/index.ts b/src/lib/ui/core/Table/index.ts index 07f941407..40320a43a 100644 --- a/src/lib/ui/core/Table/index.ts +++ b/src/lib/ui/core/Table/index.ts @@ -6,3 +6,7 @@ export { default as TableRow } from './TableRow.svelte' export { default as TableCell } from './TableCell.svelte' export { default as DataTable } from './DataTable/DataTable.svelte' + +export { default as Pagination } from './Pagination.svelte' + +export type { ColumnDef } from './DataTable/types.js' diff --git a/src/lib/ui/core/Tooltip/Tooltip.svelte b/src/lib/ui/core/Tooltip/Tooltip.svelte index 3ed0aad82..c8be5a25c 100644 --- a/src/lib/ui/core/Tooltip/Tooltip.svelte +++ b/src/lib/ui/core/Tooltip/Tooltip.svelte @@ -49,6 +49,7 @@ arrowSize: type === 'arrow' ? 11 : undefined, ...options, positioning: { + flip: true, placement: position, fitViewport: true, // NOTE: [gutter] must be set to 0 in order to offset to work diff --git a/src/stories/Design System - Core UI/Table/DataTable/DataTable.svelte b/src/stories/Design System - Core UI/Table/DataTable/DataTable.svelte index ed7ac2b05..4250bbd81 100644 --- a/src/stories/Design System - Core UI/Table/DataTable/DataTable.svelte +++ b/src/stories/Design System - Core UI/Table/DataTable/DataTable.svelte @@ -1,11 +1,47 @@
- +
diff --git a/src/stories/Design System - Core UI/Table/DataTable/PagedDataTable.svelte b/src/stories/Design System - Core UI/Table/DataTable/PagedDataTable.svelte new file mode 100644 index 000000000..3592e339c --- /dev/null +++ b/src/stories/Design System - Core UI/Table/DataTable/PagedDataTable.svelte @@ -0,0 +1,25 @@ + + +
+ { + page = p + pageSize = size + }, + }} + /> +
diff --git a/src/stories/Design System - Core UI/Table/DataTable/PagedLoadDataTable.svelte b/src/stories/Design System - Core UI/Table/DataTable/PagedLoadDataTable.svelte new file mode 100644 index 000000000..4141260e1 --- /dev/null +++ b/src/stories/Design System - Core UI/Table/DataTable/PagedLoadDataTable.svelte @@ -0,0 +1,54 @@ + + +
+ { + page = p + pageSize = size + loadItems(size) + }, + }} + /> +
diff --git a/src/stories/Design System - Core UI/Table/DataTable/SimpleDataTable.svelte b/src/stories/Design System - Core UI/Table/DataTable/SimpleDataTable.svelte new file mode 100644 index 000000000..c9170557b --- /dev/null +++ b/src/stories/Design System - Core UI/Table/DataTable/SimpleDataTable.svelte @@ -0,0 +1,11 @@ + + +
+ +
diff --git a/src/stories/Design System - Core UI/Table/DataTable/cells/Checkbox.svelte b/src/stories/Design System - Core UI/Table/DataTable/cells/Checkbox.svelte new file mode 100644 index 000000000..f9c257fd5 --- /dev/null +++ b/src/stories/Design System - Core UI/Table/DataTable/cells/Checkbox.svelte @@ -0,0 +1,20 @@ + + + +
+ onSelect(item)} /> +
+
diff --git a/src/stories/Design System - Core UI/Table/DataTable/cells/CheckboxHead.svelte b/src/stories/Design System - Core UI/Table/DataTable/cells/CheckboxHead.svelte new file mode 100644 index 000000000..254057be9 --- /dev/null +++ b/src/stories/Design System - Core UI/Table/DataTable/cells/CheckboxHead.svelte @@ -0,0 +1,15 @@ + + + + onSelectAll()} /> + diff --git a/src/stories/Design System - Core UI/Table/DataTable/CustomCell.svelte b/src/stories/Design System - Core UI/Table/DataTable/cells/CustomCell.svelte similarity index 84% rename from src/stories/Design System - Core UI/Table/DataTable/CustomCell.svelte rename to src/stories/Design System - Core UI/Table/DataTable/cells/CustomCell.svelte index e7ff6c840..0562ec41c 100644 --- a/src/stories/Design System - Core UI/Table/DataTable/CustomCell.svelte +++ b/src/stories/Design System - Core UI/Table/DataTable/cells/CustomCell.svelte @@ -1,6 +1,6 @@