@dust-tt/sparkle 0.2.278 → 0.2.280-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 (39) hide show
  1. package/dist/cjs/index.js +4166 -34377
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/components/Notification.d.ts +11 -0
  4. package/dist/esm/components/Notification.d.ts.map +1 -1
  5. package/dist/esm/components/Notification.js +46 -1
  6. package/dist/esm/components/Notification.js.map +1 -1
  7. package/dist/esm/components/Tabs.d.ts +12 -0
  8. package/dist/esm/components/Tabs.d.ts.map +1 -0
  9. package/dist/esm/components/Tabs.js +24 -0
  10. package/dist/esm/components/Tabs.js.map +1 -0
  11. package/dist/esm/components/index.d.ts +3 -2
  12. package/dist/esm/components/index.d.ts.map +1 -1
  13. package/dist/esm/components/index.js +2 -2
  14. package/dist/esm/components/index.js.map +1 -1
  15. package/dist/esm/stories/Notification.stories.d.ts +3 -4
  16. package/dist/esm/stories/Notification.stories.d.ts.map +1 -1
  17. package/dist/esm/stories/Notification.stories.js +16 -1
  18. package/dist/esm/stories/Notification.stories.js.map +1 -1
  19. package/dist/esm/stories/Tabs.stories.d.ts +7 -0
  20. package/dist/esm/stories/Tabs.stories.d.ts.map +1 -0
  21. package/dist/esm/stories/Tabs.stories.js +17 -0
  22. package/dist/esm/stories/Tabs.stories.js.map +1 -0
  23. package/dist/sparkle.css +35 -80
  24. package/package.json +6 -3
  25. package/src/components/Notification.tsx +107 -1
  26. package/src/components/Tabs.tsx +60 -0
  27. package/src/components/index.ts +3 -2
  28. package/src/stories/Notification.stories.tsx +27 -2
  29. package/src/stories/Tabs.stories.tsx +33 -0
  30. package/dist/esm/components/Tab.d.ts +0 -38
  31. package/dist/esm/components/Tab.d.ts.map +0 -1
  32. package/dist/esm/components/Tab.js +0 -130
  33. package/dist/esm/components/Tab.js.map +0 -1
  34. package/dist/esm/stories/Tab.stories.d.ts +0 -9
  35. package/dist/esm/stories/Tab.stories.d.ts.map +0 -1
  36. package/dist/esm/stories/Tab.stories.js +0 -80
  37. package/dist/esm/stories/Tab.stories.js.map +0 -1
  38. package/src/components/Tab.tsx +0 -243
  39. package/src/stories/Tab.stories.tsx +0 -104
@@ -1,243 +0,0 @@
1
- import React, { ComponentType, MouseEvent, ReactNode } from "react";
2
-
3
- import {
4
- noHrefLink,
5
- SparkleContext,
6
- SparkleContextLinkType,
7
- } from "@sparkle/context";
8
- import { ChevronRightIcon } from "@sparkle/icons";
9
- import { classNames } from "@sparkle/lib/utils";
10
-
11
- import { Icon } from "./Icon";
12
- import { Tooltip } from "./Tooltip";
13
-
14
- type TabType<E> = {
15
- current: boolean;
16
- disabled?: boolean;
17
- hasSeparator?: boolean;
18
- hideLabel?: boolean;
19
- icon?: ComponentType<{ className?: string }>;
20
- id?: E;
21
- label: string;
22
- sizing?: "hug" | "expand";
23
- } & (
24
- | { onClick?: (event: MouseEvent<HTMLAnchorElement>) => void; href?: never }
25
- | { onClick?: never; href: string }
26
- );
27
-
28
- type TabProps<E> = {
29
- variant?: "default" | "stepper";
30
- tabs: Array<TabType<E>>;
31
- setCurrentTab?: (tabId: E, e: MouseEvent<HTMLAnchorElement>) => void;
32
- tabClassName?: string;
33
- className?: string;
34
- };
35
-
36
- const tabClasses = {
37
- default: {
38
- base: "s-text-element-800 s-border-transparent s-cursor-pointer s-border-b-2",
39
- hover: "hover:s-text-action-500 hover:s-border-action-300",
40
- dark: {
41
- base: "dark:s-text-element-700-dark",
42
- hover: "dark:hover:s-text-action-600-dark",
43
- },
44
- },
45
- selected: {
46
- base: "s-border-action-500 s-text-action-500 s-cursor-default s-border-b-2",
47
- hover: "",
48
- dark: {
49
- base: "dark:s-border-action-500-dark dark:s-text-action-500-dark",
50
- hover: "",
51
- },
52
- },
53
- stepperDefault: {
54
- base: "s-text-element-800 s-cursor-pointer",
55
- hover: "hover:s-text-action-500",
56
- dark: {
57
- base: "dark:s-text-element-700-dark",
58
- hover: "dark:hover:s-text-action-600-dark",
59
- },
60
- },
61
- stepperSelected: {
62
- base: "s-text-action-500 s-cursor-default",
63
- hover: "",
64
- dark: {
65
- base: "dark:dark:s-text-action-500-dark",
66
- hover: "",
67
- },
68
- },
69
- };
70
-
71
- const iconClasses = {
72
- default: {
73
- base: "s-text-element-600",
74
- hover: "group-hover/tab:s-text-action-400",
75
- dark: {
76
- base: "dark:s-text-element-600-dark",
77
- hover: "dark:group-hover/tab:s-text-action-500-dark",
78
- },
79
- },
80
- selected: {
81
- base: "s-text-action-400",
82
- hover: "",
83
- dark: {
84
- base: "dark:s-text-action-500-dark",
85
- hover: "",
86
- },
87
- },
88
- };
89
-
90
- const tabSizingClasses = {
91
- hug: "",
92
- expand: "s-flex-1",
93
- };
94
-
95
- /**
96
- * Tab component displaying a list of tabs.
97
- *
98
- * Tab click action is specified:
99
- * - either per tab, by providing either an href or an onClick handler in tab
100
- * data (mutually exclusive);
101
- * - or globally, by providing a setCurrentTab function.
102
- * Both per-tab and global actions can be set, the per-tab action taking precedence.
103
- */
104
- export function Tab<E>({
105
- variant = "default",
106
- tabs,
107
- setCurrentTab,
108
- className,
109
- tabClassName = "",
110
- }: TabProps<E>) {
111
- const { components } = React.useContext(SparkleContext);
112
-
113
- const renderTabs = () =>
114
- tabs.map((tab, i) => {
115
- const tabStateClasses =
116
- variant === "stepper"
117
- ? tab.current
118
- ? tabClasses.stepperSelected
119
- : tabClasses.stepperDefault
120
- : tab.current
121
- ? tabClasses.selected
122
- : tabClasses.default;
123
- const iconStateClasses = tab.current
124
- ? iconClasses.selected
125
- : iconClasses.default;
126
-
127
- const finalTabClasses = classNames(
128
- "s-group/tab s-justify-center s-flex s-text-sm s-font-semibold s-py-2.5 s-transition-all ease-out s-duration-400 s-whitespace-nowrap s-select-none",
129
- variant === "default"
130
- ? tab.icon
131
- ? tab.hideLabel
132
- ? "s-px-3"
133
- : "s-pr-3.5 s-pl-2.5"
134
- : "s-px-3"
135
- : "s-pl-1",
136
-
137
- tabStateClasses.base,
138
- tabStateClasses.hover,
139
- tabStateClasses.dark.base,
140
- tabStateClasses.dark.hover,
141
- tabClassName,
142
- tab.disabled ? "s-opacity-50 s-pointer-events-none" : ""
143
- );
144
-
145
- const finalIconClasses = classNames(
146
- "s-transition-colors s-duration-400",
147
- iconStateClasses.base,
148
- iconStateClasses.hover,
149
- iconStateClasses.dark.base,
150
- iconStateClasses.dark.hover,
151
- tabClassName
152
- );
153
-
154
- const Link: SparkleContextLinkType = tab.href
155
- ? components.link
156
- : noHrefLink;
157
-
158
- // precedence on href and onClick (mutually exclusive), then setCurrentTab
159
- const setCurrentTabFn = (e: MouseEvent<HTMLAnchorElement>) => {
160
- if (!tab.id) {
161
- throw new Error("Tab id is required to use setCurrentTab");
162
- }
163
- setCurrentTab?.(tab.id, e);
164
- };
165
- const onClickAction = tab.href
166
- ? undefined
167
- : tab.onClick ?? setCurrentTabFn;
168
-
169
- const content: ReactNode = (
170
- <Link
171
- key={tab.label}
172
- className={finalTabClasses}
173
- aria-current={tab.current ? "page" : undefined}
174
- onClick={onClickAction}
175
- href={tab.href || "#"}
176
- >
177
- <div
178
- className={
179
- tab.current
180
- ? "s-flex s-gap-x-2"
181
- : "s-flex s-gap-x-2 s-transition s-duration-300 s-ease-out"
182
- }
183
- >
184
- {tab.icon && (
185
- <Icon visual={tab.icon} className={finalIconClasses} size="sm" />
186
- )}
187
- {tab.hideLabel ?? tab.label}
188
- {variant === "stepper" && i < tabs.length - 1 && (
189
- <Icon
190
- visual={ChevronRightIcon}
191
- className="s-mx-2 s-text-element-500"
192
- size="sm"
193
- />
194
- )}
195
- </div>
196
- </Link>
197
- );
198
- return tab.hideLabel ? (
199
- tab.label ? (
200
- <React.Fragment key={`tab-${i}`}>
201
- <div className={tabSizingClasses[tab.sizing ?? "hug"]}>
202
- <Tooltip trigger={content} label={tab.label} />
203
- </div>
204
- {tab.hasSeparator && (
205
- <div className="s-flex s-h-full s-grow" key={`sep-${i}`} />
206
- )}
207
- </React.Fragment>
208
- ) : (
209
- <React.Fragment key={`tab-${i}`}>
210
- <div className={tabSizingClasses[tab.sizing ?? "hug"]}>
211
- {content}
212
- </div>
213
- {tab.hasSeparator && (
214
- <div className="s-flex s-h-full s-grow" key={`sep-${i}`} />
215
- )}
216
- </React.Fragment>
217
- )
218
- ) : (
219
- <React.Fragment key={`tab-${i}`}>
220
- <div className={tabSizingClasses[tab.sizing ?? "hug"]}>{content}</div>
221
- {tab.hasSeparator && (
222
- <div className="s-flex s-h-full s-grow" key={`sep-${i}`} />
223
- )}
224
- </React.Fragment>
225
- );
226
- });
227
-
228
- return (
229
- <div
230
- className={classNames(
231
- variant === "default"
232
- ? "s-border-b s-border-structure-200 dark:s-border-structure-200-dark"
233
- : "",
234
- className ?? "",
235
- "s-overflow-x-auto s-overflow-y-hidden s-scrollbar-hide"
236
- )}
237
- >
238
- <nav className="s-flex s-space-x-0" aria-label="Tabs">
239
- {renderTabs()}
240
- </nav>
241
- </div>
242
- );
243
- }
@@ -1,104 +0,0 @@
1
- import type { Meta } from "@storybook/react";
2
- import React from "react";
3
-
4
- import {
5
- CircleIcon,
6
- RobotIcon,
7
- SquareIcon,
8
- Tab,
9
- TriangleIcon,
10
- } from "../index_with_tw_base";
11
- import {
12
- ChatBubbleBottomCenterTextIcon,
13
- Cog6ToothIcon,
14
- } from "../index_with_tw_base";
15
-
16
- const meta = {
17
- title: "Components/Tab",
18
- component: Tab,
19
- } satisfies Meta<typeof Tab>;
20
-
21
- export default meta;
22
-
23
- export const TabExample = () => {
24
- const [currentTab, setCurrentTab] = React.useState("chat");
25
- const [currentTab2, setCurrentTab2] = React.useState("instructions");
26
- return (
27
- <div className="s-flex s-flex-col s-gap-10">
28
- <div className="s-w-[320px]">
29
- <Tab
30
- tabs={[
31
- {
32
- label: "Chat",
33
- id: "chat",
34
- current: currentTab === "chat",
35
- icon: ChatBubbleBottomCenterTextIcon,
36
- sizing: "expand",
37
- },
38
- {
39
- label: "Build",
40
- id: "build",
41
- current: currentTab === "build",
42
- icon: RobotIcon,
43
- sizing: "expand",
44
- },
45
- {
46
- label: "Admin",
47
- id: "admin",
48
- current: currentTab === "admin",
49
- icon: RobotIcon,
50
- sizing: "expand",
51
- hasSeparator: true,
52
- disabled: true,
53
- },
54
- {
55
- label: "Settings",
56
- id: "settings",
57
- hideLabel: true,
58
- current: false,
59
- icon: Cog6ToothIcon,
60
- },
61
- ]}
62
- setCurrentTab={(tabId, event) => {
63
- // add logic here
64
- event.preventDefault();
65
- setCurrentTab(tabId);
66
- }}
67
- />
68
- </div>
69
- <div className="s-w-full">
70
- <Tab
71
- variant="stepper"
72
- tabs={[
73
- {
74
- label: "Instructions",
75
- id: "instructions",
76
- current: currentTab2 === "instructions",
77
- icon: SquareIcon,
78
- sizing: "hug",
79
- },
80
- {
81
- label: "Data sources & Actions",
82
- id: "data",
83
- current: currentTab2 === "data",
84
- icon: CircleIcon,
85
- sizing: "hug",
86
- },
87
- {
88
- label: "Naming",
89
- id: "naming",
90
- current: currentTab2 === "naming",
91
- icon: TriangleIcon,
92
- sizing: "hug",
93
- },
94
- ]}
95
- setCurrentTab={(tabId, event) => {
96
- // add logic here
97
- event.preventDefault();
98
- setCurrentTab2(tabId);
99
- }}
100
- />
101
- </div>
102
- </div>
103
- );
104
- };