@dust-tt/sparkle 0.2.205 → 0.2.207-pr

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dust-tt/sparkle",
3
- "version": "0.2.205",
3
+ "version": "0.2.207-pr",
4
4
  "scripts": {
5
5
  "build": "rm -rf dist && rollup -c",
6
6
  "build:with-tw-base": "rollup -c --environment INCLUDE_TW_BASE:true",
@@ -92,4 +92,4 @@
92
92
  "tailwind-scrollbar-hide": "^1.1.7"
93
93
  },
94
94
  "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
95
- }
95
+ }
@@ -10,7 +10,8 @@ import {
10
10
  } from "@tanstack/react-table";
11
11
  import React, { ReactNode, useEffect, useState } from "react";
12
12
 
13
- import { Avatar, MoreIcon } from "@sparkle/index";
13
+ import { DropdownItemProps } from "@sparkle/components/DropdownMenu";
14
+ import { Avatar, DropdownMenu, MoreIcon } from "@sparkle/index";
14
15
  import { ArrowDownIcon, ArrowUpIcon } from "@sparkle/index";
15
16
  import { classNames } from "@sparkle/lib/utils";
16
17
 
@@ -18,7 +19,7 @@ import { Icon } from "./Icon";
18
19
 
19
20
  interface TBaseData {
20
21
  onClick?: () => void;
21
- onMoreClick?: () => void;
22
+ moreMenuItems?: DropdownItemProps[];
22
23
  }
23
24
 
24
25
  interface ColumnBreakpoint {
@@ -119,7 +120,7 @@ export function DataTable<TData extends TBaseData, TValue>({
119
120
  <DataTable.Row
120
121
  key={row.id}
121
122
  onClick={row.original.onClick}
122
- onMoreClick={row.original.onMoreClick}
123
+ moreMenuItems={row.original.moreMenuItems}
123
124
  >
124
125
  {row.getVisibleCells().map((cell) => (
125
126
  <DataTable.Cell
@@ -211,14 +212,14 @@ DataTable.Body = function Body({
211
212
  interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
212
213
  children: ReactNode;
213
214
  onClick?: () => void;
214
- onMoreClick?: () => void;
215
+ moreMenuItems?: DropdownItemProps[];
215
216
  }
216
217
 
217
218
  DataTable.Row = function Row({
218
219
  children,
219
220
  className,
220
221
  onClick,
221
- onMoreClick,
222
+ moreMenuItems,
222
223
  ...props
223
224
  }: RowProps) {
224
225
  return (
@@ -232,69 +233,94 @@ DataTable.Row = function Row({
232
233
  {...props}
233
234
  >
234
235
  {children}
235
- {onMoreClick && (
236
- <td
237
- className="s-w-1 s-cursor-pointer s-pl-1 s-text-element-600"
238
- onClick={(e) => {
239
- e.stopPropagation(); // Prevent row click event
240
- onMoreClick?.();
241
- }}
242
- >
243
- <Icon visual={MoreIcon} size="sm" />
236
+ {moreMenuItems && (
237
+ <td className="s-w-1 s-cursor-pointer s-pl-1 s-text-element-600">
238
+ <DropdownMenu className="s-flex">
239
+ <DropdownMenu.Button
240
+ onClick={(e) => {
241
+ e.stopPropagation();
242
+ }}
243
+ >
244
+ <Icon visual={MoreIcon} size="sm" />
245
+ </DropdownMenu.Button>
246
+ <DropdownMenu.Items origin="topRight" width={220}>
247
+ {moreMenuItems?.map((item, index) => (
248
+ <DropdownMenu.Item key={index} {...item} />
249
+ ))}
250
+ </DropdownMenu.Items>
251
+ </DropdownMenu>
244
252
  </td>
245
253
  )}
246
254
  </tr>
247
255
  );
248
256
  };
249
- interface CellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
257
+
258
+ interface CellProps extends React.HTMLAttributes<HTMLTableCellElement> {
259
+ children: ReactNode;
260
+ }
261
+
262
+ DataTable.Cell = function Cell({ children, className, ...props }: CellProps) {
263
+ return (
264
+ <td
265
+ className={classNames(
266
+ "s-whitespace-nowrap s-py-2 s-pl-0.5 s-text-element-800",
267
+ className || ""
268
+ )}
269
+ {...props}
270
+ >
271
+ {children}
272
+ </td>
273
+ );
274
+ };
275
+
276
+ interface CellContentProps extends React.TdHTMLAttributes<HTMLDivElement> {
250
277
  avatarUrl?: string;
251
278
  icon?: React.ComponentType<{ className?: string }>;
252
279
  iconClassName?: string;
280
+ roundedAvatar?: boolean;
253
281
  children?: ReactNode;
254
282
  description?: string;
255
283
  }
256
284
 
257
- DataTable.Cell = function Cell({
285
+ DataTable.CellContent = function CellContent({
258
286
  children,
259
287
  className,
260
288
  avatarUrl,
289
+ roundedAvatar,
261
290
  icon,
262
291
  iconClassName,
263
292
  description,
264
293
  ...props
265
- }: CellProps) {
294
+ }: CellContentProps) {
266
295
  return (
267
- <td
268
- className={classNames(
269
- "s-whitespace-nowrap s-py-2 s-pl-0.5 s-text-element-800",
270
- className || ""
296
+ <div className={classNames("s-flex s-py-2", className || "")} {...props}>
297
+ {avatarUrl && (
298
+ <Avatar
299
+ visual={avatarUrl}
300
+ size="xs"
301
+ className="s-mr-2"
302
+ isRounded={roundedAvatar ?? false}
303
+ />
304
+ )}
305
+ {icon && (
306
+ <Icon
307
+ visual={icon}
308
+ size="sm"
309
+ className={classNames(
310
+ "s-mr-2 s-text-element-600",
311
+ iconClassName || ""
312
+ )}
313
+ />
271
314
  )}
272
- {...props}
273
- >
274
315
  <div className="s-flex">
275
- {avatarUrl && (
276
- <Avatar visual={avatarUrl} size="xs" className="s-mr-2" />
316
+ <span className="s-text-sm s-text-element-800">{children}</span>
317
+ {description && (
318
+ <span className="s-pl-2 s-text-sm s-text-element-600">
319
+ {description}
320
+ </span>
277
321
  )}
278
- {icon && (
279
- <Icon
280
- visual={icon}
281
- size="sm"
282
- className={classNames(
283
- "s-mr-2 s-text-element-600",
284
- iconClassName || ""
285
- )}
286
- />
287
- )}
288
- <div className="s-flex">
289
- <span className="s-text-sm s-text-element-800">{children}</span>
290
- {description && (
291
- <span className="s-pl-2 s-text-sm s-text-element-600">
292
- {description}
293
- </span>
294
- )}
295
- </div>
296
322
  </div>
297
- </td>
323
+ </div>
298
324
  );
299
325
  };
300
326
 
@@ -3,6 +3,7 @@ import React, {
3
3
  ComponentType,
4
4
  Fragment,
5
5
  JSXElementConstructor,
6
+ MouseEventHandler,
6
7
  MutableRefObject,
7
8
  ReactElement,
8
9
  useContext,
@@ -97,7 +98,7 @@ export interface DropdownButtonProps {
97
98
  className?: string;
98
99
  disabled?: boolean;
99
100
  children?: React.ReactNode;
100
- onClick?: () => void;
101
+ onClick?: MouseEventHandler;
101
102
  }
102
103
 
103
104
  DropdownMenu.Button = function ({
@@ -227,7 +228,7 @@ DropdownMenu.Button = function ({
227
228
  );
228
229
  };
229
230
 
230
- interface DropdownItemProps {
231
+ export interface DropdownItemProps {
231
232
  variant?: "default" | "warning";
232
233
  label: string;
233
234
  description?: string;
@@ -201,6 +201,7 @@ export const CitationsExample = () => (
201
201
  <h2>With zoom effect</h2>
202
202
  <div className="s-flex s-gap-2">
203
203
  <ZoomableImageCitationWrapper
204
+ size="sm"
204
205
  title="With imgSrc"
205
206
  // size="xs"
206
207
  imgSrc="https://dust.tt/static/droidavatar/Droid_Black_4.jpg"
@@ -2,6 +2,8 @@ import type { Meta } from "@storybook/react";
2
2
  import { ColumnDef } from "@tanstack/react-table";
3
3
  import React from "react";
4
4
 
5
+ import { DropdownItemProps } from "@sparkle/components/DropdownMenu";
6
+
5
7
  import { DataTable, FolderIcon } from "../index_with_tw_base";
6
8
 
7
9
  const meta = {
@@ -21,7 +23,8 @@ type Data = {
21
23
  avatarUrl?: string;
22
24
  icon?: React.ComponentType<{ className?: string }>;
23
25
  onClick?: () => void;
24
- onMoreClick?: () => void;
26
+ moreMenuItems?: DropdownItemProps[];
27
+ roundedAvatar?: boolean;
25
28
  };
26
29
 
27
30
  export const DataTableExample = () => {
@@ -34,8 +37,8 @@ export const DataTableExample = () => {
34
37
  lastUpdated: "July 8, 2023",
35
38
  size: "32kb",
36
39
  avatarUrl: "https://dust.tt/static/droidavatar/Droid_Lime_3.jpg",
40
+ roundedAvatar: true,
37
41
  onClick: () => console.log("hehe"),
38
- onMoreClick: () => console.log("show more"),
39
42
  },
40
43
  {
41
44
  name: "Design",
@@ -44,6 +47,12 @@ export const DataTableExample = () => {
44
47
  lastUpdated: "2023-07-09",
45
48
  size: "64kb",
46
49
  icon: FolderIcon,
50
+ moreMenuItems: [
51
+ {
52
+ label: "Edit",
53
+ onClick: () => console.log("Edit"),
54
+ },
55
+ ],
47
56
  },
48
57
  {
49
58
  name: "Development",
@@ -73,41 +82,50 @@ export const DataTableExample = () => {
73
82
  accessorKey: "name",
74
83
  header: "Name",
75
84
  cell: (info) => (
76
- <DataTable.Cell
85
+ <DataTable.CellContent
77
86
  avatarUrl={info.row.original.avatarUrl}
78
87
  icon={info.row.original.icon}
79
88
  description={info.row.original.description}
89
+ roundedAvatar={info.row.original.roundedAvatar}
80
90
  >
81
91
  {info.row.original.name}
82
- </DataTable.Cell>
92
+ </DataTable.CellContent>
83
93
  ),
84
94
  },
85
95
  {
86
96
  accessorKey: "usedBy",
87
97
  header: "Used by",
88
98
  cell: (info) => (
89
- <DataTable.Cell>{info.row.original.usedBy}</DataTable.Cell>
99
+ <DataTable.CellContent>
100
+ {info.row.original.usedBy}
101
+ </DataTable.CellContent>
90
102
  ),
91
103
  },
92
104
  {
93
105
  accessorKey: "addedBy",
94
106
  header: "Added by",
95
107
  cell: (info) => (
96
- <DataTable.Cell>{info.row.original.addedBy}</DataTable.Cell>
108
+ <DataTable.CellContent>
109
+ {info.row.original.addedBy}
110
+ </DataTable.CellContent>
97
111
  ),
98
112
  },
99
113
  {
100
114
  accessorKey: "lastUpdated",
101
115
  header: "Last updated",
102
116
  cell: (info) => (
103
- <DataTable.Cell>{info.row.original.lastUpdated}</DataTable.Cell>
117
+ <DataTable.CellContent>
118
+ {info.row.original.lastUpdated}
119
+ </DataTable.CellContent>
104
120
  ),
105
121
  enableSorting: false,
106
122
  },
107
123
  {
108
124
  accessorKey: "size",
109
125
  header: "Size",
110
- cell: (info) => <DataTable.Cell>{info.row.original.size}</DataTable.Cell>,
126
+ cell: (info) => (
127
+ <DataTable.CellContent>{info.row.original.size}</DataTable.CellContent>
128
+ ),
111
129
  },
112
130
  ];
113
131