@dust-tt/sparkle 0.2.210-rc → 0.2.210-rc74
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 +31 -98
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +31 -98
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/DataTable.tsx +59 -82
- package/dist/cjs/components/WindowUtility.d.ts +0 -15
- package/dist/esm/components/WindowUtility.d.ts +0 -15
- package/src/components/WindowUtility.tsx +0 -67
package/package.json
CHANGED
|
@@ -11,12 +11,11 @@ import {
|
|
|
11
11
|
import React, { ReactNode, useEffect, useState } from "react";
|
|
12
12
|
|
|
13
13
|
import { DropdownItemProps } from "@sparkle/components/DropdownMenu";
|
|
14
|
-
import { Avatar, DropdownMenu,
|
|
14
|
+
import { Avatar, DropdownMenu, MoreIcon } from "@sparkle/index";
|
|
15
15
|
import { ArrowDownIcon, ArrowUpIcon } from "@sparkle/index";
|
|
16
16
|
import { classNames } from "@sparkle/lib/utils";
|
|
17
17
|
|
|
18
18
|
import { Icon } from "./Icon";
|
|
19
|
-
import { breakpoints, useWindowSize } from "./WindowUtility";
|
|
20
19
|
|
|
21
20
|
interface TBaseData {
|
|
22
21
|
onClick?: () => void;
|
|
@@ -37,16 +36,6 @@ interface DataTableProps<TData extends TBaseData, TValue> {
|
|
|
37
36
|
columnsBreakpoints?: ColumnBreakpoint;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
function shouldRenderColumn(
|
|
41
|
-
windowWidth: number,
|
|
42
|
-
breakpoint?: keyof typeof breakpoints
|
|
43
|
-
): boolean {
|
|
44
|
-
if (!breakpoint) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return windowWidth >= breakpoints[breakpoint];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
39
|
export function DataTable<TData extends TBaseData, TValue>({
|
|
51
40
|
data,
|
|
52
41
|
columns,
|
|
@@ -56,7 +45,6 @@ export function DataTable<TData extends TBaseData, TValue>({
|
|
|
56
45
|
initialColumnOrder,
|
|
57
46
|
columnsBreakpoints = {},
|
|
58
47
|
}: DataTableProps<TData, TValue>) {
|
|
59
|
-
const windowSize = useWindowSize();
|
|
60
48
|
const [sorting, setSorting] = useState<SortingState>(
|
|
61
49
|
initialColumnOrder ?? []
|
|
62
50
|
);
|
|
@@ -87,49 +75,43 @@ export function DataTable<TData extends TBaseData, TValue>({
|
|
|
87
75
|
<DataTable.Header>
|
|
88
76
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
89
77
|
<DataTable.Row key={headerGroup.id}>
|
|
90
|
-
{headerGroup.headers.map((header) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
header.column.
|
|
78
|
+
{headerGroup.headers.map((header) => (
|
|
79
|
+
<DataTable.Head
|
|
80
|
+
key={header.id}
|
|
81
|
+
onClick={header.column.getToggleSortingHandler()}
|
|
82
|
+
className={classNames(
|
|
83
|
+
header.column.getCanSort() ? "s-cursor-pointer" : "",
|
|
84
|
+
columnsBreakpoints[header.id]
|
|
85
|
+
? `s-hidden ${columnsBreakpoints[header.id]}:s-block`
|
|
86
|
+
: ""
|
|
87
|
+
)}
|
|
88
|
+
>
|
|
89
|
+
<div className="s-flex s-items-center s-space-x-1 s-whitespace-nowrap">
|
|
90
|
+
{flexRender(
|
|
91
|
+
header.column.columnDef.header,
|
|
92
|
+
header.getContext()
|
|
104
93
|
)}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)}
|
|
127
|
-
/>
|
|
128
|
-
)}
|
|
129
|
-
</div>
|
|
130
|
-
</DataTable.Head>
|
|
131
|
-
);
|
|
132
|
-
})}
|
|
94
|
+
{header.column.getCanSort() && (
|
|
95
|
+
<Icon
|
|
96
|
+
visual={
|
|
97
|
+
header.column.getIsSorted() === "asc"
|
|
98
|
+
? ArrowUpIcon
|
|
99
|
+
: header.column.getIsSorted() === "desc"
|
|
100
|
+
? ArrowDownIcon
|
|
101
|
+
: ArrowDownIcon
|
|
102
|
+
}
|
|
103
|
+
size="xs"
|
|
104
|
+
className={classNames(
|
|
105
|
+
"s-ml-1",
|
|
106
|
+
header.column.getIsSorted()
|
|
107
|
+
? "s-opacity-100"
|
|
108
|
+
: "s-opacity-0"
|
|
109
|
+
)}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
</div>
|
|
113
|
+
</DataTable.Head>
|
|
114
|
+
))}
|
|
133
115
|
</DataTable.Row>
|
|
134
116
|
))}
|
|
135
117
|
</DataTable.Header>
|
|
@@ -140,20 +122,18 @@ export function DataTable<TData extends TBaseData, TValue>({
|
|
|
140
122
|
onClick={row.original.onClick}
|
|
141
123
|
moreMenuItems={row.original.moreMenuItems}
|
|
142
124
|
>
|
|
143
|
-
{row.getVisibleCells().map((cell) =>
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
156
|
-
})}
|
|
125
|
+
{row.getVisibleCells().map((cell) => (
|
|
126
|
+
<DataTable.Cell
|
|
127
|
+
key={cell.id}
|
|
128
|
+
className={classNames(
|
|
129
|
+
columnsBreakpoints[cell.column.id]
|
|
130
|
+
? `s-hidden ${columnsBreakpoints[cell.column.id]}:s-block`
|
|
131
|
+
: ""
|
|
132
|
+
)}
|
|
133
|
+
>
|
|
134
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
135
|
+
</DataTable.Cell>
|
|
136
|
+
))}
|
|
157
137
|
</DataTable.Row>
|
|
158
138
|
))}
|
|
159
139
|
</DataTable.Body>
|
|
@@ -245,23 +225,23 @@ DataTable.Row = function Row({
|
|
|
245
225
|
return (
|
|
246
226
|
<tr
|
|
247
227
|
className={classNames(
|
|
248
|
-
"s-
|
|
249
|
-
onClick ? "s-cursor-pointer hover:s-bg-
|
|
228
|
+
"s-border-b s-border-structure-200 s-text-sm",
|
|
229
|
+
onClick ? "s-cursor-pointer hover:s-bg-gray-50" : "",
|
|
250
230
|
className || ""
|
|
251
231
|
)}
|
|
252
232
|
onClick={onClick ? onClick : undefined}
|
|
253
233
|
{...props}
|
|
254
234
|
>
|
|
255
235
|
{children}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
<DropdownMenu className="s-
|
|
236
|
+
{moreMenuItems && (
|
|
237
|
+
<td className="s-w-1 s-cursor-pointer s-pl-1 s-text-element-600">
|
|
238
|
+
<DropdownMenu className="s-flex">
|
|
259
239
|
<DropdownMenu.Button
|
|
260
240
|
onClick={(e) => {
|
|
261
241
|
e.stopPropagation();
|
|
262
242
|
}}
|
|
263
243
|
>
|
|
264
|
-
<
|
|
244
|
+
<Icon visual={MoreIcon} size="sm" />
|
|
265
245
|
</DropdownMenu.Button>
|
|
266
246
|
<DropdownMenu.Items origin="topRight" width={220}>
|
|
267
247
|
{moreMenuItems?.map((item, index) => (
|
|
@@ -269,8 +249,8 @@ DataTable.Row = function Row({
|
|
|
269
249
|
))}
|
|
270
250
|
</DropdownMenu.Items>
|
|
271
251
|
</DropdownMenu>
|
|
272
|
-
|
|
273
|
-
|
|
252
|
+
</td>
|
|
253
|
+
)}
|
|
274
254
|
</tr>
|
|
275
255
|
);
|
|
276
256
|
};
|
|
@@ -283,7 +263,7 @@ DataTable.Cell = function Cell({ children, className, ...props }: CellProps) {
|
|
|
283
263
|
return (
|
|
284
264
|
<td
|
|
285
265
|
className={classNames(
|
|
286
|
-
"s-
|
|
266
|
+
"s-whitespace-nowrap s-py-2 s-pl-0.5 s-text-element-800",
|
|
287
267
|
className || ""
|
|
288
268
|
)}
|
|
289
269
|
{...props}
|
|
@@ -313,10 +293,7 @@ DataTable.CellContent = function CellContent({
|
|
|
313
293
|
...props
|
|
314
294
|
}: CellContentProps) {
|
|
315
295
|
return (
|
|
316
|
-
<div
|
|
317
|
-
className={classNames("s-flex s-items-center s-py-2", className || "")}
|
|
318
|
-
{...props}
|
|
319
|
-
>
|
|
296
|
+
<div className={classNames("s-flex s-py-2", className || "")} {...props}>
|
|
320
297
|
{avatarUrl && (
|
|
321
298
|
<Avatar
|
|
322
299
|
visual={avatarUrl}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const breakpoints: {
|
|
2
|
-
xs: number;
|
|
3
|
-
sm: number;
|
|
4
|
-
md: number;
|
|
5
|
-
lg: number;
|
|
6
|
-
xl: number;
|
|
7
|
-
xxl: number;
|
|
8
|
-
};
|
|
9
|
-
interface WindowSizeState {
|
|
10
|
-
width: number | undefined;
|
|
11
|
-
height: number | undefined;
|
|
12
|
-
activeBreakpoint: keyof typeof breakpoints;
|
|
13
|
-
}
|
|
14
|
-
export declare function useWindowSize(): WindowSizeState;
|
|
15
|
-
export default useWindowSize;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const breakpoints: {
|
|
2
|
-
xs: number;
|
|
3
|
-
sm: number;
|
|
4
|
-
md: number;
|
|
5
|
-
lg: number;
|
|
6
|
-
xl: number;
|
|
7
|
-
xxl: number;
|
|
8
|
-
};
|
|
9
|
-
interface WindowSizeState {
|
|
10
|
-
width: number | undefined;
|
|
11
|
-
height: number | undefined;
|
|
12
|
-
activeBreakpoint: keyof typeof breakpoints;
|
|
13
|
-
}
|
|
14
|
-
export declare function useWindowSize(): WindowSizeState;
|
|
15
|
-
export default useWindowSize;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
// Define breakpoints
|
|
4
|
-
export const breakpoints = {
|
|
5
|
-
xs: 0,
|
|
6
|
-
sm: 640,
|
|
7
|
-
md: 768,
|
|
8
|
-
lg: 1024,
|
|
9
|
-
xl: 1280,
|
|
10
|
-
xxl: 1536,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// Helper function to determine active breakpoint
|
|
14
|
-
function getActiveBreakpoint(width: number): keyof typeof breakpoints {
|
|
15
|
-
if (width >= breakpoints.xxl) {
|
|
16
|
-
return "xxl";
|
|
17
|
-
}
|
|
18
|
-
if (width >= breakpoints.xl) {
|
|
19
|
-
return "xl";
|
|
20
|
-
}
|
|
21
|
-
if (width >= breakpoints.lg) {
|
|
22
|
-
return "lg";
|
|
23
|
-
}
|
|
24
|
-
if (width >= breakpoints.md) {
|
|
25
|
-
return "md";
|
|
26
|
-
}
|
|
27
|
-
if (width >= breakpoints.sm) {
|
|
28
|
-
return "sm";
|
|
29
|
-
}
|
|
30
|
-
return "xs";
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
interface WindowSizeState {
|
|
35
|
-
width: number | undefined;
|
|
36
|
-
height: number | undefined;
|
|
37
|
-
activeBreakpoint: keyof typeof breakpoints;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Custom hook to get window size and active breakpoint
|
|
41
|
-
export function useWindowSize() {
|
|
42
|
-
const [windowSize, setWindowSize] = useState<WindowSizeState>({
|
|
43
|
-
width: undefined,
|
|
44
|
-
height: undefined,
|
|
45
|
-
activeBreakpoint: "xs"
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
function handleResize() {
|
|
50
|
-
const width = window.innerWidth;
|
|
51
|
-
setWindowSize({
|
|
52
|
-
width,
|
|
53
|
-
height: window.innerHeight,
|
|
54
|
-
activeBreakpoint: getActiveBreakpoint(width),
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
window.addEventListener("resize", handleResize);
|
|
59
|
-
handleResize();
|
|
60
|
-
|
|
61
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
62
|
-
}, []);
|
|
63
|
-
|
|
64
|
-
return windowSize;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default useWindowSize;
|