@dust-tt/sparkle 0.2.251 → 0.2.253-rc-1

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.
Files changed (104) hide show
  1. package/dist/cjs/index.js +3906 -457
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/components/BarHeader.js +3 -3
  4. package/dist/esm/components/BarHeader.js.map +1 -1
  5. package/dist/esm/components/Breadcrumbs.js +1 -1
  6. package/dist/esm/components/Breadcrumbs.js.map +1 -1
  7. package/dist/esm/components/Button.d.ts +5 -3
  8. package/dist/esm/components/Button.d.ts.map +1 -1
  9. package/dist/esm/components/Button.js +11 -3
  10. package/dist/esm/components/Button.js.map +1 -1
  11. package/dist/esm/components/Citation.d.ts.map +1 -1
  12. package/dist/esm/components/Citation.js +1 -1
  13. package/dist/esm/components/Citation.js.map +1 -1
  14. package/dist/esm/components/DataTable.d.ts +6 -0
  15. package/dist/esm/components/DataTable.d.ts.map +1 -1
  16. package/dist/esm/components/DataTable.js +33 -5
  17. package/dist/esm/components/DataTable.js.map +1 -1
  18. package/dist/esm/components/Dialog.d.ts +2 -1
  19. package/dist/esm/components/Dialog.d.ts.map +1 -1
  20. package/dist/esm/components/Dialog.js.map +1 -1
  21. package/dist/esm/components/DropdownMenu.d.ts +2 -2
  22. package/dist/esm/components/DropdownMenu.d.ts.map +1 -1
  23. package/dist/esm/components/DropdownMenu.js +8 -5
  24. package/dist/esm/components/DropdownMenu.js.map +1 -1
  25. package/dist/esm/components/ElementDialog.d.ts +1 -1
  26. package/dist/esm/components/ElementDialog.d.ts.map +1 -1
  27. package/dist/esm/components/ElementDialog.js +2 -2
  28. package/dist/esm/components/ElementDialog.js.map +1 -1
  29. package/dist/esm/components/IconButton.d.ts +2 -2
  30. package/dist/esm/components/IconButton.d.ts.map +1 -1
  31. package/dist/esm/components/IconButton.js +2 -2
  32. package/dist/esm/components/IconButton.js.map +1 -1
  33. package/dist/esm/components/IconToggleButton.d.ts +2 -2
  34. package/dist/esm/components/IconToggleButton.d.ts.map +1 -1
  35. package/dist/esm/components/IconToggleButton.js +2 -2
  36. package/dist/esm/components/IconToggleButton.js.map +1 -1
  37. package/dist/esm/components/Input.js.map +1 -1
  38. package/dist/esm/components/Searchbar.d.ts.map +1 -1
  39. package/dist/esm/components/Searchbar.js.map +1 -1
  40. package/dist/esm/components/Tab.js +1 -1
  41. package/dist/esm/components/Tab.js.map +1 -1
  42. package/dist/esm/components/TextArea.d.ts +4 -8
  43. package/dist/esm/components/TextArea.d.ts.map +1 -1
  44. package/dist/esm/components/TextArea.js +7 -9
  45. package/dist/esm/components/TextArea.js.map +1 -1
  46. package/dist/esm/components/Tooltip.d.ts +13 -7
  47. package/dist/esm/components/Tooltip.d.ts.map +1 -1
  48. package/dist/esm/components/Tooltip.js +18 -42
  49. package/dist/esm/components/Tooltip.js.map +1 -1
  50. package/dist/esm/components/index.d.ts +1 -1
  51. package/dist/esm/components/index.d.ts.map +1 -1
  52. package/dist/esm/components/index.js +1 -1
  53. package/dist/esm/components/index.js.map +1 -1
  54. package/dist/esm/stories/Button.stories.js +2 -2
  55. package/dist/esm/stories/Button.stories.js.map +1 -1
  56. package/dist/esm/stories/Citation.stories.js +1 -1
  57. package/dist/esm/stories/Citation.stories.js.map +1 -1
  58. package/dist/esm/stories/DataTable.stories.d.ts.map +1 -1
  59. package/dist/esm/stories/DataTable.stories.js +1 -1
  60. package/dist/esm/stories/DataTable.stories.js.map +1 -1
  61. package/dist/esm/stories/Dialog.stories.d.ts.map +1 -1
  62. package/dist/esm/stories/Dialog.stories.js +1 -1
  63. package/dist/esm/stories/Dialog.stories.js.map +1 -1
  64. package/dist/esm/stories/DropdownMenu.stories.d.ts.map +1 -1
  65. package/dist/esm/stories/DropdownMenu.stories.js +2 -2
  66. package/dist/esm/stories/DropdownMenu.stories.js.map +1 -1
  67. package/dist/esm/stories/IconButton.stories.js +3 -3
  68. package/dist/esm/stories/IconButton.stories.js.map +1 -1
  69. package/dist/esm/stories/TextArea.stories.d.ts +1 -2
  70. package/dist/esm/stories/TextArea.stories.d.ts.map +1 -1
  71. package/dist/esm/stories/TextArea.stories.js +23 -7
  72. package/dist/esm/stories/TextArea.stories.js.map +1 -1
  73. package/dist/esm/stories/Tooltip.stories.d.ts +3 -8
  74. package/dist/esm/stories/Tooltip.stories.d.ts.map +1 -1
  75. package/dist/esm/stories/Tooltip.stories.js +10 -23
  76. package/dist/esm/stories/Tooltip.stories.js.map +1 -1
  77. package/dist/esm/stories/Tree.stories.js.map +1 -1
  78. package/dist/sparkle.css +6 -68
  79. package/package.json +3 -1
  80. package/src/components/BarHeader.tsx +0 -3
  81. package/src/components/Breadcrumbs.tsx +1 -4
  82. package/src/components/Button.tsx +17 -14
  83. package/src/components/Citation.tsx +1 -7
  84. package/src/components/DataTable.tsx +63 -10
  85. package/src/components/Dialog.tsx +4 -4
  86. package/src/components/DropdownMenu.tsx +42 -31
  87. package/src/components/ElementDialog.tsx +4 -1
  88. package/src/components/IconButton.tsx +9 -6
  89. package/src/components/IconToggleButton.tsx +9 -6
  90. package/src/components/Input.tsx +1 -1
  91. package/src/components/Searchbar.tsx +2 -4
  92. package/src/components/Tab.tsx +1 -1
  93. package/src/components/TextArea.tsx +38 -43
  94. package/src/components/Tooltip.tsx +48 -78
  95. package/src/components/index.ts +7 -1
  96. package/src/stories/Button.stories.tsx +2 -2
  97. package/src/stories/Citation.stories.tsx +1 -1
  98. package/src/stories/DataTable.stories.tsx +3 -1
  99. package/src/stories/Dialog.stories.tsx +1 -0
  100. package/src/stories/DropdownMenu.stories.tsx +6 -3
  101. package/src/stories/IconButton.stories.tsx +3 -3
  102. package/src/stories/TextArea.stories.tsx +26 -10
  103. package/src/stories/Tooltip.stories.tsx +31 -50
  104. package/src/stories/Tree.stories.tsx +1 -1
@@ -1,86 +1,56 @@
1
- import React, { useEffect, useState } from "react";
1
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
2
+ import * as React from "react";
2
3
 
3
4
  import { classNames } from "@sparkle/lib/utils";
4
5
 
5
- export interface TooltipProps {
6
- children: React.ReactNode;
7
- label?: string;
8
- position?: "above" | "below";
9
- contentChildren?: React.ReactNode;
6
+ const TooltipProvider = TooltipPrimitive.Provider;
7
+
8
+ const TooltipRoot = TooltipPrimitive.Root;
9
+
10
+ const TooltipTrigger = TooltipPrimitive.Trigger;
11
+
12
+ interface TooltipContentProps
13
+ extends React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content> {}
14
+
15
+ const TooltipContent = React.forwardRef<
16
+ React.ElementRef<typeof TooltipPrimitive.Content>,
17
+ TooltipContentProps
18
+ >(({ className, sideOffset = 4, ...props }, ref) => (
19
+ <TooltipPrimitive.Content
20
+ ref={ref}
21
+ sideOffset={sideOffset}
22
+ className={classNames(
23
+ "s-bg-primary-50 s-text-primary-700 s-z-50 s-max-w-xs s-overflow-hidden s-rounded-md s-border s-bg-white s-px-3 s-py-1.5 s-text-sm s-shadow-md",
24
+ "s-animate-in s-fade-in-0 s-zoom-in-95",
25
+ "data-[state=closed]:s-animate-out data-[state=closed]:s-fade-out-0 data-[state=closed]:s-zoom-out-95 data-[side=bottom]:s-slide-in-from-top-2 data-[side=left]:s-slide-in-from-right-2 data-[side=right]:s-slide-in-from-left-2 data-[side=top]:s-slide-in-from-bottom-2",
26
+ className || ""
27
+ )}
28
+ {...props}
29
+ />
30
+ ));
31
+
32
+ interface TooltipProps extends TooltipContentProps {
33
+ trigger: React.ReactNode;
34
+ label: React.ReactNode;
10
35
  }
11
36
 
12
- export function Tooltip({
13
- children,
14
- label,
15
- position = "above",
16
- contentChildren,
17
- }: TooltipProps) {
18
- const [isHovered, setIsHovered] = useState(false);
19
- const [timerId, setTimerId] = useState<number | null>(null);
20
- const [isTouchDevice, setIsTouchDevice] = useState(false);
21
-
22
- const handleMouseOver = () => {
23
- const id = window.setTimeout(() => {
24
- setIsHovered(true);
25
- }, 600);
26
- setTimerId(id);
27
- };
28
-
29
- const handleMouseLeave = () => {
30
- if (timerId !== null) {
31
- clearTimeout(timerId);
32
- }
33
- setIsHovered(false);
34
- };
35
-
36
- useEffect(() => {
37
- setIsTouchDevice("ontouchstart" in window || navigator.maxTouchPoints > 0);
38
- return () => {
39
- if (timerId) {
40
- window.clearTimeout(timerId);
41
- }
42
- };
43
- }, [timerId]);
44
-
45
- if (isTouchDevice) {
46
- return <>{children}</>;
47
- }
48
-
49
- const baseClasses = classNames(
50
- "s-absolute s-z-10 s-px-3 s-py-2 s-text-sm s-rounded-xl s-border s-shadow-md s-transition-all s-duration-500 s-ease-out s-transform",
51
- "s-border-structure-100 dark:s-border-structure-50-dark s-bg-structure-0 dark:s-bg-structure-100-dark s-text-element-700 dark:s-text-element-600-dark"
52
- );
53
- const hiddenClasses = "s-translate-y-2 s-opacity-0 s-pointer-events-none"; // Added s-pointer-events-none
54
- const visibleClasses = "-s-translate-y-0 s-opacity-100";
55
- const hiddenOnMobileClasses = "s-hidden sm:s-block";
56
- const tooltipCenterClasses = "s-left-1/2 -s-translate-x-1/2";
57
- const tooltipPositionClasses =
58
- position === "above" ? "s-bottom-full s-mb-2" : "s-top-full s-mt-2";
59
-
60
- // if tooltip text is too long we need to wrap it
61
- const labelLength = label?.length || 0;
62
- const labelClasses = labelLength > 80 ? "s-w-[38em]" : "s-whitespace-nowrap";
63
-
37
+ function Tooltip({ trigger, label, ...props }: TooltipProps) {
64
38
  return (
65
- <div
66
- onMouseEnter={handleMouseOver}
67
- onMouseLeave={handleMouseLeave}
68
- className="s-relative s-inline-block"
69
- >
70
- {children}
71
- <div
72
- className={classNames(
73
- `${isHovered ? visibleClasses : hiddenClasses}`,
74
- baseClasses,
75
- hiddenOnMobileClasses,
76
- tooltipPositionClasses,
77
- tooltipCenterClasses,
78
- contentChildren ? "" : labelClasses
79
- )}
80
- onAnimationEnd={() => setIsHovered(false)}
81
- >
82
- {contentChildren || label}
83
- </div>
84
- </div>
39
+ <TooltipProvider>
40
+ <TooltipRoot>
41
+ <TooltipTrigger asChild>{trigger}</TooltipTrigger>
42
+ <TooltipContent {...props}>{label}</TooltipContent>
43
+ </TooltipRoot>
44
+ </TooltipProvider>
85
45
  );
86
46
  }
47
+
48
+ TooltipContent.displayName = TooltipPrimitive.Content.displayName;
49
+
50
+ export {
51
+ Tooltip,
52
+ TooltipContent,
53
+ TooltipProvider,
54
+ TooltipRoot,
55
+ TooltipTrigger,
56
+ };
@@ -43,6 +43,12 @@ export { SliderToggle } from "./SliderToggle";
43
43
  export { default as Spinner } from "./Spinner";
44
44
  export { Tab } from "./Tab";
45
45
  export { TextArea } from "./TextArea";
46
- export { Tooltip } from "./Tooltip";
46
+ export {
47
+ Tooltip,
48
+ TooltipContent,
49
+ TooltipProvider,
50
+ TooltipRoot,
51
+ TooltipTrigger,
52
+ } from "./Tooltip";
47
53
  export { Tree } from "./Tree";
48
54
  export { ZoomableImageCitationWrapper } from "./ZoomableImageCitationWrapper";
@@ -622,7 +622,7 @@ export const IconOnlyPlusTooltip: Story = {
622
622
  labelVisible: false,
623
623
  icon: Cog6ToothIcon,
624
624
  disabled: false,
625
- tooltipPosition: "below",
625
+ tooltipPosition: "bottom",
626
626
  },
627
627
  };
628
628
 
@@ -634,7 +634,7 @@ export const IconOnlyNoTooltip: Story = {
634
634
  labelVisible: false,
635
635
  icon: Cog6ToothIcon,
636
636
  disabled: false,
637
- tooltipPosition: "below",
637
+ tooltipPosition: "bottom",
638
638
  disabledTooltip: true,
639
639
  },
640
640
  };
@@ -133,7 +133,7 @@ export const CitationsExample = () => (
133
133
  type="google_drive"
134
134
  index="3"
135
135
  href="https://www.google.com"
136
- description="Write a 120 character description of the citation here to be displayed in the citation list."
136
+ description="Write a 120 character description of the citation here to be displayed in the citation list. Write a 120 character description of the citation here to be displayed in the citation list. Write a 120 character description of the citation here to be displayed in the citation list."
137
137
  isBlinking={true}
138
138
  />
139
139
  <Citation
@@ -161,7 +161,9 @@ const columns: ColumnDef<Data>[] = [
161
161
  width: "100px",
162
162
  },
163
163
  cell: (info) => (
164
- <DataTable.CellContent>{info.row.original.addedBy}</DataTable.CellContent>
164
+ <DataTable.CellContentWithCopy>
165
+ {info.row.original.addedBy}
166
+ </DataTable.CellContentWithCopy>
165
167
  ),
166
168
  },
167
169
  {
@@ -26,6 +26,7 @@ export const DialogExample = () => {
26
26
  cancelLabel="Cancel"
27
27
  onValidate={() => setisOpen1(false)}
28
28
  onCancel={() => setisOpen1(false)}
29
+ validateVariant="primary"
29
30
  >
30
31
  <div>I'm the modal content</div>
31
32
  </Dialog>
@@ -48,7 +48,10 @@ export const DropdownExample = () => {
48
48
  <div className="s-flex s-gap-6">
49
49
  <div className="s-text-sm">Action</div>
50
50
  <DropdownMenu>
51
- <DropdownMenu.Button label="Action" onClick={() => console.log("CLICK")}/>
51
+ <DropdownMenu.Button
52
+ label="Action"
53
+ onClick={() => console.log("CLICK")}
54
+ />
52
55
  <DropdownMenu.Items width={220}>
53
56
  <DropdownMenu.SectionHeader label="Edition" />
54
57
  <DropdownMenu.Item
@@ -311,7 +314,7 @@ export const DropdownExample = () => {
311
314
  <DropdownMenu.Button
312
315
  icon={ChatBubbleBottomCenterTextIcon}
313
316
  tooltip="Moonlab"
314
- tooltipPosition="below"
317
+ tooltipPosition="bottom"
315
318
  />
316
319
  <DropdownMenu.Items origin="topLeft" width={120}>
317
320
  <DropdownMenu.Item label="item 1 is longish" link={{ href: "#" }} />
@@ -355,7 +358,7 @@ export const DropdownExample = () => {
355
358
  <DropdownMenu.Button
356
359
  icon={ChatBubbleBottomCenterTextIcon}
357
360
  tooltip="Moonlab"
358
- tooltipPosition="below"
361
+ tooltipPosition="bottom"
359
362
  />
360
363
  <DropdownMenu.Items origin="topLeft">
361
364
  <DropdownMenu.Item label="item 1" link={{ href: "#" }} />
@@ -22,7 +22,7 @@ export const IconButtonWithTooltip: Story = {
22
22
  args: {
23
23
  variant: "primary",
24
24
  tooltip: "Your settings",
25
- tooltipPosition: "below",
25
+ tooltipPosition: "bottom",
26
26
  icon: Cog6ToothIcon,
27
27
  },
28
28
  };
@@ -31,7 +31,7 @@ export const IconButtonSecondary: Story = {
31
31
  args: {
32
32
  variant: "secondary",
33
33
  tooltip: "This a secondary IconButton",
34
- tooltipPosition: "below",
34
+ tooltipPosition: "bottom",
35
35
  icon: Cog6ToothIcon,
36
36
  },
37
37
  };
@@ -40,7 +40,7 @@ export const IconButtonTertiary: Story = {
40
40
  args: {
41
41
  variant: "tertiary",
42
42
  tooltip: "This a tertiary IconButton",
43
- tooltipPosition: "below",
43
+ tooltipPosition: "bottom",
44
44
  icon: Cog6ToothIcon,
45
45
  },
46
46
  };
@@ -22,26 +22,42 @@ export const TextAreaExample = () => {
22
22
  <div className="s-grid s-grid-cols-3 s-gap-4">
23
23
  <TextArea
24
24
  placeholder="placeholder"
25
- value={textValues[0]}
26
- onChange={(v) =>
27
- setTextValues([v, textValues[1], textValues[2], textValues[3]])
28
- }
25
+ onChange={(e) => {
26
+ console.log(e.target.value);
27
+ setTextValues([
28
+ e.target.value,
29
+ textValues[1],
30
+ textValues[2],
31
+ textValues[3],
32
+ ]);
33
+ }}
29
34
  minRows={2}
35
+ defaultValue={textValues[0]}
30
36
  />
31
37
  <TextArea
32
38
  placeholder="placeholder"
33
- value={textValues[1]}
39
+ defaultValue={textValues[1]}
34
40
  error={"errored because blah"}
35
- onChange={(v) =>
36
- setTextValues([textValues[0], v, textValues[2], textValues[3]])
41
+ onChange={(e) =>
42
+ setTextValues([
43
+ textValues[0],
44
+ e.target.value,
45
+ textValues[2],
46
+ textValues[3],
47
+ ])
37
48
  }
38
49
  showErrorLabel
39
50
  />
40
51
  <TextArea
41
52
  placeholder="placeholder"
42
- value={textValues[2]}
43
- onChange={(v) =>
44
- setTextValues([textValues[0], textValues[1], v, textValues[3]])
53
+ defaultValue={textValues[2]}
54
+ onChange={(e) =>
55
+ setTextValues([
56
+ textValues[0],
57
+ textValues[1],
58
+ e.target.value,
59
+ textValues[3],
60
+ ])
45
61
  }
46
62
  error={"errored because blah"}
47
63
  />
@@ -1,62 +1,43 @@
1
- import type { Meta, StoryObj } from "@storybook/react";
1
+ import type { Meta } from "@storybook/react";
2
2
  import React from "react";
3
3
 
4
- import { Tooltip } from "../index_with_tw_base";
4
+ import {
5
+ Icon,
6
+ RobotIcon,
7
+ Tooltip,
8
+ TooltipContent,
9
+ TooltipProvider,
10
+ TooltipRoot,
11
+ TooltipTrigger,
12
+ } from "../index_with_tw_base";
5
13
 
6
14
  const meta = {
7
15
  title: "Primitives/Tooltip",
8
- component: Tooltip,
9
- } satisfies Meta<typeof Tooltip>;
16
+ component: TooltipProvider,
17
+ } satisfies Meta<typeof TooltipProvider>;
10
18
 
11
19
  export default meta;
12
- type Story = StoryObj<typeof meta>;
13
20
 
14
- export const TooltipAbove: Story = {
15
- args: {
16
- label: "This is a tooltip",
17
- children: "Hover me",
18
- position: "above",
19
- },
20
- };
21
-
22
- export const TooltipBelow: Story = {
23
- args: {
24
- label: "This is a tooltip",
25
- children: "Hover me",
26
- position: "below",
27
- },
28
- };
29
-
30
- export const ToolTipWithContent = () => (
31
- <div className="s-pl-32">
32
- <Tooltip
33
- contentChildren={
34
- <div className="s-w-64">
35
- <div className="s-flex s-flex-col s-gap-y-2 s-break-words">
36
- <div className="s-flex s-font-semibold">
37
- This is a more complex tooltip:
38
- </div>
39
- <div className="s-flex s-flex-wrap s-break-words">
40
- It has some content that is long here and describes something
41
- about the content associated with this.
42
- </div>
43
- </div>
44
- </div>
45
- }
46
- position="below"
47
- >
48
- Hover me
49
- </Tooltip>
50
- </div>
21
+ export const TooltipExample = () => (
22
+ <Tooltip trigger={<div>Hover</div>} label={<p>Add to library</p>} />
51
23
  );
52
24
 
53
- export const TooltipLongLabel = () => (
54
- <div className="s-pl-64">
55
- <Tooltip
56
- label="This is a tooltip with a very long label that should wrap onto multiple lines. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor."
57
- position="below"
25
+ export const TooltipWithManual = () => (
26
+ <TooltipProvider delayDuration={800} skipDelayDuration={500}>
27
+ <TooltipRoot
28
+ onOpenChange={(open: boolean) => {
29
+ console.log(`Is open: ${open}`);
30
+ }}
58
31
  >
59
- Hover me
60
- </Tooltip>
61
- </div>
32
+ <TooltipTrigger>
33
+ <Icon visual={RobotIcon} size="xs" />
34
+ </TooltipTrigger>
35
+ <TooltipContent side="right" sideOffset={50}>
36
+ This is a tooltip with a very long label that should wrap onto multiple
37
+ lines. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non
38
+ risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec,
39
+ ultricies sed, dolor.
40
+ </TooltipContent>
41
+ </TooltipRoot>
42
+ </TooltipProvider>
62
43
  );
@@ -89,7 +89,7 @@ export const TreeExample = () => {
89
89
  visual={FolderIcon}
90
90
  collapsed={false}
91
91
  >
92
- <Tree.Empty label="No documents"/>
92
+ <Tree.Empty label="No documents" />
93
93
  </Tree.Item>
94
94
  </Tree>
95
95
  </Tree.Item>