@solidpb/ui-kit 0.6.1 → 0.6.2

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.
@@ -38,13 +38,11 @@ export const Pagination = (props) => {
38
38
  </p>
39
39
  </Show>
40
40
  <DropdownMenu>
41
- <DropdownMenu.Trigger>
42
- <Button size={props.size} class="min-w-25">
43
- <div class="flex items-center gap-1">
44
- <span>{props.perPage()} / page </span>
45
- <ChevronDown size={iconSize[props.size ?? "md"]}/>
46
- </div>
47
- </Button>
41
+ <DropdownMenu.Trigger size={props.size} class="min-w-25">
42
+ <div class="flex items-center gap-1">
43
+ <span>{props.perPage()} / page </span>
44
+ <ChevronDown size={iconSize[props.size ?? "md"]}/>
45
+ </div>
48
46
  </DropdownMenu.Trigger>
49
47
  <DropdownMenu.Content size={props.size}>
50
48
  <For each={props.perPageOptions}>
@@ -1,11 +1,6 @@
1
1
  import { JSXElement } from "solid-js";
2
2
  import { ColumnDef, Row } from "@tanstack/solid-table";
3
- interface TableItem {
4
- id: string;
5
- collectionId: string;
6
- tablePosition?: number;
7
- }
8
- interface TableProps<T extends TableItem> {
3
+ interface TableProps<T> {
9
4
  data: T[];
10
5
  createFunc?: () => Promise<void>;
11
6
  headerActions?: JSXElement;
@@ -19,9 +14,11 @@ interface TableProps<T extends TableItem> {
19
14
  showItemCount?: boolean;
20
15
  class?: string;
21
16
  search?: boolean;
22
- headers?: boolean;
17
+ showHeaders?: boolean;
23
18
  size?: "xs" | "sm" | "md" | "lg" | "xl";
19
+ canReorder?: boolean;
20
+ tableDataKey?: string | symbol;
24
21
  onReorderRow?: (item: T, oldInd: number, newInd: number) => void;
25
22
  }
26
- export declare const Table: <T extends TableItem>(props: TableProps<T>) => JSXElement;
23
+ export declare const Table: <T extends object>(props: TableProps<T>) => JSXElement;
27
24
  export default Table;
@@ -30,12 +30,12 @@ const TableRow = (props) => {
30
30
  const [dragging, setDragging] = createSignal("idle");
31
31
  const [closestEdge, setClosestEdge] = createSignal();
32
32
  createEffect(() => {
33
- if (props.flashSignal?.() === props.row.original.id && ref) {
33
+ if (props.flashSignal?.() === props.ind && ref) {
34
34
  triggerFlash(ref);
35
35
  }
36
36
  });
37
37
  createEffect(() => {
38
- if (!props.dragEnabled())
38
+ if (!props.canReorder)
39
39
  return;
40
40
  const element = ref;
41
41
  invariant(element);
@@ -46,11 +46,10 @@ const TableRow = (props) => {
46
46
  if (source.element === element) {
47
47
  return false;
48
48
  }
49
- // only allowing same collection for now to be dropped on me
50
- return source.data.collectionId == props.row.original.collectionId;
49
+ return props.isTableData(source.data);
51
50
  },
52
51
  getData({ input }) {
53
- return attachClosestEdge({ id: props.row.original.id, ind: props.row.index, collectionId: props.row.original.collectionId }, { element, input, allowedEdges: ["top", "bottom"] });
52
+ return attachClosestEdge({ [props.tableDataKey]: true, ind: props.row.index }, { element, input, allowedEdges: ["top", "bottom"] });
54
53
  },
55
54
  onDragEnter({ self }) {
56
55
  const _closestEdge = extractClosestEdge(self.data);
@@ -75,7 +74,7 @@ const TableRow = (props) => {
75
74
  onCleanup(dispose);
76
75
  });
77
76
  createEffect(() => {
78
- if (!props.dragEnabled())
77
+ if (!props.canReorder)
79
78
  return;
80
79
  const element = ref;
81
80
  const elementHandle = handleRef;
@@ -86,9 +85,8 @@ const TableRow = (props) => {
86
85
  dragHandle: elementHandle,
87
86
  getInitialData() {
88
87
  return {
89
- id: props.row.original.id,
88
+ [props.tableDataKey]: true,
90
89
  ind: props.row.index,
91
- collectionId: props.row.original.collectionId,
92
90
  };
93
91
  },
94
92
  onDragStart() {
@@ -101,7 +99,7 @@ const TableRow = (props) => {
101
99
  onCleanup(dispose);
102
100
  });
103
101
  return (<tr ref={ref} data-drop-edge={dragging() === "dragging-over" ? (closestEdge() ?? undefined) : undefined} class="row-hover relative" style={{ opacity: dragging() == "dragging" ? 0.2 : 1 }} onClick={() => props.onRowClick(props.row.original)}>
104
- <Show when={props.row.original.tablePosition !== undefined}>
102
+ <Show when={props.canReorder}>
105
103
  <th ref={handleRef} class="cursor-pointer">
106
104
  <GripVertical size={iconSize[props.size ?? "md"]}/>
107
105
  </th>
@@ -120,17 +118,16 @@ export const Table = (props) => {
120
118
  getCoreRowModel: getCoreRowModel(),
121
119
  });
122
120
  const rowCount = createMemo(() => table.getRowModel().rows.length);
123
- const rows = createMemo(() => table.getRowModel().rows);
124
- const dragEnabled = createMemo(() => {
125
- return props.data.length > 0 && "tablePosition" in props.data[0];
126
- });
127
- const [flashedRowId, setFlashedRowId] = createSignal(null);
121
+ const tableDataKey = props.tableDataKey ?? Symbol("tableData");
122
+ const isTableData = (data) => data[tableDataKey] === true;
123
+ const rows = createMemo(() => table.getRowModel().rows.map((r) => ({ [tableDataKey]: true, ...r })));
124
+ const [flashedRow, setFlashedRow] = createSignal(null);
128
125
  createEffect(() => {
129
- if (!rows().length || !dragEnabled())
126
+ if (!rows().length || !props.canReorder)
130
127
  return;
131
128
  const dispose = monitorForElements({
132
129
  canMonitor({ source }) {
133
- return source.data.collectionId == props.data[0].collectionId;
130
+ return isTableData(source.data);
134
131
  },
135
132
  onDrop({ location, source }) {
136
133
  const target = location.current.dropTargets[0];
@@ -139,7 +136,7 @@ export const Table = (props) => {
139
136
  }
140
137
  const sourceData = source.data;
141
138
  const targetData = target.data;
142
- if (sourceData.collectionId !== targetData.collectionId) {
139
+ if (!isTableData(sourceData) || !isTableData(targetData)) {
143
140
  return;
144
141
  }
145
142
  if (sourceData.ind < 0 || targetData.ind < 0) {
@@ -151,8 +148,8 @@ export const Table = (props) => {
151
148
  newInd--;
152
149
  }
153
150
  if (sourceData.ind !== newInd) {
154
- setFlashedRowId(sourceData.id);
155
- setTimeout(() => setFlashedRowId(null), 10);
151
+ setFlashedRow(newInd);
152
+ setTimeout(() => setFlashedRow(null), 10);
156
153
  }
157
154
  props.onReorderRow?.(props.data[sourceData.ind], sourceData.ind, newInd);
158
155
  },
@@ -165,11 +162,11 @@ export const Table = (props) => {
165
162
  </div>)}>
166
163
  <Show when={rowCount() > 0} fallback={props.emptyState || <div class="text-center py-4">No results found.</div>}>
167
164
  <table class={tableClass({ class: props.class, size: props.size })}>
168
- <Show when={props.headers}>
165
+ <Show when={props.showHeaders || props.showHeaders === undefined}>
169
166
  <thead>
170
167
  <For each={table.getHeaderGroups()}>
171
168
  {(headerGroup) => (<tr>
172
- <Show when={dragEnabled()}>
169
+ <Show when={props.canReorder}>
173
170
  <th></th>
174
171
  </Show>
175
172
  <For each={headerGroup.headers}>
@@ -182,7 +179,7 @@ export const Table = (props) => {
182
179
 
183
180
  <tbody>
184
181
  <For each={rows()}>
185
- {(row, ind) => (<TableRow row={row} ind={ind()} onRowClick={() => props.onRowClick?.(row.original)} dragEnabled={dragEnabled} flashSignal={() => flashedRowId()}/>)}
182
+ {(row, ind) => (<TableRow row={row} ind={ind()} onRowClick={() => props.onRowClick?.(row.original)} canReorder={!!props.canReorder} flashSignal={flashedRow} isTableData={isTableData} tableDataKey={tableDataKey}/>)}
186
183
  </For>
187
184
  </tbody>
188
185
  </table>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidpb/ui-kit",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",