@solidpb/ui-kit 0.6.1 → 0.6.3
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.
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSXElement
|
|
1
|
+
import { JSXElement } from "solid-js";
|
|
2
2
|
import { type SwitchProps } from "./Switch";
|
|
3
3
|
import { type SelectProps } from "./Select";
|
|
4
4
|
import { type InputRootProps } from "./Input";
|
|
@@ -11,7 +11,7 @@ import { type FileInputProps } from "./FileInput";
|
|
|
11
11
|
import { RelationPickerProps } from "./RelationPicker";
|
|
12
12
|
export interface FormProps<T> {
|
|
13
13
|
data: Partial<T>;
|
|
14
|
-
setData:
|
|
14
|
+
setData: (data: Partial<T>) => void;
|
|
15
15
|
title?: string;
|
|
16
16
|
onSave?: (values: Partial<T>) => Promise<void>;
|
|
17
17
|
onCancel?: () => void;
|
package/dist/components/Form.jsx
CHANGED
|
@@ -18,7 +18,7 @@ const formClass = tv({
|
|
|
18
18
|
export function createForm() {
|
|
19
19
|
const Form = (props) => {
|
|
20
20
|
const setValue = (key, value) => {
|
|
21
|
-
props.setData(
|
|
21
|
+
props.setData({ ...props.data, [key]: value });
|
|
22
22
|
};
|
|
23
23
|
const getValue = (key) => {
|
|
24
24
|
return props.data[key];
|
|
@@ -38,13 +38,11 @@ export const Pagination = (props) => {
|
|
|
38
38
|
</p>
|
|
39
39
|
</Show>
|
|
40
40
|
<DropdownMenu>
|
|
41
|
-
<DropdownMenu.Trigger>
|
|
42
|
-
<
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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.
|
|
33
|
+
if (props.flashSignal?.() === props.ind && ref) {
|
|
34
34
|
triggerFlash(ref);
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
createEffect(() => {
|
|
38
|
-
if (!props.
|
|
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
|
-
|
|
50
|
-
return source.data.collectionId == props.row.original.collectionId;
|
|
49
|
+
return props.isTableData(source.data);
|
|
51
50
|
},
|
|
52
51
|
getData({ input }) {
|
|
53
|
-
return attachClosestEdge({
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
|
124
|
-
const
|
|
125
|
-
|
|
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 || !
|
|
126
|
+
if (!rows().length || !props.canReorder)
|
|
130
127
|
return;
|
|
131
128
|
const dispose = monitorForElements({
|
|
132
129
|
canMonitor({ source }) {
|
|
133
|
-
return source.data
|
|
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
|
|
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
|
-
|
|
155
|
-
setTimeout(() =>
|
|
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.
|
|
165
|
+
<Show when={props.showHeaders || props.showHeaders === undefined}>
|
|
169
166
|
<thead>
|
|
170
167
|
<For each={table.getHeaderGroups()}>
|
|
171
168
|
{(headerGroup) => (<tr>
|
|
172
|
-
<Show when={
|
|
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)}
|
|
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>
|