@dust-tt/sparkle 0.2.206 → 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.206",
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",
@@ -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,21 +233,47 @@ 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;
@@ -255,7 +282,7 @@ interface CellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
255
282
  description?: string;
256
283
  }
257
284
 
258
- DataTable.Cell = function Cell({
285
+ DataTable.CellContent = function CellContent({
259
286
  children,
260
287
  className,
261
288
  avatarUrl,
@@ -264,44 +291,36 @@ DataTable.Cell = function Cell({
264
291
  iconClassName,
265
292
  description,
266
293
  ...props
267
- }: CellProps) {
294
+ }: CellContentProps) {
268
295
  return (
269
- <td
270
- className={classNames(
271
- "s-whitespace-nowrap s-py-2 s-pl-0.5 s-text-element-800",
272
- 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
+ />
273
314
  )}
274
- {...props}
275
- >
276
315
  <div className="s-flex">
277
- {avatarUrl && (
278
- <Avatar
279
- visual={avatarUrl}
280
- size="xs"
281
- className="s-mr-2"
282
- isRounded={roundedAvatar ?? false}
283
- />
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>
284
321
  )}
285
- {icon && (
286
- <Icon
287
- visual={icon}
288
- size="sm"
289
- className={classNames(
290
- "s-mr-2 s-text-element-600",
291
- iconClassName || ""
292
- )}
293
- />
294
- )}
295
- <div className="s-flex">
296
- <span className="s-text-sm s-text-element-800">{children}</span>
297
- {description && (
298
- <span className="s-pl-2 s-text-sm s-text-element-600">
299
- {description}
300
- </span>
301
- )}
302
- </div>
303
322
  </div>
304
- </td>
323
+ </div>
305
324
  );
306
325
  };
307
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,7 @@ type Data = {
21
23
  avatarUrl?: string;
22
24
  icon?: React.ComponentType<{ className?: string }>;
23
25
  onClick?: () => void;
24
- onMoreClick?: () => void;
26
+ moreMenuItems?: DropdownItemProps[];
25
27
  roundedAvatar?: boolean;
26
28
  };
27
29
 
@@ -37,7 +39,6 @@ export const DataTableExample = () => {
37
39
  avatarUrl: "https://dust.tt/static/droidavatar/Droid_Lime_3.jpg",
38
40
  roundedAvatar: true,
39
41
  onClick: () => console.log("hehe"),
40
- onMoreClick: () => console.log("show more"),
41
42
  },
42
43
  {
43
44
  name: "Design",
@@ -46,6 +47,12 @@ export const DataTableExample = () => {
46
47
  lastUpdated: "2023-07-09",
47
48
  size: "64kb",
48
49
  icon: FolderIcon,
50
+ moreMenuItems: [
51
+ {
52
+ label: "Edit",
53
+ onClick: () => console.log("Edit"),
54
+ },
55
+ ],
49
56
  },
50
57
  {
51
58
  name: "Development",
@@ -75,42 +82,50 @@ export const DataTableExample = () => {
75
82
  accessorKey: "name",
76
83
  header: "Name",
77
84
  cell: (info) => (
78
- <DataTable.Cell
85
+ <DataTable.CellContent
79
86
  avatarUrl={info.row.original.avatarUrl}
80
87
  icon={info.row.original.icon}
81
88
  description={info.row.original.description}
82
89
  roundedAvatar={info.row.original.roundedAvatar}
83
90
  >
84
91
  {info.row.original.name}
85
- </DataTable.Cell>
92
+ </DataTable.CellContent>
86
93
  ),
87
94
  },
88
95
  {
89
96
  accessorKey: "usedBy",
90
97
  header: "Used by",
91
98
  cell: (info) => (
92
- <DataTable.Cell>{info.row.original.usedBy}</DataTable.Cell>
99
+ <DataTable.CellContent>
100
+ {info.row.original.usedBy}
101
+ </DataTable.CellContent>
93
102
  ),
94
103
  },
95
104
  {
96
105
  accessorKey: "addedBy",
97
106
  header: "Added by",
98
107
  cell: (info) => (
99
- <DataTable.Cell>{info.row.original.addedBy}</DataTable.Cell>
108
+ <DataTable.CellContent>
109
+ {info.row.original.addedBy}
110
+ </DataTable.CellContent>
100
111
  ),
101
112
  },
102
113
  {
103
114
  accessorKey: "lastUpdated",
104
115
  header: "Last updated",
105
116
  cell: (info) => (
106
- <DataTable.Cell>{info.row.original.lastUpdated}</DataTable.Cell>
117
+ <DataTable.CellContent>
118
+ {info.row.original.lastUpdated}
119
+ </DataTable.CellContent>
107
120
  ),
108
121
  enableSorting: false,
109
122
  },
110
123
  {
111
124
  accessorKey: "size",
112
125
  header: "Size",
113
- cell: (info) => <DataTable.Cell>{info.row.original.size}</DataTable.Cell>,
126
+ cell: (info) => (
127
+ <DataTable.CellContent>{info.row.original.size}</DataTable.CellContent>
128
+ ),
114
129
  },
115
130
  ];
116
131