@emamid/svelte-data-table 0.0.21 → 1.0.1

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.
Files changed (81) hide show
  1. package/dist/DataTable.svelte +303 -239
  2. package/dist/DataTable.svelte.d.ts +30 -60
  3. package/dist/DataTableDataCell.svelte +157 -90
  4. package/dist/DataTableDataCell.svelte.d.ts +18 -27
  5. package/dist/DataTableHeaderCell.svelte +63 -21
  6. package/dist/DataTableHeaderCell.svelte.d.ts +9 -23
  7. package/dist/DataTableIcon.svelte +25 -0
  8. package/dist/DataTableIcon.svelte.d.ts +9 -0
  9. package/dist/DataTableRow.svelte +150 -80
  10. package/dist/DataTableRow.svelte.d.ts +26 -34
  11. package/dist/cells/Actions.d.ts +1 -1
  12. package/dist/cells/Actions.js +10 -11
  13. package/dist/cells/ActionsCell.svelte +58 -23
  14. package/dist/cells/ActionsCell.svelte.d.ts +9 -34
  15. package/dist/cells/ButtonCell.svelte +58 -16
  16. package/dist/cells/ButtonCell.svelte.d.ts +11 -20
  17. package/dist/cells/CheckboxCell.svelte +72 -19
  18. package/dist/cells/CheckboxCell.svelte.d.ts +11 -22
  19. package/dist/cells/InputCell.svelte +93 -49
  20. package/dist/cells/InputCell.svelte.d.ts +14 -25
  21. package/dist/cells/MultiSelectCell.svelte +85 -26
  22. package/dist/cells/MultiSelectCell.svelte.d.ts +15 -26
  23. package/dist/cells/NumberInputCell.svelte +90 -45
  24. package/dist/cells/NumberInputCell.svelte.d.ts +13 -24
  25. package/dist/cells/RadioCell.svelte +66 -0
  26. package/dist/cells/RadioCell.svelte.d.ts +12 -0
  27. package/dist/cells/RangeCell.svelte +66 -17
  28. package/dist/cells/RangeCell.svelte.d.ts +13 -22
  29. package/dist/cells/SelectCell.svelte +87 -26
  30. package/dist/cells/SelectCell.svelte.d.ts +15 -26
  31. package/dist/cells/SpinCell.svelte +91 -42
  32. package/dist/cells/SpinCell.svelte.d.ts +13 -28
  33. package/dist/cells/TabWrapper.svelte +23 -21
  34. package/dist/cells/TabWrapper.svelte.d.ts +10 -22
  35. package/dist/cells/index.d.ts +2 -4
  36. package/dist/cells/index.js +2 -4
  37. package/dist/common.d.ts +199 -53
  38. package/dist/common.js +30 -11
  39. package/dist/index.d.ts +2 -2
  40. package/dist/index.js +1 -1
  41. package/dist/themes/active.d.ts +4 -0
  42. package/dist/themes/active.js +12 -0
  43. package/dist/themes/daisyUI.d.ts +2 -0
  44. package/dist/themes/daisyUI.js +47 -0
  45. package/dist/themes/default.d.ts +2 -0
  46. package/dist/themes/default.js +57 -0
  47. package/dist/themes/iconify.d.ts +2 -0
  48. package/dist/themes/iconify.js +33 -0
  49. package/dist/themes/index.d.ts +4 -0
  50. package/dist/themes/index.js +4 -0
  51. package/package.json +28 -30
  52. package/dist/DataTable.doc.d.ts +0 -81
  53. package/dist/DataTable.doc.js +0 -81
  54. package/dist/cells/ActionsCell.doc.d.ts +0 -28
  55. package/dist/cells/ActionsCell.doc.js +0 -28
  56. package/dist/cells/ButtonCell.doc.d.ts +0 -9
  57. package/dist/cells/ButtonCell.doc.js +0 -9
  58. package/dist/cells/CheckboxCell.doc.d.ts +0 -6
  59. package/dist/cells/CheckboxCell.doc.js +0 -6
  60. package/dist/cells/InputCell.doc.d.ts +0 -6
  61. package/dist/cells/InputCell.doc.js +0 -6
  62. package/dist/cells/MultiSelectCell.doc.d.ts +0 -8
  63. package/dist/cells/MultiSelectCell.doc.js +0 -8
  64. package/dist/cells/NumberInputCell.doc.d.ts +0 -6
  65. package/dist/cells/NumberInputCell.doc.js +0 -6
  66. package/dist/cells/RangeCell.doc.d.ts +0 -7
  67. package/dist/cells/RangeCell.doc.js +0 -7
  68. package/dist/cells/RatingCell.doc.d.ts +0 -7
  69. package/dist/cells/RatingCell.doc.js +0 -7
  70. package/dist/cells/RatingCell.svelte +0 -13
  71. package/dist/cells/RatingCell.svelte.d.ts +0 -22
  72. package/dist/cells/SelectCell.doc.d.ts +0 -8
  73. package/dist/cells/SelectCell.doc.js +0 -8
  74. package/dist/cells/SpinCell.doc.d.ts +0 -13
  75. package/dist/cells/SpinCell.doc.js +0 -13
  76. package/dist/cells/TabWrapper.doc.d.ts +0 -5
  77. package/dist/cells/TabWrapper.doc.js +0 -5
  78. package/dist/cells/ToggleCell.doc.d.ts +0 -6
  79. package/dist/cells/ToggleCell.doc.js +0 -6
  80. package/dist/cells/ToggleCell.svelte +0 -21
  81. package/dist/cells/ToggleCell.svelte.d.ts +0 -23
@@ -1,78 +1,146 @@
1
- <script>import { createEventDispatcher, onDestroy, onMount } from "svelte";
2
- import { TableBodyRow } from "flowbite-svelte";
3
- import DataTableDataCell from "./DataTableDataCell.svelte";
4
- import {
5
- evalRowDropBoolean,
6
- evalRowBoolean,
7
- getColumnID,
8
- getDataTableContext
9
- } from "./common.js";
10
- export let allowRowDrag;
11
- export let allowRowDrop;
12
- export let columns;
13
- export let focusedColumnKeyID;
14
- export let getTRClass;
15
- export let isRowFocused;
16
- export let item;
17
- const context = getDataTableContext();
18
- let span;
19
- const dispatch = createEventDispatcher();
20
- const cellClicked = (column) => dispatch("cellClicked", { column, item });
21
- const rowClicked = () => dispatch("rowClicked", { item });
22
- const dragOverHandler = (event) => {
23
- const { draggedItem } = context;
24
- const canDrop = evalRowDropBoolean(draggedItem, item, allowRowDrop);
25
- if (canDrop) {
26
- event.preventDefault();
27
- if (event.dataTransfer) {
28
- event.dataTransfer.dropEffect = "move";
29
- }
30
- }
31
- };
32
- const dragStartHandler = (dragEvent) => {
33
- context.draggedColumn = void 0;
34
- context.draggedItem = item;
35
- dispatch("rowDragStart", {
36
- dragEvent,
37
- sourceItem: item
38
- });
39
- };
40
- const dropHandler = (event) => {
41
- const { draggedItem } = context;
42
- const canDrop = evalRowDropBoolean(draggedItem, item, allowRowDrop);
43
- if (canDrop) {
44
- event.preventDefault();
45
- dispatch("rowDropped", {
46
- sourceItem: draggedItem,
47
- targetItem: item
48
- });
49
- }
50
- };
51
- onMount(() => {
52
- if (span && span.parentElement) {
53
- span.parentElement.addEventListener("click", rowClicked);
54
- span.parentElement.addEventListener("dragover", dragOverHandler);
55
- span.parentElement.addEventListener("dragstart", dragStartHandler);
56
- span.parentElement.addEventListener("drop", dropHandler);
57
- }
58
- });
59
- onDestroy(() => {
60
- if (span && span.parentElement) {
61
- span.parentElement.removeEventListener("click", rowClicked);
62
- span.parentElement.removeEventListener("dragover", dragOverHandler);
63
- span.parentElement.removeEventListener("dragstart", dragStartHandler);
64
- span.parentElement.removeEventListener("drop", dropHandler);
65
- }
66
- });
1
+ <script lang="ts">
2
+ import { activeTheme } from './themes/active';
3
+ import DataTableDataCell from './DataTableDataCell.svelte';
4
+ import {
5
+ evalRowDropBoolean,
6
+ evalRowBoolean,
7
+ getColumnID,
8
+ getDataTableContext,
9
+ joinPartClasses,
10
+ } from './common';
11
+ import type {
12
+ ActionEvent,
13
+ ColumnConfig,
14
+ DataCellChangedEvent,
15
+ DataCellDragEvent,
16
+ DataCellDropEvent,
17
+ DataCellEvent,
18
+ DataCellMouseEvent,
19
+ RowBoolean,
20
+ RowClassFunction,
21
+ RowDragEvent,
22
+ RowDropBoolean,
23
+ RowDropEvent,
24
+ RowEvent,
25
+ } from './common';
26
+
27
+ interface Props {
28
+ allowRowDrag: RowBoolean;
29
+ allowRowDrop: RowDropBoolean;
30
+ columns: ColumnConfig[];
31
+ focusedColumnKeyID: any;
32
+ isRowFocused: boolean;
33
+ item: any;
34
+ onaction?: (event: ActionEvent) => void;
35
+ onbutton?: (event: DataCellEvent) => void;
36
+ oncellchanged?: (event: DataCellChangedEvent) => void;
37
+ oncellclick?: (event: DataCellMouseEvent) => void;
38
+ oncelldragend?: (event: DataCellDragEvent) => void;
39
+ oncelldragstart?: (event: DataCellDragEvent) => void;
40
+ oncelldropped?: (event: DataCellDropEvent) => void;
41
+ ondragend?: (event: RowDragEvent) => void;
42
+ ondragstart?: (event: RowDragEvent) => void;
43
+ ondropped?: (event: RowDropEvent) => void;
44
+ onenterpressed?: (event: DataCellEvent) => void;
45
+ onnexttab?: (event: DataCellEvent) => void;
46
+ onprevtab?: (event: DataCellEvent) => void;
47
+ onrowclick?: (event: RowEvent) => void;
48
+ trClassGetter?: RowClassFunction;
49
+ }
50
+
51
+ let {
52
+ allowRowDrag,
53
+ allowRowDrop,
54
+ columns,
55
+ focusedColumnKeyID,
56
+ isRowFocused,
57
+ item,
58
+ onaction,
59
+ onbutton,
60
+ oncellchanged,
61
+ oncellclick,
62
+ oncelldragend,
63
+ oncelldragstart,
64
+ oncelldropped,
65
+ ondragend,
66
+ ondragstart,
67
+ ondropped,
68
+ onenterpressed,
69
+ onnexttab,
70
+ onprevtab,
71
+ onrowclick,
72
+ trClassGetter,
73
+ }: Props = $props();
74
+
75
+ const context = getDataTableContext();
76
+ const tableTheme = context.theme || {};
77
+
78
+ const rowClicked = () => onrowclick?.({ item });
79
+
80
+ const dragEnd = (event: DragEvent) => {
81
+ ondragend?.({
82
+ ...event,
83
+ sourceItem: item,
84
+ })
85
+ }
86
+
87
+ const dragOver = (event: DragEvent) => {
88
+ const { draggedItem } = context;
89
+ const canDrop = evalRowDropBoolean(draggedItem, item, allowRowDrop);
90
+ if (canDrop) {
91
+ event.preventDefault();
92
+ if (event.dataTransfer) {
93
+ event.dataTransfer.dropEffect = 'move';
94
+ }
95
+ }
96
+ }
97
+
98
+ const dragStart = (dragEvent: DragEvent) => {
99
+ if (context.dragType) {
100
+ return;
101
+ }
102
+ ondragstart?.({
103
+ ...dragEvent,
104
+ sourceItem: item,
105
+ });
106
+ }
107
+
108
+ const drop = (event: DragEvent) => {
109
+ const { draggedItem } = context;
110
+ const canDrop = evalRowDropBoolean(draggedItem, item, allowRowDrop);
111
+ if (!canDrop) {
112
+ return;
113
+ }
114
+
115
+ event.preventDefault();
116
+ ondropped?.({
117
+ ...event,
118
+ sourceItem: draggedItem,
119
+ targetItem: item,
120
+ });
121
+ }
122
+
123
+ const baseTRClass = $derived(joinPartClasses(
124
+ 'row',
125
+ 'tr', [
126
+ activeTheme,
127
+ tableTheme,
128
+ ],
129
+ isRowFocused,
130
+ ));
131
+
132
+ const trClass = $derived(trClassGetter ? trClassGetter(item, isRowFocused, baseTRClass) : baseTRClass);
67
133
  </script>
68
134
 
69
- <TableBodyRow
70
- class={getTRClass(item, isRowFocused)}
135
+ <tr
136
+ class={trClass}
71
137
  draggable={evalRowBoolean(item, allowRowDrag)}
138
+ onclick={rowClicked}
139
+ ondragend={dragEnd}
140
+ ondragover={dragOver}
141
+ ondragstart={dragStart}
142
+ ondrop={drop}
72
143
  >
73
- {#if !!allowRowDrag || !!allowRowDrop}
74
- <span style="display:none" bind:this={span}></span>
75
- {/if}
76
144
  {#each columns as column}
77
145
  {@const isCellFocused =
78
146
  isRowFocused && focusedColumnKeyID && focusedColumnKeyID === getColumnID(column)}
@@ -80,14 +148,16 @@ onDestroy(() => {
80
148
  {column}
81
149
  {isCellFocused}
82
150
  {item}
83
- on:click={() => cellClicked(column)}
84
- on:enterPressed
85
- on:prevTab
86
- on:nextTab
87
- on:action
88
- on:cellChanged
89
- on:cellDragStart
90
- on:cellDropped
151
+ {onaction}
152
+ {onbutton}
153
+ {oncellchanged}
154
+ {oncelldragend}
155
+ {oncelldragstart}
156
+ {oncelldropped}
157
+ onclick={oncellclick}
158
+ {onenterpressed}
159
+ {onnexttab}
160
+ {onprevtab}
91
161
  />
92
162
  {/each}
93
- </TableBodyRow>
163
+ </tr>
@@ -1,35 +1,27 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { RowBoolean, RowDropBoolean, GetTRClassFunction, InternalColumnConfig } from './common.js';
3
- declare const __propDef: {
4
- props: {
5
- allowRowDrag: RowBoolean;
6
- allowRowDrop: RowDropBoolean;
7
- columns: InternalColumnConfig[];
8
- focusedColumnKeyID: any;
9
- getTRClass: GetTRClassFunction;
10
- isRowFocused: boolean;
11
- item: any;
12
- };
13
- events: {
14
- enterPressed: any;
15
- prevTab: any;
16
- nextTab: any;
17
- action: any;
18
- cellChanged: any;
19
- cellDragStart: CustomEvent<any>;
20
- cellDropped: CustomEvent<any>;
21
- cellClicked: CustomEvent<any>;
22
- rowClicked: CustomEvent<any>;
23
- rowDragStart: CustomEvent<any>;
24
- rowDropped: CustomEvent<any>;
25
- } & {
26
- [evt: string]: CustomEvent<any>;
27
- };
28
- slots: {};
29
- };
30
- export type DataTableRowProps = typeof __propDef.props;
31
- export type DataTableRowEvents = typeof __propDef.events;
32
- export type DataTableRowSlots = typeof __propDef.slots;
33
- export default class DataTableRow extends SvelteComponent<DataTableRowProps, DataTableRowEvents, DataTableRowSlots> {
1
+ import type { ActionEvent, ColumnConfig, DataCellChangedEvent, DataCellDragEvent, DataCellDropEvent, DataCellEvent, DataCellMouseEvent, RowBoolean, RowClassFunction, RowDragEvent, RowDropBoolean, RowDropEvent, RowEvent } from './common';
2
+ interface Props {
3
+ allowRowDrag: RowBoolean;
4
+ allowRowDrop: RowDropBoolean;
5
+ columns: ColumnConfig[];
6
+ focusedColumnKeyID: any;
7
+ isRowFocused: boolean;
8
+ item: any;
9
+ onaction?: (event: ActionEvent) => void;
10
+ onbutton?: (event: DataCellEvent) => void;
11
+ oncellchanged?: (event: DataCellChangedEvent) => void;
12
+ oncellclick?: (event: DataCellMouseEvent) => void;
13
+ oncelldragend?: (event: DataCellDragEvent) => void;
14
+ oncelldragstart?: (event: DataCellDragEvent) => void;
15
+ oncelldropped?: (event: DataCellDropEvent) => void;
16
+ ondragend?: (event: RowDragEvent) => void;
17
+ ondragstart?: (event: RowDragEvent) => void;
18
+ ondropped?: (event: RowDropEvent) => void;
19
+ onenterpressed?: (event: DataCellEvent) => void;
20
+ onnexttab?: (event: DataCellEvent) => void;
21
+ onprevtab?: (event: DataCellEvent) => void;
22
+ onrowclick?: (event: RowEvent) => void;
23
+ trClassGetter?: RowClassFunction;
34
24
  }
35
- export {};
25
+ declare const DataTableRow: import("svelte").Component<Props, {}, "">;
26
+ type DataTableRow = ReturnType<typeof DataTableRow>;
27
+ export default DataTableRow;
@@ -1,4 +1,4 @@
1
- import type { Action } from './ActionsCell.svelte';
1
+ import type { Action } from '../common';
2
2
  /**
3
3
  * @constant bookmarkAction
4
4
  * @type {Action}
@@ -1,4 +1,3 @@
1
- import { ArrowDownSolid, ArrowUpSolid, BellActiveOutline, BookmarkOutline, CogOutline, EditOutline, HeartSolid, InfoCircleOutline, ShareNodesOutline, TrashBinOutline, } from 'flowbite-svelte-icons';
2
1
  /**
3
2
  * @constant bookmarkAction
4
3
  * @type {Action}
@@ -6,7 +5,7 @@ import { ArrowDownSolid, ArrowUpSolid, BellActiveOutline, BookmarkOutline, CogOu
6
5
  * @property {ConstructorOfATypedSvelteComponent} icon - BookmarkOutline
7
6
  */
8
7
  export const bookmarkAction = {
9
- icon: BookmarkOutline,
8
+ icon: '🔖',
10
9
  name: 'bookmark',
11
10
  };
12
11
  /**
@@ -16,7 +15,7 @@ export const bookmarkAction = {
16
15
  * @property {ConstructorOfATypedSvelteComponent} icon - TrashBinOutline
17
16
  */
18
17
  export const deleteAction = {
19
- icon: TrashBinOutline,
18
+ icon: '🗑',
20
19
  name: 'delete',
21
20
  };
22
21
  /**
@@ -26,7 +25,7 @@ export const deleteAction = {
26
25
  * @property {ConstructorOfATypedSvelteComponent} icon - ArrowDownSolid
27
26
  */
28
27
  export const downAction = {
29
- icon: ArrowDownSolid,
28
+ icon: '▼',
30
29
  name: 'down',
31
30
  };
32
31
  /**
@@ -36,7 +35,7 @@ export const downAction = {
36
35
  * @property {ConstructorOfATypedSvelteComponent} icon - EditOutline
37
36
  */
38
37
  export const editAction = {
39
- icon: EditOutline,
38
+ icon: '✎',
40
39
  name: 'edit',
41
40
  };
42
41
  /**
@@ -46,7 +45,7 @@ export const editAction = {
46
45
  * @property {ConstructorOfATypedSvelteComponent} icon - HeartSolid
47
46
  */
48
47
  export const favoriteAction = {
49
- icon: HeartSolid,
48
+ icon: '♥',
50
49
  name: 'favorite',
51
50
  };
52
51
  /**
@@ -56,7 +55,7 @@ export const favoriteAction = {
56
55
  * @property {ConstructorOfATypedSvelteComponent} icon - InfoCircleOutline
57
56
  */
58
57
  export const infoAction = {
59
- icon: InfoCircleOutline,
58
+ icon: 'ℹ',
60
59
  name: 'info',
61
60
  };
62
61
  /**
@@ -66,7 +65,7 @@ export const infoAction = {
66
65
  * @property {ConstructorOfATypedSvelteComponent} icon - BellActiveOutline
67
66
  */
68
67
  export const notificationAction = {
69
- icon: BellActiveOutline,
68
+ icon: '🔔',
70
69
  name: 'notification',
71
70
  };
72
71
  /**
@@ -76,7 +75,7 @@ export const notificationAction = {
76
75
  * @property {ConstructorOfATypedSvelteComponent} icon - CogOutline
77
76
  */
78
77
  export const settingsAction = {
79
- icon: CogOutline,
78
+ icon: '⚙',
80
79
  name: 'settings',
81
80
  };
82
81
  /**
@@ -86,7 +85,7 @@ export const settingsAction = {
86
85
  * @property {ConstructorOfATypedSvelteComponent} icon - ShareNodesOutline
87
86
  */
88
87
  export const shareAction = {
89
- icon: ShareNodesOutline,
88
+ icon: '<',
90
89
  name: 'share',
91
90
  };
92
91
  /**
@@ -96,6 +95,6 @@ export const shareAction = {
96
95
  * @property {ConstructorOfATypedSvelteComponent} icon - UpArrowSolid
97
96
  */
98
97
  export const upAction = {
99
- icon: ArrowUpSolid,
98
+ icon: '▲',
100
99
  name: 'up',
101
100
  };
@@ -1,31 +1,66 @@
1
- <script context="module"></script>
1
+ <script lang="ts">
2
+ import {
3
+ getDataTableContext,
4
+ joinInputClasses,
5
+ } from '../common';
6
+ import type {
7
+ Action,
8
+ ActionEvent,
9
+ ColumnConfig,
10
+ } from '../common';
11
+ import { activeTheme } from '../themes/active';
2
12
 
3
- <script>import { createEventDispatcher } from "svelte";
4
- import { Button } from "flowbite-svelte";
5
- export let buttonClass = "border-0 p-1";
6
- export let buttonColor = "light";
7
- export let iconClass = "w-4 h-4";
8
- export let column;
9
- export let item;
10
- export let actions = [];
11
- const dispatch = createEventDispatcher();
12
- const actionClicked = (action) => {
13
- dispatch("action", {
14
- action: action.name,
15
- column,
16
- item
17
- });
18
- };
13
+ import DataTableIcon from '../DataTableIcon.svelte';
14
+
15
+ interface Props {
16
+ actions?: Action[];
17
+ column: ColumnConfig;
18
+ item: any;
19
+ onaction?: (event: ActionEvent) => void;
20
+ }
21
+
22
+ let {
23
+ actions = [],
24
+ column,
25
+ item,
26
+ onaction,
27
+ }: Props = $props();
28
+
29
+ const tableTheme = getDataTableContext()?.theme || {};
30
+
31
+ const actionClicked = (action: Action) => {
32
+ onaction?.({
33
+ action,
34
+ column,
35
+ item,
36
+ });
37
+ };
38
+
39
+ const getClass = (element: string, action: Action) => joinInputClasses(
40
+ 'action',
41
+ element, [
42
+ activeTheme,
43
+ tableTheme,
44
+ column.theme,
45
+ {
46
+ inputs: {
47
+ action: action?.theme,
48
+ }
49
+ }
50
+ ],
51
+ )
19
52
  </script>
20
53
 
21
54
  {#each actions as action}
22
- <Button
23
- class={action.buttonClass || buttonClass}
24
- color={action.buttonColor || buttonColor}
55
+ <button
56
+ class={getClass('button', action)}
25
57
  disabled={action.isDisabled?.(item, column, action)}
26
- on:click={() => actionClicked(action)}
58
+ onclick={() => actionClicked(action)}
59
+ title={action.tooltip}
27
60
  >
28
- <svelte:component this={action.icon} class={action.iconClass || iconClass} />
61
+ {#if action.icon}
62
+ <DataTableIcon classes={getClass('icon', action)} icon={action.icon}/>
63
+ {/if}
29
64
  {#if action.caption}{action.caption}{/if}
30
- </Button>
65
+ </button>
31
66
  {/each}
@@ -1,35 +1,10 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { ColumnConfig } from '../common.js';
3
- type ButtonColor = 'red' | 'yellow' | 'green' | 'purple' | 'blue' | 'light' | 'dark' | 'primary' | 'none' | 'alternative' | undefined;
4
- export type ActionDisablementFunction = (item: any, column: ColumnConfig, action: Action) => boolean;
5
- export interface Action {
6
- buttonClass?: string;
7
- buttonColor?: ButtonColor;
8
- caption?: string;
9
- name: string;
10
- icon: ConstructorOfATypedSvelteComponent;
11
- iconClass?: string;
12
- isDisabled?: ActionDisablementFunction;
1
+ import type { Action, ActionEvent, ColumnConfig } from '../common';
2
+ interface Props {
3
+ actions?: Action[];
4
+ column: ColumnConfig;
5
+ item: any;
6
+ onaction?: (event: ActionEvent) => void;
13
7
  }
14
- declare const __propDef: {
15
- props: {
16
- buttonClass?: string | undefined;
17
- buttonColor?: ButtonColor;
18
- iconClass?: string | undefined;
19
- column: ColumnConfig;
20
- item: any;
21
- actions?: Action[] | undefined;
22
- };
23
- events: {
24
- action: CustomEvent<any>;
25
- } & {
26
- [evt: string]: CustomEvent<any>;
27
- };
28
- slots: {};
29
- };
30
- export type ActionsCellProps = typeof __propDef.props;
31
- export type ActionsCellEvents = typeof __propDef.events;
32
- export type ActionsCellSlots = typeof __propDef.slots;
33
- export default class ActionsCell extends SvelteComponent<ActionsCellProps, ActionsCellEvents, ActionsCellSlots> {
34
- }
35
- export {};
8
+ declare const ActionsCell: import("svelte").Component<Props, {}, "">;
9
+ type ActionsCell = ReturnType<typeof ActionsCell>;
10
+ export default ActionsCell;
@@ -1,18 +1,60 @@
1
- <script>import { Button } from "flowbite-svelte";
2
- export let caption = "";
3
- export let column;
4
- export let item;
5
- export let icon = null;
6
- export let iconClass = "";
7
- export let iconPosition = "right";
1
+ <script lang="ts">
2
+ import {
3
+ getDataTableContext,
4
+ joinInputClasses,
5
+ } from '../common';
6
+ import type {
7
+ ColumnConfig,
8
+ DataCellEvent,
9
+ IconProp,
10
+ } from '../common';
11
+ import { activeTheme } from '../themes/active';
12
+
13
+ import DataTableIcon from '../DataTableIcon.svelte';
14
+
15
+ interface Props {
16
+ caption?: string;
17
+ column: ColumnConfig;
18
+ item: any;
19
+ icon?: IconProp;
20
+ iconPosition?: 'left' | 'right';
21
+ onbutton?: (event: DataCellEvent) => void;
22
+ }
23
+
24
+ let {
25
+ caption = '',
26
+ column,
27
+ item,
28
+ icon,
29
+ iconPosition = 'right',
30
+ onbutton,
31
+ }: Props = $props();
32
+
33
+ const tableTheme = getDataTableContext()?.theme || {};
34
+
35
+ const getClass = (element: string) => joinInputClasses(
36
+ 'button',
37
+ element, [
38
+ activeTheme,
39
+ tableTheme,
40
+ column.theme,
41
+ ],
42
+ )
43
+
44
+ const buttonClass = $derived(getClass('button'));
45
+ const iconClass = $derived(getClass('icon'));
46
+
8
47
  </script>
9
48
 
10
- <Button>
11
- {#if icon && iconPosition === 'left'}
12
- <svelte:component this={icon} class={iconClass} />
13
- {/if}
14
- {#if caption}{caption}{/if}
15
- {#if icon && iconPosition === 'right'}
16
- <svelte:component this={icon} class={iconClass} />
17
- {/if}
18
- </Button>
49
+ <button
50
+ class={buttonClass}
51
+ onclick={() => onbutton?.({ column, item })}
52
+ >
53
+ {#if icon && iconPosition === 'left'}
54
+ <DataTableIcon classes={iconClass} {icon}/>
55
+ {/if}
56
+ {#if caption}{caption}{/if}
57
+ {#if icon && iconPosition === 'right'}
58
+ <DataTableIcon classes={iconClass} {icon}/>
59
+ {/if}
60
+ </button>
@@ -1,21 +1,12 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- caption?: string | undefined;
5
- column: ColumnConfig;
6
- item: any;
7
- icon?: ConstructorOfATypedSvelteComponent | null | undefined;
8
- iconClass?: string | undefined;
9
- iconPosition?: "left" | "right" | undefined;
10
- };
11
- events: {
12
- [evt: string]: CustomEvent<any>;
13
- };
14
- slots: {};
15
- };
16
- export type ButtonCellProps = typeof __propDef.props;
17
- export type ButtonCellEvents = typeof __propDef.events;
18
- export type ButtonCellSlots = typeof __propDef.slots;
19
- export default class ButtonCell extends SvelteComponent<ButtonCellProps, ButtonCellEvents, ButtonCellSlots> {
1
+ import type { ColumnConfig, DataCellEvent, IconProp } from '../common';
2
+ interface Props {
3
+ caption?: string;
4
+ column: ColumnConfig;
5
+ item: any;
6
+ icon?: IconProp;
7
+ iconPosition?: 'left' | 'right';
8
+ onbutton?: (event: DataCellEvent) => void;
20
9
  }
21
- export {};
10
+ declare const ButtonCell: import("svelte").Component<Props, {}, "">;
11
+ type ButtonCell = ReturnType<typeof ButtonCell>;
12
+ export default ButtonCell;