@spear-ai/spectral 1.3.48 → 1.3.49
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/.js +130 -128
- package/dist/Alert.d.ts +6 -6
- package/dist/Button.d.ts +9 -9
- package/dist/Button.js +18 -18
- package/dist/Input.d.ts +12 -12
- package/dist/MultiSelect/MultiSelectBase.d.ts +24 -24
- package/dist/MultiSelect/MutiSelect.d.ts +7 -7
- package/dist/Select/SelectBase.d.ts +16 -16
- package/dist/Select/SelectBase.js +103 -103
- package/dist/Select.d.ts +16 -16
- package/dist/Tabs/TabsBase.d.ts +38 -0
- package/dist/Tabs/TabsBase.js +209 -0
- package/dist/Tabs/tabsStoryData.d.ts +6 -0
- package/dist/Tabs/tabsStoryData.js +81 -0
- package/dist/Tabs/tabsUtils.d.ts +57 -0
- package/dist/Tabs/tabsUtils.js +71 -0
- package/dist/Tabs.d.ts +29 -0
- package/dist/Tabs.js +157 -0
- package/dist/components/Alert/Alert.d.ts +6 -6
- package/dist/components/Alert/Alert.d.ts.map +1 -1
- package/dist/components/Button/Button.d.ts +9 -9
- package/dist/components/Button/Button.d.ts.map +1 -1
- package/dist/components/Input/Input.d.ts +12 -12
- package/dist/components/Input/Input.d.ts.map +1 -1
- package/dist/components/MultiSelect/MultiSelectBase.d.ts +24 -24
- package/dist/components/MultiSelect/MultiSelectBase.d.ts.map +1 -1
- package/dist/components/MultiSelect/MutiSelect.d.ts +7 -7
- package/dist/components/MultiSelect/MutiSelect.d.ts.map +1 -1
- package/dist/components/Select/Select.d.ts +16 -16
- package/dist/components/Select/Select.d.ts.map +1 -1
- package/dist/components/Select/SelectBase.d.ts +16 -16
- package/dist/components/Select/SelectBase.d.ts.map +1 -1
- package/dist/components/Tabs/Tabs.d.ts +29 -0
- package/dist/components/Tabs/Tabs.d.ts.map +1 -0
- package/dist/components/Tabs/TabsBase.d.ts +38 -0
- package/dist/components/Tabs/TabsBase.d.ts.map +1 -0
- package/dist/components/Tabs/tabsStoryData.d.ts +6 -0
- package/dist/components/Tabs/tabsStoryData.d.ts.map +1 -0
- package/dist/components/Tabs/tabsUtils.d.ts +57 -0
- package/dist/components/Tabs/tabsUtils.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/styles/main.css +1 -1
- package/package.json +1 -1
|
@@ -1,152 +1,152 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "../styles/main.css";
|
|
3
|
-
import { jsxs as
|
|
4
|
-
import { c as
|
|
3
|
+
import { jsxs as g, jsx as s, Fragment as ee } from "react/jsx-runtime";
|
|
4
|
+
import { c as p } from "../twUtils-CRiPKpXj.js";
|
|
5
5
|
import { forwardRef as te, useId as re, useState as C, useRef as T, useMemo as _, useCallback as E, useEffect as S } from "react";
|
|
6
6
|
import { L as $ } from "../loader-circle-CvdzOiQ_.js";
|
|
7
7
|
import { C as se, a as ne } from "../chevron-down-UbkgS76q.js";
|
|
8
|
-
const B = "h-4 w-4", G = "h-5 w-5", ae = (
|
|
8
|
+
const B = "h-4 w-4", G = "h-5 w-5", ae = (n) => ({
|
|
9
9
|
error: "border-danger hover:border-danger focus-visible:border-danger focus-visible:ring-danger",
|
|
10
10
|
loading: "cursor-wait pointer-events-none border-input-border--disabled",
|
|
11
11
|
disabled: "cursor-not-allowed opacity-50 border-input-border--disabled bg-input-bg--disabled",
|
|
12
12
|
default: ""
|
|
13
|
-
})[
|
|
13
|
+
})[n], de = (n, d, u) => p(
|
|
14
14
|
"flex h-12 w-full items-center justify-between rounded-lg border border-input-border bg-input-bg px-4 py-3 text-sm",
|
|
15
15
|
"hover:border-input-border--hover focus:border-input-border--focus focus:outline-none",
|
|
16
16
|
"focus:ring-2 focus:ring-black focus:ring-offset-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black focus-visible:ring-offset-2",
|
|
17
17
|
"disabled:cursor-not-allowed disabled:opacity-50 disabled:border-input-border--disabled disabled:bg-input-bg--disabled",
|
|
18
18
|
"transition duration-200 text-input-text [&>span]:line-clamp-1",
|
|
19
|
-
|
|
20
|
-
ae(
|
|
21
|
-
|
|
22
|
-
), le = (
|
|
19
|
+
d && "border-input-border--focus ring-2 ring-black ring-offset-2",
|
|
20
|
+
ae(n),
|
|
21
|
+
u
|
|
22
|
+
), le = (n) => p(
|
|
23
23
|
"absolute top-full left-0 right-0 z-50 mt-1 max-h-96 min-w-[8rem] overflow-hidden rounded-lg border border-input-border bg-input-bg shadow-md",
|
|
24
24
|
"transition-all duration-200 origin-top",
|
|
25
|
-
|
|
26
|
-
), ie = (
|
|
27
|
-
const
|
|
25
|
+
n ? "scale-100 opacity-100 translate-y-0" : "scale-95 opacity-0 -translate-y-1 pointer-events-none"
|
|
26
|
+
), ie = (n) => {
|
|
27
|
+
const d = T(null);
|
|
28
28
|
return S(() => {
|
|
29
|
-
const
|
|
30
|
-
|
|
29
|
+
const u = (t) => {
|
|
30
|
+
d.current && !d.current.contains(t.target) && n();
|
|
31
31
|
};
|
|
32
|
-
return document.addEventListener("mousedown",
|
|
33
|
-
}, [
|
|
34
|
-
}, oe = (
|
|
35
|
-
const [
|
|
32
|
+
return document.addEventListener("mousedown", u), () => document.removeEventListener("mousedown", u);
|
|
33
|
+
}, [n]), d;
|
|
34
|
+
}, oe = (n, d, u, t, v) => {
|
|
35
|
+
const [l, b] = C(-1);
|
|
36
36
|
S(() => {
|
|
37
|
-
if (
|
|
38
|
-
const
|
|
39
|
-
|
|
37
|
+
if (n) {
|
|
38
|
+
const r = t.findIndex((i) => i.value === v);
|
|
39
|
+
b(r >= 0 ? r : 0);
|
|
40
40
|
} else
|
|
41
|
-
|
|
42
|
-
}, [
|
|
43
|
-
const
|
|
44
|
-
(
|
|
45
|
-
if (!
|
|
46
|
-
return
|
|
47
|
-
const
|
|
41
|
+
b(-1);
|
|
42
|
+
}, [n, v, t]);
|
|
43
|
+
const y = E(
|
|
44
|
+
(r) => {
|
|
45
|
+
if (!n)
|
|
46
|
+
return r.key === "ArrowDown" || r.key === "ArrowUp" || r.key === " " || r.key === "Enter" ? (r.preventDefault(), "open") : void 0;
|
|
47
|
+
const w = {
|
|
48
48
|
ArrowDown: () => {
|
|
49
|
-
|
|
50
|
-
const o = Math.min(
|
|
49
|
+
r.preventDefault(), b((c) => {
|
|
50
|
+
const o = Math.min(c + 1, t.length - 1);
|
|
51
51
|
return t[o]?.disabled && o < t.length - 1 ? Math.min(o + 1, t.length - 1) : o;
|
|
52
52
|
});
|
|
53
53
|
},
|
|
54
54
|
ArrowUp: () => {
|
|
55
|
-
|
|
56
|
-
const o = Math.max(
|
|
55
|
+
r.preventDefault(), b((c) => {
|
|
56
|
+
const o = Math.max(c - 1, 0);
|
|
57
57
|
return t[o]?.disabled && o > 0 ? Math.max(o - 1, 0) : o;
|
|
58
58
|
});
|
|
59
59
|
},
|
|
60
60
|
Enter: () => {
|
|
61
|
-
|
|
61
|
+
r.preventDefault(), l >= 0 && t[l] && !t[l].disabled && (u(t[l].value), d());
|
|
62
62
|
},
|
|
63
63
|
" ": () => {
|
|
64
|
-
|
|
64
|
+
r.preventDefault(), l >= 0 && t[l] && !t[l].disabled && (u(t[l].value), d());
|
|
65
65
|
},
|
|
66
66
|
Escape: () => {
|
|
67
|
-
|
|
67
|
+
r.preventDefault(), d();
|
|
68
68
|
},
|
|
69
69
|
Home: () => {
|
|
70
|
-
|
|
70
|
+
r.preventDefault(), b(0);
|
|
71
71
|
},
|
|
72
72
|
End: () => {
|
|
73
|
-
|
|
73
|
+
r.preventDefault(), b(t.length - 1);
|
|
74
74
|
}
|
|
75
|
-
}[
|
|
76
|
-
|
|
75
|
+
}[r.key];
|
|
76
|
+
w && w();
|
|
77
77
|
},
|
|
78
|
-
[t,
|
|
78
|
+
[t, l, u, d, n]
|
|
79
79
|
);
|
|
80
|
-
return { focusedIndex:
|
|
80
|
+
return { focusedIndex: l, setFocusedIndex: b, handleKeyDown: y };
|
|
81
81
|
}, ce = te(
|
|
82
82
|
({
|
|
83
|
-
|
|
84
|
-
defaultValue:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
className: n,
|
|
84
|
+
defaultValue: d,
|
|
85
|
+
emptyMessage: u = "No options found",
|
|
86
|
+
errorMessage: t,
|
|
87
|
+
loadingMessage: v = "Loading...",
|
|
88
|
+
id: l,
|
|
89
|
+
label: b,
|
|
90
|
+
name: y,
|
|
91
|
+
onChange: r,
|
|
92
|
+
options: i = [],
|
|
93
|
+
placeholder: w = "Select an option",
|
|
94
|
+
state: c = "default",
|
|
95
|
+
value: o,
|
|
96
96
|
"aria-label": I,
|
|
97
97
|
"aria-describedby": U,
|
|
98
98
|
...j
|
|
99
99
|
}, Z) => {
|
|
100
|
-
const z = re(), L =
|
|
101
|
-
const e = {},
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
}), { groups: e, ungrouped:
|
|
105
|
-
}, [
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
const z = re(), L = l || `${y}-${z}`, M = `${L}-error`, [m, h] = C(!1), [P, W] = C(d || ""), A = o !== void 0, N = A ? o : P, q = ie(() => h(!1)), D = T(null), O = j.disabled || c === "disabled", J = c === "loading", Q = c === "error", x = _(() => {
|
|
101
|
+
const e = {}, f = [];
|
|
102
|
+
return i.forEach((a) => {
|
|
103
|
+
a.group ? (e[a.group] || (e[a.group] = []), e[a.group].push(a)) : f.push(a);
|
|
104
|
+
}), { groups: e, ungrouped: f, hasGroups: Object.keys(e).length > 0 };
|
|
105
|
+
}, [i]), K = _(() => i.find((e) => e.value === N), [i, N]), { focusedIndex: k, handleKeyDown: R } = oe(
|
|
106
|
+
m,
|
|
107
|
+
() => h(!1),
|
|
108
108
|
F,
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
i,
|
|
110
|
+
N
|
|
111
111
|
), V = E(() => {
|
|
112
|
-
O ||
|
|
112
|
+
O || h((e) => !e);
|
|
113
113
|
}, [O]);
|
|
114
114
|
function F(e) {
|
|
115
|
-
|
|
115
|
+
i.find((a) => a.value === e)?.disabled || (A || W(e), r?.(e), h(!1));
|
|
116
116
|
}
|
|
117
117
|
const X = E(
|
|
118
118
|
(e) => {
|
|
119
|
-
R(e) === "open" &&
|
|
119
|
+
R(e) === "open" && h(!0);
|
|
120
120
|
},
|
|
121
121
|
[R]
|
|
122
122
|
);
|
|
123
123
|
S(() => {
|
|
124
|
-
if (
|
|
125
|
-
const e = D.current.children[
|
|
124
|
+
if (m && k >= 0 && D.current) {
|
|
125
|
+
const e = D.current.children[k];
|
|
126
126
|
e && e.scrollIntoView({ block: "nearest" });
|
|
127
127
|
}
|
|
128
|
-
}, [
|
|
129
|
-
const H = (e,
|
|
130
|
-
const
|
|
131
|
-
return /* @__PURE__ */
|
|
128
|
+
}, [k, m]);
|
|
129
|
+
const H = (e, f) => {
|
|
130
|
+
const a = N === e.value;
|
|
131
|
+
return /* @__PURE__ */ g(
|
|
132
132
|
"button",
|
|
133
133
|
{
|
|
134
134
|
type: "button",
|
|
135
|
-
className:
|
|
135
|
+
className: p(
|
|
136
136
|
"relative flex w-full cursor-default items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none",
|
|
137
137
|
"hover:bg-input-bg--hover focus:bg-input-bg--hover hover:cursor-pointer",
|
|
138
138
|
"data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
f === k && "bg-input-bg--hover",
|
|
140
|
+
a && "bg-input-bg--selected text-input-text"
|
|
141
141
|
),
|
|
142
142
|
onClick: () => F(e.value),
|
|
143
143
|
disabled: e.disabled,
|
|
144
144
|
"data-disabled": e.disabled,
|
|
145
|
-
"aria-selected":
|
|
145
|
+
"aria-selected": a,
|
|
146
146
|
role: "option",
|
|
147
147
|
children: [
|
|
148
|
-
/* @__PURE__ */
|
|
149
|
-
|
|
148
|
+
/* @__PURE__ */ s("span", { className: "block truncate", children: e.label }),
|
|
149
|
+
a && /* @__PURE__ */ s("span", { className: "absolute right-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ s(ne, { className: p(B, "text-input-text") }) })
|
|
150
150
|
]
|
|
151
151
|
},
|
|
152
152
|
e.value
|
|
@@ -156,42 +156,42 @@ const B = "h-4 w-4", G = "h-5 w-5", ae = (t) => ({
|
|
|
156
156
|
"--select-border-radius": "0.5rem",
|
|
157
157
|
"--select-trigger-height": "3rem"
|
|
158
158
|
});
|
|
159
|
-
return /* @__PURE__ */
|
|
160
|
-
/* @__PURE__ */
|
|
161
|
-
/* @__PURE__ */
|
|
159
|
+
return /* @__PURE__ */ g("div", { className: "w-full", "data-testid": "select-root", children: [
|
|
160
|
+
/* @__PURE__ */ g("div", { ref: q, className: "relative", "data-testid": "select-wrapper", children: [
|
|
161
|
+
/* @__PURE__ */ g(
|
|
162
162
|
"button",
|
|
163
163
|
{
|
|
164
164
|
ref: Z,
|
|
165
165
|
type: "button",
|
|
166
166
|
id: L,
|
|
167
|
-
name:
|
|
168
|
-
className: de(
|
|
167
|
+
name: y,
|
|
168
|
+
className: de(c, m, n),
|
|
169
169
|
onClick: V,
|
|
170
170
|
onKeyDown: X,
|
|
171
171
|
disabled: O,
|
|
172
|
-
"aria-label": I ||
|
|
173
|
-
"aria-describedby":
|
|
174
|
-
"aria-expanded":
|
|
172
|
+
"aria-label": I || b,
|
|
173
|
+
"aria-describedby": p(Q && M, U),
|
|
174
|
+
"aria-expanded": m,
|
|
175
175
|
"aria-haspopup": "listbox",
|
|
176
|
-
"data-state":
|
|
176
|
+
"data-state": c,
|
|
177
177
|
style: Y(),
|
|
178
178
|
...j,
|
|
179
179
|
children: [
|
|
180
|
-
/* @__PURE__ */
|
|
181
|
-
/* @__PURE__ */
|
|
180
|
+
/* @__PURE__ */ s("span", { className: "block truncate", children: K ? K.label : /* @__PURE__ */ s("span", { className: "text-input-text-placeholder", children: w }) }),
|
|
181
|
+
/* @__PURE__ */ s("div", { className: "flex items-center", children: c === "loading" ? /* @__PURE__ */ s($, { className: p(G, "text-input-icon animate-spin") }) : /* @__PURE__ */ s(
|
|
182
182
|
se,
|
|
183
183
|
{
|
|
184
|
-
className:
|
|
184
|
+
className: p(
|
|
185
185
|
G,
|
|
186
186
|
"text-input-icon transition-transform duration-200",
|
|
187
|
-
|
|
187
|
+
m && "rotate-180"
|
|
188
188
|
)
|
|
189
189
|
}
|
|
190
190
|
) })
|
|
191
191
|
]
|
|
192
192
|
}
|
|
193
193
|
),
|
|
194
|
-
/* @__PURE__ */
|
|
194
|
+
/* @__PURE__ */ s("div", { className: le(m), "data-testid": "select-dropdown", children: /* @__PURE__ */ s("div", { className: "p-1", children: /* @__PURE__ */ s(
|
|
195
195
|
"div",
|
|
196
196
|
{
|
|
197
197
|
ref: D,
|
|
@@ -199,21 +199,21 @@ const B = "h-4 w-4", G = "h-5 w-5", ae = (t) => ({
|
|
|
199
199
|
role: "listbox",
|
|
200
200
|
"aria-multiselectable": "false",
|
|
201
201
|
tabIndex: -1,
|
|
202
|
-
children: J ? /* @__PURE__ */
|
|
203
|
-
/* @__PURE__ */
|
|
204
|
-
|
|
205
|
-
] }) :
|
|
206
|
-
|
|
207
|
-
Object.entries(
|
|
208
|
-
(
|
|
209
|
-
/* @__PURE__ */
|
|
210
|
-
|
|
202
|
+
children: J ? /* @__PURE__ */ g("div", { className: "text-input-text-secondary flex items-center justify-center gap-2 py-6 text-sm", children: [
|
|
203
|
+
/* @__PURE__ */ s($, { className: p(B, "animate-spin") }),
|
|
204
|
+
v
|
|
205
|
+
] }) : i.length === 0 ? /* @__PURE__ */ s("div", { className: "text-input-text-secondary py-6 text-center text-sm", children: u }) : /* @__PURE__ */ g(ee, { children: [
|
|
206
|
+
x.ungrouped.length > 0 && /* @__PURE__ */ s("div", { className: "mb-1", children: x.ungrouped.map((e) => H(e, i.indexOf(e))) }),
|
|
207
|
+
Object.entries(x.groups).map(([e, f]) => /* @__PURE__ */ g("div", { className: "mb-1", children: [
|
|
208
|
+
(x.ungrouped.length > 0 || Object.keys(x.groups).indexOf(e) > 0) && /* @__PURE__ */ s("div", { className: "bg-input-border -mx-1 my-1 h-px" }),
|
|
209
|
+
/* @__PURE__ */ s("div", { className: "text-input-text-secondary px-2 py-1.5 text-sm font-semibold", children: e }),
|
|
210
|
+
f.map((a) => H(a, i.indexOf(a)))
|
|
211
211
|
] }, e))
|
|
212
212
|
] })
|
|
213
213
|
}
|
|
214
214
|
) }) })
|
|
215
215
|
] }),
|
|
216
|
-
|
|
216
|
+
c === "error" && t && /* @__PURE__ */ s(
|
|
217
217
|
"p",
|
|
218
218
|
{
|
|
219
219
|
id: M,
|
|
@@ -221,7 +221,7 @@ const B = "h-4 w-4", G = "h-5 w-5", ae = (t) => ({
|
|
|
221
221
|
"data-testid": "select-error-message",
|
|
222
222
|
"aria-live": "polite",
|
|
223
223
|
"aria-atomic": "true",
|
|
224
|
-
children:
|
|
224
|
+
children: t
|
|
225
225
|
}
|
|
226
226
|
)
|
|
227
227
|
] });
|
package/dist/Select.d.ts
CHANGED
|
@@ -2,28 +2,28 @@ import { SelectBase, SelectBaseProps, SelectOption } from './SelectBase';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
export type SelectState = 'default' | 'error' | 'disabled' | 'loading';
|
|
4
4
|
export type SelectItem = {
|
|
5
|
-
label: string;
|
|
6
|
-
value: string;
|
|
7
|
-
disabled?: boolean;
|
|
5
|
+
readonly label: string;
|
|
6
|
+
readonly value: string;
|
|
7
|
+
readonly disabled?: boolean;
|
|
8
8
|
};
|
|
9
9
|
export interface SelectProps extends Omit<SelectBaseProps, 'options' | 'onChange'> {
|
|
10
|
-
contentClassName?: string;
|
|
10
|
+
readonly contentClassName?: string;
|
|
11
11
|
defaultValue?: string;
|
|
12
|
-
itemClassName?: string;
|
|
13
|
-
items: SelectItem[];
|
|
12
|
+
readonly itemClassName?: string;
|
|
13
|
+
readonly items: readonly SelectItem[];
|
|
14
14
|
onValueChange?: (value: string) => void;
|
|
15
|
-
placeholder: string;
|
|
16
|
-
triggerClassName?: string;
|
|
15
|
+
readonly placeholder: string;
|
|
16
|
+
readonly triggerClassName?: string;
|
|
17
17
|
value?: string;
|
|
18
18
|
disabled?: boolean;
|
|
19
|
-
name?: string;
|
|
20
|
-
id?: string;
|
|
21
|
-
state?: SelectState;
|
|
22
|
-
emptyMessage?: ReactNode;
|
|
23
|
-
errorMessage?: string;
|
|
24
|
-
label?: string;
|
|
25
|
-
'aria-label'?: string;
|
|
26
|
-
'aria-describedby'?: string;
|
|
19
|
+
readonly name?: string;
|
|
20
|
+
readonly id?: string;
|
|
21
|
+
readonly state?: SelectState;
|
|
22
|
+
readonly emptyMessage?: ReactNode;
|
|
23
|
+
readonly errorMessage?: string;
|
|
24
|
+
readonly label?: string;
|
|
25
|
+
readonly 'aria-label'?: string;
|
|
26
|
+
readonly 'aria-describedby'?: string;
|
|
27
27
|
}
|
|
28
28
|
declare const Select: import('react').ForwardRefExoticComponent<SelectProps & import('react').RefAttributes<HTMLButtonElement>> & {
|
|
29
29
|
Root: ({ children, ...props }: {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
2
|
+
export interface TabsContextValue {
|
|
3
|
+
onValueChange: (value: string) => void;
|
|
4
|
+
readonly activationMode: 'automatic' | 'manual';
|
|
5
|
+
readonly baseId: string;
|
|
6
|
+
readonly dir: 'ltr' | 'rtl';
|
|
7
|
+
readonly disabled: boolean;
|
|
8
|
+
readonly orientation: 'horizontal' | 'vertical';
|
|
9
|
+
readonly value: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const TabsContext: import('react').Context<TabsContextValue | null>;
|
|
12
|
+
export declare const useTabsContext: (componentName?: string) => TabsContextValue;
|
|
13
|
+
export interface TabsBaseProps extends Omit<ComponentPropsWithoutRef<'div'>, 'dir' | 'defaultValue'> {
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
readonly activationMode?: 'automatic' | 'manual';
|
|
16
|
+
readonly defaultValue?: string;
|
|
17
|
+
readonly children: ReactNode;
|
|
18
|
+
readonly dir?: 'ltr' | 'rtl';
|
|
19
|
+
readonly disabled?: boolean;
|
|
20
|
+
readonly orientation?: 'horizontal' | 'vertical';
|
|
21
|
+
readonly value?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const TabsBase: import('react').ForwardRefExoticComponent<TabsBaseProps & import('react').RefAttributes<HTMLElement>>;
|
|
24
|
+
export interface TabsListProps extends ComponentPropsWithoutRef<'div'> {
|
|
25
|
+
readonly loop?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const TabsList: import('react').ForwardRefExoticComponent<TabsListProps & import('react').RefAttributes<HTMLElement>>;
|
|
28
|
+
export interface TabsTriggerProps extends ComponentPropsWithoutRef<'button'> {
|
|
29
|
+
readonly value: string;
|
|
30
|
+
readonly disabled?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare const TabsTrigger: import('react').ForwardRefExoticComponent<TabsTriggerProps & import('react').RefAttributes<HTMLElement>>;
|
|
33
|
+
export interface TabsContentProps extends ComponentPropsWithoutRef<'div'> {
|
|
34
|
+
readonly value: string;
|
|
35
|
+
readonly forceMount?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare const TabsContent: import('react').ForwardRefExoticComponent<TabsContentProps & import('react').RefAttributes<HTMLElement>>;
|
|
38
|
+
//# sourceMappingURL=TabsBase.d.ts.map
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../styles/main.css";
|
|
3
|
+
import { jsx as x, jsxs as R } from "react/jsx-runtime";
|
|
4
|
+
import { generateId as $, prefersReducedMotion as _, debounce as L, getIndicatorPosition as S, calculateIndicatorStyle as K } from "./tabsUtils.js";
|
|
5
|
+
import { c as y } from "../twUtils-CRiPKpXj.js";
|
|
6
|
+
import { createContext as M, forwardRef as z, useState as D, useId as N, useCallback as p, useRef as k, useEffect as O, useContext as P } from "react";
|
|
7
|
+
const E = M(null), C = (I = "Tabs") => {
|
|
8
|
+
const d = P(E);
|
|
9
|
+
if (d === null)
|
|
10
|
+
throw new Error(`${I} components must be used within a Tabs.Root`);
|
|
11
|
+
return d;
|
|
12
|
+
}, B = z(function({
|
|
13
|
+
value: d,
|
|
14
|
+
defaultValue: n,
|
|
15
|
+
onValueChange: f,
|
|
16
|
+
orientation: b = "horizontal",
|
|
17
|
+
activationMode: h = "automatic",
|
|
18
|
+
dir: u = "ltr",
|
|
19
|
+
disabled: o = !1,
|
|
20
|
+
children: m,
|
|
21
|
+
...s
|
|
22
|
+
}, l) {
|
|
23
|
+
const [v, g] = D(n ?? ""), c = N() ?? $("tabs"), r = d !== void 0, t = r ? d : v, e = p(
|
|
24
|
+
(w) => {
|
|
25
|
+
o || (r || g(w), f?.(w));
|
|
26
|
+
},
|
|
27
|
+
[r, f, o]
|
|
28
|
+
), a = {
|
|
29
|
+
value: t,
|
|
30
|
+
onValueChange: e,
|
|
31
|
+
orientation: b,
|
|
32
|
+
activationMode: h,
|
|
33
|
+
dir: u,
|
|
34
|
+
disabled: o,
|
|
35
|
+
baseId: c
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ x(E.Provider, { value: a, children: /* @__PURE__ */ x(
|
|
38
|
+
"div",
|
|
39
|
+
{
|
|
40
|
+
ref: l,
|
|
41
|
+
"data-orientation": b,
|
|
42
|
+
"data-disabled": o ? "" : void 0,
|
|
43
|
+
dir: u,
|
|
44
|
+
...s,
|
|
45
|
+
children: m
|
|
46
|
+
}
|
|
47
|
+
) });
|
|
48
|
+
}), H = z(function({ className: d, loop: n = !0, ...f }, b) {
|
|
49
|
+
const { orientation: h, disabled: u } = C("TabsList"), [o, m] = D(() => ({
|
|
50
|
+
left: 0,
|
|
51
|
+
top: 0,
|
|
52
|
+
width: 0,
|
|
53
|
+
height: 0,
|
|
54
|
+
orientation: "horizontal",
|
|
55
|
+
isEnclosed: !1
|
|
56
|
+
})), s = k(null), l = _(), v = p(
|
|
57
|
+
L(() => {
|
|
58
|
+
const c = K(s);
|
|
59
|
+
m(c);
|
|
60
|
+
}, 16),
|
|
61
|
+
// ~60fps
|
|
62
|
+
[]
|
|
63
|
+
);
|
|
64
|
+
O(() => {
|
|
65
|
+
v();
|
|
66
|
+
const c = new ResizeObserver(v), r = new MutationObserver(v), t = s.current;
|
|
67
|
+
return t && (c.observe(t), r.observe(t, {
|
|
68
|
+
attributes: !0,
|
|
69
|
+
childList: !0,
|
|
70
|
+
subtree: !0
|
|
71
|
+
})), () => {
|
|
72
|
+
c.disconnect(), r.disconnect();
|
|
73
|
+
};
|
|
74
|
+
}, [v]);
|
|
75
|
+
const g = p(
|
|
76
|
+
(c) => {
|
|
77
|
+
if (u) return;
|
|
78
|
+
const r = Array.from(
|
|
79
|
+
s.current?.querySelectorAll(
|
|
80
|
+
"[role='tab']:not([disabled]):not([aria-disabled='true'])"
|
|
81
|
+
) ?? []
|
|
82
|
+
);
|
|
83
|
+
if (r.length === 0) return;
|
|
84
|
+
const t = r.findIndex((T) => T === document.activeElement);
|
|
85
|
+
if (t === -1) return;
|
|
86
|
+
let e = null;
|
|
87
|
+
const { key: a, ctrlKey: w, metaKey: A } = c, i = w || A;
|
|
88
|
+
h === "horizontal" ? a === "ArrowLeft" || a === "ArrowUp" && i ? e = t > 0 ? t - 1 : n ? r.length - 1 : t : (a === "ArrowRight" || a === "ArrowDown" && i) && (e = t < r.length - 1 ? t + 1 : n ? 0 : t) : a === "ArrowUp" || a === "ArrowLeft" && i ? e = t > 0 ? t - 1 : n ? r.length - 1 : t : (a === "ArrowDown" || a === "ArrowRight" && i) && (e = t < r.length - 1 ? t + 1 : n ? 0 : t), a === "Home" ? e = 0 : a === "End" && (e = r.length - 1), e !== null && e !== t && (c.preventDefault(), c.stopPropagation(), r[e]?.focus());
|
|
89
|
+
},
|
|
90
|
+
[u, h, n]
|
|
91
|
+
);
|
|
92
|
+
return /* @__PURE__ */ R("div", { className: "relative", ref: s, children: [
|
|
93
|
+
/* @__PURE__ */ x(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
ref: b,
|
|
97
|
+
role: "tablist",
|
|
98
|
+
"aria-orientation": h,
|
|
99
|
+
"aria-disabled": u,
|
|
100
|
+
className: y("tabs-list", d),
|
|
101
|
+
onKeyDown: g,
|
|
102
|
+
...f
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
/* @__PURE__ */ x(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
className: y(
|
|
109
|
+
"pointer-events-none absolute select-none",
|
|
110
|
+
!l && "transition-all duration-300 ease-out",
|
|
111
|
+
o.orientation === "horizontal" && !o.isEnclosed && [
|
|
112
|
+
"bottom-[1px] after:absolute after:bottom-0 after:left-0 after:w-full after:content-['']",
|
|
113
|
+
"after:border-tabs-indicator z-10 after:rounded-t-[0.3rem] after:border-b-[0.3rem]"
|
|
114
|
+
],
|
|
115
|
+
o.orientation === "vertical" && !o.isEnclosed && [
|
|
116
|
+
"right-[1px]",
|
|
117
|
+
!l && "transition-[top_300ms_ease,height_300ms_ease]",
|
|
118
|
+
"after:absolute after:top-0 after:right-0 after:h-full after:w-1 after:content-['']",
|
|
119
|
+
"after:border-tabs-indicator z-10 after:rounded-l-[0.3rem] after:border-r-[0.3rem]"
|
|
120
|
+
],
|
|
121
|
+
o.orientation === "horizontal" && o.isEnclosed && [
|
|
122
|
+
"bg-tabs-enclosed-indicator top-[10%] bottom-[10%] z-0 rounded-lg shadow-lg",
|
|
123
|
+
!l && "transition-[left_300ms_ease,width_300ms_ease]"
|
|
124
|
+
],
|
|
125
|
+
o.orientation === "vertical" && o.isEnclosed && [
|
|
126
|
+
"bg-tabs-enclosed-indicator right-1 left-1 z-0 max-h-10 w-auto rounded-lg shadow-lg"
|
|
127
|
+
]
|
|
128
|
+
),
|
|
129
|
+
style: {
|
|
130
|
+
...S(o),
|
|
131
|
+
...o.isEnclosed && o.orientation === "vertical" ? { height: "40px" } : {}
|
|
132
|
+
},
|
|
133
|
+
"aria-hidden": "true"
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
] });
|
|
137
|
+
}), G = z(function({ className: d, value: n, onClick: f, onKeyDown: b, disabled: h = !1, ...u }, o) {
|
|
138
|
+
const { value: m, onValueChange: s, activationMode: l, disabled: v, baseId: g } = C("TabsTrigger"), c = `${g}-trigger-${n}`, r = `${g}-content-${n}`, t = m === n, e = v || h, a = p(
|
|
139
|
+
(i) => {
|
|
140
|
+
if (e) {
|
|
141
|
+
i.preventDefault();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
s(n), f?.(i);
|
|
145
|
+
},
|
|
146
|
+
[n, s, f, e]
|
|
147
|
+
), w = p(
|
|
148
|
+
(i) => {
|
|
149
|
+
if (e) {
|
|
150
|
+
i.preventDefault();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const { key: T } = i;
|
|
154
|
+
(T === "Enter" || T === " ") && (i.preventDefault(), i.stopPropagation(), s(n)), b?.(i);
|
|
155
|
+
},
|
|
156
|
+
[n, s, b, e]
|
|
157
|
+
), A = p(() => {
|
|
158
|
+
e || l === "automatic" && s(n);
|
|
159
|
+
}, [l, s, n, e]);
|
|
160
|
+
return /* @__PURE__ */ x(
|
|
161
|
+
"button",
|
|
162
|
+
{
|
|
163
|
+
ref: o,
|
|
164
|
+
role: "tab",
|
|
165
|
+
type: "button",
|
|
166
|
+
id: c,
|
|
167
|
+
"aria-controls": r,
|
|
168
|
+
"aria-selected": t,
|
|
169
|
+
"aria-disabled": e,
|
|
170
|
+
disabled: e,
|
|
171
|
+
"data-state": t ? "active" : "inactive",
|
|
172
|
+
"data-disabled": e ? "" : void 0,
|
|
173
|
+
tabIndex: t ? 0 : -1,
|
|
174
|
+
className: y(
|
|
175
|
+
"tabs-trigger z-10 focus:outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600",
|
|
176
|
+
e && ["cursor-not-allowed opacity-50"],
|
|
177
|
+
d
|
|
178
|
+
),
|
|
179
|
+
onClick: a,
|
|
180
|
+
onKeyDown: w,
|
|
181
|
+
onFocus: A,
|
|
182
|
+
...u
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
}), J = z(function({ className: d, value: n, forceMount: f = !1, ...b }, h) {
|
|
186
|
+
const { value: u, baseId: o } = C("TabsContent"), m = `${o}-content-${n}`, s = `${o}-trigger-${n}`, l = u === n;
|
|
187
|
+
return !f && !l ? null : /* @__PURE__ */ x(
|
|
188
|
+
"div",
|
|
189
|
+
{
|
|
190
|
+
ref: h,
|
|
191
|
+
role: "tabpanel",
|
|
192
|
+
id: m,
|
|
193
|
+
"aria-labelledby": s,
|
|
194
|
+
"data-state": l ? "active" : "inactive",
|
|
195
|
+
tabIndex: 0,
|
|
196
|
+
className: y("tabs-content focus:outline-none focus-visible:outline-none", d),
|
|
197
|
+
hidden: !l,
|
|
198
|
+
...b
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
export {
|
|
203
|
+
B as TabsBase,
|
|
204
|
+
J as TabsContent,
|
|
205
|
+
E as TabsContext,
|
|
206
|
+
H as TabsList,
|
|
207
|
+
G as TabsTrigger,
|
|
208
|
+
C as useTabsContext
|
|
209
|
+
};
|