@dmsi/wedgekit-react 0.0.551 → 0.0.552
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/package.json +2 -3
- package/src/brand.css +0 -125
- package/src/classNames.ts +0 -174
- package/src/components/AccessChangerTabItem.tsx +0 -71
- package/src/components/Accordion.tsx +0 -108
- package/src/components/Alert.tsx +0 -81
- package/src/components/Breadcrumbs.tsx +0 -142
- package/src/components/Button.tsx +0 -216
- package/src/components/CalendarRange.tsx +0 -628
- package/src/components/Caption.tsx +0 -144
- package/src/components/Card.tsx +0 -88
- package/src/components/Checkbox.tsx +0 -206
- package/src/components/CompactImagesPreview.tsx +0 -135
- package/src/components/ContentTab.tsx +0 -84
- package/src/components/ContentTabs.tsx +0 -136
- package/src/components/DMSiLogo.tsx +0 -33
- package/src/components/DataGrid/ColumnSelectorHeaderCell/ColumnSelectorMenuOption.tsx +0 -35
- package/src/components/DataGrid/ColumnSelectorHeaderCell/index.tsx +0 -74
- package/src/components/DataGrid/PinnedColumns.tsx +0 -183
- package/src/components/DataGrid/TableBody/LoadingCell.tsx +0 -44
- package/src/components/DataGrid/TableBody/TableBodyRow.tsx +0 -157
- package/src/components/DataGrid/TableBody/index.tsx +0 -185
- package/src/components/DataGrid/index.tsx +0 -756
- package/src/components/DataGrid/types.ts +0 -98
- package/src/components/DataGrid/utils.tsx +0 -15
- package/src/components/DataGridCell.tsx +0 -526
- package/src/components/DataTable.tsx +0 -881
- package/src/components/DateInput.tsx +0 -306
- package/src/components/DateRangeInput.tsx +0 -758
- package/src/components/DebugJson.tsx +0 -28
- package/src/components/Display.tsx +0 -66
- package/src/components/EditingContext.tsx +0 -43
- package/src/components/EmptyCartIcon.tsx +0 -18
- package/src/components/FilterGroup.tsx +0 -264
- package/src/components/FullViewportBox.tsx +0 -19
- package/src/components/Grid.tsx +0 -97
- package/src/components/Heading.tsx +0 -72
- package/src/components/HorizontalDivider.tsx +0 -22
- package/src/components/Icon.tsx +0 -39
- package/src/components/ImagePlaceholder.tsx +0 -22
- package/src/components/Input.tsx +0 -609
- package/src/components/InputGroup.tsx +0 -59
- package/src/components/Label.tsx +0 -46
- package/src/components/Link.tsx +0 -117
- package/src/components/List.tsx +0 -18
- package/src/components/ListGroup.tsx +0 -82
- package/src/components/LiveChatComponent.tsx +0 -56
- package/src/components/LoadingScrim.tsx +0 -33
- package/src/components/LogoAgilityTopBar.tsx +0 -54
- package/src/components/LogoDMSiTopBar.tsx +0 -33
- package/src/components/LogoMillworkTopBar.tsx +0 -119
- package/src/components/MainBar.tsx +0 -91
- package/src/components/MaxViewportBox.tsx +0 -19
- package/src/components/Menu.tsx +0 -316
- package/src/components/MenuOption.tsx +0 -330
- package/src/components/MobileDataGrid/ColumnList.tsx +0 -66
- package/src/components/MobileDataGrid/ColumnSelector/index.tsx +0 -97
- package/src/components/MobileDataGrid/GridContextProvider/GridContext.tsx +0 -25
- package/src/components/MobileDataGrid/GridContextProvider/index.tsx +0 -132
- package/src/components/MobileDataGrid/GridContextProvider/useGridContext.ts +0 -10
- package/src/components/MobileDataGrid/MobileDataGridCard/MobileDataGridColumn.tsx +0 -27
- package/src/components/MobileDataGrid/MobileDataGridCard/index.tsx +0 -138
- package/src/components/MobileDataGrid/MobileDataGridHeader.tsx +0 -81
- package/src/components/MobileDataGrid/RowDetailModalProvider/ModalContent.tsx +0 -42
- package/src/components/MobileDataGrid/RowDetailModalProvider/index.tsx +0 -68
- package/src/components/MobileDataGrid/dataGridReducer.ts +0 -55
- package/src/components/MobileDataGrid/index.tsx +0 -92
- package/src/components/MobileDataGrid/types.ts +0 -4
- package/src/components/Modal.tsx +0 -312
- package/src/components/ModalButtons.tsx +0 -62
- package/src/components/ModalContent.tsx +0 -31
- package/src/components/ModalHeader.tsx +0 -78
- package/src/components/ModalScrim.tsx +0 -42
- package/src/components/NavigationTab.tsx +0 -95
- package/src/components/NavigationTabs.tsx +0 -70
- package/src/components/NestedMenu.tsx +0 -131
- package/src/components/Notification.tsx +0 -128
- package/src/components/OptionPill.tsx +0 -139
- package/src/components/OrderCheckIcon.tsx +0 -19
- package/src/components/PDFViewer/DownloadIcon.tsx +0 -25
- package/src/components/PDFViewer/PDFElement.tsx +0 -90
- package/src/components/PDFViewer/PDFNavigation.tsx +0 -68
- package/src/components/PDFViewer/PDFPage.tsx +0 -34
- package/src/components/PDFViewer/index.tsx +0 -128
- package/src/components/Pagination.tsx +0 -182
- package/src/components/Paragraph.tsx +0 -55
- package/src/components/Password.tsx +0 -62
- package/src/components/ProductImagePreview/CarouselPagination.tsx +0 -54
- package/src/components/ProductImagePreview/MobileImageCarousel.tsx +0 -226
- package/src/components/ProductImagePreview/ProductPrimaryImage.tsx +0 -219
- package/src/components/ProductImagePreview/Thumbnail.tsx +0 -55
- package/src/components/ProductImagePreview/ZoomWindow.tsx +0 -136
- package/src/components/ProductImagePreview/index.tsx +0 -182
- package/src/components/ProductImagePreview/useProductImagePreview.ts +0 -211
- package/src/components/ProjectBar.tsx +0 -82
- package/src/components/Radio.tsx +0 -146
- package/src/components/Search.tsx +0 -152
- package/src/components/SearchResultImage/index.tsx +0 -39
- package/src/components/Select.tsx +0 -114
- package/src/components/SideMenu.tsx +0 -30
- package/src/components/SideMenuGroup.tsx +0 -95
- package/src/components/SideMenuItem.tsx +0 -109
- package/src/components/SimpleTable.tsx +0 -77
- package/src/components/SkeletonParagraph.tsx +0 -31
- package/src/components/Spinner.tsx +0 -32
- package/src/components/Stack.tsx +0 -347
- package/src/components/StatusPill.tsx +0 -59
- package/src/components/Stepper.tsx +0 -128
- package/src/components/Subheader.tsx +0 -50
- package/src/components/Surface.tsx +0 -37
- package/src/components/Swatch.tsx +0 -1341
- package/src/components/Textarea.tsx +0 -102
- package/src/components/Theme.tsx +0 -27
- package/src/components/Time.tsx +0 -460
- package/src/components/Toast.tsx +0 -268
- package/src/components/Tooltip.tsx +0 -159
- package/src/components/TopBar.tsx +0 -139
- package/src/components/Upload.tsx +0 -107
- package/src/components/WorldpayIframe.tsx +0 -7
- package/src/components/index.ts +0 -34
- package/src/components/useMenuSystem.tsx +0 -456
- package/src/components/useMounted.tsx +0 -14
- package/src/darkmode.css +0 -278
- package/src/fonts.css +0 -23
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useInfiniteScroll.tsx +0 -40
- package/src/hooks/useKeydown.ts +0 -42
- package/src/hooks/useMatchesMedia.ts +0 -18
- package/src/hooks/useTableLayout.ts +0 -106
- package/src/index.css +0 -800
- package/src/index.tsx +0 -5
- package/src/types.ts +0 -150
- package/src/utils/date.ts +0 -236
- package/src/utils/formatting.tsx +0 -81
- package/src/utils/index.ts +0 -4
- package/src/utils/mergeObjectArrays.ts +0 -18
- package/src/utils.ts +0 -24
|
@@ -1,881 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import React, {
|
|
3
|
-
createContext,
|
|
4
|
-
CSSProperties,
|
|
5
|
-
PropsWithChildren,
|
|
6
|
-
ReactNode,
|
|
7
|
-
useContext,
|
|
8
|
-
useState,
|
|
9
|
-
} from "react";
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
Cell,
|
|
13
|
-
Column,
|
|
14
|
-
ColumnDef,
|
|
15
|
-
ColumnFiltersState,
|
|
16
|
-
flexRender,
|
|
17
|
-
getCoreRowModel,
|
|
18
|
-
getFilteredRowModel,
|
|
19
|
-
getPaginationRowModel,
|
|
20
|
-
getSortedRowModel,
|
|
21
|
-
Header,
|
|
22
|
-
PaginationState,
|
|
23
|
-
// RowData,
|
|
24
|
-
SortingState,
|
|
25
|
-
useReactTable,
|
|
26
|
-
} from "@tanstack/react-table";
|
|
27
|
-
import clsx from "clsx";
|
|
28
|
-
|
|
29
|
-
import {
|
|
30
|
-
closestCenter,
|
|
31
|
-
DndContext,
|
|
32
|
-
type DragEndEvent,
|
|
33
|
-
KeyboardSensor,
|
|
34
|
-
MouseSensor,
|
|
35
|
-
TouchSensor,
|
|
36
|
-
useSensor,
|
|
37
|
-
useSensors,
|
|
38
|
-
} from "@dnd-kit/core";
|
|
39
|
-
import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
|
|
40
|
-
import {
|
|
41
|
-
arrayMove,
|
|
42
|
-
horizontalListSortingStrategy,
|
|
43
|
-
SortableContext,
|
|
44
|
-
} from "@dnd-kit/sortable";
|
|
45
|
-
|
|
46
|
-
import { useSortable } from "@dnd-kit/sortable";
|
|
47
|
-
import { CSS } from "@dnd-kit/utilities";
|
|
48
|
-
import { Switch } from "@headlessui/react";
|
|
49
|
-
|
|
50
|
-
export interface DataTableProps {
|
|
51
|
-
id?: string;
|
|
52
|
-
data: OrderRow[];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export type OrderRow = {
|
|
56
|
-
orderId: string;
|
|
57
|
-
poId: string;
|
|
58
|
-
jobId: string;
|
|
59
|
-
reference: string;
|
|
60
|
-
reference1: string;
|
|
61
|
-
reference12: string;
|
|
62
|
-
reference13: string;
|
|
63
|
-
reference14: string;
|
|
64
|
-
reference15: string;
|
|
65
|
-
reference16: string;
|
|
66
|
-
reference17: string;
|
|
67
|
-
reference18: string;
|
|
68
|
-
reference19: string;
|
|
69
|
-
reference10: string;
|
|
70
|
-
reference11: string;
|
|
71
|
-
shipToStatus: string;
|
|
72
|
-
orderedDate: string;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const columns: ColumnDef<OrderRow>[] = [
|
|
76
|
-
{
|
|
77
|
-
header: "Order ID",
|
|
78
|
-
accessorKey: "orderId",
|
|
79
|
-
id: "orderId",
|
|
80
|
-
meta: {
|
|
81
|
-
sticky: true,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
header: "Actions",
|
|
86
|
-
id: "actions",
|
|
87
|
-
cell: () => {
|
|
88
|
-
const items = [
|
|
89
|
-
{
|
|
90
|
-
label: "Release",
|
|
91
|
-
icon: <i className="w-3 h-3" />,
|
|
92
|
-
},
|
|
93
|
-
{ label: "XML", icon: <i className="w-3 h-3" /> },
|
|
94
|
-
{ label: "Copy", icon: <i className="w-3 h-3" /> },
|
|
95
|
-
{ label: "Quote", icon: <i className="w-3 h-3" /> },
|
|
96
|
-
{ label: "Retail", icon: <i className="w-3 h-3" /> },
|
|
97
|
-
];
|
|
98
|
-
return (
|
|
99
|
-
<div className="flex flex-row gap-3">
|
|
100
|
-
{items.map((item, index) => (
|
|
101
|
-
<div
|
|
102
|
-
className="flex flex-col items-center justify-center gap-1"
|
|
103
|
-
key={index}
|
|
104
|
-
>
|
|
105
|
-
{item.icon}
|
|
106
|
-
<span className="text-[0.6rem] block text-neutral-500 font-semibold">
|
|
107
|
-
{item.label}
|
|
108
|
-
</span>
|
|
109
|
-
</div>
|
|
110
|
-
))}
|
|
111
|
-
</div>
|
|
112
|
-
);
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
header: "PO ID",
|
|
117
|
-
accessorKey: "poId",
|
|
118
|
-
id: "poId",
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
header: "Job ID",
|
|
122
|
-
accessorKey: "jobId",
|
|
123
|
-
id: "jobId",
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
header: "Reference",
|
|
127
|
-
accessorKey: "reference",
|
|
128
|
-
id: "reference",
|
|
129
|
-
meta: {
|
|
130
|
-
className: "hidden md:table-cell",
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
header: "Status",
|
|
135
|
-
accessorKey: "shipToStatus",
|
|
136
|
-
id: "shipToStatus",
|
|
137
|
-
meta: {
|
|
138
|
-
filterVariant: "select",
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
header: "Ordered date",
|
|
143
|
-
accessorKey: "orderedDate",
|
|
144
|
-
id: "orderedDate",
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
header: "Reference 1",
|
|
148
|
-
accessorKey: "reference1",
|
|
149
|
-
id: "reference1",
|
|
150
|
-
meta: { className: "hidden md:table-cell" },
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
header: "Reference 12",
|
|
154
|
-
accessorKey: "reference12",
|
|
155
|
-
id: "reference12",
|
|
156
|
-
meta: { className: "hidden md:table-cell" },
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
header: "Reference 13",
|
|
160
|
-
accessorKey: "reference13",
|
|
161
|
-
id: "reference13",
|
|
162
|
-
meta: { className: "hidden md:table-cell" },
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
header: "Reference 14",
|
|
166
|
-
accessorKey: "reference14",
|
|
167
|
-
id: "reference14",
|
|
168
|
-
meta: { className: "hidden md:table-cell" },
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
header: "Reference 15",
|
|
172
|
-
accessorKey: "reference15",
|
|
173
|
-
id: "reference15",
|
|
174
|
-
meta: { className: "hidden md:table-cell" },
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
header: "Reference 16",
|
|
178
|
-
accessorKey: "reference16",
|
|
179
|
-
id: "reference16",
|
|
180
|
-
meta: { className: "hidden md:table-cell" },
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
header: "Reference 17",
|
|
184
|
-
accessorKey: "reference17",
|
|
185
|
-
id: "reference17",
|
|
186
|
-
meta: { className: "hidden md:table-cell" },
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
header: "Reference 18",
|
|
190
|
-
accessorKey: "reference18",
|
|
191
|
-
id: "reference18",
|
|
192
|
-
meta: { className: "hidden md:table-cell" },
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
header: "Reference 19",
|
|
196
|
-
accessorKey: "reference19",
|
|
197
|
-
id: "reference19",
|
|
198
|
-
meta: { className: "hidden md:table-cell" },
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
header: "Reference 10",
|
|
202
|
-
accessorKey: "reference10",
|
|
203
|
-
id: "reference10",
|
|
204
|
-
meta: { className: "hidden md:table-cell" },
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
header: "Reference 11",
|
|
208
|
-
accessorKey: "reference11",
|
|
209
|
-
id: "reference11",
|
|
210
|
-
meta: { className: "hidden md:table-cell" },
|
|
211
|
-
},
|
|
212
|
-
];
|
|
213
|
-
|
|
214
|
-
const EditingContext = createContext<{
|
|
215
|
-
data: OrderRow[];
|
|
216
|
-
setValue: (row: number, key: string, value: string) => void;
|
|
217
|
-
}>({
|
|
218
|
-
data: [],
|
|
219
|
-
setValue: (row: number, key: string, value: string) => {},
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
type EditingProviderProps = PropsWithChildren<{ data: OrderRow[] }>;
|
|
223
|
-
|
|
224
|
-
export const EditingProvider = ({ data, children }: EditingProviderProps) => {
|
|
225
|
-
const [actual, setData] = useState(data);
|
|
226
|
-
const context = {
|
|
227
|
-
data: actual,
|
|
228
|
-
setValue: (row: number, key: string, value: string) => {
|
|
229
|
-
setData((prev) => {
|
|
230
|
-
const newData = [...prev];
|
|
231
|
-
newData[row] = {
|
|
232
|
-
...newData[row],
|
|
233
|
-
[key]: value,
|
|
234
|
-
};
|
|
235
|
-
return newData;
|
|
236
|
-
});
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
return (
|
|
240
|
-
<EditingContext.Provider value={context}>
|
|
241
|
-
{children}
|
|
242
|
-
</EditingContext.Provider>
|
|
243
|
-
);
|
|
244
|
-
};
|
|
245
|
-
export const DataTable = ({ id, data }: DataTableProps) => {
|
|
246
|
-
return (
|
|
247
|
-
<EditingProvider data={data}>
|
|
248
|
-
<DataTableInternals id={id} />
|
|
249
|
-
</EditingProvider>
|
|
250
|
-
);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const DraggableTableHeader = ({
|
|
254
|
-
header,
|
|
255
|
-
id,
|
|
256
|
-
}: {
|
|
257
|
-
header: Header<OrderRow, unknown>;
|
|
258
|
-
id?: string;
|
|
259
|
-
}) => {
|
|
260
|
-
const { attributes, isDragging, listeners, setNodeRef, transform } =
|
|
261
|
-
useSortable({
|
|
262
|
-
id: header.column.id,
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
const style: CSSProperties = {
|
|
266
|
-
opacity: isDragging ? 0.8 : 1,
|
|
267
|
-
position: "relative",
|
|
268
|
-
transform: CSS.Translate.toString(transform),
|
|
269
|
-
transition: "width transform 0.2s ease-in-out",
|
|
270
|
-
whiteSpace: "nowrap",
|
|
271
|
-
width: header.column.getSize(),
|
|
272
|
-
zIndex: isDragging ? 1 : 0,
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
return (
|
|
276
|
-
<th
|
|
277
|
-
id={id}
|
|
278
|
-
colSpan={header.colSpan}
|
|
279
|
-
ref={setNodeRef}
|
|
280
|
-
style={style}
|
|
281
|
-
className={clsx(
|
|
282
|
-
header.column.columnDef.meta?.className,
|
|
283
|
-
"px-3 py-3.5 text-left text-sm font-semibold text-dmsi-white bg-dmsi-red ",
|
|
284
|
-
{
|
|
285
|
-
"sticky left-0": header.column.columnDef.meta?.sticky ?? false,
|
|
286
|
-
},
|
|
287
|
-
)}
|
|
288
|
-
>
|
|
289
|
-
{header.isPlaceholder ? null : (
|
|
290
|
-
<div className="flex space-x-1 justify-start items-center">
|
|
291
|
-
<button
|
|
292
|
-
id={id ? `${id}-drag-handle` : undefined}
|
|
293
|
-
className="cursor-grab shrink-0"
|
|
294
|
-
{...attributes}
|
|
295
|
-
{...listeners}
|
|
296
|
-
>
|
|
297
|
-
<i className="w-3 h-3" />
|
|
298
|
-
</button>
|
|
299
|
-
|
|
300
|
-
<div
|
|
301
|
-
className={clsx(
|
|
302
|
-
"grow",
|
|
303
|
-
header.column.getCanSort() ? "cursor-pointer select-none" : "",
|
|
304
|
-
"flex flex-col gap-1 justify-between items-start",
|
|
305
|
-
)}
|
|
306
|
-
title={
|
|
307
|
-
header.column.getCanSort()
|
|
308
|
-
? header.column.getNextSortingOrder() === "asc"
|
|
309
|
-
? "Sort ascending"
|
|
310
|
-
: header.column.getNextSortingOrder() === "desc"
|
|
311
|
-
? "Sort descending"
|
|
312
|
-
: "Clear sort"
|
|
313
|
-
: undefined
|
|
314
|
-
}
|
|
315
|
-
>
|
|
316
|
-
<div>
|
|
317
|
-
{flexRender(header.column.columnDef.header, header.getContext())}
|
|
318
|
-
</div>
|
|
319
|
-
<div>
|
|
320
|
-
{header.column.getCanFilter() ? (
|
|
321
|
-
<Filter
|
|
322
|
-
id={id ? `${id}-filter` : undefined}
|
|
323
|
-
column={header.column}
|
|
324
|
-
/>
|
|
325
|
-
) : (
|
|
326
|
-
<div className="invisible">
|
|
327
|
-
<Filter
|
|
328
|
-
id={id ? `${id}-filter` : undefined}
|
|
329
|
-
column={header.column}
|
|
330
|
-
/>
|
|
331
|
-
</div>
|
|
332
|
-
)}
|
|
333
|
-
</div>
|
|
334
|
-
</div>
|
|
335
|
-
<div
|
|
336
|
-
id={id ? `${id}-sort-button` : undefined}
|
|
337
|
-
className="shrink-0 cursor-pointer"
|
|
338
|
-
onClick={header.column.getToggleSortingHandler()}
|
|
339
|
-
>
|
|
340
|
-
{{
|
|
341
|
-
asc: <i className="w-3 h-3" />,
|
|
342
|
-
desc: <i className="w-3 h-3" />,
|
|
343
|
-
}[header.column.getIsSorted() as string] ?? (
|
|
344
|
-
<i className="w-3 h-3" />
|
|
345
|
-
)}
|
|
346
|
-
</div>
|
|
347
|
-
</div>
|
|
348
|
-
)}
|
|
349
|
-
</th>
|
|
350
|
-
);
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
const DragAlongCell = ({
|
|
354
|
-
cell,
|
|
355
|
-
setValue,
|
|
356
|
-
id,
|
|
357
|
-
}: {
|
|
358
|
-
cell: Cell<OrderRow, unknown>;
|
|
359
|
-
setValue: (row: number, key: string, value: string) => void;
|
|
360
|
-
id?: string;
|
|
361
|
-
}) => {
|
|
362
|
-
const { isDragging, setNodeRef, transform } = useSortable({
|
|
363
|
-
id: cell.column.id,
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
const style: CSSProperties = {
|
|
367
|
-
opacity: isDragging ? 0.8 : 1,
|
|
368
|
-
position: "relative",
|
|
369
|
-
transform: CSS.Translate.toString(transform),
|
|
370
|
-
transition: "width transform 0.2s ease-in-out",
|
|
371
|
-
width: cell.column.getSize(),
|
|
372
|
-
zIndex: isDragging ? 1 : 0,
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
return (
|
|
376
|
-
<EditCell
|
|
377
|
-
id={id}
|
|
378
|
-
ref={setNodeRef}
|
|
379
|
-
style={style}
|
|
380
|
-
cell={cell}
|
|
381
|
-
className={clsx(
|
|
382
|
-
cell.column.columnDef.meta?.className ?? "",
|
|
383
|
-
"text-sm whitespace-nowrap text-gray-900 bg-neutral-100",
|
|
384
|
-
{
|
|
385
|
-
"sticky left-0": cell.column.columnDef.meta?.sticky ?? false,
|
|
386
|
-
},
|
|
387
|
-
)}
|
|
388
|
-
setValue={setValue}
|
|
389
|
-
/>
|
|
390
|
-
);
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
const DataTableInternals = ({ id }: { id?: string }) => {
|
|
394
|
-
// use state client bullshit
|
|
395
|
-
|
|
396
|
-
const { data, setValue } = useContext(EditingContext);
|
|
397
|
-
const [columnOrder, setColumnOrder] = React.useState<string[]>(() =>
|
|
398
|
-
columns.map((c) => c.id!),
|
|
399
|
-
);
|
|
400
|
-
const [pagination, setPagination] = useState<PaginationState>({
|
|
401
|
-
pageIndex: 0,
|
|
402
|
-
pageSize: 10,
|
|
403
|
-
});
|
|
404
|
-
const [columnVisibility, setColumnVisibility] = useState(
|
|
405
|
-
columns.reduce(
|
|
406
|
-
(acc, column) => {
|
|
407
|
-
if ("accessorKey" in column) {
|
|
408
|
-
acc[column.accessorKey as string] = true;
|
|
409
|
-
}
|
|
410
|
-
return acc;
|
|
411
|
-
},
|
|
412
|
-
{} as Record<string, boolean>,
|
|
413
|
-
),
|
|
414
|
-
);
|
|
415
|
-
const [sorting, setSorting] = useState<SortingState>([]);
|
|
416
|
-
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]); // can set initial column filter state here
|
|
417
|
-
const table = useReactTable<OrderRow>({
|
|
418
|
-
columns,
|
|
419
|
-
data,
|
|
420
|
-
debugAll: true,
|
|
421
|
-
getCoreRowModel: getCoreRowModel(),
|
|
422
|
-
getFilteredRowModel: getFilteredRowModel(),
|
|
423
|
-
getSortedRowModel: getSortedRowModel(),
|
|
424
|
-
getPaginationRowModel: getPaginationRowModel(),
|
|
425
|
-
onSortingChange: setSorting,
|
|
426
|
-
onColumnFiltersChange: setColumnFilters,
|
|
427
|
-
onPaginationChange: setPagination,
|
|
428
|
-
onColumnVisibilityChange: setColumnVisibility,
|
|
429
|
-
onColumnOrderChange: setColumnOrder,
|
|
430
|
-
state: {
|
|
431
|
-
sorting,
|
|
432
|
-
columnFilters,
|
|
433
|
-
pagination,
|
|
434
|
-
columnVisibility,
|
|
435
|
-
columnOrder,
|
|
436
|
-
},
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
function handleDragEnd(event: DragEndEvent) {
|
|
440
|
-
const { active, over } = event;
|
|
441
|
-
if (active && over && active.id !== over.id) {
|
|
442
|
-
setColumnOrder((columnOrder) => {
|
|
443
|
-
const oldIndex = columnOrder.indexOf(active.id as string);
|
|
444
|
-
const newIndex = columnOrder.indexOf(over.id as string);
|
|
445
|
-
return arrayMove(columnOrder, oldIndex, newIndex);
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
const sensors = useSensors(
|
|
451
|
-
useSensor(MouseSensor, {}),
|
|
452
|
-
useSensor(TouchSensor, {}),
|
|
453
|
-
useSensor(KeyboardSensor, {}),
|
|
454
|
-
);
|
|
455
|
-
|
|
456
|
-
return (
|
|
457
|
-
<DndContext
|
|
458
|
-
collisionDetection={closestCenter}
|
|
459
|
-
modifiers={[restrictToHorizontalAxis]}
|
|
460
|
-
onDragEnd={handleDragEnd}
|
|
461
|
-
sensors={sensors}
|
|
462
|
-
>
|
|
463
|
-
<div id={id}>
|
|
464
|
-
<div
|
|
465
|
-
id={id ? `${id}-column-visibility` : undefined}
|
|
466
|
-
className="border border-gray-300 rounded p-3 m-4 max-w-xl min-w-0"
|
|
467
|
-
>
|
|
468
|
-
<p className="mb-3 font-semibold">Show/Hide Columns</p>
|
|
469
|
-
<div className="grid grid-cols-1 md:grid-cols-3 gap-2">
|
|
470
|
-
{table.getAllColumns().map((column) => (
|
|
471
|
-
<label
|
|
472
|
-
className="cursor-pointer flex flex-row items-center space-x-1"
|
|
473
|
-
key={column.id}
|
|
474
|
-
>
|
|
475
|
-
<Toggle
|
|
476
|
-
id={id ? `${id}-toggle-${column.id}` : undefined}
|
|
477
|
-
enabled={column.getIsVisible()}
|
|
478
|
-
onToggle={(checked) =>
|
|
479
|
-
column.getToggleVisibilityHandler()({
|
|
480
|
-
target: { checked },
|
|
481
|
-
})
|
|
482
|
-
}
|
|
483
|
-
/>
|
|
484
|
-
|
|
485
|
-
<span className="block">
|
|
486
|
-
{column.columnDef.header as ReactNode}
|
|
487
|
-
</span>
|
|
488
|
-
</label>
|
|
489
|
-
))}
|
|
490
|
-
</div>
|
|
491
|
-
</div>
|
|
492
|
-
|
|
493
|
-
<div className="overflow-x-scroll scrollbar-thin">
|
|
494
|
-
<table className="min-w-full divide-x divide-neutral-500">
|
|
495
|
-
<thead>
|
|
496
|
-
{table.getHeaderGroups().map((headerGroup) => (
|
|
497
|
-
<tr key={headerGroup.id}>
|
|
498
|
-
<SortableContext
|
|
499
|
-
items={columnOrder}
|
|
500
|
-
strategy={horizontalListSortingStrategy}
|
|
501
|
-
>
|
|
502
|
-
{headerGroup.headers.map((header) => (
|
|
503
|
-
<DraggableTableHeader
|
|
504
|
-
key={header.id}
|
|
505
|
-
id={id ? `${id}-header-${header.id}` : undefined}
|
|
506
|
-
header={header}
|
|
507
|
-
/>
|
|
508
|
-
))}
|
|
509
|
-
</SortableContext>
|
|
510
|
-
</tr>
|
|
511
|
-
))}
|
|
512
|
-
</thead>
|
|
513
|
-
<tbody>
|
|
514
|
-
{table.getRowModel().rows.map((row) => (
|
|
515
|
-
<tr
|
|
516
|
-
key={row.id}
|
|
517
|
-
className="bg-neutral-100 divide-y divide-neutral-200"
|
|
518
|
-
>
|
|
519
|
-
{row.getVisibleCells().map((cell) => (
|
|
520
|
-
<SortableContext
|
|
521
|
-
key={cell.id}
|
|
522
|
-
items={columnOrder}
|
|
523
|
-
strategy={horizontalListSortingStrategy}
|
|
524
|
-
>
|
|
525
|
-
<DragAlongCell
|
|
526
|
-
key={cell.id}
|
|
527
|
-
id={id ? `${id}-cell-${cell.id}` : undefined}
|
|
528
|
-
cell={cell}
|
|
529
|
-
setValue={setValue}
|
|
530
|
-
/>
|
|
531
|
-
</SortableContext>
|
|
532
|
-
))}
|
|
533
|
-
</tr>
|
|
534
|
-
))}
|
|
535
|
-
</tbody>
|
|
536
|
-
</table>
|
|
537
|
-
</div>
|
|
538
|
-
<div
|
|
539
|
-
id={id ? `${id}-pagination` : undefined}
|
|
540
|
-
className="flex flex-col gap-6 md:flex-row items-center md:gap-2 w-full justify-between p-2"
|
|
541
|
-
>
|
|
542
|
-
<div className="flex flex-row items-center">
|
|
543
|
-
<button
|
|
544
|
-
id={id ? `${id}-first-page` : undefined}
|
|
545
|
-
className={clsx(
|
|
546
|
-
"group flex items-center justify-center h-8 w-8 border border-gray-500/50 text-gray-700 rounded p-1 hover:bg-dmsi-blue hover:text-white transition-colors cursor-pointer border-r-0 rounded-r-none",
|
|
547
|
-
{
|
|
548
|
-
"pointer-events-none": !table.getCanPreviousPage(),
|
|
549
|
-
},
|
|
550
|
-
)}
|
|
551
|
-
onClick={() => table.setPageIndex(0)}
|
|
552
|
-
disabled={!table.getCanPreviousPage()}
|
|
553
|
-
>
|
|
554
|
-
<i className="w-4 h-4 group-disabled:stroke-gray-400" />
|
|
555
|
-
</button>
|
|
556
|
-
<button
|
|
557
|
-
id={id ? `${id}-prev-page` : undefined}
|
|
558
|
-
className={clsx(
|
|
559
|
-
"-mr-px group flex items-center justify-center h-8 w-8 border border-gray-500/50 text-gray-700 p-1 hover:bg-dmsi-blue hover:text-white transition-colors cursor-pointer",
|
|
560
|
-
{
|
|
561
|
-
"pointer-events-none": !table.getCanPreviousPage(),
|
|
562
|
-
},
|
|
563
|
-
)}
|
|
564
|
-
onClick={() => table.previousPage()}
|
|
565
|
-
disabled={!table.getCanPreviousPage()}
|
|
566
|
-
>
|
|
567
|
-
<i className="w-4 h-4 group-disabled:stroke-gray-400" />
|
|
568
|
-
</button>
|
|
569
|
-
{Array.from({ length: Math.min(5, table.getPageCount()) }).map(
|
|
570
|
-
(_, i) => {
|
|
571
|
-
const current = table.getState().pagination.pageIndex;
|
|
572
|
-
const index = current - 2 + i;
|
|
573
|
-
const active = index === current;
|
|
574
|
-
if (index < 0) return null;
|
|
575
|
-
if (index > table.getPageCount() - 1) return null;
|
|
576
|
-
return (
|
|
577
|
-
<button
|
|
578
|
-
key={i}
|
|
579
|
-
id={id ? `${id}-page-${index + 1}` : undefined}
|
|
580
|
-
className={clsx(
|
|
581
|
-
"group h-8 w-8 border-y border-gray-500/50 text-gray-700 p-1 hover:bg-dmsi-blue hover:text-white transition-colors cursor-pointer flex items-center justify-center",
|
|
582
|
-
{
|
|
583
|
-
"bg-neutral-200 border-x": active,
|
|
584
|
-
"border-r-0": !active,
|
|
585
|
-
},
|
|
586
|
-
)}
|
|
587
|
-
onClick={() => table.setPageIndex(index)}
|
|
588
|
-
>
|
|
589
|
-
<span className={clsx({})}>{index + 1}</span>
|
|
590
|
-
</button>
|
|
591
|
-
);
|
|
592
|
-
},
|
|
593
|
-
)}
|
|
594
|
-
<button
|
|
595
|
-
id={id ? `${id}-next-page` : undefined}
|
|
596
|
-
className={clsx(
|
|
597
|
-
"-ml-px group flex items-center justify-center h-8 w-8 border border-gray-500/50 text-gray-700 p-1 hover:bg-dmsi-blue hover:text-white transition-colors cursor-pointer border-r-0 group",
|
|
598
|
-
{
|
|
599
|
-
"pointer-events-none": !table.getCanNextPage(),
|
|
600
|
-
},
|
|
601
|
-
)}
|
|
602
|
-
onClick={() => table.nextPage()}
|
|
603
|
-
disabled={!table.getCanNextPage()}
|
|
604
|
-
>
|
|
605
|
-
<i className="w-4 h-4 group-disabled:stroke-gray-400 " />
|
|
606
|
-
</button>
|
|
607
|
-
<button
|
|
608
|
-
id={id ? `${id}-last-page` : undefined}
|
|
609
|
-
className={clsx(
|
|
610
|
-
"group flex items-center justify-center h-8 w-8 border border-gray-500/50 text-gray-700 rounded rounded-l-none p-1 hover:bg-dmsi-blue hover:text-white transition-colors cursor-pointer",
|
|
611
|
-
{
|
|
612
|
-
"pointer-events-none": !table.getCanNextPage(),
|
|
613
|
-
},
|
|
614
|
-
)}
|
|
615
|
-
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
|
|
616
|
-
disabled={!table.getCanNextPage()}
|
|
617
|
-
>
|
|
618
|
-
<i className="w-4 h-4 group-disabled:stroke-gray-400" />
|
|
619
|
-
</button>
|
|
620
|
-
</div>
|
|
621
|
-
<div className="flex flex-row items-center gap-6">
|
|
622
|
-
<span className="flex items-center gap-1">
|
|
623
|
-
<div>Page</div>
|
|
624
|
-
<strong>
|
|
625
|
-
{table.getState().pagination.pageIndex + 1} of{" "}
|
|
626
|
-
{table.getPageCount()}
|
|
627
|
-
</strong>
|
|
628
|
-
</span>
|
|
629
|
-
<span className="flex items-center gap-2">
|
|
630
|
-
Page:
|
|
631
|
-
<input
|
|
632
|
-
id={id ? `${id}-page-input` : undefined}
|
|
633
|
-
type="number"
|
|
634
|
-
min="1"
|
|
635
|
-
max={table.getPageCount()}
|
|
636
|
-
defaultValue={table.getState().pagination.pageIndex + 1}
|
|
637
|
-
onChange={(e) => {
|
|
638
|
-
const page = e.target.value ? Number(e.target.value) - 1 : 0;
|
|
639
|
-
table.setPageIndex(page);
|
|
640
|
-
}}
|
|
641
|
-
className="border border-gray-500 px-2 py-1 rounded w-16"
|
|
642
|
-
/>
|
|
643
|
-
</span>
|
|
644
|
-
</div>
|
|
645
|
-
<select
|
|
646
|
-
id={id ? `${id}-pagesize-select` : undefined}
|
|
647
|
-
className="border border-gray-500 px-2 py-1 rounded"
|
|
648
|
-
value={table.getState().pagination.pageSize}
|
|
649
|
-
onChange={(e) => {
|
|
650
|
-
table.setPageSize(Number(e.target.value));
|
|
651
|
-
}}
|
|
652
|
-
>
|
|
653
|
-
{[10, 20, 30, 40, 50].map((pageSize) => (
|
|
654
|
-
<option key={pageSize} value={pageSize}>
|
|
655
|
-
Show {pageSize}
|
|
656
|
-
</option>
|
|
657
|
-
))}
|
|
658
|
-
</select>
|
|
659
|
-
</div>
|
|
660
|
-
</div>
|
|
661
|
-
</DndContext>
|
|
662
|
-
);
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
function EditCell({
|
|
666
|
-
className,
|
|
667
|
-
cell,
|
|
668
|
-
setValue,
|
|
669
|
-
style,
|
|
670
|
-
ref,
|
|
671
|
-
id,
|
|
672
|
-
}: {
|
|
673
|
-
className?: string;
|
|
674
|
-
cell: Cell<OrderRow, unknown>;
|
|
675
|
-
setValue: (row: number, key: string, value: string) => void;
|
|
676
|
-
style: CSSProperties;
|
|
677
|
-
ref: (node: HTMLElement | null) => void;
|
|
678
|
-
id?: string;
|
|
679
|
-
}) {
|
|
680
|
-
const [editing, setEditing] = useState(false);
|
|
681
|
-
const value = cell.getValue();
|
|
682
|
-
const isString = typeof value === "string";
|
|
683
|
-
const [editedValue, setEditedValue] = useState<string>(isString ? value : "");
|
|
684
|
-
const onStartEdit = () => {
|
|
685
|
-
if (isString) {
|
|
686
|
-
setEditing(true);
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
const onEditValue = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
690
|
-
setEditedValue(e.target.value);
|
|
691
|
-
};
|
|
692
|
-
const onStopEdit = () => {
|
|
693
|
-
setValue(cell.row.index, cell.column.id, editedValue);
|
|
694
|
-
setEditing(false);
|
|
695
|
-
};
|
|
696
|
-
const onKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
697
|
-
if (e.key === "Enter") {
|
|
698
|
-
onStopEdit();
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
return (
|
|
703
|
-
<td
|
|
704
|
-
id={id}
|
|
705
|
-
key={cell.id}
|
|
706
|
-
className={clsx(
|
|
707
|
-
className,
|
|
708
|
-
cell.column.columnDef.meta?.className ?? "",
|
|
709
|
-
"px-2 py-3 text-sm whitespace-nowrap text-gray-500",
|
|
710
|
-
)}
|
|
711
|
-
style={style}
|
|
712
|
-
ref={ref}
|
|
713
|
-
>
|
|
714
|
-
{isString && editing && (
|
|
715
|
-
<div className="flex flex-row gap-1">
|
|
716
|
-
<input
|
|
717
|
-
id={id ? `${id}-input` : undefined}
|
|
718
|
-
type="text"
|
|
719
|
-
value={editedValue}
|
|
720
|
-
onChange={onEditValue}
|
|
721
|
-
onKeyUp={onKeyUp}
|
|
722
|
-
onBlur={onStopEdit}
|
|
723
|
-
className="border px-2 py-0.5 rounded inline min-w-0 shrink border-neutral-400 focus:outline-neutral-300 bg-white"
|
|
724
|
-
/>
|
|
725
|
-
<button
|
|
726
|
-
id={id ? `${id}-save-button` : undefined}
|
|
727
|
-
onClick={onStopEdit}
|
|
728
|
-
className="border cursor-pointer px-2 py-0.5 rounded flex items-center justify-center w-12 border-dmsi-blue text-dmsi-blue bg-white"
|
|
729
|
-
>
|
|
730
|
-
Save
|
|
731
|
-
</button>
|
|
732
|
-
</div>
|
|
733
|
-
)}
|
|
734
|
-
{!editing && (
|
|
735
|
-
<div
|
|
736
|
-
onClick={onStartEdit}
|
|
737
|
-
className="px-2 py-1 flex flex-row items-center"
|
|
738
|
-
>
|
|
739
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
740
|
-
<div className="w-16"></div>
|
|
741
|
-
</div>
|
|
742
|
-
)}
|
|
743
|
-
</td>
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
function Filter({ column, id }: { column: Column<OrderRow>; id?: string }) {
|
|
748
|
-
const columnFilterValue = column.getFilterValue();
|
|
749
|
-
|
|
750
|
-
const { filterVariant } = column.columnDef.meta ?? {};
|
|
751
|
-
|
|
752
|
-
return filterVariant === "range" ? (
|
|
753
|
-
<div id={id}>
|
|
754
|
-
<div className="flex space-x-2">
|
|
755
|
-
{/* See faceted column filters example for min max values functionality */}
|
|
756
|
-
<input
|
|
757
|
-
id={id ? `${id}-min` : undefined}
|
|
758
|
-
className="block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-neutral-400 sm:text-sm/6"
|
|
759
|
-
type="number"
|
|
760
|
-
value={(columnFilterValue as [number, number])?.[0] ?? ""}
|
|
761
|
-
onChange={(e) =>
|
|
762
|
-
column.setFilterValue((old: [number, number]) => [
|
|
763
|
-
e.target.value,
|
|
764
|
-
old?.[1],
|
|
765
|
-
])
|
|
766
|
-
}
|
|
767
|
-
autoComplete="off"
|
|
768
|
-
placeholder={`Min`}
|
|
769
|
-
/>
|
|
770
|
-
<input
|
|
771
|
-
id={id ? `${id}-max` : undefined}
|
|
772
|
-
className="block w-full rounded-md bg-white px-3 py-0.5 text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-neutral-400 sm:text-sm/6"
|
|
773
|
-
type="number"
|
|
774
|
-
value={(columnFilterValue as [number, number])?.[1] ?? ""}
|
|
775
|
-
onChange={(e) =>
|
|
776
|
-
column.setFilterValue((old: [number, number]) => [
|
|
777
|
-
old?.[0],
|
|
778
|
-
e.target.value,
|
|
779
|
-
])
|
|
780
|
-
}
|
|
781
|
-
autoComplete="off"
|
|
782
|
-
placeholder={`Max`}
|
|
783
|
-
/>
|
|
784
|
-
</div>
|
|
785
|
-
<div className="h-1" />
|
|
786
|
-
</div>
|
|
787
|
-
) : filterVariant === "select" ? (
|
|
788
|
-
<select
|
|
789
|
-
id={id}
|
|
790
|
-
className="block min-w-36 w-full rounded-md bg-white px-2 py-2 text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-neutral-400 sm:text-sm/6"
|
|
791
|
-
onChange={(e) => column.setFilterValue(e.target.value)}
|
|
792
|
-
value={columnFilterValue?.toString()}
|
|
793
|
-
>
|
|
794
|
-
{/* See faceted column filters example for dynamic select options */}
|
|
795
|
-
<option value="">Status: All</option>
|
|
796
|
-
<option value="cancelled">Status: Cancelled</option>
|
|
797
|
-
<option value="pending">Status: Pending</option>
|
|
798
|
-
<option value="shipped">Status: Shipped</option>
|
|
799
|
-
</select>
|
|
800
|
-
) : (
|
|
801
|
-
<input
|
|
802
|
-
id={id}
|
|
803
|
-
className="block min-w-36 w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-neutral-400 sm:text-sm/6"
|
|
804
|
-
onChange={(e) => column.setFilterValue(e.target.value)}
|
|
805
|
-
placeholder={column.columnDef.header?.toString() ?? "..."}
|
|
806
|
-
type="text"
|
|
807
|
-
autoComplete="off"
|
|
808
|
-
value={(columnFilterValue ?? "") as string}
|
|
809
|
-
/>
|
|
810
|
-
// See faceted column filters example for datalist search suggestions
|
|
811
|
-
);
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
// // A typical debounced input react component
|
|
815
|
-
// // This debounce is not working correctly?
|
|
816
|
-
// function DebouncedInput({
|
|
817
|
-
// value: initialValue,
|
|
818
|
-
// onChange,
|
|
819
|
-
// debounce = 500,
|
|
820
|
-
// ...props
|
|
821
|
-
// }: {
|
|
822
|
-
// value: string | number;
|
|
823
|
-
// onChange: (value: string | number) => void;
|
|
824
|
-
// debounce?: number;
|
|
825
|
-
// } & Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange">) {
|
|
826
|
-
// const [value, setValue] = React.useState(initialValue);
|
|
827
|
-
|
|
828
|
-
// React.useEffect(() => {
|
|
829
|
-
// if (value !== initialValue) {
|
|
830
|
-
// setValue(initialValue);
|
|
831
|
-
// }
|
|
832
|
-
// }, [initialValue, setValue, value]);
|
|
833
|
-
|
|
834
|
-
// React.useEffect(() => {
|
|
835
|
-
// if (value === initialValue) {
|
|
836
|
-
// return;
|
|
837
|
-
// }
|
|
838
|
-
|
|
839
|
-
// const timeout = setTimeout(() => {
|
|
840
|
-
// onChange(value);
|
|
841
|
-
// }, debounce);
|
|
842
|
-
|
|
843
|
-
// return () => clearTimeout(timeout);
|
|
844
|
-
// }, [value, debounce, onChange, initialValue]);
|
|
845
|
-
|
|
846
|
-
// return (
|
|
847
|
-
// <input
|
|
848
|
-
// {...props}
|
|
849
|
-
// value={value}
|
|
850
|
-
// onChange={(e) => setValue(e.target.value)}
|
|
851
|
-
// />
|
|
852
|
-
// );
|
|
853
|
-
// }
|
|
854
|
-
|
|
855
|
-
Switch.displayName = "Switch";
|
|
856
|
-
|
|
857
|
-
export default function Toggle({
|
|
858
|
-
enabled,
|
|
859
|
-
onToggle,
|
|
860
|
-
id,
|
|
861
|
-
}: {
|
|
862
|
-
enabled: boolean;
|
|
863
|
-
onToggle: (enabled: boolean) => void;
|
|
864
|
-
id?: string;
|
|
865
|
-
}) {
|
|
866
|
-
return (
|
|
867
|
-
<Switch
|
|
868
|
-
id={id}
|
|
869
|
-
checked={enabled}
|
|
870
|
-
onChange={onToggle}
|
|
871
|
-
className="group relative flex h-4 w-7 cursor-pointer rounded-full p-0.5 transition-colors duration-200 ease-in-out focus:outline-none data-[focus]:outline-1 data-[focus]:outline-white bg-neutral-900/10 data-[checked]:bg-dmsi-blue"
|
|
872
|
-
>
|
|
873
|
-
<span
|
|
874
|
-
aria-hidden="true"
|
|
875
|
-
className="pointer-events-none inline-block size-3 translate-x-0 rounded-full bg-white ring-0 shadow-lg transition duration-200 ease-in-out group-data-[checked]:translate-x-3 group-data-[checked]:shadow-lg"
|
|
876
|
-
/>
|
|
877
|
-
</Switch>
|
|
878
|
-
);
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
Toggle.displayName = "Toggle";
|