@dust-tt/sparkle 0.2.210-rc → 0.2.210-rc75
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/components/Tree.d.ts +4 -2
- package/dist/cjs/index.js +46 -105
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/Tree.d.ts +4 -2
- package/dist/esm/index.js +46 -105
- 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/src/components/Tree.tsx +19 -4
- package/src/stories/Tree.stories.tsx +12 -4
- 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}
|
package/src/components/Tree.tsx
CHANGED
|
@@ -11,6 +11,7 @@ export interface TreeProps {
|
|
|
11
11
|
children?: ReactNode;
|
|
12
12
|
isBoxed?: boolean;
|
|
13
13
|
isLoading?: boolean;
|
|
14
|
+
tailwindIconTextColor?: string;
|
|
14
15
|
variant?: "navigator" | "finder";
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -18,11 +19,23 @@ export function Tree({
|
|
|
18
19
|
children,
|
|
19
20
|
isLoading,
|
|
20
21
|
isBoxed = false,
|
|
22
|
+
tailwindIconTextColor,
|
|
21
23
|
variant = "finder",
|
|
22
24
|
}: TreeProps) {
|
|
23
25
|
const modifiedChildren = React.Children.map(children, (child) => {
|
|
24
|
-
if (React.isValidElement<TreeItemProps>(child)
|
|
25
|
-
|
|
26
|
+
if (React.isValidElement<TreeItemProps>(child)) {
|
|
27
|
+
// Clone the child element and pass the necessary props
|
|
28
|
+
const childProps: Partial<TreeItemProps> = {};
|
|
29
|
+
|
|
30
|
+
if (variant === "navigator") {
|
|
31
|
+
childProps.isNavigatable = true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (tailwindIconTextColor) {
|
|
35
|
+
childProps.tailwindIconTextColor = tailwindIconTextColor;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return React.cloneElement(child, childProps);
|
|
26
39
|
}
|
|
27
40
|
return child;
|
|
28
41
|
});
|
|
@@ -36,7 +49,7 @@ export function Tree({
|
|
|
36
49
|
className={classNames(
|
|
37
50
|
"s-flex s-flex-col s-gap-1 s-overflow-hidden",
|
|
38
51
|
isBoxed
|
|
39
|
-
? "s-
|
|
52
|
+
? "s-rounded-xl s-border s-border-structure-200 s-bg-structure-50 s-p-4"
|
|
40
53
|
: ""
|
|
41
54
|
)}
|
|
42
55
|
>
|
|
@@ -49,6 +62,7 @@ interface TreeItemProps {
|
|
|
49
62
|
label?: string;
|
|
50
63
|
type?: "node" | "item" | "leaf";
|
|
51
64
|
size?: "sm" | "md";
|
|
65
|
+
tailwindIconTextColor?: string;
|
|
52
66
|
visual?: ComponentType<{ className?: string }>;
|
|
53
67
|
checkbox?: CheckboxProps;
|
|
54
68
|
onChevronClick?: () => void;
|
|
@@ -77,6 +91,7 @@ Tree.Item = function ({
|
|
|
77
91
|
type = "node",
|
|
78
92
|
className = "",
|
|
79
93
|
size = "sm",
|
|
94
|
+
tailwindIconTextColor = "s-text-element-600",
|
|
80
95
|
visual,
|
|
81
96
|
checkbox,
|
|
82
97
|
onChevronClick,
|
|
@@ -165,7 +180,7 @@ Tree.Item = function ({
|
|
|
165
180
|
<Icon
|
|
166
181
|
visual={visual}
|
|
167
182
|
size={size === "sm" ? "sm" : "md"}
|
|
168
|
-
className="s-flex-shrink-0
|
|
183
|
+
className={classNames("s-flex-shrink-0", tailwindIconTextColor)}
|
|
169
184
|
/>
|
|
170
185
|
|
|
171
186
|
<div
|
|
@@ -265,7 +265,7 @@ export const TreeExample = () => {
|
|
|
265
265
|
isSelected={true}
|
|
266
266
|
size="md"
|
|
267
267
|
>
|
|
268
|
-
<Tree variant="navigator">
|
|
268
|
+
<Tree variant="navigator" tailwindIconTextColor="s-text-brand">
|
|
269
269
|
<Tree.Item label="item 1" visual={FolderIcon}>
|
|
270
270
|
<Tree variant="navigator">
|
|
271
271
|
<Tree.Item label="item 1" visual={FolderIcon} />
|
|
@@ -273,14 +273,22 @@ export const TreeExample = () => {
|
|
|
273
273
|
<Tree.Item label="item 3" visual={FolderIcon} />
|
|
274
274
|
</Tree>
|
|
275
275
|
</Tree.Item>
|
|
276
|
-
<Tree.Item
|
|
276
|
+
<Tree.Item
|
|
277
|
+
label="item 2"
|
|
278
|
+
visual={FolderIcon}
|
|
279
|
+
tailwindIconTextColor="s-text-brand"
|
|
280
|
+
>
|
|
277
281
|
<Tree variant="navigator">
|
|
278
282
|
<Tree.Item label="item 1" visual={FolderIcon} />
|
|
279
283
|
<Tree.Item label="item 2" visual={FolderIcon} />
|
|
280
284
|
<Tree.Item label="item 3" visual={FolderIcon} />
|
|
281
285
|
</Tree>
|
|
282
286
|
</Tree.Item>
|
|
283
|
-
<Tree.Item
|
|
287
|
+
<Tree.Item
|
|
288
|
+
label="item 3"
|
|
289
|
+
visual={FolderIcon}
|
|
290
|
+
tailwindIconTextColor="s-text-brand"
|
|
291
|
+
>
|
|
284
292
|
<Tree variant="navigator">
|
|
285
293
|
<Tree.Item label="item 1" visual={FolderIcon} />
|
|
286
294
|
<Tree.Item label="item 2" visual={FolderIcon} />
|
|
@@ -583,7 +591,7 @@ export const TreeExample = () => {
|
|
|
583
591
|
onItemClick={() => console.log("Clickable")}
|
|
584
592
|
isSelected={true}
|
|
585
593
|
>
|
|
586
|
-
<Tree>
|
|
594
|
+
<Tree tailwindIconTextColor="s-text-brand">
|
|
587
595
|
<Tree.Item label="item 1" visual={FolderIcon}>
|
|
588
596
|
<Tree>
|
|
589
597
|
<Tree.Item label="item 1" visual={FolderIcon} />
|
|
@@ -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;
|