@dust-tt/sparkle 0.2.206 → 0.2.207

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",
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,15 +233,22 @@ 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>
@@ -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;
@@ -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",