@adam-milo/ui 1.0.32 → 1.0.34
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/index.cjs +1 -1
- package/dist/index.js +58 -22
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +94 -56
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +199 -40
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +305 -105
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +260 -74
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +135 -27
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +52 -469
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +57 -111
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +101 -20
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +76 -21
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +25 -29
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +6 -4
- package/dist/index20.cjs +1 -1
- package/dist/index20.js +468 -31
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +155 -41
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +42 -12
- package/dist/index23.cjs +1 -0
- package/dist/index23.js +38 -0
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +32 -287
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +115 -13
- package/dist/index26.cjs +1 -0
- package/dist/index26.js +55 -0
- package/dist/index27.cjs +1 -0
- package/dist/index27.js +45 -0
- package/dist/index28.cjs +1 -0
- package/dist/index28.js +53 -0
- package/dist/index29.cjs +1 -0
- package/dist/index29.js +55 -0
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +33 -33
- package/dist/index30.cjs +1 -0
- package/dist/index30.js +72 -0
- package/dist/index31.cjs +1 -0
- package/dist/index31.js +14 -0
- package/dist/index32.cjs +1 -0
- package/dist/index32.js +332 -0
- package/dist/index36.cjs +1 -0
- package/dist/index36.js +386 -0
- package/dist/index37.cjs +1 -0
- package/dist/index37.js +16 -0
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +59 -11
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +19 -35
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +11 -101
- package/dist/index62.cjs +1 -0
- package/dist/index62.js +502 -0
- package/dist/index64.cjs +1 -0
- package/dist/index64.js +11 -0
- package/dist/index65.cjs +1 -0
- package/dist/index65.js +39 -0
- package/dist/index66.cjs +1 -0
- package/dist/index66.js +64 -0
- package/dist/index67.cjs +1 -0
- package/dist/index67.js +212 -0
- package/dist/index68.cjs +1 -0
- package/dist/index68.js +14 -0
- package/dist/index69.cjs +1 -0
- package/dist/index69.js +293 -0
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +46 -97
- package/dist/index70.cjs +1 -0
- package/dist/index70.js +18 -0
- package/dist/index71.cjs +1 -0
- package/dist/index71.js +129 -0
- package/dist/index72.cjs +1 -0
- package/dist/index72.js +43 -0
- package/dist/index73.cjs +1 -0
- package/dist/index73.js +99 -0
- package/dist/index74.cjs +1 -0
- package/dist/index74.js +71 -0
- package/dist/index75.cjs +1 -0
- package/dist/index75.js +36 -0
- package/dist/index76.cjs +1 -0
- package/dist/index76.js +14 -0
- package/dist/index77.cjs +1 -0
- package/dist/index77.js +17 -0
- package/dist/index78.cjs +1 -0
- package/dist/index78.js +6 -0
- package/dist/index79.cjs +1 -0
- package/dist/index79.js +297 -0
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +97 -88
- package/dist/index80.cjs +1 -0
- package/dist/index80.js +25 -0
- package/dist/index81.cjs +1 -0
- package/dist/index81.js +39 -0
- package/dist/index82.cjs +1 -0
- package/dist/index82.js +625 -0
- package/dist/index83.cjs +1 -0
- package/dist/index83.js +721 -0
- package/dist/index84.cjs +1 -0
- package/dist/index84.js +154 -0
- package/dist/index85.cjs +1 -0
- package/dist/index85.js +173 -0
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +55 -197
- package/dist/src/components/core/button/Button.component.d.ts +13 -7
- package/dist/src/components/core/button/Button.component.d.ts.map +1 -1
- package/dist/src/components/core/icon/Icon.component.d.ts +1 -1
- package/dist/src/components/core/icon/Icon.component.d.ts.map +1 -1
- package/dist/src/components/core/icon-button/IconButton.component.d.ts +36 -0
- package/dist/src/components/core/icon-button/IconButton.component.d.ts.map +1 -0
- package/dist/src/components/core/menu-icon-button/MenuIconButton.component.d.ts +79 -0
- package/dist/src/components/core/menu-icon-button/MenuIconButton.component.d.ts.map +1 -0
- package/dist/src/components/feedback/spinner/Spinner.component.d.ts +62 -0
- package/dist/src/components/feedback/spinner/Spinner.component.d.ts.map +1 -0
- package/dist/src/components/forms/input/Input.component.d.ts +5 -0
- package/dist/src/components/forms/input/Input.component.d.ts.map +1 -1
- package/dist/src/components/forms/otp-input/OTPInput.component.d.ts +82 -0
- package/dist/src/components/forms/otp-input/OTPInput.component.d.ts.map +1 -0
- package/dist/src/components/forms/phone-input/PhoneInput.component.d.ts +96 -0
- package/dist/src/components/forms/phone-input/PhoneInput.component.d.ts.map +1 -0
- package/dist/src/components/forms/phone-input/countries.d.ts +93 -0
- package/dist/src/components/forms/phone-input/countries.d.ts.map +1 -0
- package/dist/src/components/forms/select/Select.component.d.ts +5 -1
- package/dist/src/components/forms/select/Select.component.d.ts.map +1 -1
- package/dist/src/components/forms/toggle/Toggle.component.d.ts +80 -0
- package/dist/src/components/forms/toggle/Toggle.component.d.ts.map +1 -0
- package/dist/src/components/layout/auth-layout/AuthLayout.component.d.ts +86 -0
- package/dist/src/components/layout/auth-layout/AuthLayout.component.d.ts.map +1 -0
- package/dist/src/components/overlays/dialog/Dialog.component.d.ts +36 -2
- package/dist/src/components/overlays/dialog/Dialog.component.d.ts.map +1 -1
- package/dist/src/components/typography/heading/Heading.component.d.ts +92 -0
- package/dist/src/components/typography/heading/Heading.component.d.ts.map +1 -0
- package/dist/src/components/typography/link/Link.component.d.ts +80 -0
- package/dist/src/components/typography/link/Link.component.d.ts.map +1 -0
- package/dist/src/index.d.ts +24 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -1
- /package/dist/{index35.cjs → index50.cjs} +0 -0
- /package/dist/{index35.js → index50.js} +0 -0
- /package/dist/{index42.cjs → index61.cjs} +0 -0
- /package/dist/{index42.js → index61.js} +0 -0
package/dist/index13.js
CHANGED
|
@@ -1,93 +1,279 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forwardRef } from "react";
|
|
3
|
-
import { cn } from "./
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useId, useRef, useState, useEffect, useCallback, useImperativeHandle } from "react";
|
|
3
|
+
import { cn } from "./index31.js";
|
|
4
4
|
/* empty css */
|
|
5
|
-
const
|
|
5
|
+
const OTPInput = forwardRef(
|
|
6
6
|
({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
length = 4,
|
|
8
|
+
label,
|
|
9
|
+
value = "",
|
|
10
|
+
onChange,
|
|
11
|
+
onComplete,
|
|
12
|
+
error,
|
|
13
|
+
helperText,
|
|
14
|
+
disabled = false,
|
|
15
|
+
autoFocus = false,
|
|
16
|
+
fullWidth = false,
|
|
17
|
+
centered = false,
|
|
18
|
+
type = "numeric",
|
|
19
|
+
required = false,
|
|
12
20
|
"data-cy": dataCy,
|
|
13
|
-
"data-testid": dataTestId
|
|
14
|
-
...props
|
|
21
|
+
"data-testid": dataTestId
|
|
15
22
|
}, ref) => {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
23
|
+
const generatedId = useId();
|
|
24
|
+
const errorId = `${generatedId}-error`;
|
|
25
|
+
const helperId = `${generatedId}-helper`;
|
|
26
|
+
const finalDataCy = dataCy || "otp-input";
|
|
27
|
+
const finalTestId = dataTestId || "otp-input";
|
|
28
|
+
const inputRefs = useRef([]);
|
|
29
|
+
const [otp, setOtp] = useState(
|
|
30
|
+
() => value.split("").slice(0, length).concat(Array(length).fill("")).slice(0, length)
|
|
31
|
+
);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const newOtp = value.split("").slice(0, length).concat(Array(length).fill("")).slice(0, length);
|
|
34
|
+
setOtp(newOtp);
|
|
35
|
+
}, [value, length]);
|
|
36
|
+
const isValidInput = useCallback(
|
|
37
|
+
(char) => {
|
|
38
|
+
if (type === "numeric") {
|
|
39
|
+
return /^\d$/.test(char);
|
|
40
|
+
}
|
|
41
|
+
return /^[a-zA-Z0-9]$/.test(char);
|
|
42
|
+
},
|
|
43
|
+
[type]
|
|
44
|
+
);
|
|
45
|
+
const updateOtp = useCallback(
|
|
46
|
+
(newOtp) => {
|
|
47
|
+
setOtp(newOtp);
|
|
48
|
+
const otpValue = newOtp.join("");
|
|
49
|
+
onChange == null ? void 0 : onChange(otpValue);
|
|
50
|
+
if (newOtp.every((digit) => digit !== "") && newOtp.length === length) {
|
|
51
|
+
onComplete == null ? void 0 : onComplete(otpValue);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
[onChange, onComplete, length]
|
|
55
|
+
);
|
|
56
|
+
const focusInput = useCallback((index) => {
|
|
57
|
+
const input = inputRefs.current[index];
|
|
58
|
+
if (input) {
|
|
59
|
+
input.focus();
|
|
60
|
+
input.select();
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
63
|
+
const handleChange = useCallback(
|
|
64
|
+
(index, e) => {
|
|
65
|
+
const inputValue = e.target.value;
|
|
66
|
+
if (inputValue.length === 1 && isValidInput(inputValue)) {
|
|
67
|
+
const newOtp = [...otp];
|
|
68
|
+
newOtp[index] = inputValue;
|
|
69
|
+
updateOtp(newOtp);
|
|
70
|
+
if (index < length - 1) {
|
|
71
|
+
focusInput(index + 1);
|
|
72
|
+
}
|
|
73
|
+
} else if (inputValue.length > 1) {
|
|
74
|
+
const chars = inputValue.split("").filter(isValidInput);
|
|
75
|
+
const newOtp = [...otp];
|
|
76
|
+
chars.forEach((char, i) => {
|
|
77
|
+
if (index + i < length) {
|
|
78
|
+
newOtp[index + i] = char;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
updateOtp(newOtp);
|
|
82
|
+
const nextEmptyIndex = newOtp.findIndex((d) => d === "");
|
|
83
|
+
focusInput(nextEmptyIndex === -1 ? length - 1 : nextEmptyIndex);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
[otp, length, isValidInput, updateOtp, focusInput]
|
|
87
|
+
);
|
|
88
|
+
const handleKeyDown = useCallback(
|
|
89
|
+
(index, e) => {
|
|
90
|
+
switch (e.key) {
|
|
91
|
+
case "Backspace":
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
if (otp[index]) {
|
|
94
|
+
const newOtp = [...otp];
|
|
95
|
+
newOtp[index] = "";
|
|
96
|
+
updateOtp(newOtp);
|
|
97
|
+
} else if (index > 0) {
|
|
98
|
+
const newOtp = [...otp];
|
|
99
|
+
newOtp[index - 1] = "";
|
|
100
|
+
updateOtp(newOtp);
|
|
101
|
+
focusInput(index - 1);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
case "Delete":
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
if (otp[index]) {
|
|
107
|
+
const newOtp = [...otp];
|
|
108
|
+
newOtp[index] = "";
|
|
109
|
+
updateOtp(newOtp);
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
case "ArrowLeft":
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
if (index > 0) {
|
|
115
|
+
focusInput(index - 1);
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case "ArrowRight":
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
if (index < length - 1) {
|
|
121
|
+
focusInput(index + 1);
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case "Home":
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
focusInput(0);
|
|
127
|
+
break;
|
|
128
|
+
case "End":
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
focusInput(length - 1);
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
if (e.key.length === 1 && isValidInput(e.key)) {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
const newOtp = [...otp];
|
|
136
|
+
newOtp[index] = e.key;
|
|
137
|
+
updateOtp(newOtp);
|
|
138
|
+
if (index < length - 1) {
|
|
139
|
+
focusInput(index + 1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
[otp, length, isValidInput, updateOtp, focusInput]
|
|
146
|
+
);
|
|
147
|
+
const handlePaste = useCallback(
|
|
148
|
+
(index, e) => {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
const pastedData = e.clipboardData.getData("text");
|
|
151
|
+
const chars = pastedData.split("").filter(isValidInput);
|
|
152
|
+
if (chars.length === 0) return;
|
|
153
|
+
const newOtp = [...otp];
|
|
154
|
+
chars.forEach((char, i) => {
|
|
155
|
+
if (index + i < length) {
|
|
156
|
+
newOtp[index + i] = char;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
updateOtp(newOtp);
|
|
160
|
+
const nextEmptyIndex = newOtp.findIndex((d) => d === "");
|
|
161
|
+
focusInput(nextEmptyIndex === -1 ? length - 1 : nextEmptyIndex);
|
|
162
|
+
},
|
|
163
|
+
[otp, length, isValidInput, updateOtp, focusInput]
|
|
164
|
+
);
|
|
165
|
+
const handleFocus = useCallback((e) => {
|
|
166
|
+
e.target.select();
|
|
167
|
+
}, []);
|
|
168
|
+
useImperativeHandle(
|
|
169
|
+
ref,
|
|
170
|
+
() => ({
|
|
171
|
+
focus: () => {
|
|
172
|
+
const emptyIndex = otp.findIndex((d) => d === "");
|
|
173
|
+
focusInput(emptyIndex === -1 ? length - 1 : emptyIndex);
|
|
174
|
+
},
|
|
175
|
+
clear: () => {
|
|
176
|
+
const newOtp = Array(length).fill("");
|
|
177
|
+
updateOtp(newOtp);
|
|
178
|
+
focusInput(0);
|
|
179
|
+
},
|
|
180
|
+
getValue: () => otp.join("")
|
|
181
|
+
}),
|
|
182
|
+
[otp, length, focusInput, updateOtp]
|
|
183
|
+
);
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (autoFocus && !disabled) {
|
|
186
|
+
focusInput(0);
|
|
187
|
+
}
|
|
188
|
+
}, [autoFocus, disabled, focusInput]);
|
|
189
|
+
return /* @__PURE__ */ jsxs(
|
|
19
190
|
"div",
|
|
20
191
|
{
|
|
21
|
-
className: "
|
|
192
|
+
className: cn("otp-input-wrapper", fullWidth && "otp-input-wrapper--full-width"),
|
|
22
193
|
"data-cy": `${finalDataCy}-wrapper`,
|
|
23
194
|
"data-testid": `${finalTestId}-wrapper`,
|
|
24
|
-
children:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
children: [
|
|
33
|
-
/* @__PURE__ */ jsx(
|
|
34
|
-
"thead",
|
|
35
|
-
{
|
|
36
|
-
className: "datatable__head",
|
|
37
|
-
"data-cy": `${finalDataCy}-head`,
|
|
38
|
-
"data-testid": `${finalTestId}-head`,
|
|
39
|
-
children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx(
|
|
40
|
-
"th",
|
|
41
|
-
{
|
|
42
|
-
className: "datatable__header-cell",
|
|
43
|
-
"data-cy": `${finalDataCy}-header-${column.key}`,
|
|
44
|
-
"data-testid": `${finalTestId}-header-${column.key}`,
|
|
45
|
-
children: column.header
|
|
46
|
-
},
|
|
47
|
-
column.key
|
|
48
|
-
)) })
|
|
49
|
-
}
|
|
195
|
+
children: [
|
|
196
|
+
label && /* @__PURE__ */ jsx(
|
|
197
|
+
"label",
|
|
198
|
+
{
|
|
199
|
+
className: cn(
|
|
200
|
+
"otp-input__label",
|
|
201
|
+
error && "otp-input__label--error",
|
|
202
|
+
disabled && "otp-input__label--disabled"
|
|
50
203
|
),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
204
|
+
"data-cy": `${finalDataCy}-label`,
|
|
205
|
+
"data-testid": `${finalTestId}-label`,
|
|
206
|
+
children: label
|
|
207
|
+
}
|
|
208
|
+
),
|
|
209
|
+
/* @__PURE__ */ jsx(
|
|
210
|
+
"div",
|
|
211
|
+
{
|
|
212
|
+
className: cn("otp-input__container", centered && "otp-input__container--centered"),
|
|
213
|
+
role: "group",
|
|
214
|
+
"aria-label": label || "OTP Input",
|
|
215
|
+
"data-cy": `${finalDataCy}-container`,
|
|
216
|
+
"data-testid": `${finalTestId}-container`,
|
|
217
|
+
children: Array.from({ length }, (_, index) => /* @__PURE__ */ jsx(
|
|
218
|
+
"input",
|
|
62
219
|
{
|
|
220
|
+
ref: (el) => {
|
|
221
|
+
inputRefs.current[index] = el;
|
|
222
|
+
},
|
|
223
|
+
type: "text",
|
|
224
|
+
inputMode: type === "numeric" ? "numeric" : "text",
|
|
225
|
+
pattern: type === "numeric" ? "[0-9]*" : "[a-zA-Z0-9]*",
|
|
226
|
+
maxLength: 1,
|
|
227
|
+
value: otp[index] || "",
|
|
228
|
+
onChange: (e) => handleChange(index, e),
|
|
229
|
+
onKeyDown: (e) => handleKeyDown(index, e),
|
|
230
|
+
onPaste: (e) => handlePaste(index, e),
|
|
231
|
+
onFocus: handleFocus,
|
|
232
|
+
disabled,
|
|
233
|
+
required,
|
|
234
|
+
"aria-label": `Digit ${index + 1} of ${length}`,
|
|
235
|
+
"aria-invalid": error ? "true" : "false",
|
|
236
|
+
"aria-describedby": error ? errorId : helperText ? helperId : void 0,
|
|
63
237
|
className: cn(
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
238
|
+
"otp-input__digit",
|
|
239
|
+
otp[index] && "otp-input__digit--filled",
|
|
240
|
+
error && "otp-input__digit--error"
|
|
67
241
|
),
|
|
68
|
-
"data-cy": `${finalDataCy}-
|
|
69
|
-
"data-testid": `${finalTestId}-
|
|
70
|
-
|
|
71
|
-
"td",
|
|
72
|
-
{
|
|
73
|
-
className: "datatable__body-cell",
|
|
74
|
-
"data-cy": `${finalDataCy}-cell-${rowIndex}-${column.key}`,
|
|
75
|
-
"data-testid": `${finalTestId}-cell-${rowIndex}-${column.key}`,
|
|
76
|
-
children: String(row[column.key] ?? "")
|
|
77
|
-
},
|
|
78
|
-
column.key
|
|
79
|
-
))
|
|
242
|
+
"data-cy": `${finalDataCy}-digit-${index}`,
|
|
243
|
+
"data-testid": `${finalTestId}-digit-${index}`,
|
|
244
|
+
autoComplete: "one-time-code"
|
|
80
245
|
},
|
|
81
|
-
|
|
82
|
-
))
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
246
|
+
index
|
|
247
|
+
))
|
|
248
|
+
}
|
|
249
|
+
),
|
|
250
|
+
error && /* @__PURE__ */ jsx(
|
|
251
|
+
"span",
|
|
252
|
+
{
|
|
253
|
+
id: errorId,
|
|
254
|
+
className: "otp-input__error",
|
|
255
|
+
role: "alert",
|
|
256
|
+
"data-cy": `${finalDataCy}-error`,
|
|
257
|
+
"data-testid": `${finalTestId}-error`,
|
|
258
|
+
children: error
|
|
259
|
+
}
|
|
260
|
+
),
|
|
261
|
+
helperText && !error && /* @__PURE__ */ jsx(
|
|
262
|
+
"span",
|
|
263
|
+
{
|
|
264
|
+
id: helperId,
|
|
265
|
+
className: "otp-input__helper",
|
|
266
|
+
"data-cy": `${finalDataCy}-helper`,
|
|
267
|
+
"data-testid": `${finalTestId}-helper`,
|
|
268
|
+
children: helperText
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
]
|
|
86
272
|
}
|
|
87
273
|
);
|
|
88
274
|
}
|
|
89
275
|
);
|
|
90
|
-
|
|
276
|
+
OTPInput.displayName = "OTPInput";
|
|
91
277
|
export {
|
|
92
|
-
|
|
278
|
+
OTPInput
|
|
93
279
|
};
|
package/dist/index14.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),t=require("./index31.cjs");;/* empty css */const l=a.forwardRef(({label:l,labelPosition:r="end",helperText:s,size:d="md",className:c,id:n,disabled:o,checked:i,defaultChecked:g,"data-cy":p,"data-testid":u,...b},_)=>{const h=a.useId(),k=n||h,$=`${k}-helper`,x=p||"toggle",m=u||"toggle",[y,j]=a.useState(!1),N=a.useRef(null),f=a.useCallback(e=>{N.current=e,_&&("function"==typeof _?_(e):"current"in _&&(_.current=e))},[_]);return e.jsxs("div",{className:t.cn("toggle-wrapper",o&&"toggle-wrapper--disabled",`toggle-wrapper--${d}`),"data-cy":`${x}-wrapper`,"data-testid":`${m}-wrapper`,children:[e.jsxs("label",{className:t.cn("toggle__container","start"===r&&"toggle__container--label-start"),htmlFor:k,onMouseEnter:()=>{o||j(!0)},onMouseLeave:()=>{j(!1)},children:[l&&"start"===r&&e.jsx("span",{className:"toggle__label","data-cy":`${x}-label`,"data-testid":`${m}-label`,children:l}),e.jsx("input",{ref:f,id:k,type:"checkbox",role:"switch",checked:i,defaultChecked:g,className:t.cn("toggle__input",c),"aria-describedby":s?$:void 0,"data-cy":x,"data-testid":m,disabled:o,...b}),e.jsx("span",{className:t.cn("toggle__track",`toggle__track--${d}`,y&&!o&&"toggle__track--hover"),"data-cy":`${x}-track`,"data-testid":`${m}-track`,"aria-hidden":"true",children:e.jsx("span",{className:t.cn("toggle__knob",`toggle__knob--${d}`,y&&!o&&"toggle__knob--hover"),"data-cy":`${x}-knob`,"data-testid":`${m}-knob`})}),l&&"end"===r&&e.jsx("span",{className:"toggle__label","data-cy":`${x}-label`,"data-testid":`${m}-label`,children:l})]}),s&&e.jsx("span",{id:$,className:"toggle__helper","data-cy":`${x}-helper`,"data-testid":`${m}-helper`,children:s})]})});l.displayName="Toggle",exports.Toggle=l;
|
package/dist/index14.js
CHANGED
|
@@ -1,42 +1,150 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from "react";
|
|
3
|
-
import { cn } from "./
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useId, useState, useRef, useCallback } from "react";
|
|
3
|
+
import { cn } from "./index31.js";
|
|
4
4
|
/* empty css */
|
|
5
|
-
const
|
|
5
|
+
const Toggle = forwardRef(
|
|
6
6
|
({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
label,
|
|
8
|
+
labelPosition = "end",
|
|
9
|
+
helperText,
|
|
10
|
+
size = "md",
|
|
10
11
|
className,
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
id: providedId,
|
|
13
|
+
disabled,
|
|
14
|
+
checked,
|
|
15
|
+
defaultChecked,
|
|
13
16
|
"data-cy": dataCy,
|
|
17
|
+
"data-testid": dataTestId,
|
|
14
18
|
...props
|
|
15
19
|
}, ref) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const generatedId = useId();
|
|
21
|
+
const id = providedId || generatedId;
|
|
22
|
+
const helperId = `${id}-helper`;
|
|
23
|
+
const finalDataCy = dataCy || "toggle";
|
|
24
|
+
const finalTestId = dataTestId || "toggle";
|
|
25
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
26
|
+
const internalRef = useRef(null);
|
|
27
|
+
const combinedRef = useCallback(
|
|
28
|
+
(element) => {
|
|
29
|
+
internalRef.current = element;
|
|
30
|
+
if (!ref) return;
|
|
31
|
+
if (typeof ref === "function") {
|
|
32
|
+
ref(element);
|
|
33
|
+
} else if ("current" in ref) {
|
|
34
|
+
ref.current = element;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
[ref]
|
|
22
38
|
);
|
|
23
|
-
|
|
39
|
+
const handleMouseEnter = () => {
|
|
40
|
+
if (!disabled) {
|
|
41
|
+
setIsHovered(true);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const handleMouseLeave = () => {
|
|
45
|
+
setIsHovered(false);
|
|
46
|
+
};
|
|
47
|
+
return /* @__PURE__ */ jsxs(
|
|
24
48
|
"div",
|
|
25
49
|
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
className: cn(
|
|
51
|
+
"toggle-wrapper",
|
|
52
|
+
disabled && "toggle-wrapper--disabled",
|
|
53
|
+
`toggle-wrapper--${size}`
|
|
54
|
+
),
|
|
55
|
+
"data-cy": `${finalDataCy}-wrapper`,
|
|
56
|
+
"data-testid": `${finalTestId}-wrapper`,
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsxs(
|
|
59
|
+
"label",
|
|
60
|
+
{
|
|
61
|
+
className: cn(
|
|
62
|
+
"toggle__container",
|
|
63
|
+
labelPosition === "start" && "toggle__container--label-start"
|
|
64
|
+
),
|
|
65
|
+
htmlFor: id,
|
|
66
|
+
onMouseEnter: handleMouseEnter,
|
|
67
|
+
onMouseLeave: handleMouseLeave,
|
|
68
|
+
children: [
|
|
69
|
+
label && labelPosition === "start" && /* @__PURE__ */ jsx(
|
|
70
|
+
"span",
|
|
71
|
+
{
|
|
72
|
+
className: "toggle__label",
|
|
73
|
+
"data-cy": `${finalDataCy}-label`,
|
|
74
|
+
"data-testid": `${finalTestId}-label`,
|
|
75
|
+
children: label
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
/* @__PURE__ */ jsx(
|
|
79
|
+
"input",
|
|
80
|
+
{
|
|
81
|
+
ref: combinedRef,
|
|
82
|
+
id,
|
|
83
|
+
type: "checkbox",
|
|
84
|
+
role: "switch",
|
|
85
|
+
checked,
|
|
86
|
+
defaultChecked,
|
|
87
|
+
className: cn("toggle__input", className),
|
|
88
|
+
"aria-describedby": helperText ? helperId : void 0,
|
|
89
|
+
"data-cy": finalDataCy,
|
|
90
|
+
"data-testid": finalTestId,
|
|
91
|
+
disabled,
|
|
92
|
+
...props
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
/* @__PURE__ */ jsx(
|
|
96
|
+
"span",
|
|
97
|
+
{
|
|
98
|
+
className: cn(
|
|
99
|
+
"toggle__track",
|
|
100
|
+
`toggle__track--${size}`,
|
|
101
|
+
isHovered && !disabled && "toggle__track--hover"
|
|
102
|
+
),
|
|
103
|
+
"data-cy": `${finalDataCy}-track`,
|
|
104
|
+
"data-testid": `${finalTestId}-track`,
|
|
105
|
+
"aria-hidden": "true",
|
|
106
|
+
children: /* @__PURE__ */ jsx(
|
|
107
|
+
"span",
|
|
108
|
+
{
|
|
109
|
+
className: cn(
|
|
110
|
+
"toggle__knob",
|
|
111
|
+
`toggle__knob--${size}`,
|
|
112
|
+
isHovered && !disabled && "toggle__knob--hover"
|
|
113
|
+
),
|
|
114
|
+
"data-cy": `${finalDataCy}-knob`,
|
|
115
|
+
"data-testid": `${finalTestId}-knob`
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
label && labelPosition === "end" && /* @__PURE__ */ jsx(
|
|
121
|
+
"span",
|
|
122
|
+
{
|
|
123
|
+
className: "toggle__label",
|
|
124
|
+
"data-cy": `${finalDataCy}-label`,
|
|
125
|
+
"data-testid": `${finalTestId}-label`,
|
|
126
|
+
children: label
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
helperText && /* @__PURE__ */ jsx(
|
|
133
|
+
"span",
|
|
134
|
+
{
|
|
135
|
+
id: helperId,
|
|
136
|
+
className: "toggle__helper",
|
|
137
|
+
"data-cy": `${finalDataCy}-helper`,
|
|
138
|
+
"data-testid": `${finalTestId}-helper`,
|
|
139
|
+
children: helperText
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
]
|
|
35
143
|
}
|
|
36
144
|
);
|
|
37
145
|
}
|
|
38
146
|
);
|
|
39
|
-
|
|
147
|
+
Toggle.displayName = "Toggle";
|
|
40
148
|
export {
|
|
41
|
-
|
|
149
|
+
Toggle
|
|
42
150
|
};
|
package/dist/index15.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),e=require("react"),a=require("@radix-ui/react-tabs"),s=require("./index31.cjs");function r(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const a in t)if("default"!==a){const s=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(e,a,s.get?s:{enumerable:!0,get:()=>t[a]})}return e.default=t,Object.freeze(e)};/* empty css */const i=r(a),n=i.Root,c=e.forwardRef(({className:e,"data-cy":a,"data-testid":r,...n},c)=>{const o=a||"tabs-list",d=r||"tabs-list";return t.jsx(i.List,{ref:c,className:s.cn("tabs-list",e),"data-cy":o,"data-testid":d,...n})});c.displayName=i.List.displayName;const o=e.forwardRef(({className:e,value:a,"data-cy":r,"data-testid":n,...c},o)=>{const d=r||(a?`tabs-trigger-${a}`:"tabs-trigger"),l=n||(a?`tabs-trigger-${a}`:"tabs-trigger");return t.jsx(i.Trigger,{ref:o,className:s.cn("tabs-trigger",e),value:a,"data-cy":d,"data-testid":l,...c})});o.displayName=i.Trigger.displayName;const d=e.forwardRef(({className:e,value:a,"data-cy":r,"data-testid":n,...c},o)=>{const d=r||(a?`tabs-content-${a}`:"tabs-content"),l=n||(a?`tabs-content-${a}`:"tabs-content");return t.jsx(i.Content,{ref:o,className:s.cn("tabs-content",e),value:a,"data-cy":d,"data-testid":l,...c})});d.displayName=i.Content.displayName,exports.Tabs=n,exports.TabsContent=d,exports.TabsList=c,exports.TabsTrigger=o;
|