@nori-ui/core 1.7.0 → 1.8.0
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/chunk-BOMPFNM4.js +165 -0
- package/dist/chunk-BOMPFNM4.js.map +1 -0
- package/dist/chunk-BVLOX4A3.js +256 -0
- package/dist/chunk-BVLOX4A3.js.map +1 -0
- package/dist/chunk-VFUV6XJR.js +257 -0
- package/dist/chunk-VFUV6XJR.js.map +1 -0
- package/dist/client.cjs +650 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +3 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.js +14 -11
- package/dist/client.js.map +1 -1
- package/dist/components/Carousel/index.cjs +297 -0
- package/dist/components/Carousel/index.cjs.map +1 -0
- package/dist/components/Carousel/index.d.cts +67 -0
- package/dist/components/Carousel/index.d.ts +67 -0
- package/dist/components/Carousel/index.js +5 -0
- package/dist/components/Carousel/index.js.map +1 -0
- package/dist/components/HoverCard/index.cjs +894 -0
- package/dist/components/HoverCard/index.cjs.map +1 -0
- package/dist/components/HoverCard/index.d.cts +66 -0
- package/dist/components/HoverCard/index.d.ts +66 -0
- package/dist/components/HoverCard/index.js +9 -0
- package/dist/components/HoverCard/index.js.map +1 -0
- package/dist/components/InputOTP/index.cjs +580 -0
- package/dist/components/InputOTP/index.cjs.map +1 -0
- package/dist/components/InputOTP/index.d.cts +49 -0
- package/dist/components/InputOTP/index.d.ts +49 -0
- package/dist/components/InputOTP/index.js +7 -0
- package/dist/components/InputOTP/index.js.map +1 -0
- package/dist/index.cjs +650 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +14 -11
- package/package.json +1 -1
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var reactNative = require('react-native');
|
|
5
|
+
var jsxRuntime = require('nativewind/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
|
|
10
|
+
// src/theme/px.ts
|
|
11
|
+
function px(value) {
|
|
12
|
+
if (typeof value === "number") {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
const n = Number.parseFloat(value);
|
|
16
|
+
return Number.isFinite(n) ? n : 0;
|
|
17
|
+
}
|
|
18
|
+
__name(px, "px");
|
|
19
|
+
|
|
20
|
+
// ../tokens/build/theme.ts
|
|
21
|
+
var theme = {
|
|
22
|
+
color: {
|
|
23
|
+
danger: "#ef4444",
|
|
24
|
+
info: "#3b82f6",
|
|
25
|
+
neutral: {
|
|
26
|
+
"100": "#f4f4f5",
|
|
27
|
+
"200": "#e4e4e7",
|
|
28
|
+
"300": "#d4d4d8",
|
|
29
|
+
"400": "#a1a1aa",
|
|
30
|
+
"50": "#fafafa",
|
|
31
|
+
"500": "#71717a",
|
|
32
|
+
"600": "#52525b",
|
|
33
|
+
"700": "#3f3f46",
|
|
34
|
+
"800": "#27272a",
|
|
35
|
+
"900": "#18181b"
|
|
36
|
+
},
|
|
37
|
+
primary: {
|
|
38
|
+
"100": "#ccfbf1",
|
|
39
|
+
"200": "#99f6e4",
|
|
40
|
+
"300": "#5eead4",
|
|
41
|
+
"400": "#2dd4bf",
|
|
42
|
+
"50": "#f0fdfa",
|
|
43
|
+
"500": "#14b8a6",
|
|
44
|
+
"600": "#0d9488",
|
|
45
|
+
"700": "#0f766e",
|
|
46
|
+
"800": "#115e59",
|
|
47
|
+
"900": "#134e4a"
|
|
48
|
+
},
|
|
49
|
+
success: "#22c55e",
|
|
50
|
+
warning: "#f59e0b"
|
|
51
|
+
},
|
|
52
|
+
fontFamily: {
|
|
53
|
+
body: "system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",
|
|
54
|
+
display: "ui-serif, Georgia, 'Times New Roman', serif",
|
|
55
|
+
mono: "ui-monospace, 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', monospace"
|
|
56
|
+
},
|
|
57
|
+
fontSize: {
|
|
58
|
+
"2xl": "24px",
|
|
59
|
+
"3xl": "30px",
|
|
60
|
+
"4xl": "36px",
|
|
61
|
+
lg: "18px",
|
|
62
|
+
md: "16px",
|
|
63
|
+
sm: "14px",
|
|
64
|
+
xl: "20px",
|
|
65
|
+
xs: "12px"
|
|
66
|
+
},
|
|
67
|
+
fontWeight: {
|
|
68
|
+
bold: "700",
|
|
69
|
+
medium: "500",
|
|
70
|
+
regular: "400",
|
|
71
|
+
semibold: "600"
|
|
72
|
+
},
|
|
73
|
+
lineHeight: {
|
|
74
|
+
normal: "1.4",
|
|
75
|
+
relaxed: "1.6",
|
|
76
|
+
tight: "1.2"
|
|
77
|
+
},
|
|
78
|
+
radius: {
|
|
79
|
+
"2xl": "16px",
|
|
80
|
+
full: "9999px",
|
|
81
|
+
lg: "8px",
|
|
82
|
+
md: "6px",
|
|
83
|
+
none: "0px",
|
|
84
|
+
sm: "4px",
|
|
85
|
+
xl: "12px"
|
|
86
|
+
},
|
|
87
|
+
semantic: {
|
|
88
|
+
background: {
|
|
89
|
+
default: "#fafafa",
|
|
90
|
+
elevated: "#ffffff",
|
|
91
|
+
subtle: "#f4f4f5"
|
|
92
|
+
},
|
|
93
|
+
border: {
|
|
94
|
+
default: "#e4e4e7",
|
|
95
|
+
strong: "#d4d4d8"
|
|
96
|
+
},
|
|
97
|
+
interactive: {
|
|
98
|
+
destructive: "#ef4444",
|
|
99
|
+
primary: "#0d9488",
|
|
100
|
+
primaryHover: "#0f766e",
|
|
101
|
+
primaryPressed: "#115e59"
|
|
102
|
+
},
|
|
103
|
+
text: {
|
|
104
|
+
default: "#18181b",
|
|
105
|
+
inverted: "#fafafa",
|
|
106
|
+
muted: "#52525b"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
shadow: {
|
|
110
|
+
lg: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",
|
|
111
|
+
md: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
|
|
112
|
+
sm: "0 1px 2px 0 rgba(0, 0, 0, 0.05)"
|
|
113
|
+
},
|
|
114
|
+
spacing: {
|
|
115
|
+
"0": "0px",
|
|
116
|
+
"1": "4px",
|
|
117
|
+
"10": "40px",
|
|
118
|
+
"12": "48px",
|
|
119
|
+
"16": "64px",
|
|
120
|
+
"2": "8px",
|
|
121
|
+
"20": "80px",
|
|
122
|
+
"24": "96px",
|
|
123
|
+
"3": "12px",
|
|
124
|
+
"4": "16px",
|
|
125
|
+
"5": "20px",
|
|
126
|
+
"6": "24px",
|
|
127
|
+
"8": "32px"
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var themeDark = {
|
|
131
|
+
color: {
|
|
132
|
+
danger: "#ef4444",
|
|
133
|
+
info: "#3b82f6",
|
|
134
|
+
neutral: {
|
|
135
|
+
"100": "#f4f4f5",
|
|
136
|
+
"200": "#e4e4e7",
|
|
137
|
+
"300": "#d4d4d8",
|
|
138
|
+
"400": "#a1a1aa",
|
|
139
|
+
"50": "#fafafa",
|
|
140
|
+
"500": "#71717a",
|
|
141
|
+
"600": "#52525b",
|
|
142
|
+
"700": "#3f3f46",
|
|
143
|
+
"800": "#27272a",
|
|
144
|
+
"900": "#18181b"
|
|
145
|
+
},
|
|
146
|
+
primary: {
|
|
147
|
+
"100": "#ccfbf1",
|
|
148
|
+
"200": "#99f6e4",
|
|
149
|
+
"300": "#5eead4",
|
|
150
|
+
"400": "#2dd4bf",
|
|
151
|
+
"50": "#f0fdfa",
|
|
152
|
+
"500": "#14b8a6",
|
|
153
|
+
"600": "#0d9488",
|
|
154
|
+
"700": "#0f766e",
|
|
155
|
+
"800": "#115e59",
|
|
156
|
+
"900": "#134e4a"
|
|
157
|
+
},
|
|
158
|
+
success: "#22c55e",
|
|
159
|
+
warning: "#f59e0b"
|
|
160
|
+
},
|
|
161
|
+
fontFamily: {
|
|
162
|
+
body: "system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",
|
|
163
|
+
display: "ui-serif, Georgia, 'Times New Roman', serif",
|
|
164
|
+
mono: "ui-monospace, 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', monospace"
|
|
165
|
+
},
|
|
166
|
+
fontSize: {
|
|
167
|
+
"2xl": "24px",
|
|
168
|
+
"3xl": "30px",
|
|
169
|
+
"4xl": "36px",
|
|
170
|
+
lg: "18px",
|
|
171
|
+
md: "16px",
|
|
172
|
+
sm: "14px",
|
|
173
|
+
xl: "20px",
|
|
174
|
+
xs: "12px"
|
|
175
|
+
},
|
|
176
|
+
fontWeight: {
|
|
177
|
+
bold: "700",
|
|
178
|
+
medium: "500",
|
|
179
|
+
regular: "400",
|
|
180
|
+
semibold: "600"
|
|
181
|
+
},
|
|
182
|
+
lineHeight: {
|
|
183
|
+
normal: "1.4",
|
|
184
|
+
relaxed: "1.6",
|
|
185
|
+
tight: "1.2"
|
|
186
|
+
},
|
|
187
|
+
radius: {
|
|
188
|
+
"2xl": "16px",
|
|
189
|
+
full: "9999px",
|
|
190
|
+
lg: "8px",
|
|
191
|
+
md: "6px",
|
|
192
|
+
none: "0px",
|
|
193
|
+
sm: "4px",
|
|
194
|
+
xl: "12px"
|
|
195
|
+
},
|
|
196
|
+
semantic: {
|
|
197
|
+
background: {
|
|
198
|
+
default: "#18181b",
|
|
199
|
+
elevated: "#3f3f46",
|
|
200
|
+
subtle: "#27272a"
|
|
201
|
+
},
|
|
202
|
+
border: {
|
|
203
|
+
default: "#3f3f46",
|
|
204
|
+
strong: "#52525b"
|
|
205
|
+
},
|
|
206
|
+
interactive: {
|
|
207
|
+
destructive: "#ef4444",
|
|
208
|
+
primary: "#2dd4bf",
|
|
209
|
+
primaryHover: "#5eead4",
|
|
210
|
+
primaryPressed: "#99f6e4"
|
|
211
|
+
},
|
|
212
|
+
text: {
|
|
213
|
+
default: "#fafafa",
|
|
214
|
+
inverted: "#18181b",
|
|
215
|
+
muted: "#a1a1aa"
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
shadow: {
|
|
219
|
+
lg: "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",
|
|
220
|
+
md: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
|
|
221
|
+
sm: "0 1px 2px 0 rgba(0, 0, 0, 0.05)"
|
|
222
|
+
},
|
|
223
|
+
spacing: {
|
|
224
|
+
"0": "0px",
|
|
225
|
+
"1": "4px",
|
|
226
|
+
"10": "40px",
|
|
227
|
+
"12": "48px",
|
|
228
|
+
"16": "64px",
|
|
229
|
+
"2": "8px",
|
|
230
|
+
"20": "80px",
|
|
231
|
+
"24": "96px",
|
|
232
|
+
"3": "12px",
|
|
233
|
+
"4": "16px",
|
|
234
|
+
"5": "20px",
|
|
235
|
+
"6": "24px",
|
|
236
|
+
"8": "32px"
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
var defaultTheme = {
|
|
240
|
+
light: theme,
|
|
241
|
+
dark: themeDark
|
|
242
|
+
};
|
|
243
|
+
var ThemeContext = react.createContext(defaultTheme);
|
|
244
|
+
ThemeContext.displayName = "ThemeContext";
|
|
245
|
+
var ColorSchemeOverrideContext = react.createContext(null);
|
|
246
|
+
ColorSchemeOverrideContext.displayName = "ColorSchemeOverrideContext";
|
|
247
|
+
var isWeb = reactNative.Platform.OS === "web";
|
|
248
|
+
function readWebScheme() {
|
|
249
|
+
if (typeof document === "undefined") {
|
|
250
|
+
return "light";
|
|
251
|
+
}
|
|
252
|
+
const root = document.documentElement;
|
|
253
|
+
if (root.classList.contains("dark")) {
|
|
254
|
+
return "dark";
|
|
255
|
+
}
|
|
256
|
+
if (root.getAttribute("data-theme") === "dark") {
|
|
257
|
+
return "dark";
|
|
258
|
+
}
|
|
259
|
+
return "light";
|
|
260
|
+
}
|
|
261
|
+
__name(readWebScheme, "readWebScheme");
|
|
262
|
+
function useColorScheme() {
|
|
263
|
+
const override = react.useContext(ColorSchemeOverrideContext);
|
|
264
|
+
const [scheme, setScheme] = react.useState(() => {
|
|
265
|
+
if (isWeb) {
|
|
266
|
+
return readWebScheme();
|
|
267
|
+
}
|
|
268
|
+
return reactNative.Appearance.getColorScheme() ?? "light";
|
|
269
|
+
});
|
|
270
|
+
react.useEffect(() => {
|
|
271
|
+
if (isWeb) {
|
|
272
|
+
const root = document.documentElement;
|
|
273
|
+
const update = /* @__PURE__ */ __name(() => setScheme(readWebScheme()), "update");
|
|
274
|
+
const observer = new MutationObserver(update);
|
|
275
|
+
observer.observe(root, { attributes: true, attributeFilter: ["class", "data-theme"] });
|
|
276
|
+
update();
|
|
277
|
+
return () => observer.disconnect();
|
|
278
|
+
}
|
|
279
|
+
const sub = reactNative.Appearance.addChangeListener(({ colorScheme }) => {
|
|
280
|
+
setScheme(colorScheme ?? "light");
|
|
281
|
+
});
|
|
282
|
+
return () => sub.remove();
|
|
283
|
+
}, []);
|
|
284
|
+
return override ?? scheme;
|
|
285
|
+
}
|
|
286
|
+
__name(useColorScheme, "useColorScheme");
|
|
287
|
+
|
|
288
|
+
// src/theme/use-theme-colors.ts
|
|
289
|
+
function useThemeColors() {
|
|
290
|
+
const scheme = useColorScheme();
|
|
291
|
+
const themePair = react.useContext(ThemeContext);
|
|
292
|
+
return scheme === "dark" ? themePair.dark : themePair.light;
|
|
293
|
+
}
|
|
294
|
+
__name(useThemeColors, "useThemeColors");
|
|
295
|
+
|
|
296
|
+
// src/utils/cn.ts
|
|
297
|
+
function cn(...inputs) {
|
|
298
|
+
const out = [];
|
|
299
|
+
for (const input of inputs) {
|
|
300
|
+
append(out, input);
|
|
301
|
+
}
|
|
302
|
+
return out.join(" ");
|
|
303
|
+
}
|
|
304
|
+
__name(cn, "cn");
|
|
305
|
+
function append(out, input) {
|
|
306
|
+
if (!input) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (typeof input === "string") {
|
|
310
|
+
if (input.length > 0) {
|
|
311
|
+
out.push(input);
|
|
312
|
+
}
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (typeof input === "number") {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (Array.isArray(input)) {
|
|
319
|
+
for (const inner of input) {
|
|
320
|
+
append(out, inner);
|
|
321
|
+
}
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (typeof input === "object") {
|
|
325
|
+
for (const key of Object.keys(input)) {
|
|
326
|
+
if (input[key]) {
|
|
327
|
+
out.push(key);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
__name(append, "append");
|
|
333
|
+
function isAllowed(char, pattern) {
|
|
334
|
+
if (pattern === "numeric") {
|
|
335
|
+
return /^\d$/.test(char);
|
|
336
|
+
}
|
|
337
|
+
return /^[a-zA-Z0-9]$/.test(char);
|
|
338
|
+
}
|
|
339
|
+
__name(isAllowed, "isAllowed");
|
|
340
|
+
function filterValue(value, pattern, length) {
|
|
341
|
+
return value.split("").filter((c) => isAllowed(c, pattern)).slice(0, length).join("");
|
|
342
|
+
}
|
|
343
|
+
__name(filterValue, "filterValue");
|
|
344
|
+
var InputOTP = /* @__PURE__ */ __name(({
|
|
345
|
+
value = "",
|
|
346
|
+
onChange,
|
|
347
|
+
onComplete,
|
|
348
|
+
length = 6,
|
|
349
|
+
placeholder = "\xB7",
|
|
350
|
+
pattern = "numeric",
|
|
351
|
+
disabled = false,
|
|
352
|
+
autoFocus = false,
|
|
353
|
+
id,
|
|
354
|
+
name,
|
|
355
|
+
"aria-label": ariaLabel = "One-time code",
|
|
356
|
+
"aria-labelledby": ariaLabelledBy,
|
|
357
|
+
"aria-describedby": ariaDescribedBy,
|
|
358
|
+
"aria-invalid": ariaInvalid,
|
|
359
|
+
className,
|
|
360
|
+
testID
|
|
361
|
+
}) => {
|
|
362
|
+
const colors = useThemeColors();
|
|
363
|
+
const [cells, setCells] = react.useState(() => {
|
|
364
|
+
const filtered = filterValue(value, pattern, length);
|
|
365
|
+
return Array.from({ length }, (_, i) => filtered[i] ?? "");
|
|
366
|
+
});
|
|
367
|
+
const prevValue = react.useRef(value);
|
|
368
|
+
react.useEffect(() => {
|
|
369
|
+
if (value !== prevValue.current) {
|
|
370
|
+
prevValue.current = value;
|
|
371
|
+
const filtered = filterValue(value, pattern, length);
|
|
372
|
+
setCells(Array.from({ length }, (_, i) => filtered[i] ?? ""));
|
|
373
|
+
}
|
|
374
|
+
}, [value, pattern, length]);
|
|
375
|
+
const inputRefs = react.useRef([]);
|
|
376
|
+
const focusCell = react.useCallback(
|
|
377
|
+
(idx) => {
|
|
378
|
+
if (idx >= 0 && idx < length) {
|
|
379
|
+
inputRefs.current[idx]?.focus();
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
[length]
|
|
383
|
+
);
|
|
384
|
+
const updateCells = react.useCallback(
|
|
385
|
+
(next) => {
|
|
386
|
+
setCells(next);
|
|
387
|
+
const joined = next.join("");
|
|
388
|
+
onChange?.(joined);
|
|
389
|
+
if (joined.length === length && !next.includes("")) {
|
|
390
|
+
onComplete?.(joined);
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
[onChange, onComplete, length]
|
|
394
|
+
);
|
|
395
|
+
const onContainerPaste = react.useCallback(
|
|
396
|
+
(e) => {
|
|
397
|
+
e.preventDefault();
|
|
398
|
+
const text = e.clipboardData.getData("text/plain") ?? "";
|
|
399
|
+
const filtered = filterValue(text, pattern, length);
|
|
400
|
+
const next = Array.from({ length }, (_, i) => filtered[i] ?? "");
|
|
401
|
+
updateCells(next);
|
|
402
|
+
const nextEmpty = next.indexOf("");
|
|
403
|
+
focusCell(nextEmpty === -1 ? length - 1 : nextEmpty);
|
|
404
|
+
},
|
|
405
|
+
[pattern, length, updateCells, focusCell]
|
|
406
|
+
);
|
|
407
|
+
const handleChangeText = react.useCallback(
|
|
408
|
+
(text, idx) => {
|
|
409
|
+
if (text.length > 1) {
|
|
410
|
+
const filtered = filterValue(text, pattern, length);
|
|
411
|
+
const next2 = Array.from({ length }, (_, i) => filtered[i] ?? "");
|
|
412
|
+
updateCells(next2);
|
|
413
|
+
const nextEmpty = next2.indexOf("");
|
|
414
|
+
focusCell(nextEmpty === -1 ? length - 1 : nextEmpty);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const char = text.slice(-1);
|
|
418
|
+
if (char && !isAllowed(char, pattern)) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const next = [...cells];
|
|
422
|
+
next[idx] = char;
|
|
423
|
+
updateCells(next);
|
|
424
|
+
if (char) {
|
|
425
|
+
focusCell(idx + 1);
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
[cells, pattern, length, updateCells, focusCell]
|
|
429
|
+
);
|
|
430
|
+
const handleWebKeyDown = react.useCallback(
|
|
431
|
+
(e, idx) => {
|
|
432
|
+
if (e.key === "Backspace") {
|
|
433
|
+
if (cells[idx] !== "") {
|
|
434
|
+
const next = [...cells];
|
|
435
|
+
next[idx] = "";
|
|
436
|
+
updateCells(next);
|
|
437
|
+
} else {
|
|
438
|
+
focusCell(idx - 1);
|
|
439
|
+
}
|
|
440
|
+
e.preventDefault();
|
|
441
|
+
} else if (e.key === "ArrowLeft") {
|
|
442
|
+
focusCell(idx - 1);
|
|
443
|
+
e.preventDefault();
|
|
444
|
+
} else if (e.key === "ArrowRight") {
|
|
445
|
+
focusCell(idx + 1);
|
|
446
|
+
e.preventDefault();
|
|
447
|
+
} else if (e.key.length === 1 && isAllowed(e.key, pattern)) {
|
|
448
|
+
const next = [...cells];
|
|
449
|
+
next[idx] = e.key;
|
|
450
|
+
updateCells(next);
|
|
451
|
+
focusCell(idx + 1);
|
|
452
|
+
e.preventDefault();
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
[cells, pattern, focusCell, updateCells]
|
|
456
|
+
);
|
|
457
|
+
const handleNativeKeyPress = react.useCallback(
|
|
458
|
+
(e, idx) => {
|
|
459
|
+
if (e.nativeEvent.key === "Backspace") {
|
|
460
|
+
if (cells[idx] !== "") {
|
|
461
|
+
const next = [...cells];
|
|
462
|
+
next[idx] = "";
|
|
463
|
+
updateCells(next);
|
|
464
|
+
} else {
|
|
465
|
+
focusCell(idx - 1);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
[cells, focusCell, updateCells]
|
|
470
|
+
);
|
|
471
|
+
const cellStyle = [
|
|
472
|
+
styles.cell,
|
|
473
|
+
{
|
|
474
|
+
width: px(48),
|
|
475
|
+
height: px(56),
|
|
476
|
+
borderRadius: px(colors.radius.md),
|
|
477
|
+
borderColor: colors.semantic.border.default,
|
|
478
|
+
backgroundColor: colors.semantic.background.elevated,
|
|
479
|
+
color: colors.semantic.text.default,
|
|
480
|
+
fontSize: px(colors.fontSize.xl),
|
|
481
|
+
fontFamily: colors.fontFamily.body
|
|
482
|
+
},
|
|
483
|
+
disabled ? styles.disabled : null,
|
|
484
|
+
ariaInvalid === true || ariaInvalid === "true" ? { borderColor: colors.color.danger } : null
|
|
485
|
+
];
|
|
486
|
+
const isWeb2 = reactNative.Platform.OS === "web";
|
|
487
|
+
const containerProps = isWeb2 ? {
|
|
488
|
+
onPaste: onContainerPaste,
|
|
489
|
+
role: "group",
|
|
490
|
+
"aria-label": ariaLabel,
|
|
491
|
+
"aria-labelledby": ariaLabelledBy,
|
|
492
|
+
"aria-describedby": ariaDescribedBy
|
|
493
|
+
} : {};
|
|
494
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
495
|
+
reactNative.View,
|
|
496
|
+
{
|
|
497
|
+
testID,
|
|
498
|
+
...isWeb2 ? {} : { accessible: true, accessibilityLabel: ariaLabel },
|
|
499
|
+
...containerProps,
|
|
500
|
+
className: cn("flex-row items-center gap-2", className),
|
|
501
|
+
style: styles.container,
|
|
502
|
+
children: [
|
|
503
|
+
Array.from({ length }, (_, idx) => {
|
|
504
|
+
const cellValue = cells[idx] ?? "";
|
|
505
|
+
const cellRef = /* @__PURE__ */ __name((el) => {
|
|
506
|
+
inputRefs.current[idx] = el;
|
|
507
|
+
}, "cellRef");
|
|
508
|
+
const webProps = isWeb2 ? {
|
|
509
|
+
onKeyDown: /* @__PURE__ */ __name((e) => handleWebKeyDown(e, idx), "onKeyDown"),
|
|
510
|
+
// id only on the first cell
|
|
511
|
+
...idx === 0 && id ? { id, nativeID: id } : {},
|
|
512
|
+
...idx === 0 && name ? { name } : {},
|
|
513
|
+
...idx === 0 && ariaLabelledBy ? { "aria-labelledby": ariaLabelledBy } : {},
|
|
514
|
+
...idx === 0 && ariaDescribedBy ? { "aria-describedby": ariaDescribedBy } : {},
|
|
515
|
+
...idx === 0 && ariaInvalid !== void 0 ? { "aria-invalid": ariaInvalid } : {},
|
|
516
|
+
inputMode: pattern === "numeric" ? "numeric" : "text"
|
|
517
|
+
} : {};
|
|
518
|
+
const nativeOnlyProps = isWeb2 ? {} : {
|
|
519
|
+
keyboardType: pattern === "numeric" ? "number-pad" : "default",
|
|
520
|
+
textAlign: "center",
|
|
521
|
+
selectTextOnFocus: true,
|
|
522
|
+
onKeyPress: /* @__PURE__ */ __name((e) => handleNativeKeyPress(e, idx), "onKeyPress")
|
|
523
|
+
};
|
|
524
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
525
|
+
reactNative.TextInput,
|
|
526
|
+
{
|
|
527
|
+
ref: cellRef,
|
|
528
|
+
value: cellValue,
|
|
529
|
+
placeholder: placeholder,
|
|
530
|
+
maxLength: 1,
|
|
531
|
+
editable: !disabled,
|
|
532
|
+
autoFocus: autoFocus && idx === 0,
|
|
533
|
+
testID: testID ? `${testID}-cell-${idx}` : void 0,
|
|
534
|
+
onChangeText: (text) => handleChangeText(text, idx),
|
|
535
|
+
accessibilityLabel: `Digit ${idx + 1} of ${length}`,
|
|
536
|
+
...nativeOnlyProps,
|
|
537
|
+
...webProps,
|
|
538
|
+
style: cellStyle
|
|
539
|
+
},
|
|
540
|
+
idx
|
|
541
|
+
);
|
|
542
|
+
}),
|
|
543
|
+
isWeb2 && name ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
544
|
+
reactNative.TextInput,
|
|
545
|
+
{
|
|
546
|
+
style: styles.hidden,
|
|
547
|
+
value: cells.join(""),
|
|
548
|
+
"aria-hidden": true,
|
|
549
|
+
tabIndex: -1,
|
|
550
|
+
...{ name }
|
|
551
|
+
}
|
|
552
|
+
) : null
|
|
553
|
+
]
|
|
554
|
+
}
|
|
555
|
+
);
|
|
556
|
+
}, "InputOTP");
|
|
557
|
+
var styles = reactNative.StyleSheet.create({
|
|
558
|
+
container: {
|
|
559
|
+
flexDirection: "row",
|
|
560
|
+
alignItems: "center",
|
|
561
|
+
gap: 8
|
|
562
|
+
},
|
|
563
|
+
cell: {
|
|
564
|
+
borderWidth: 1,
|
|
565
|
+
textAlign: "center"
|
|
566
|
+
},
|
|
567
|
+
disabled: {
|
|
568
|
+
opacity: 0.6
|
|
569
|
+
},
|
|
570
|
+
hidden: {
|
|
571
|
+
position: "absolute",
|
|
572
|
+
width: 0,
|
|
573
|
+
height: 0,
|
|
574
|
+
opacity: 0
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
exports.InputOTP = InputOTP;
|
|
579
|
+
//# sourceMappingURL=index.cjs.map
|
|
580
|
+
//# sourceMappingURL=index.cjs.map
|