@dust-tt/sparkle 0.2.97 → 0.2.98-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/dist/cjs/components/Tab.d.ts +29 -13
- package/dist/cjs/index.js +26 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/Tab.d.ts +29 -13
- package/dist/esm/index.js +26 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
import React, { ComponentType, MouseEvent } from "react";
|
|
2
|
+
type TabType = {
|
|
3
|
+
label: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
hideLabel?: boolean;
|
|
6
|
+
current: boolean;
|
|
7
|
+
sizing?: "hug" | "expand";
|
|
8
|
+
icon?: ComponentType<{
|
|
9
|
+
className?: string;
|
|
10
|
+
}>;
|
|
11
|
+
hasSeparator?: boolean;
|
|
12
|
+
} & ({
|
|
13
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
14
|
+
href?: never;
|
|
15
|
+
} | {
|
|
16
|
+
onClick?: never;
|
|
17
|
+
href: string;
|
|
18
|
+
});
|
|
2
19
|
type TabProps = {
|
|
3
20
|
variant?: "default" | "stepper";
|
|
4
|
-
tabs: Array<
|
|
5
|
-
|
|
6
|
-
hideLabel?: boolean;
|
|
7
|
-
current: boolean;
|
|
8
|
-
sizing?: "hug" | "expand";
|
|
9
|
-
icon?: ComponentType<{
|
|
10
|
-
className?: string;
|
|
11
|
-
}>;
|
|
12
|
-
href?: string;
|
|
13
|
-
hasSeparator?: boolean;
|
|
14
|
-
}>;
|
|
15
|
-
onTabClick?: (tabName: string, event: MouseEvent<HTMLAnchorElement>) => void;
|
|
21
|
+
tabs: Array<TabType>;
|
|
22
|
+
setCurrentTab?: (tabId: string, e: MouseEvent<HTMLAnchorElement>) => void;
|
|
16
23
|
className?: string;
|
|
17
24
|
};
|
|
18
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Tab component displaying a list of tabs.
|
|
27
|
+
*
|
|
28
|
+
* Tab click action is specified:
|
|
29
|
+
* - either per tab, by providing either an href or an onClick handler in tab
|
|
30
|
+
* data (mutually exclusive);
|
|
31
|
+
* - or globally, by providing a setCurrentTab function.
|
|
32
|
+
* Both per-tab and global actions can be set, the per-tab action taking precedence.
|
|
33
|
+
*/
|
|
34
|
+
export declare function Tab({ variant, tabs, setCurrentTab, className, }: TabProps): React.JSX.Element;
|
|
19
35
|
export {};
|
package/dist/cjs/index.js
CHANGED
|
@@ -32097,12 +32097,21 @@ var tabSizingClasses = {
|
|
|
32097
32097
|
hug: "",
|
|
32098
32098
|
expand: "s-flex-1",
|
|
32099
32099
|
};
|
|
32100
|
+
/**
|
|
32101
|
+
* Tab component displaying a list of tabs.
|
|
32102
|
+
*
|
|
32103
|
+
* Tab click action is specified:
|
|
32104
|
+
* - either per tab, by providing either an href or an onClick handler in tab
|
|
32105
|
+
* data (mutually exclusive);
|
|
32106
|
+
* - or globally, by providing a setCurrentTab function.
|
|
32107
|
+
* Both per-tab and global actions can be set, the per-tab action taking precedence.
|
|
32108
|
+
*/
|
|
32100
32109
|
function Tab(_a) {
|
|
32101
|
-
var _b = _a.variant, variant = _b === void 0 ? "default" : _b, tabs = _a.tabs,
|
|
32110
|
+
var _b = _a.variant, variant = _b === void 0 ? "default" : _b, tabs = _a.tabs, setCurrentTab = _a.setCurrentTab, _c = _a.className, className = _c === void 0 ? "" : _c;
|
|
32102
32111
|
var components = React.useContext(SparkleContext).components;
|
|
32103
32112
|
var renderTabs = function () {
|
|
32104
32113
|
return tabs.map(function (tab, i) {
|
|
32105
|
-
var _a, _b, _c, _d;
|
|
32114
|
+
var _a, _b, _c, _d, _e;
|
|
32106
32115
|
var tabStateClasses = variant === "stepper"
|
|
32107
32116
|
? tab.current
|
|
32108
32117
|
? tabClasses.stepperSelected
|
|
@@ -32124,19 +32133,29 @@ function Tab(_a) {
|
|
|
32124
32133
|
var Link = tab.href
|
|
32125
32134
|
? components.link
|
|
32126
32135
|
: noHrefLink;
|
|
32127
|
-
|
|
32136
|
+
// precedence on href and onClick (mutually exclusive), then setCurrentTab
|
|
32137
|
+
var setCurrentTabFn = function (e) {
|
|
32138
|
+
if (!tab.id) {
|
|
32139
|
+
throw new Error("Tab id is required to use setCurrentTab");
|
|
32140
|
+
}
|
|
32141
|
+
setCurrentTab === null || setCurrentTab === void 0 ? void 0 : setCurrentTab(tab.id, e);
|
|
32142
|
+
};
|
|
32143
|
+
var onClickAction = tab.href
|
|
32144
|
+
? undefined
|
|
32145
|
+
: (_a = tab.onClick) !== null && _a !== void 0 ? _a : setCurrentTabFn;
|
|
32146
|
+
var content = (React.createElement(Link, { key: tab.label, className: finalTabClasses, "aria-current": tab.current ? "page" : undefined, onClick: onClickAction, href: tab.href || "#" },
|
|
32128
32147
|
React.createElement("div", { className: tab.current
|
|
32129
32148
|
? "s-flex s-gap-x-2"
|
|
32130
32149
|
: "s-flex s-gap-x-2 s-transition s-duration-300 s-ease-out" },
|
|
32131
|
-
tab.icon && (React.createElement(Icon, { visual: tab.icon, className: finalIconClasses, size: "sm" })), (
|
|
32150
|
+
tab.icon && (React.createElement(Icon, { visual: tab.icon, className: finalIconClasses, size: "sm" })), (_b = tab.hideLabel) !== null && _b !== void 0 ? _b : tab.label,
|
|
32132
32151
|
variant === "stepper" && i < tabs.length - 1 && (React.createElement(Icon, { visual: SvgChevronRight$1, className: "s-mx-2 s-text-element-500", size: "sm" })))));
|
|
32133
32152
|
return tab.hideLabel ? (tab.label ? (React.createElement(React.Fragment, { key: "tab-".concat(i) },
|
|
32134
|
-
React.createElement("div", { className: tabSizingClasses[(
|
|
32153
|
+
React.createElement("div", { className: tabSizingClasses[(_c = tab.sizing) !== null && _c !== void 0 ? _c : "hug"] },
|
|
32135
32154
|
React.createElement(Tooltip, { label: tab.label }, content)),
|
|
32136
32155
|
tab.hasSeparator && (React.createElement("div", { className: "s-flex s-h-full s-grow", key: "sep-".concat(i) })))) : (React.createElement(React.Fragment, { key: "tab-".concat(i) },
|
|
32137
|
-
React.createElement("div", { className: tabSizingClasses[(_c = tab.sizing) !== null && _c !== void 0 ? _c : "hug"] }, content),
|
|
32138
|
-
tab.hasSeparator && (React.createElement("div", { className: "s-flex s-h-full s-grow", key: "sep-".concat(i) }))))) : (React.createElement(React.Fragment, { key: "tab-".concat(i) },
|
|
32139
32156
|
React.createElement("div", { className: tabSizingClasses[(_d = tab.sizing) !== null && _d !== void 0 ? _d : "hug"] }, content),
|
|
32157
|
+
tab.hasSeparator && (React.createElement("div", { className: "s-flex s-h-full s-grow", key: "sep-".concat(i) }))))) : (React.createElement(React.Fragment, { key: "tab-".concat(i) },
|
|
32158
|
+
React.createElement("div", { className: tabSizingClasses[(_e = tab.sizing) !== null && _e !== void 0 ? _e : "hug"] }, content),
|
|
32140
32159
|
tab.hasSeparator && (React.createElement("div", { className: "s-flex s-h-full s-grow", key: "sep-".concat(i) }))));
|
|
32141
32160
|
});
|
|
32142
32161
|
};
|