@dust-tt/sparkle 0.2.559 → 0.2.562
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/dist/cjs/index.js +1 -1
- package/dist/esm/components/DataTable.d.ts +4 -2
- package/dist/esm/components/DataTable.d.ts.map +1 -1
- package/dist/esm/components/DataTable.js +27 -9
- package/dist/esm/components/DataTable.js.map +1 -1
- package/dist/esm/components/RadioGroup.d.ts +4 -1
- package/dist/esm/components/RadioGroup.d.ts.map +1 -1
- package/dist/esm/components/RadioGroup.js +2 -2
- package/dist/esm/components/RadioGroup.js.map +1 -1
- package/dist/esm/components/TextArea.d.ts +4 -1
- package/dist/esm/components/TextArea.d.ts.map +1 -1
- package/dist/esm/components/TextArea.js +5 -1
- package/dist/esm/components/TextArea.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -1
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -1
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +0 -2
- package/dist/esm/hooks/index.d.ts.map +1 -1
- package/dist/esm/hooks/index.js +0 -2
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/stories/DataTable.stories.d.ts +1 -0
- package/dist/esm/stories/DataTable.stories.d.ts.map +1 -1
- package/dist/esm/stories/DataTable.stories.js +21 -1
- package/dist/esm/stories/DataTable.stories.js.map +1 -1
- package/dist/sparkle.css +8 -4
- package/package.json +1 -1
- package/src/components/DataTable.tsx +44 -3
- package/src/components/RadioGroup.tsx +2 -2
- package/src/components/TextArea.tsx +16 -1
- package/src/components/index.ts +1 -1
- package/src/hooks/index.ts +0 -2
- package/src/stories/DataTable.stories.tsx +61 -1
- package/dist/esm/hooks/useHashParams.d.ts +0 -19
- package/dist/esm/hooks/useHashParams.d.ts.map +0 -1
- package/dist/esm/hooks/useHashParams.js +0 -69
- package/dist/esm/hooks/useHashParams.js.map +0 -1
- package/dist/esm/hooks/usePaginationFromUrl.d.ts +0 -11
- package/dist/esm/hooks/usePaginationFromUrl.d.ts.map +0 -1
- package/dist/esm/hooks/usePaginationFromUrl.js +0 -25
- package/dist/esm/hooks/usePaginationFromUrl.js.map +0 -1
- package/dist/esm/stories/Pagination.stories.d.ts +0 -13
- package/dist/esm/stories/Pagination.stories.d.ts.map +0 -1
- package/dist/esm/stories/Pagination.stories.js +0 -49
- package/dist/esm/stories/Pagination.stories.js.map +0 -1
- package/src/hooks/useHashParams.ts +0 -101
- package/src/hooks/usePaginationFromUrl.ts +0 -46
- package/src/stories/Pagination.stories.tsx +0 -92
package/package.json
CHANGED
|
@@ -39,6 +39,10 @@ import {
|
|
|
39
39
|
Spinner,
|
|
40
40
|
Tooltip,
|
|
41
41
|
} from "@sparkle/components";
|
|
42
|
+
import {
|
|
43
|
+
radioIndicatorStyles,
|
|
44
|
+
radioStyles,
|
|
45
|
+
} from "@sparkle/components/RadioGroup";
|
|
42
46
|
import { useCopyToClipboard } from "@sparkle/hooks";
|
|
43
47
|
import {
|
|
44
48
|
ArrowDownIcon,
|
|
@@ -107,6 +111,7 @@ interface DataTableProps<TData extends TBaseData> {
|
|
|
107
111
|
rowSelection?: RowSelectionState;
|
|
108
112
|
setRowSelection?: (rowSelection: RowSelectionState) => void;
|
|
109
113
|
enableRowSelection?: boolean | ((row: Row<TData>) => boolean);
|
|
114
|
+
enableMultiRowSelection?: boolean;
|
|
110
115
|
}
|
|
111
116
|
|
|
112
117
|
export function DataTable<TData extends TBaseData>({
|
|
@@ -128,6 +133,7 @@ export function DataTable<TData extends TBaseData>({
|
|
|
128
133
|
rowSelection,
|
|
129
134
|
setRowSelection,
|
|
130
135
|
enableRowSelection = false,
|
|
136
|
+
enableMultiRowSelection = true,
|
|
131
137
|
getRowId,
|
|
132
138
|
}: DataTableProps<TData>) {
|
|
133
139
|
const windowSize = useWindowSize();
|
|
@@ -198,6 +204,7 @@ export function DataTable<TData extends TBaseData>({
|
|
|
198
204
|
},
|
|
199
205
|
onPaginationChange,
|
|
200
206
|
enableRowSelection,
|
|
207
|
+
enableMultiRowSelection,
|
|
201
208
|
getRowId,
|
|
202
209
|
});
|
|
203
210
|
|
|
@@ -328,6 +335,7 @@ export function ScrollableDataTable<TData extends TBaseData>({
|
|
|
328
335
|
rowSelection,
|
|
329
336
|
setRowSelection,
|
|
330
337
|
enableRowSelection,
|
|
338
|
+
enableMultiRowSelection = true,
|
|
331
339
|
getRowId,
|
|
332
340
|
}: ScrollableDataTableProps<TData>) {
|
|
333
341
|
const windowSize = useWindowSize();
|
|
@@ -369,7 +377,6 @@ export function ScrollableDataTable<TData extends TBaseData>({
|
|
|
369
377
|
rowCount: totalRowCount,
|
|
370
378
|
getCoreRowModel: getCoreRowModel(),
|
|
371
379
|
enableColumnResizing: true,
|
|
372
|
-
onRowSelectionChange,
|
|
373
380
|
...(enableRowSelection && {
|
|
374
381
|
onRowSelectionChange,
|
|
375
382
|
}),
|
|
@@ -377,6 +384,7 @@ export function ScrollableDataTable<TData extends TBaseData>({
|
|
|
377
384
|
...(enableRowSelection && { rowSelection }),
|
|
378
385
|
},
|
|
379
386
|
enableRowSelection,
|
|
387
|
+
enableMultiRowSelection,
|
|
380
388
|
getRowId,
|
|
381
389
|
});
|
|
382
390
|
|
|
@@ -693,8 +701,7 @@ DataTable.Row = function Row({
|
|
|
693
701
|
onClick
|
|
694
702
|
? "s-cursor-pointer hover:s-bg-muted dark:hover:s-bg-muted-night"
|
|
695
703
|
: "",
|
|
696
|
-
props["data-selected"] &&
|
|
697
|
-
"s-bg-highlight-50 dark:s-bg-highlight-900/10",
|
|
704
|
+
props["data-selected"] && "s-bg-muted/50 dark:s-bg-muted/50",
|
|
698
705
|
widthClassName,
|
|
699
706
|
className
|
|
700
707
|
)}
|
|
@@ -1119,3 +1126,37 @@ export function createSelectionColumn<TData>(): ColumnDef<TData> {
|
|
|
1119
1126
|
},
|
|
1120
1127
|
};
|
|
1121
1128
|
}
|
|
1129
|
+
|
|
1130
|
+
export function createRadioSelectionColumn<TData>(): ColumnDef<TData> {
|
|
1131
|
+
return {
|
|
1132
|
+
id: "radio-select",
|
|
1133
|
+
enableSorting: false,
|
|
1134
|
+
enableHiding: false,
|
|
1135
|
+
header: () => null,
|
|
1136
|
+
cell: ({ row }) => (
|
|
1137
|
+
<div className="s-flex s-h-full s-w-full s-items-center">
|
|
1138
|
+
<button
|
|
1139
|
+
type="button"
|
|
1140
|
+
className={cn(
|
|
1141
|
+
radioStyles({ size: "xs" }),
|
|
1142
|
+
row.getIsSelected() && "s-bg-muted/50 dark:s-bg-muted/50",
|
|
1143
|
+
row.getCanSelect() && "s-cursor-pointer"
|
|
1144
|
+
)}
|
|
1145
|
+
onClick={() =>
|
|
1146
|
+
row.getCanSelect() && row.toggleSelected(!row.getIsSelected())
|
|
1147
|
+
}
|
|
1148
|
+
disabled={!row.getCanSelect()}
|
|
1149
|
+
aria-checked={row.getIsSelected()}
|
|
1150
|
+
role="radio"
|
|
1151
|
+
>
|
|
1152
|
+
{row.getIsSelected() && (
|
|
1153
|
+
<div className={radioIndicatorStyles({ size: "xs" })} />
|
|
1154
|
+
)}
|
|
1155
|
+
</button>
|
|
1156
|
+
</div>
|
|
1157
|
+
),
|
|
1158
|
+
meta: {
|
|
1159
|
+
className: "s-w-10",
|
|
1160
|
+
},
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
@@ -7,7 +7,7 @@ import { Label } from "@sparkle/components/Label";
|
|
|
7
7
|
import { Tooltip } from "@sparkle/components/Tooltip";
|
|
8
8
|
import { cn } from "@sparkle/lib/utils";
|
|
9
9
|
|
|
10
|
-
const radioStyles = cva(
|
|
10
|
+
export const radioStyles = cva(
|
|
11
11
|
cn(
|
|
12
12
|
"s-aspect-square s-rounded-full s-border",
|
|
13
13
|
"s-s-border-border-dark dark:s-border-primary-500",
|
|
@@ -32,7 +32,7 @@ const radioStyles = cva(
|
|
|
32
32
|
}
|
|
33
33
|
);
|
|
34
34
|
|
|
35
|
-
const radioIndicatorStyles = cva(
|
|
35
|
+
export const radioIndicatorStyles = cva(
|
|
36
36
|
"s-bg-primary dark:s-bg-primary-night s-flex s-items-center s-justify-center s-rounded-full",
|
|
37
37
|
{
|
|
38
38
|
variants: {
|
|
@@ -110,4 +110,19 @@ const TextArea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
|
110
110
|
);
|
|
111
111
|
TextArea.displayName = "TextArea";
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
const ReadOnlyTextArea = ({ content }: { content: string | null }) => {
|
|
114
|
+
return (
|
|
115
|
+
<TextArea
|
|
116
|
+
disabled
|
|
117
|
+
isDisplay
|
|
118
|
+
className={cn(
|
|
119
|
+
"s-copy-sm s-h-full s-min-h-60 s-w-full s-min-w-0 s-rounded-xl",
|
|
120
|
+
"s-resize-none s-border-border s-bg-muted-background",
|
|
121
|
+
"dark:s-border-border-night dark:s-bg-muted-background-night"
|
|
122
|
+
)}
|
|
123
|
+
defaultValue={content ?? ""}
|
|
124
|
+
/>
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export { ReadOnlyTextArea, TextArea };
|
package/src/components/index.ts
CHANGED
|
@@ -162,7 +162,7 @@ export { SliderToggle } from "./SliderToggle";
|
|
|
162
162
|
export { default as Spinner } from "./Spinner";
|
|
163
163
|
export { FlexSplitButton, SplitButton } from "./SplitButton";
|
|
164
164
|
export { Tabs, TabsContent, TabsList, TabsTrigger } from "./Tabs";
|
|
165
|
-
export { TextArea } from "./TextArea";
|
|
165
|
+
export { ReadOnlyTextArea, TextArea } from "./TextArea";
|
|
166
166
|
export {
|
|
167
167
|
Tooltip,
|
|
168
168
|
TooltipContent,
|
package/src/hooks/index.ts
CHANGED
|
@@ -20,7 +20,11 @@ import {
|
|
|
20
20
|
Input,
|
|
21
21
|
ScrollableDataTable,
|
|
22
22
|
} from "@sparkle/components/";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
createRadioSelectionColumn,
|
|
25
|
+
createSelectionColumn,
|
|
26
|
+
MenuItem,
|
|
27
|
+
} from "@sparkle/components/DataTable";
|
|
24
28
|
import { FolderIcon } from "@sparkle/icons/app";
|
|
25
29
|
|
|
26
30
|
const meta = {
|
|
@@ -649,3 +653,59 @@ export const DataTableWithRowSelectionExample = () => {
|
|
|
649
653
|
</div>
|
|
650
654
|
);
|
|
651
655
|
};
|
|
656
|
+
|
|
657
|
+
export const DataTableWithRadioSelectionExample = () => {
|
|
658
|
+
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
|
659
|
+
const [data] = useState<Data[]>(() => createData(0, 10));
|
|
660
|
+
const [filter, setFilter] = useState("");
|
|
661
|
+
|
|
662
|
+
const columnsWithRadioSelection: ColumnDef<Data>[] = useMemo(
|
|
663
|
+
() => [createRadioSelectionColumn<Data>(), ...columns],
|
|
664
|
+
[]
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
// Get the selected row ID from rowSelection state
|
|
668
|
+
const selectedRowId = Object.keys(rowSelection).find(
|
|
669
|
+
(id) => rowSelection[id]
|
|
670
|
+
);
|
|
671
|
+
|
|
672
|
+
return (
|
|
673
|
+
<div className="s-flex s-w-full s-max-w-4xl s-flex-col s-gap-6">
|
|
674
|
+
<h3 className="s-text-lg s-font-medium">
|
|
675
|
+
DataTable with Radio Selection (Single Row)
|
|
676
|
+
</h3>
|
|
677
|
+
|
|
678
|
+
<div className="s-flex s-flex-col s-gap-4">
|
|
679
|
+
<Input
|
|
680
|
+
name="filter"
|
|
681
|
+
placeholder="Filter"
|
|
682
|
+
value={filter}
|
|
683
|
+
onChange={(e) => setFilter(e.target.value)}
|
|
684
|
+
/>
|
|
685
|
+
|
|
686
|
+
<DataTable
|
|
687
|
+
data={data}
|
|
688
|
+
filter={filter}
|
|
689
|
+
filterColumn="name"
|
|
690
|
+
columns={columnsWithRadioSelection}
|
|
691
|
+
rowSelection={rowSelection}
|
|
692
|
+
setRowSelection={setRowSelection}
|
|
693
|
+
enableRowSelection={true}
|
|
694
|
+
enableMultiRowSelection={false}
|
|
695
|
+
getRowId={(row) => row.name}
|
|
696
|
+
/>
|
|
697
|
+
|
|
698
|
+
<div className="s-rounded-md s-border s-bg-muted/50 s-p-2">
|
|
699
|
+
<h4 className="s-mb-2 s-font-medium">Radio Selection State:</h4>
|
|
700
|
+
<pre className="s-overflow-auto s-text-xs">
|
|
701
|
+
{JSON.stringify(rowSelection, null, 2)}
|
|
702
|
+
</pre>
|
|
703
|
+
<p className="s-mt-2 s-text-sm">
|
|
704
|
+
{selectedRowId ? `Selected: ${selectedRowId}` : "No row selected"}{" "}
|
|
705
|
+
(only one row can be selected at a time)
|
|
706
|
+
</p>
|
|
707
|
+
</div>
|
|
708
|
+
</div>
|
|
709
|
+
</div>
|
|
710
|
+
);
|
|
711
|
+
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Original code from : https://www.npmjs.com/package/use-hash-param
|
|
3
|
-
* ISC License
|
|
4
|
-
*/
|
|
5
|
-
type Updater = (prevValue?: string) => string;
|
|
6
|
-
export type HistoryOptions = "replace" | "push";
|
|
7
|
-
type SetterOptions = {
|
|
8
|
-
history: HistoryOptions;
|
|
9
|
-
};
|
|
10
|
-
type Setter = (value?: string | Updater, options?: SetterOptions) => void;
|
|
11
|
-
/**
|
|
12
|
-
* @param key The parameter-name to use from the hash-string query string.
|
|
13
|
-
* @param defaultValue A default value to use if the parameter is not specified and on the server.
|
|
14
|
-
* @returns A two-tuple, the first element is the selected param value (either extracted from the hash param or the default value).
|
|
15
|
-
* The second element is a setter function to change the param value.
|
|
16
|
-
*/
|
|
17
|
-
export declare const useHashParam: (key: string, defaultValue?: string) => [string | undefined, Setter];
|
|
18
|
-
export {};
|
|
19
|
-
//# sourceMappingURL=useHashParams.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHashParams.d.ts","sourceRoot":"","sources":["../../../src/hooks/useHashParams.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgDH,KAAK,OAAO,GAAG,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAE9C,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,MAAM,CAAC;AAEhD,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AACF,KAAK,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;AAE1E;;;;;GAKG;AAEH,eAAO,MAAM,YAAY,QAClB,MAAM,iBACI,MAAM,KACpB,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,CA8B7B,CAAC"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Original code from : https://www.npmjs.com/package/use-hash-param
|
|
3
|
-
* ISC License
|
|
4
|
-
*/
|
|
5
|
-
import { __read } from "tslib";
|
|
6
|
-
import { useCallback, useEffect, useState } from "react";
|
|
7
|
-
var getHashSearchParams = function (location) {
|
|
8
|
-
var hash = location.hash.slice(1);
|
|
9
|
-
var _a = __read(hash.split("?"), 2), prefix = _a[0], query = _a[1];
|
|
10
|
-
return [prefix, new URLSearchParams(query)];
|
|
11
|
-
};
|
|
12
|
-
var getHashParam = function (key, defaultValue) {
|
|
13
|
-
var _a;
|
|
14
|
-
if (typeof window === "undefined") {
|
|
15
|
-
return defaultValue;
|
|
16
|
-
}
|
|
17
|
-
var _b = __read(getHashSearchParams(window.location), 2), searchParams = _b[1];
|
|
18
|
-
return (_a = searchParams.get(key)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
19
|
-
};
|
|
20
|
-
var setHashParam = function (key, value, shouldReplaceState) {
|
|
21
|
-
if (typeof window !== "undefined") {
|
|
22
|
-
var _a = window.location, pathname = _a.pathname, search = _a.search;
|
|
23
|
-
var _b = __read(getHashSearchParams(window.location), 2), prefix = _b[0], searchParams = _b[1];
|
|
24
|
-
if (typeof value === "undefined" || value === "") {
|
|
25
|
-
searchParams.delete(key);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
searchParams.set(key, value);
|
|
29
|
-
}
|
|
30
|
-
var hashSearch = searchParams.toString();
|
|
31
|
-
var hash = hashSearch ? "".concat(prefix, "?").concat(hashSearch) : prefix;
|
|
32
|
-
var newUrl = "".concat(pathname).concat(search, "#").concat(hash);
|
|
33
|
-
if (shouldReplaceState && "replaceState" in history) {
|
|
34
|
-
history.replaceState(null, "", newUrl);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
window.location.hash = hash;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* @param key The parameter-name to use from the hash-string query string.
|
|
43
|
-
* @param defaultValue A default value to use if the parameter is not specified and on the server.
|
|
44
|
-
* @returns A two-tuple, the first element is the selected param value (either extracted from the hash param or the default value).
|
|
45
|
-
* The second element is a setter function to change the param value.
|
|
46
|
-
*/
|
|
47
|
-
export var useHashParam = function (key, defaultValue) {
|
|
48
|
-
var _a = __read(useState(function () {
|
|
49
|
-
return getHashParam(key, defaultValue);
|
|
50
|
-
}), 2), innerValue = _a[0], setInnerValue = _a[1];
|
|
51
|
-
useEffect(function () {
|
|
52
|
-
var handleHashChange = function () {
|
|
53
|
-
return setInnerValue(getHashParam(key, defaultValue));
|
|
54
|
-
};
|
|
55
|
-
handleHashChange();
|
|
56
|
-
window.addEventListener("hashchange", handleHashChange);
|
|
57
|
-
return function () { return window.removeEventListener("hashchange", handleHashChange); };
|
|
58
|
-
}, [key]);
|
|
59
|
-
var setValue = useCallback(function (newValue, options) {
|
|
60
|
-
if (options === void 0) { options = { history: "replace" }; }
|
|
61
|
-
var newInnerValue = typeof newValue === "function"
|
|
62
|
-
? newValue(getHashParam(key, defaultValue))
|
|
63
|
-
: newValue;
|
|
64
|
-
setInnerValue(newInnerValue);
|
|
65
|
-
setHashParam(key, newInnerValue, options.history === "replace");
|
|
66
|
-
}, [key]);
|
|
67
|
-
return [innerValue || defaultValue, setValue];
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=useHashParams.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHashParams.js","sourceRoot":"","sources":["../../../src/hooks/useHashParams.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PaginationState } from "@tanstack/react-table";
|
|
2
|
-
import { HistoryOptions } from "../hooks/useHashParams";
|
|
3
|
-
export declare const usePaginationFromUrl: ({ urlPrefix, initialPageSize, defaultHistory, }: {
|
|
4
|
-
urlPrefix?: string;
|
|
5
|
-
initialPageSize?: number;
|
|
6
|
-
defaultHistory?: HistoryOptions;
|
|
7
|
-
}) => {
|
|
8
|
-
pagination: PaginationState;
|
|
9
|
-
setPagination: (newValue: PaginationState, history?: HistoryOptions) => void;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=usePaginationFromUrl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePaginationFromUrl.d.ts","sourceRoot":"","sources":["../../../src/hooks/usePaginationFromUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,cAAc,EAAgB,MAAM,8BAA8B,CAAC;AAI5E,eAAO,MAAM,oBAAoB,oDAI9B;IACD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;;8BAee,eAAe,YACf,cAAc;CAc7B,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { __read } from "tslib";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { useHashParam } from "../hooks/useHashParams";
|
|
4
|
-
var defaultPageSize = 25;
|
|
5
|
-
export var usePaginationFromUrl = function (_a) {
|
|
6
|
-
var urlPrefix = _a.urlPrefix, _b = _a.initialPageSize, initialPageSize = _b === void 0 ? defaultPageSize : _b, _c = _a.defaultHistory, defaultHistory = _c === void 0 ? "push" : _c;
|
|
7
|
-
var _d = __read(useHashParam(urlPrefix ? "".concat(urlPrefix, "PageIndex") : "pageIndex"), 2), pageIndexParam = _d[0], setPageIndexParam = _d[1];
|
|
8
|
-
var _e = __read(useHashParam(urlPrefix ? "".concat(urlPrefix, "PageSize") : "pageSize"), 2), pageSizeParam = _e[0], setPageSizeParam = _e[1];
|
|
9
|
-
var pageIndex = pageIndexParam ? parseInt(pageIndexParam) : 0;
|
|
10
|
-
var pageSize = pageSizeParam ? parseInt(pageSizeParam) : initialPageSize;
|
|
11
|
-
var res = useMemo(function () {
|
|
12
|
-
var pagination = { pageIndex: pageIndex, pageSize: pageSize };
|
|
13
|
-
var setPagination = function (newValue, history) {
|
|
14
|
-
if (newValue.pageIndex !== pageIndex || newValue.pageSize !== pageSize) {
|
|
15
|
-
setPageIndexParam(newValue.pageIndex.toString(), {
|
|
16
|
-
history: history !== null && history !== void 0 ? history : defaultHistory,
|
|
17
|
-
});
|
|
18
|
-
setPageSizeParam(newValue.pageSize.toString());
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
return { pagination: pagination, setPagination: setPagination };
|
|
22
|
-
}, [pageIndex, pageSize, urlPrefix]);
|
|
23
|
-
return res;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=usePaginationFromUrl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePaginationFromUrl.js","sourceRoot":"","sources":["../../../src/hooks/usePaginationFromUrl.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAkB,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5E,IAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAAC,EAQpC;QAPC,SAAS,eAAA,EACT,uBAAiC,EAAjC,eAAe,mBAAG,eAAe,KAAA,EACjC,sBAAuB,EAAvB,cAAc,mBAAG,MAAM,KAAA;IAMjB,IAAA,KAAA,OAAsC,YAAY,CACtD,SAAS,CAAC,CAAC,CAAC,UAAG,SAAS,cAAW,CAAC,CAAC,CAAC,WAAW,CAClD,IAAA,EAFM,cAAc,QAAA,EAAE,iBAAiB,QAEvC,CAAC;IACI,IAAA,KAAA,OAAoC,YAAY,CACpD,SAAS,CAAC,CAAC,CAAC,UAAG,SAAS,aAAU,CAAC,CAAC,CAAC,UAAU,CAChD,IAAA,EAFM,aAAa,QAAA,EAAE,gBAAgB,QAErC,CAAC;IAEF,IAAM,SAAS,GAAG,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,IAAM,QAAQ,GAAG,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;IAE3E,IAAM,GAAG,GAAG,OAAO,CAAC;QAClB,IAAM,UAAU,GAAoB,EAAE,SAAS,WAAA,EAAE,QAAQ,UAAA,EAAE,CAAC;QAE5D,IAAM,aAAa,GAAG,UACpB,QAAyB,EACzB,OAAwB;YAExB,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACvE,iBAAiB,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE;oBAC/C,OAAO,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,cAAc;iBACnC,CAAC,CAAC;gBACH,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjD,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,EAAE,UAAU,YAAA,EAAE,aAAa,eAAA,EAAE,CAAC;IACvC,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;IAErC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Pagination } from "../index_with_tw_base";
|
|
3
|
-
declare const meta: {
|
|
4
|
-
title: string;
|
|
5
|
-
component: typeof Pagination;
|
|
6
|
-
};
|
|
7
|
-
export default meta;
|
|
8
|
-
export declare const PaginationSM: () => React.JSX.Element;
|
|
9
|
-
export declare const PaginationXS: () => React.JSX.Element;
|
|
10
|
-
export declare const PaginationNoPageButtons: () => React.JSX.Element;
|
|
11
|
-
export declare const PaginationButtonsDisabled: () => React.JSX.Element;
|
|
12
|
-
export declare const PaginationWithUrl: () => React.JSX.Element;
|
|
13
|
-
//# sourceMappingURL=Pagination.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.stories.d.ts","sourceRoot":"","sources":["../../../src/stories/Pagination.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,QAAA,MAAM,IAAI;;;CAGyB,CAAC;AAEpC,eAAe,IAAI,CAAC;AACpB,eAAO,MAAM,YAAY,yBAYxB,CAAC;AAEF,eAAO,MAAM,YAAY,yBAcxB,CAAC;AAEF,eAAO,MAAM,uBAAuB,yBAenC,CAAC;AAEF,eAAO,MAAM,yBAAyB,yBAarC,CAAC;AAEF,eAAO,MAAM,iBAAiB,yBAgB7B,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { __read } from "tslib";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { usePaginationFromUrl } from "../hooks/usePaginationFromUrl";
|
|
4
|
-
import { Pagination } from "../index_with_tw_base";
|
|
5
|
-
var meta = {
|
|
6
|
-
title: "Components/Pagination",
|
|
7
|
-
component: Pagination,
|
|
8
|
-
};
|
|
9
|
-
export default meta;
|
|
10
|
-
export var PaginationSM = function () {
|
|
11
|
-
var _a = __read(React.useState({
|
|
12
|
-
pageIndex: 0,
|
|
13
|
-
pageSize: 50,
|
|
14
|
-
}), 2), pagination = _a[0], setPagination = _a[1];
|
|
15
|
-
return (React.createElement(Pagination, { rowCount: 960, pagination: pagination, setPagination: setPagination }));
|
|
16
|
-
};
|
|
17
|
-
export var PaginationXS = function () {
|
|
18
|
-
var _a = __read(React.useState({
|
|
19
|
-
pageIndex: 0,
|
|
20
|
-
pageSize: 50,
|
|
21
|
-
}), 2), pagination = _a[0], setPagination = _a[1];
|
|
22
|
-
return (React.createElement(Pagination, { rowCount: 960, size: "xs", showDetails: false, pagination: pagination, setPagination: setPagination }));
|
|
23
|
-
};
|
|
24
|
-
export var PaginationNoPageButtons = function () {
|
|
25
|
-
var _a = __read(React.useState({
|
|
26
|
-
pageIndex: 0,
|
|
27
|
-
pageSize: 50,
|
|
28
|
-
}), 2), pagination = _a[0], setPagination = _a[1];
|
|
29
|
-
return (React.createElement(Pagination, { rowCount: 960, size: "xs", showDetails: false, showPageButtons: false, pagination: pagination, setPagination: setPagination }));
|
|
30
|
-
};
|
|
31
|
-
export var PaginationButtonsDisabled = function () {
|
|
32
|
-
var _a = __read(React.useState({
|
|
33
|
-
pageIndex: 0,
|
|
34
|
-
pageSize: 50,
|
|
35
|
-
}), 2), pagination = _a[0], setPagination = _a[1];
|
|
36
|
-
return (React.createElement(Pagination, { rowCount: 960, pagination: pagination, setPagination: setPagination, disablePaginationNumbers: true }));
|
|
37
|
-
};
|
|
38
|
-
export var PaginationWithUrl = function () {
|
|
39
|
-
var _a = usePaginationFromUrl({
|
|
40
|
-
urlPrefix: "example",
|
|
41
|
-
initialPageSize: 50,
|
|
42
|
-
}), pagination = _a.pagination, setPagination = _a.setPagination;
|
|
43
|
-
return (React.createElement(React.Fragment, null,
|
|
44
|
-
React.createElement("div", { className: "s-p-2" },
|
|
45
|
-
"Current hash: ",
|
|
46
|
-
location.hash),
|
|
47
|
-
React.createElement(Pagination, { rowCount: 960, pagination: pagination, setPagination: setPagination })));
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=Pagination.stories.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Pagination.stories.js","sourceRoot":"","sources":["../../../src/stories/Pagination.stories.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,IAAM,IAAI,GAAG;IACX,KAAK,EAAE,uBAAuB;IAC9B,SAAS,EAAE,UAAU;CACY,CAAC;AAEpC,eAAe,IAAI,CAAC;AACpB,MAAM,CAAC,IAAM,YAAY,GAAG;IACpB,IAAA,KAAA,OAA8B,KAAK,CAAC,QAAQ,CAAC;QACjD,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,EAAE;KACb,CAAC,IAAA,EAHK,UAAU,QAAA,EAAE,aAAa,QAG9B,CAAC;IACH,OAAO,CACL,oBAAC,UAAU,IACT,QAAQ,EAAE,GAAG,EACb,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,GAC5B,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,YAAY,GAAG;IACpB,IAAA,KAAA,OAA8B,KAAK,CAAC,QAAQ,CAAC;QACjD,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,EAAE;KACb,CAAC,IAAA,EAHK,UAAU,QAAA,EAAE,aAAa,QAG9B,CAAC;IACH,OAAO,CACL,oBAAC,UAAU,IACT,QAAQ,EAAE,GAAG,EACb,IAAI,EAAC,IAAI,EACT,WAAW,EAAE,KAAK,EAClB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,GAC5B,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,uBAAuB,GAAG;IAC/B,IAAA,KAAA,OAA8B,KAAK,CAAC,QAAQ,CAAC;QACjD,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,EAAE;KACb,CAAC,IAAA,EAHK,UAAU,QAAA,EAAE,aAAa,QAG9B,CAAC;IACH,OAAO,CACL,oBAAC,UAAU,IACT,QAAQ,EAAE,GAAG,EACb,IAAI,EAAC,IAAI,EACT,WAAW,EAAE,KAAK,EAClB,eAAe,EAAE,KAAK,EACtB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,GAC5B,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,yBAAyB,GAAG;IACjC,IAAA,KAAA,OAA8B,KAAK,CAAC,QAAQ,CAAC;QACjD,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,EAAE;KACb,CAAC,IAAA,EAHK,UAAU,QAAA,EAAE,aAAa,QAG9B,CAAC;IACH,OAAO,CACL,oBAAC,UAAU,IACT,QAAQ,EAAE,GAAG,EACb,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EAC5B,wBAAwB,SACxB,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,iBAAiB,GAAG;IACzB,IAAA,KAAgC,oBAAoB,CAAC;QACzD,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,EAAE;KACpB,CAAC,EAHM,UAAU,gBAAA,EAAE,aAAa,mBAG/B,CAAC;IAEH,OAAO,CACL;QACE,6BAAK,SAAS,EAAC,OAAO;;YAAgB,QAAQ,CAAC,IAAI,CAAO;QAC1D,oBAAC,UAAU,IACT,QAAQ,EAAE,GAAG,EACb,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,GAC5B,CACD,CACJ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Original code from : https://www.npmjs.com/package/use-hash-param
|
|
3
|
-
* ISC License
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useCallback, useEffect, useState } from "react";
|
|
7
|
-
|
|
8
|
-
const getHashSearchParams = (location: Location): [string, URLSearchParams] => {
|
|
9
|
-
const hash = location.hash.slice(1);
|
|
10
|
-
const [prefix, query] = hash.split("?");
|
|
11
|
-
|
|
12
|
-
return [prefix, new URLSearchParams(query)];
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const getHashParam = (key: string, defaultValue?: string) => {
|
|
16
|
-
if (typeof window === "undefined") {
|
|
17
|
-
return defaultValue;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const [, searchParams] = getHashSearchParams(window.location);
|
|
21
|
-
|
|
22
|
-
return searchParams.get(key) ?? defaultValue;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const setHashParam = (
|
|
26
|
-
key: string,
|
|
27
|
-
value: string | undefined,
|
|
28
|
-
shouldReplaceState: boolean
|
|
29
|
-
) => {
|
|
30
|
-
if (typeof window !== "undefined") {
|
|
31
|
-
const { pathname, search } = window.location;
|
|
32
|
-
const [prefix, searchParams] = getHashSearchParams(window.location);
|
|
33
|
-
|
|
34
|
-
if (typeof value === "undefined" || value === "") {
|
|
35
|
-
searchParams.delete(key);
|
|
36
|
-
} else {
|
|
37
|
-
searchParams.set(key, value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const hashSearch = searchParams.toString();
|
|
41
|
-
const hash = hashSearch ? `${prefix}?${hashSearch}` : prefix;
|
|
42
|
-
const newUrl = `${pathname}${search}#${hash}`;
|
|
43
|
-
|
|
44
|
-
if (shouldReplaceState && "replaceState" in history) {
|
|
45
|
-
history.replaceState(null, "", newUrl);
|
|
46
|
-
} else {
|
|
47
|
-
window.location.hash = hash;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
type Updater = (prevValue?: string) => string;
|
|
53
|
-
|
|
54
|
-
export type HistoryOptions = "replace" | "push";
|
|
55
|
-
|
|
56
|
-
type SetterOptions = {
|
|
57
|
-
history: HistoryOptions;
|
|
58
|
-
};
|
|
59
|
-
type Setter = (value?: string | Updater, options?: SetterOptions) => void;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @param key The parameter-name to use from the hash-string query string.
|
|
63
|
-
* @param defaultValue A default value to use if the parameter is not specified and on the server.
|
|
64
|
-
* @returns A two-tuple, the first element is the selected param value (either extracted from the hash param or the default value).
|
|
65
|
-
* The second element is a setter function to change the param value.
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
export const useHashParam = (
|
|
69
|
-
key: string,
|
|
70
|
-
defaultValue?: string
|
|
71
|
-
): [string | undefined, Setter] => {
|
|
72
|
-
const [innerValue, setInnerValue] = useState<string | undefined>(() =>
|
|
73
|
-
getHashParam(key, defaultValue)
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
const handleHashChange = () =>
|
|
78
|
-
setInnerValue(getHashParam(key, defaultValue));
|
|
79
|
-
handleHashChange();
|
|
80
|
-
window.addEventListener("hashchange", handleHashChange);
|
|
81
|
-
return () => window.removeEventListener("hashchange", handleHashChange);
|
|
82
|
-
}, [key]);
|
|
83
|
-
|
|
84
|
-
const setValue = useCallback<Setter>(
|
|
85
|
-
(
|
|
86
|
-
newValue?: string | Updater,
|
|
87
|
-
options: SetterOptions = { history: "replace" }
|
|
88
|
-
) => {
|
|
89
|
-
const newInnerValue =
|
|
90
|
-
typeof newValue === "function"
|
|
91
|
-
? newValue(getHashParam(key, defaultValue))
|
|
92
|
-
: newValue;
|
|
93
|
-
|
|
94
|
-
setInnerValue(newInnerValue);
|
|
95
|
-
setHashParam(key, newInnerValue, options.history === "replace");
|
|
96
|
-
},
|
|
97
|
-
[key]
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
return [innerValue || defaultValue, setValue];
|
|
101
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { PaginationState } from "@tanstack/react-table";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
|
|
4
|
-
import { HistoryOptions, useHashParam } from "@sparkle/hooks/useHashParams";
|
|
5
|
-
|
|
6
|
-
const defaultPageSize = 25;
|
|
7
|
-
|
|
8
|
-
export const usePaginationFromUrl = ({
|
|
9
|
-
urlPrefix,
|
|
10
|
-
initialPageSize = defaultPageSize,
|
|
11
|
-
defaultHistory = "push",
|
|
12
|
-
}: {
|
|
13
|
-
urlPrefix?: string;
|
|
14
|
-
initialPageSize?: number;
|
|
15
|
-
defaultHistory?: HistoryOptions;
|
|
16
|
-
}) => {
|
|
17
|
-
const [pageIndexParam, setPageIndexParam] = useHashParam(
|
|
18
|
-
urlPrefix ? `${urlPrefix}PageIndex` : "pageIndex"
|
|
19
|
-
);
|
|
20
|
-
const [pageSizeParam, setPageSizeParam] = useHashParam(
|
|
21
|
-
urlPrefix ? `${urlPrefix}PageSize` : "pageSize"
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const pageIndex = pageIndexParam ? parseInt(pageIndexParam) : 0;
|
|
25
|
-
const pageSize = pageSizeParam ? parseInt(pageSizeParam) : initialPageSize;
|
|
26
|
-
|
|
27
|
-
const res = useMemo(() => {
|
|
28
|
-
const pagination: PaginationState = { pageIndex, pageSize };
|
|
29
|
-
|
|
30
|
-
const setPagination = (
|
|
31
|
-
newValue: PaginationState,
|
|
32
|
-
history?: HistoryOptions
|
|
33
|
-
) => {
|
|
34
|
-
if (newValue.pageIndex !== pageIndex || newValue.pageSize !== pageSize) {
|
|
35
|
-
setPageIndexParam(newValue.pageIndex.toString(), {
|
|
36
|
-
history: history ?? defaultHistory,
|
|
37
|
-
});
|
|
38
|
-
setPageSizeParam(newValue.pageSize.toString());
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
return { pagination, setPagination };
|
|
43
|
-
}, [pageIndex, pageSize, urlPrefix]);
|
|
44
|
-
|
|
45
|
-
return res;
|
|
46
|
-
};
|