@dust-tt/sparkle 0.2.455 → 0.2.456

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.
@@ -8,6 +8,8 @@ import {
8
8
  getPaginationRowModel,
9
9
  getSortedRowModel,
10
10
  PaginationState,
11
+ Row,
12
+ RowSelectionState,
11
13
  type SortingState,
12
14
  Updater,
13
15
  useReactTable,
@@ -18,6 +20,7 @@ import React, { ReactNode, useEffect, useRef, useState } from "react";
18
20
  import {
19
21
  Avatar,
20
22
  Button,
23
+ Checkbox,
21
24
  DropdownMenu,
22
25
  DropdownMenuContent,
23
26
  DropdownMenuGroup,
@@ -95,6 +98,9 @@ interface DataTableProps<TData extends TBaseData> {
95
98
  setSorting?: (sorting: SortingState) => void;
96
99
  isServerSideSorting?: boolean;
97
100
  disablePaginationNumbers?: boolean;
101
+ rowSelection?: RowSelectionState;
102
+ setRowSelection?: (rowSelection: RowSelectionState) => void;
103
+ enableRowSelection?: boolean | ((row: Row<TData>) => boolean);
98
104
  }
99
105
 
100
106
  export function DataTable<TData extends TBaseData>({
@@ -113,6 +119,9 @@ export function DataTable<TData extends TBaseData>({
113
119
  setSorting,
114
120
  isServerSideSorting = false,
115
121
  disablePaginationNumbers = false,
122
+ rowSelection,
123
+ setRowSelection,
124
+ enableRowSelection = false,
116
125
  }: DataTableProps<TData>) {
117
126
  const windowSize = useWindowSize();
118
127
 
@@ -140,6 +149,15 @@ export function DataTable<TData extends TBaseData>({
140
149
  }
141
150
  : undefined;
142
151
 
152
+ const onRowSelectionChange =
153
+ rowSelection && setRowSelection
154
+ ? (updater: Updater<RowSelectionState>) => {
155
+ const newValue =
156
+ typeof updater === "function" ? updater(rowSelection) : updater;
157
+ setRowSelection(newValue);
158
+ }
159
+ : undefined;
160
+
143
161
  const table = useReactTable({
144
162
  data,
145
163
  columns,
@@ -157,17 +175,20 @@ export function DataTable<TData extends TBaseData>({
157
175
  getFilteredRowModel: getFilteredRowModel(),
158
176
  getPaginationRowModel: pagination ? getPaginationRowModel() : undefined,
159
177
  onColumnFiltersChange: setColumnFilters,
178
+ onRowSelectionChange,
160
179
  state: {
161
180
  columnFilters,
162
181
  ...(isServerSideSorting && {
163
182
  sorting,
164
183
  }),
165
184
  pagination,
185
+ rowSelection,
166
186
  },
167
187
  initialState: {
168
188
  sorting,
169
189
  },
170
190
  onPaginationChange,
191
+ enableRowSelection,
171
192
  });
172
193
 
173
194
  useEffect(() => {
@@ -235,6 +256,7 @@ export function DataTable<TData extends TBaseData>({
235
256
  widthClassName={widthClassName}
236
257
  key={row.id}
237
258
  onClick={row.original.onClick}
259
+ data-selected={row.getIsSelected()}
238
260
  >
239
261
  {row.getVisibleCells().map((cell) => {
240
262
  const breakpoint = columnsBreakpoints[cell.column.id];
@@ -291,6 +313,9 @@ export function ScrollableDataTable<TData extends TBaseData>({
291
313
  maxHeight = "s-h-100",
292
314
  onLoadMore,
293
315
  isLoading = false,
316
+ rowSelection,
317
+ setRowSelection,
318
+ enableRowSelection,
294
319
  }: ScrollableDataTableProps<TData>) {
295
320
  const windowSize = useWindowSize();
296
321
  const tableContainerRef = useRef<HTMLDivElement>(null);
@@ -316,12 +341,26 @@ export function ScrollableDataTable<TData extends TBaseData>({
316
341
  };
317
342
  }, []);
318
343
 
344
+ const onRowSelectionChange =
345
+ rowSelection && setRowSelection
346
+ ? (updater: Updater<RowSelectionState>) => {
347
+ const newValue =
348
+ typeof updater === "function" ? updater(rowSelection) : updater;
349
+ setRowSelection(newValue);
350
+ }
351
+ : undefined;
352
+
319
353
  const table = useReactTable({
320
354
  data,
321
355
  columns,
322
356
  rowCount: totalRowCount,
323
357
  getCoreRowModel: getCoreRowModel(),
324
358
  enableColumnResizing: true,
359
+ onRowSelectionChange,
360
+ enableRowSelection,
361
+ state: {
362
+ rowSelection,
363
+ },
325
364
  });
326
365
 
327
366
  useEffect(() => {
@@ -466,6 +505,7 @@ export function ScrollableDataTable<TData extends TBaseData>({
466
505
  widthClassName={widthClassName}
467
506
  onClick={row.original.onClick}
468
507
  className="s-absolute s-w-full"
508
+ data-selected={row.getIsSelected()}
469
509
  style={{
470
510
  transform: `translateY(${virtualRow.start}px)`,
471
511
  }}
@@ -616,6 +656,7 @@ interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
616
656
  children: ReactNode;
617
657
  onClick?: () => void;
618
658
  widthClassName: string;
659
+ "data-selected"?: boolean;
619
660
  }
620
661
 
621
662
  DataTable.Row = function Row({
@@ -633,6 +674,8 @@ DataTable.Row = function Row({
633
674
  onClick
634
675
  ? "s-cursor-pointer hover:s-bg-muted dark:hover:s-bg-muted-night"
635
676
  : "",
677
+ props["data-selected"] &&
678
+ "s-bg-highlight-50 dark:s-bg-highlight-900/10",
636
679
  widthClassName,
637
680
  className
638
681
  )}
@@ -1013,3 +1056,47 @@ DataTable.Caption = function Caption({
1013
1056
  </caption>
1014
1057
  );
1015
1058
  };
1059
+
1060
+ export function createSelectionColumn<TData>(): ColumnDef<TData> {
1061
+ return {
1062
+ id: "select",
1063
+ enableSorting: false,
1064
+ enableHiding: false,
1065
+ header: ({ table }) => (
1066
+ <Checkbox
1067
+ size="xs"
1068
+ checked={
1069
+ table.getIsAllRowsSelected()
1070
+ ? true
1071
+ : table.getIsSomeRowsSelected()
1072
+ ? "partial"
1073
+ : false
1074
+ }
1075
+ onCheckedChange={(state) => {
1076
+ if (state === "indeterminate") {
1077
+ return;
1078
+ }
1079
+ table.toggleAllRowsSelected(state);
1080
+ }}
1081
+ />
1082
+ ),
1083
+ cell: ({ row }) => (
1084
+ <div className="s-flex s-h-full s-w-full s-items-center">
1085
+ <Checkbox
1086
+ size="xs"
1087
+ checked={row.getIsSelected()}
1088
+ disabled={!row.getCanSelect()}
1089
+ onCheckedChange={(state) => {
1090
+ if (state === "indeterminate") {
1091
+ return;
1092
+ }
1093
+ row.toggleSelected(state);
1094
+ }}
1095
+ />
1096
+ </div>
1097
+ ),
1098
+ meta: {
1099
+ className: "s-w-10",
1100
+ },
1101
+ };
1102
+ }
@@ -87,7 +87,6 @@ export { Div3D, Hover3D } from "./Hover3D";
87
87
  export { Hoverable } from "./Hoverable";
88
88
  export { Icon } from "./Icon";
89
89
  export { IconButton } from "./IconButton";
90
- export { IconToggleButton } from "./IconToggleButton";
91
90
  export { Input } from "./Input";
92
91
  export { Label } from "./Label";
93
92
  export type { LinkWrapperProps } from "./LinkWrapper";
@@ -2,6 +2,7 @@ import type { Meta } from "@storybook/react";
2
2
  import {
3
3
  ColumnDef,
4
4
  PaginationState,
5
+ RowSelectionState,
5
6
  SortingState,
6
7
  } from "@tanstack/react-table";
7
8
  import React, { useCallback, useMemo, useState } from "react";
@@ -19,7 +20,7 @@ import {
19
20
  Input,
20
21
  ScrollableDataTable,
21
22
  } from "@sparkle/components/";
22
- import { MenuItem } from "@sparkle/components/DataTable";
23
+ import { createSelectionColumn, MenuItem } from "@sparkle/components/DataTable";
23
24
  import { FolderIcon } from "@sparkle/icons";
24
25
 
25
26
  const meta = {
@@ -45,6 +46,7 @@ type Data = {
45
46
  React.ComponentPropsWithoutRef<typeof DropdownMenu>,
46
47
  "modal"
47
48
  >;
49
+ id?: number;
48
50
  roundedAvatar?: boolean;
49
51
  };
50
52
 
@@ -529,6 +531,7 @@ const createData = (start: number, count: number) => {
529
531
  return Array(count)
530
532
  .fill(0)
531
533
  .map((_, i) => ({
534
+ id: i,
532
535
  name: `Item ${start + i + 1}`,
533
536
  usedBy: Math.floor(Math.random() * 100),
534
537
  addedBy: `UserUserUserUserUserUserUserUserUserUserUser ${Math.floor(Math.random() * 10) + 1}`,
@@ -542,6 +545,7 @@ const createData = (start: number, count: number) => {
542
545
 
543
546
  export const ScrollableDataTableExample = () => {
544
547
  const [filter, setFilter] = useState("");
548
+ const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
545
549
  const [data, setData] = useState(() => createData(0, 50));
546
550
  const [isLoading, setIsLoading] = useState(false);
547
551
 
@@ -559,6 +563,11 @@ export const ScrollableDataTableExample = () => {
559
563
  const columnsWithSize = columns.map((column, index) => {
560
564
  return { ...column, meta: { sizeRatio: index % 2 === 0 ? 15 : 10 } };
561
565
  });
566
+
567
+ const columnsWithSelection: ColumnDef<Data>[] = useMemo(
568
+ () => [createSelectionColumn<Data>(), ...columnsWithSize],
569
+ []
570
+ );
562
571
  return (
563
572
  <div className="s-flex s-w-full s-max-w-4xl s-flex-col s-gap-6">
564
573
  <h3 className="s-text-lg s-font-medium">
@@ -577,10 +586,13 @@ export const ScrollableDataTableExample = () => {
577
586
  data={data}
578
587
  filter={filter}
579
588
  filterColumn="name"
580
- columns={columnsWithSize}
589
+ columns={columnsWithSelection}
581
590
  onLoadMore={loadMore}
582
591
  isLoading={isLoading}
583
592
  maxHeight="s-max-h-[500px]"
593
+ rowSelection={rowSelection}
594
+ setRowSelection={setRowSelection}
595
+ enableRowSelection={true}
584
596
  />
585
597
 
586
598
  <div className="s-text-sm s-text-muted-foreground">
@@ -590,3 +602,49 @@ export const ScrollableDataTableExample = () => {
590
602
  </div>
591
603
  );
592
604
  };
605
+
606
+ export const DataTableWithRowSelectionExample = () => {
607
+ const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
608
+ const [data] = useState<Data[]>(() => createData(0, 10));
609
+ const [filter, setFilter] = useState("");
610
+
611
+ const columnsWithSelection: ColumnDef<Data>[] = useMemo(
612
+ () => [createSelectionColumn<Data>(), ...columns],
613
+ []
614
+ );
615
+
616
+ return (
617
+ <div className="s-flex s-w-full s-max-w-4xl s-flex-col s-gap-6">
618
+ <h3 className="s-text-lg s-font-medium">DataTable with Row Selection</h3>
619
+
620
+ <div className="s-flex s-flex-col s-gap-4">
621
+ <Input
622
+ name="filter"
623
+ placeholder="Filter"
624
+ value={filter}
625
+ onChange={(e) => setFilter(e.target.value)}
626
+ />
627
+
628
+ <DataTable
629
+ data={data}
630
+ filter={filter}
631
+ filterColumn="name"
632
+ columns={columnsWithSelection}
633
+ rowSelection={rowSelection}
634
+ setRowSelection={setRowSelection}
635
+ enableRowSelection={true}
636
+ />
637
+
638
+ <div className="s-rounded-md s-border s-bg-muted/50 s-p-2">
639
+ <h4 className="s-mb-2 s-font-medium">Selection State:</h4>
640
+ <pre className="s-overflow-auto s-text-xs">
641
+ {JSON.stringify(rowSelection, null, 2)}
642
+ </pre>
643
+ <p className="s-mt-2 s-text-sm">
644
+ Selected {Object.keys(rowSelection).length} of {data.length} rows
645
+ </p>
646
+ </div>
647
+ </div>
648
+ </div>
649
+ );
650
+ };
@@ -1,17 +0,0 @@
1
- import React, { ComponentType, MouseEventHandler } from "react";
2
- import { Tooltip } from "./Tooltip";
3
- type IconToggleButtonProps = {
4
- variant?: "secondary" | "tertiary";
5
- onClick?: MouseEventHandler<HTMLButtonElement>;
6
- size?: "xs" | "sm" | "md";
7
- tooltip?: string;
8
- tooltipPosition?: React.ComponentProps<typeof Tooltip>["side"];
9
- icon: ComponentType;
10
- iconSelected?: ComponentType;
11
- className?: string;
12
- disabled?: boolean;
13
- selected?: boolean;
14
- };
15
- export declare function IconToggleButton({ variant, onClick, disabled, tooltip, tooltipPosition, icon, iconSelected, className, selected, size, }: IconToggleButtonProps): React.JSX.Element;
16
- export {};
17
- //# sourceMappingURL=IconToggleButton.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IconToggleButton.d.ts","sourceRoot":"","sources":["../../../src/components/IconToggleButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKhE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,KAAK,qBAAqB,GAAG;IAC3B,OAAO,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;IACnC,OAAO,CAAC,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAC/C,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/D,IAAI,EAAE,aAAa,CAAC;IACpB,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAkCF,wBAAgB,gBAAgB,CAAC,EAC/B,OAAoB,EACpB,OAAO,EACP,QAAgB,EAChB,OAAO,EACP,eAAuB,EACvB,IAAI,EACJ,YAAY,EACZ,SAAc,EACd,QAAgB,EAChB,IAAW,GACZ,EAAE,qBAAqB,qBA0CvB"}
@@ -1,37 +0,0 @@
1
- import React from "react";
2
- import { classNames, cn } from "../lib/utils";
3
- import { Icon } from "./Icon";
4
- import { Tooltip } from "./Tooltip";
5
- var baseClasses = "s-transition-all s-ease-out s-duration-300 s-cursor-pointer hover:s-scale-110";
6
- var iconClasses = {
7
- secondary: {
8
- idle: cn("s-text-foreground", "dark:s-text-foreground-night"),
9
- selected: cn("s-text-highlight-500", "dark:s-text-highlight-500-night"),
10
- hover: cn("hover:s-text-highlight-400", "dark:hover:s-text-highlight-400-night"),
11
- active: cn("active:s-text-highlight-600", "dark:active:s-text-highlight-600-night"),
12
- disabled: cn("s-text-primary-500", "dark:s-text-primary-500-night"),
13
- },
14
- tertiary: {
15
- idle: cn("s-text-primary-600", "dark:s-text-primary-600-night"),
16
- selected: cn("s-text-highlight-500", "dark:s-text-highlight-500-night"),
17
- hover: cn("hover:s-text-highlight-400", "dark:hover:s-text-highlight-400-night"),
18
- active: cn("active:s-text-highlight-600", "dark:active:s-text-highlight-600-night"),
19
- disabled: cn("s-text-primary-500", "dark:s-text-primary-500-night"),
20
- },
21
- };
22
- export function IconToggleButton(_a) {
23
- var _b = _a.variant, variant = _b === void 0 ? "tertiary" : _b, onClick = _a.onClick, _c = _a.disabled, disabled = _c === void 0 ? false : _c, tooltip = _a.tooltip, _d = _a.tooltipPosition, tooltipPosition = _d === void 0 ? "top" : _d, icon = _a.icon, iconSelected = _a.iconSelected, _e = _a.className, className = _e === void 0 ? "" : _e, _f = _a.selected, selected = _f === void 0 ? false : _f, _g = _a.size, size = _g === void 0 ? "sm" : _g;
24
- var iconGroup = iconClasses[variant];
25
- var finalIconClasses = classNames(className, baseClasses, disabled
26
- ? iconGroup.disabled
27
- : selected
28
- ? iconGroup.selected
29
- : iconGroup.idle, disabled ? "" : selected ? "" : iconGroup.hover, disabled ? "" : iconGroup.active);
30
- var IconButtonToggleContent = (React.createElement("button", { className: finalIconClasses, onClick: function (e) {
31
- if (!disabled) {
32
- onClick === null || onClick === void 0 ? void 0 : onClick(e); // Run passed onClick event
33
- }
34
- }, disabled: disabled }, icon && (React.createElement(Icon, { visual: selected && iconSelected ? iconSelected : icon, size: size }))));
35
- return tooltip ? (React.createElement(Tooltip, { trigger: IconButtonToggleContent, label: tooltip, side: tooltipPosition })) : (IconButtonToggleContent);
36
- }
37
- //# sourceMappingURL=IconToggleButton.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IconToggleButton.js","sourceRoot":"","sources":["../../../src/components/IconToggleButton.tsx"],"names":[],"mappings":"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"}
@@ -1,11 +0,0 @@
1
- import type { StoryObj } from "@storybook/react";
2
- import { IconToggleButton } from "../index_with_tw_base";
3
- declare const meta: {
4
- title: string;
5
- component: typeof IconToggleButton;
6
- };
7
- export default meta;
8
- type Story = StoryObj<typeof meta>;
9
- export declare const IconToggleButtonSecondary: Story;
10
- export declare const IconToggleButtonTertiary: Story;
11
- //# sourceMappingURL=IconToggleButton.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IconToggleButton.stories.d.ts","sourceRoot":"","sources":["../../../src/stories/IconToggleButton.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAiB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAExE,QAAA,MAAM,IAAI;;;CAG+B,CAAC;AAE1C,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,yBAAyB,EAAE,KAQvC,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,KAOtC,CAAC"}
@@ -1,24 +0,0 @@
1
- import { Cog6ToothIcon, IconToggleButton } from "../index_with_tw_base";
2
- var meta = {
3
- title: "Primitives/IconToggleButton",
4
- component: IconToggleButton,
5
- };
6
- export default meta;
7
- export var IconToggleButtonSecondary = {
8
- args: {
9
- variant: "secondary",
10
- tooltip: "This a secondary IconButton",
11
- icon: Cog6ToothIcon,
12
- iconSelected: Cog6ToothIcon,
13
- selected: false,
14
- },
15
- };
16
- export var IconToggleButtonTertiary = {
17
- args: {
18
- variant: "tertiary",
19
- tooltip: "This a tertiary IconButton",
20
- icon: Cog6ToothIcon,
21
- selected: false,
22
- },
23
- };
24
- //# sourceMappingURL=IconToggleButton.stories.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IconToggleButton.stories.js","sourceRoot":"","sources":["../../../src/stories/IconToggleButton.stories.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAExE,IAAM,IAAI,GAAG;IACX,KAAK,EAAE,6BAA6B;IACpC,SAAS,EAAE,gBAAgB;CACY,CAAC;AAE1C,eAAe,IAAI,CAAC;AAGpB,MAAM,CAAC,IAAM,yBAAyB,GAAU;IAC9C,IAAI,EAAE;QACJ,OAAO,EAAE,WAAW;QACpB,OAAO,EAAE,6BAA6B;QACtC,IAAI,EAAE,aAAa;QACnB,YAAY,EAAE,aAAa;QAC3B,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,MAAM,CAAC,IAAM,wBAAwB,GAAU;IAC7C,IAAI,EAAE;QACJ,OAAO,EAAE,UAAU;QACnB,OAAO,EAAE,4BAA4B;QACrC,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC"}
@@ -1,106 +0,0 @@
1
- import React, { ComponentType, MouseEventHandler } from "react";
2
-
3
- import { classNames, cn } from "@sparkle/lib/utils";
4
-
5
- import { Icon, IconProps } from "./Icon";
6
- import { Tooltip } from "./Tooltip";
7
-
8
- type IconToggleButtonProps = {
9
- variant?: "secondary" | "tertiary";
10
- onClick?: MouseEventHandler<HTMLButtonElement>;
11
- size?: "xs" | "sm" | "md";
12
- tooltip?: string;
13
- tooltipPosition?: React.ComponentProps<typeof Tooltip>["side"];
14
- icon: ComponentType;
15
- iconSelected?: ComponentType;
16
- className?: string;
17
- disabled?: boolean;
18
- selected?: boolean;
19
- };
20
-
21
- const baseClasses =
22
- "s-transition-all s-ease-out s-duration-300 s-cursor-pointer hover:s-scale-110";
23
-
24
- const iconClasses = {
25
- secondary: {
26
- idle: cn("s-text-foreground", "dark:s-text-foreground-night"),
27
- selected: cn("s-text-highlight-500", "dark:s-text-highlight-500-night"),
28
- hover: cn(
29
- "hover:s-text-highlight-400",
30
- "dark:hover:s-text-highlight-400-night"
31
- ),
32
- active: cn(
33
- "active:s-text-highlight-600",
34
- "dark:active:s-text-highlight-600-night"
35
- ),
36
- disabled: cn("s-text-primary-500", "dark:s-text-primary-500-night"),
37
- },
38
- tertiary: {
39
- idle: cn("s-text-primary-600", "dark:s-text-primary-600-night"),
40
- selected: cn("s-text-highlight-500", "dark:s-text-highlight-500-night"),
41
- hover: cn(
42
- "hover:s-text-highlight-400",
43
- "dark:hover:s-text-highlight-400-night"
44
- ),
45
- active: cn(
46
- "active:s-text-highlight-600",
47
- "dark:active:s-text-highlight-600-night"
48
- ),
49
- disabled: cn("s-text-primary-500", "dark:s-text-primary-500-night"),
50
- },
51
- };
52
-
53
- export function IconToggleButton({
54
- variant = "tertiary",
55
- onClick,
56
- disabled = false,
57
- tooltip,
58
- tooltipPosition = "top",
59
- icon,
60
- iconSelected,
61
- className = "",
62
- selected = false,
63
- size = "sm",
64
- }: IconToggleButtonProps) {
65
- const iconGroup = iconClasses[variant];
66
- const finalIconClasses = classNames(
67
- className,
68
- baseClasses,
69
- disabled
70
- ? iconGroup.disabled
71
- : selected
72
- ? iconGroup.selected
73
- : iconGroup.idle,
74
- disabled ? "" : selected ? "" : iconGroup.hover,
75
- disabled ? "" : iconGroup.active
76
- );
77
-
78
- const IconButtonToggleContent = (
79
- <button
80
- className={finalIconClasses}
81
- onClick={(e) => {
82
- if (!disabled) {
83
- onClick?.(e); // Run passed onClick event
84
- }
85
- }}
86
- disabled={disabled}
87
- >
88
- {icon && (
89
- <Icon
90
- visual={selected && iconSelected ? iconSelected : icon}
91
- size={size as IconProps["size"]}
92
- />
93
- )}
94
- </button>
95
- );
96
-
97
- return tooltip ? (
98
- <Tooltip
99
- trigger={IconButtonToggleContent}
100
- label={tooltip}
101
- side={tooltipPosition}
102
- />
103
- ) : (
104
- IconButtonToggleContent
105
- );
106
- }
@@ -1,30 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/react";
2
-
3
- import { Cog6ToothIcon, IconToggleButton } from "../index_with_tw_base";
4
-
5
- const meta = {
6
- title: "Primitives/IconToggleButton",
7
- component: IconToggleButton,
8
- } satisfies Meta<typeof IconToggleButton>;
9
-
10
- export default meta;
11
- type Story = StoryObj<typeof meta>;
12
-
13
- export const IconToggleButtonSecondary: Story = {
14
- args: {
15
- variant: "secondary",
16
- tooltip: "This a secondary IconButton",
17
- icon: Cog6ToothIcon,
18
- iconSelected: Cog6ToothIcon,
19
- selected: false,
20
- },
21
- };
22
-
23
- export const IconToggleButtonTertiary: Story = {
24
- args: {
25
- variant: "tertiary",
26
- tooltip: "This a tertiary IconButton",
27
- icon: Cog6ToothIcon,
28
- selected: false,
29
- },
30
- };