@invopop/popui 0.1.4-beta.10 → 0.1.4-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@
14
14
  {/snippet}
15
15
 
16
16
  <TooltipProvider>
17
- <div class="flex flex-col space-y-2 sm:flex-row sm:space-y-0 items-center">
17
+ <div class="flex flex-col space-y-2 sm:flex-row sm:flex-nowrap sm:space-y-0 items-center">
18
18
  {#each mainIcons as icon, i (i)}
19
19
  <Tooltip>
20
20
  <TooltipTrigger class="shrink-0">
@@ -0,0 +1,15 @@
1
+ <script lang="ts">
2
+ import ButtonUuidCopy from '../../ButtonUuidCopy.svelte'
3
+ import type { UuidCellConfig } from '../data-table-types.js'
4
+
5
+ let { value, config }: { value: string; config?: UuidCellConfig } = $props()
6
+ </script>
7
+
8
+ <ButtonUuidCopy
9
+ uuid={value}
10
+ prefixLength={config?.prefixLength}
11
+ suffixLength={config?.suffixLength}
12
+ full={config?.full}
13
+ disabled={config?.disabled}
14
+ oncopied={config?.onCopy}
15
+ />
@@ -0,0 +1,8 @@
1
+ import type { UuidCellConfig } from '../data-table-types.js';
2
+ type $$ComponentProps = {
3
+ value: string;
4
+ config?: UuidCellConfig;
5
+ };
6
+ declare const UuidCell: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type UuidCell = ReturnType<typeof UuidCell>;
8
+ export default UuidCell;
@@ -4,6 +4,8 @@ import BooleanCell from './cells/boolean-cell.svelte';
4
4
  import TagCell from './cells/tag-cell.svelte';
5
5
  import DateCell from './cells/date-cell.svelte';
6
6
  import CurrencyCell from './cells/currency-cell.svelte';
7
+ import UuidCell from './cells/uuid-cell.svelte';
8
+ import { renderSnippet } from './render-helpers.js';
7
9
  export function createColumns(columns) {
8
10
  return columns.map((col) => {
9
11
  const tanstackCol = {
@@ -19,10 +21,17 @@ export function createColumns(columns) {
19
21
  };
20
22
  // Cell renderer
21
23
  if (col.cell) {
22
- // Custom cell renderer
24
+ // Custom cell renderer - can be a Snippet or a function
23
25
  tanstackCol.cell = ({ row }) => {
24
26
  const value = col.accessorKey ? row.original[col.accessorKey] : undefined;
25
- return col.cell(value, row.original);
27
+ // Check if it's a function or a Snippet
28
+ if (typeof col.cell === 'function') {
29
+ return col.cell(value, row.original);
30
+ }
31
+ else {
32
+ // It's a Snippet, render it with the row data
33
+ return renderSnippet(col.cell, row.original);
34
+ }
26
35
  };
27
36
  }
28
37
  else if (col.cellType) {
@@ -40,6 +49,8 @@ export function createColumns(columns) {
40
49
  return renderComponent(DateCell, { value: value, config: col.cellConfig });
41
50
  case 'currency':
42
51
  return renderComponent(CurrencyCell, { value: value, config: col.cellConfig });
52
+ case 'uuid':
53
+ return renderComponent(UuidCell, { value: value, config: col.cellConfig });
43
54
  default:
44
55
  return value;
45
56
  }
@@ -2,7 +2,7 @@ import type { Component, Snippet } from 'svelte';
2
2
  import type { StatusType, AnyProp, TableAction, EmptyStateProps } from '../types.js';
3
3
  import type { IconSource } from '@steeze-ui/svelte-icon';
4
4
  import type { Table } from '@tanstack/table-core';
5
- export type CellType = 'text' | 'boolean' | 'tag' | 'date' | 'currency' | 'custom';
5
+ export type CellType = 'text' | 'boolean' | 'tag' | 'date' | 'currency' | 'uuid' | 'custom';
6
6
  export interface TextCellConfig {
7
7
  className?: string;
8
8
  }
@@ -26,14 +26,21 @@ export interface DateCellConfig {
26
26
  export interface CurrencyCellConfig {
27
27
  className?: string;
28
28
  }
29
- export type CellConfig = TextCellConfig | BooleanCellConfig | TagCellConfig | DateCellConfig | CurrencyCellConfig;
29
+ export interface UuidCellConfig {
30
+ prefixLength?: number;
31
+ suffixLength?: number;
32
+ full?: boolean;
33
+ disabled?: boolean;
34
+ onCopy?: (value: string) => void;
35
+ }
36
+ export type CellConfig = TextCellConfig | BooleanCellConfig | TagCellConfig | DateCellConfig | CurrencyCellConfig | UuidCellConfig;
30
37
  export interface DataTableColumn<TData> {
31
38
  id: string;
32
39
  accessorKey?: keyof TData;
33
40
  header?: string;
34
41
  cellType?: CellType;
35
42
  cellConfig?: CellConfig;
36
- cell?: (value: any, row: TData) => Snippet | Component | string;
43
+ cell?: Snippet<[TData]> | ((value: any, row: TData) => Snippet | Component | string);
37
44
  enableSorting?: boolean;
38
45
  enableHiding?: boolean;
39
46
  enableResizing?: boolean;
@@ -63,6 +70,7 @@ export interface DataTableProps<TData> {
63
70
  onPageChange?: (pageIndex: number) => void;
64
71
  onPageSizeChange?: (pageSize: number) => void;
65
72
  onSortingChange?: (columnId: string, direction: 'asc' | 'desc') => void;
73
+ getRowClassName?: (row: TData) => string;
66
74
  }
67
75
  export interface DataTablePaginationProps<T> {
68
76
  table: Table<T>;
@@ -51,7 +51,8 @@
51
51
  rowCount,
52
52
  onPageChange,
53
53
  onPageSizeChange,
54
- onSortingChange
54
+ onSortingChange,
55
+ getRowClassName
55
56
  }: DataTableProps<TData> = $props()
56
57
 
57
58
  const enableSelection = !disableSelection
@@ -75,7 +76,12 @@
75
76
 
76
77
  // Build TanStack columns from config
77
78
  const columns = $derived.by(() =>
78
- buildColumns<TData>(columnConfig, enableSelection, RowActions, getRowActions !== undefined || rowActions.length > 0)
79
+ buildColumns<TData>(
80
+ columnConfig,
81
+ enableSelection,
82
+ RowActions,
83
+ getRowActions !== undefined || rowActions.length > 0
84
+ )
79
85
  )
80
86
 
81
87
  // Calculate initial column sizes based on available width
@@ -259,7 +265,7 @@
259
265
  {#each table.getRowModel().rows as row (row.id)}
260
266
  <Table.Row
261
267
  data-state={row.getIsSelected() ? 'selected' : undefined}
262
- class="border-b border-border"
268
+ class={cn('border-b border-border', getRowClassName?.(row.original as TData))}
263
269
  onclick={() => onRowClick?.(row.original as TData)}
264
270
  >
265
271
  {#each row.getVisibleCells() as cell, index (cell.id)}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@invopop/popui",
3
3
  "license": "MIT",
4
- "version": "0.1.4-beta.10",
4
+ "version": "0.1.4-beta.12",
5
5
  "repository": {
6
6
  "url": "https://github.com/invopop/popui"
7
7
  },