@xaui/native 0.9.1-alpha.26 → 0.9.1-alpha.28
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-3YN7JQ55.js +342 -0
- package/dist/{chunk-PQHC65AG.js → chunk-56KVKM27.js} +15 -15
- package/dist/chunk-5A4M6X5B.cjs +289 -0
- package/dist/{chunk-BULNTP5N.cjs → chunk-63TWVWHG.cjs} +9 -45
- package/dist/chunk-7EIHHOHP.cjs +42 -0
- package/dist/{chunk-WVCAFORA.cjs → chunk-CQRUNV6S.cjs} +15 -15
- package/dist/chunk-E6EFYPJR.cjs +41 -0
- package/dist/chunk-EYJEUXXC.js +98 -0
- package/dist/chunk-F6W3JQ7K.js +42 -0
- package/dist/chunk-LKB3RIR2.js +289 -0
- package/dist/{chunk-I6UCYAO2.js → chunk-N4UJYDOW.js} +23 -56
- package/dist/chunk-V6DGGDHF.cjs +342 -0
- package/dist/components/alert/index.cjs +1 -1
- package/dist/components/alert/index.d.cts +1 -1
- package/dist/components/alert/index.d.ts +1 -1
- package/dist/components/alert/index.js +1 -1
- package/dist/components/button/index.cjs +3 -3
- package/dist/components/button/index.d.cts +1 -1
- package/dist/components/button/index.d.ts +1 -1
- package/dist/components/button/index.js +2 -2
- package/dist/components/card/index.d.cts +1 -1
- package/dist/components/card/index.d.ts +1 -1
- package/dist/components/checkbox/index.cjs +24 -0
- package/dist/components/checkbox/index.d.cts +1136 -0
- package/dist/components/checkbox/index.d.ts +1136 -0
- package/dist/components/checkbox/index.js +24 -0
- package/dist/components/chip/index.cjs +3 -3
- package/dist/components/chip/index.d.cts +1 -1
- package/dist/components/chip/index.d.ts +1 -1
- package/dist/components/chip/index.js +2 -2
- package/dist/components/input/index.d.cts +3 -3
- package/dist/components/input/index.d.ts +3 -3
- package/dist/components/input-otp/index.cjs +3 -2
- package/dist/components/input-otp/index.d.cts +3 -3
- package/dist/components/input-otp/index.d.ts +3 -3
- package/dist/components/input-otp/index.js +2 -1
- package/dist/components/radio/index.cjs +24 -0
- package/dist/components/radio/index.d.cts +1102 -0
- package/dist/components/radio/index.d.ts +1102 -0
- package/dist/components/radio/index.js +24 -0
- package/dist/components/typography/index.d.cts +1 -1
- package/dist/components/typography/index.d.ts +1 -1
- package/dist/{create-recipe-dBN_ewZc.d.cts → create-recipe-CWvI5ot3.d.cts} +8 -1
- package/dist/{create-recipe-C4JkINrA.d.ts → create-recipe-DUo8doTt.d.ts} +8 -1
- package/dist/index.cjs +45 -11
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +50 -16
- package/dist/system/index.cjs +7 -3
- package/dist/system/index.d.cts +36 -3
- package/dist/system/index.d.ts +36 -3
- package/dist/system/index.js +6 -2
- package/package.json +21 -1
- package/dist/{chunk-3WISQT22.js → chunk-EHARM2EN.js} +3 -3
- package/dist/{chunk-I7G77Q65.cjs → chunk-H7DVR52Z.cjs} +2 -2
- /package/dist/{chunk-6HXWQ5AU.cjs → chunk-VZGBEGDV.cjs} +0 -0
- /package/dist/{chunk-AKXG43S4.js → chunk-Y4BPKSD3.js} +0 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useControllableState
|
|
3
|
+
} from "./chunk-F6W3JQ7K.js";
|
|
4
|
+
import {
|
|
5
|
+
SelectionFill
|
|
6
|
+
} from "./chunk-EYJEUXXC.js";
|
|
7
|
+
import {
|
|
8
|
+
PressableFeedback,
|
|
9
|
+
usePressState
|
|
10
|
+
} from "./chunk-4HELPMAK.js";
|
|
11
|
+
import {
|
|
12
|
+
createRecipe,
|
|
13
|
+
radiusAxis
|
|
14
|
+
} from "./chunk-3JATAB7S.js";
|
|
15
|
+
import {
|
|
16
|
+
childrenToString,
|
|
17
|
+
createSlotContext,
|
|
18
|
+
useStyleProps
|
|
19
|
+
} from "./chunk-PMO62QK4.js";
|
|
20
|
+
import {
|
|
21
|
+
useXAUITheme
|
|
22
|
+
} from "./chunk-A3EGFI6T.js";
|
|
23
|
+
|
|
24
|
+
// src/components/radio/radio-indicator.tsx
|
|
25
|
+
import { forwardRef } from "react";
|
|
26
|
+
import { View } from "react-native";
|
|
27
|
+
|
|
28
|
+
// src/components/radio/radio.context.ts
|
|
29
|
+
var [RadioProvider, useRadio] = createSlotContext("Radio");
|
|
30
|
+
|
|
31
|
+
// src/components/radio/radio-indicator.tsx
|
|
32
|
+
import { jsx } from "react/jsx-runtime";
|
|
33
|
+
var RadioIndicator = forwardRef(
|
|
34
|
+
function RadioIndicator2({ children, animation = true, style, ...props }, ref) {
|
|
35
|
+
const { indicatorStyle, fillStyle, isSelected } = useRadio();
|
|
36
|
+
const [styleProps, rest] = useStyleProps(props);
|
|
37
|
+
return /* @__PURE__ */ jsx(View, { ref, ...rest, style: [indicatorStyle, styleProps, style], children: /* @__PURE__ */ jsx(
|
|
38
|
+
SelectionFill,
|
|
39
|
+
{
|
|
40
|
+
isVisible: isSelected,
|
|
41
|
+
style: fillStyle,
|
|
42
|
+
animation,
|
|
43
|
+
children: children ?? /* @__PURE__ */ jsx(Thumb, {})
|
|
44
|
+
}
|
|
45
|
+
) });
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
RadioIndicator.displayName = "XAUI.Radio.Indicator";
|
|
49
|
+
function Thumb() {
|
|
50
|
+
const { thumbStyle } = useRadio();
|
|
51
|
+
return /* @__PURE__ */ jsx(View, { style: thumbStyle });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/components/radio/radio-label.tsx
|
|
55
|
+
import { forwardRef as forwardRef2 } from "react";
|
|
56
|
+
import { Text } from "react-native";
|
|
57
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
58
|
+
var RadioLabel = forwardRef2(function RadioLabel2({ children, style, ...props }, ref) {
|
|
59
|
+
const { labelStyle } = useRadio();
|
|
60
|
+
const [styleProps, rest] = useStyleProps(props);
|
|
61
|
+
return /* @__PURE__ */ jsx2(Text, { ref, style: [labelStyle, styleProps, style], ...rest, children });
|
|
62
|
+
});
|
|
63
|
+
RadioLabel.displayName = "XAUI.Radio.Label";
|
|
64
|
+
|
|
65
|
+
// src/components/radio/radio.tsx
|
|
66
|
+
import { forwardRef as forwardRef3, useCallback, useMemo } from "react";
|
|
67
|
+
|
|
68
|
+
// src/components/radio/radio.recipe.ts
|
|
69
|
+
var SLOTS = ["root", "indicator", "fill", "thumb", "label"];
|
|
70
|
+
var VARIANT_TOKENS = {
|
|
71
|
+
primary: {
|
|
72
|
+
bg: "fieldBackground",
|
|
73
|
+
border: "fieldBorder",
|
|
74
|
+
bgSelected: "accent",
|
|
75
|
+
fgSelected: "accentForeground"
|
|
76
|
+
},
|
|
77
|
+
secondary: {
|
|
78
|
+
bg: "default",
|
|
79
|
+
border: "fieldBorder",
|
|
80
|
+
bgSelected: "accent",
|
|
81
|
+
fgSelected: "accentForeground"
|
|
82
|
+
},
|
|
83
|
+
tertiary: {
|
|
84
|
+
border: "fieldBorder",
|
|
85
|
+
bgSelected: "accent",
|
|
86
|
+
fgSelected: "accentForeground"
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
function sizeAxis(step) {
|
|
90
|
+
const { box, label, gap } = step;
|
|
91
|
+
return (theme) => {
|
|
92
|
+
const side = theme.spacing(box);
|
|
93
|
+
const dot = Math.round(side * THUMB_RATIO);
|
|
94
|
+
return {
|
|
95
|
+
root: { gap: theme.spacing(gap) },
|
|
96
|
+
indicator: { width: side, height: side },
|
|
97
|
+
thumb: { width: dot, height: dot, borderRadius: dot / 2 },
|
|
98
|
+
label: {
|
|
99
|
+
fontSize: theme.fontSizes[label],
|
|
100
|
+
lineHeight: theme.lineHeights[label]
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
var THUMB_RATIO = 10 / 24;
|
|
106
|
+
var SIZES = {
|
|
107
|
+
sm: { box: 5, gap: 2, label: "sm" },
|
|
108
|
+
md: { box: 6, gap: 2, label: "md" },
|
|
109
|
+
lg: { box: 7, gap: 2.5, label: "lg" }
|
|
110
|
+
};
|
|
111
|
+
var radioRecipe = createRecipe({
|
|
112
|
+
slots: SLOTS,
|
|
113
|
+
base: (theme) => ({
|
|
114
|
+
root: { flexDirection: "row", alignItems: "center", alignSelf: "flex-start" },
|
|
115
|
+
indicator: {
|
|
116
|
+
alignItems: "center",
|
|
117
|
+
justifyContent: "center",
|
|
118
|
+
borderWidth: theme.borderWidth.field,
|
|
119
|
+
// The one shape decision this component makes, and the whole difference between it
|
|
120
|
+
// and the `Checkbox`: a radio is round, at every size. `radius` still overrides it.
|
|
121
|
+
borderRadius: theme.radius.full,
|
|
122
|
+
overflow: "hidden"
|
|
123
|
+
},
|
|
124
|
+
fill: {
|
|
125
|
+
position: "absolute",
|
|
126
|
+
top: 0,
|
|
127
|
+
bottom: 0,
|
|
128
|
+
start: 0,
|
|
129
|
+
end: 0,
|
|
130
|
+
alignItems: "center",
|
|
131
|
+
justifyContent: "center"
|
|
132
|
+
},
|
|
133
|
+
label: {
|
|
134
|
+
fontFamily: theme.fontFamilies.body,
|
|
135
|
+
color: theme.colors.foreground
|
|
136
|
+
}
|
|
137
|
+
}),
|
|
138
|
+
variantTokens: VARIANT_TOKENS,
|
|
139
|
+
/** The `Checkbox`'s paint, with a dot where the check was. */
|
|
140
|
+
paint: (theme, colors) => ({
|
|
141
|
+
indicator: {
|
|
142
|
+
backgroundColor: colors.bg,
|
|
143
|
+
borderColor: colors.border,
|
|
144
|
+
borderWidth: colors.border ? theme.borderWidth.field : 0
|
|
145
|
+
},
|
|
146
|
+
fill: { backgroundColor: colors.bgSelected },
|
|
147
|
+
thumb: { backgroundColor: colors.fgSelected }
|
|
148
|
+
}),
|
|
149
|
+
variants: {
|
|
150
|
+
size: {
|
|
151
|
+
sm: sizeAxis(SIZES.sm),
|
|
152
|
+
md: sizeAxis(SIZES.md),
|
|
153
|
+
lg: sizeAxis(SIZES.lg)
|
|
154
|
+
},
|
|
155
|
+
radius: radiusAxis("indicator"),
|
|
156
|
+
/** Declared after `size` so its border wins. The `Checkbox`'s rule, to the letter. */
|
|
157
|
+
isInvalid: {
|
|
158
|
+
true: (theme) => ({
|
|
159
|
+
indicator: { borderColor: theme.colors.danger, backgroundColor: void 0 },
|
|
160
|
+
fill: { backgroundColor: theme.colors.danger },
|
|
161
|
+
thumb: { backgroundColor: theme.colors.dangerForeground },
|
|
162
|
+
label: { color: theme.colors.danger }
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
compoundVariants: [
|
|
167
|
+
{
|
|
168
|
+
when: { variant: "primary" },
|
|
169
|
+
style: (theme) => ({ indicator: theme.shadows.field })
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
states: {
|
|
173
|
+
disabled: (theme) => ({ root: { opacity: theme.opacity.disabled } })
|
|
174
|
+
},
|
|
175
|
+
defaultVariants: { variant: "secondary", size: "md" }
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// src/components/radio/radio.tsx
|
|
179
|
+
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
180
|
+
var RadioRoot = forwardRef3(function Radio({
|
|
181
|
+
children,
|
|
182
|
+
variant,
|
|
183
|
+
size,
|
|
184
|
+
radius,
|
|
185
|
+
color,
|
|
186
|
+
isSelected,
|
|
187
|
+
defaultSelected = false,
|
|
188
|
+
onSelectedChange,
|
|
189
|
+
isInvalid = false,
|
|
190
|
+
isDisabled = false,
|
|
191
|
+
asChild = false,
|
|
192
|
+
accessibilityRole,
|
|
193
|
+
accessibilityState,
|
|
194
|
+
animation,
|
|
195
|
+
style,
|
|
196
|
+
onPress,
|
|
197
|
+
onPressIn,
|
|
198
|
+
onPressOut,
|
|
199
|
+
...props
|
|
200
|
+
}, ref) {
|
|
201
|
+
const theme = useXAUITheme();
|
|
202
|
+
const [styleProps, rest] = useStyleProps(props);
|
|
203
|
+
const [isPressed, press] = usePressState({ onPressIn, onPressOut });
|
|
204
|
+
const [selected, setSelected] = useControllableState({
|
|
205
|
+
value: isSelected,
|
|
206
|
+
defaultValue: defaultSelected,
|
|
207
|
+
onChange: onSelectedChange
|
|
208
|
+
});
|
|
209
|
+
const handlePress = useCallback(
|
|
210
|
+
(event) => {
|
|
211
|
+
setSelected(true);
|
|
212
|
+
onPress?.(event);
|
|
213
|
+
},
|
|
214
|
+
[setSelected, onPress]
|
|
215
|
+
);
|
|
216
|
+
const selection = {
|
|
217
|
+
variant,
|
|
218
|
+
size,
|
|
219
|
+
radius,
|
|
220
|
+
isInvalid: isInvalid ? "true" : void 0
|
|
221
|
+
};
|
|
222
|
+
const states = { pressed: isPressed, disabled: isDisabled };
|
|
223
|
+
const styles = radioRecipe.resolve({ theme, selection, states });
|
|
224
|
+
const tint = color && !isInvalid ? radioRecipe.tint({ theme, color, selection, states }) : void 0;
|
|
225
|
+
const context = useMemo(
|
|
226
|
+
() => ({
|
|
227
|
+
// The tint never reaches the circle at rest — only the fill and the dot that say it
|
|
228
|
+
// is the chosen one. The `Checkbox` says why, at the same line.
|
|
229
|
+
indicatorStyle: styles.indicator,
|
|
230
|
+
fillStyle: tint ? [styles.fill, tint.fill] : styles.fill,
|
|
231
|
+
thumbStyle: tint ? [styles.thumb, tint.thumb] : styles.thumb,
|
|
232
|
+
labelStyle: styles.label,
|
|
233
|
+
isSelected: selected,
|
|
234
|
+
isDisabled,
|
|
235
|
+
isInvalid
|
|
236
|
+
}),
|
|
237
|
+
[styles, tint, selected, isDisabled, isInvalid]
|
|
238
|
+
);
|
|
239
|
+
const rootStyle = [
|
|
240
|
+
styles.root,
|
|
241
|
+
tint?.root,
|
|
242
|
+
styleProps,
|
|
243
|
+
typeof style === "function" ? style({ pressed: isPressed }) : style
|
|
244
|
+
];
|
|
245
|
+
const text = childrenToString(children);
|
|
246
|
+
const content = text !== null ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
247
|
+
/* @__PURE__ */ jsx3(RadioIndicator, {}),
|
|
248
|
+
/* @__PURE__ */ jsx3(RadioLabel, { children: text })
|
|
249
|
+
] }) : children ?? /* @__PURE__ */ jsx3(RadioIndicator, {});
|
|
250
|
+
return /* @__PURE__ */ jsx3(RadioProvider, { value: context, children: /* @__PURE__ */ jsx3(
|
|
251
|
+
PressableFeedback,
|
|
252
|
+
{
|
|
253
|
+
ref,
|
|
254
|
+
isPressed,
|
|
255
|
+
isDisabled,
|
|
256
|
+
asChild,
|
|
257
|
+
animation,
|
|
258
|
+
accessibilityRole: accessibilityRole ?? "radio",
|
|
259
|
+
accessibilityState: {
|
|
260
|
+
checked: selected,
|
|
261
|
+
disabled: isDisabled,
|
|
262
|
+
...accessibilityState
|
|
263
|
+
},
|
|
264
|
+
"aria-invalid": isInvalid,
|
|
265
|
+
...rest,
|
|
266
|
+
style: rootStyle,
|
|
267
|
+
onPress: handlePress,
|
|
268
|
+
onPressIn: press.onPressIn,
|
|
269
|
+
onPressOut: press.onPressOut,
|
|
270
|
+
children: asChild ? children : content
|
|
271
|
+
}
|
|
272
|
+
) });
|
|
273
|
+
});
|
|
274
|
+
RadioRoot.displayName = "XAUI.Radio.Root";
|
|
275
|
+
|
|
276
|
+
// src/components/radio/index.ts
|
|
277
|
+
var Radio2 = Object.assign(RadioRoot, {
|
|
278
|
+
Indicator: RadioIndicator,
|
|
279
|
+
Label: RadioLabel
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
export {
|
|
283
|
+
useRadio,
|
|
284
|
+
RadioIndicator,
|
|
285
|
+
RadioLabel,
|
|
286
|
+
radioRecipe,
|
|
287
|
+
RadioRoot,
|
|
288
|
+
Radio2 as Radio
|
|
289
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useControllableState } from "./chunk-F6W3JQ7K.js";
|
|
2
2
|
import { createRecipe, radiusAxis } from "./chunk-3JATAB7S.js";
|
|
3
3
|
import { createSlotContext, useStyleProps } from "./chunk-PMO62QK4.js";
|
|
4
4
|
import { useXAUITheme } from "./chunk-A3EGFI6T.js";
|
|
@@ -39,10 +39,10 @@ function InputOTPCaret({
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
InputOTPCaret.displayName = "XAUI.InputOTP.Caret";
|
|
42
|
-
const
|
|
43
|
-
code: "function
|
|
44
|
-
location: "/home/runner/work/xaui/xaui/packages/native/dist/chunk-
|
|
45
|
-
sourceMap: "{\"version\":3,\"names\":[\"
|
|
42
|
+
const _worklet_16954378841596_init_data = {
|
|
43
|
+
code: "function chunkN4UJYDOWJs1(){const{opacity}=this.__closure;return{opacity:opacity.value};}",
|
|
44
|
+
location: "/home/runner/work/xaui/xaui/packages/native/dist/chunk-N4UJYDOW.js",
|
|
45
|
+
sourceMap: "{\"version\":3,\"names\":[\"chunkN4UJYDOWJs1\",\"opacity\",\"__closure\",\"value\"],\"sources\":[\"/home/runner/work/xaui/xaui/packages/native/dist/chunk-N4UJYDOW.js\"],\"mappings\":\"AA4DyC,SAAAA,iBAAA,QAAAC,OAAA,OAAAC,SAAA,OAAO,CAAED,OAAO,CAAEA,OAAO,CAACE,KAAM,CAAC\",\"ignoreList\":[]}"
|
|
46
46
|
};
|
|
47
47
|
function BlinkingCaret({
|
|
48
48
|
style
|
|
@@ -55,24 +55,24 @@ function BlinkingCaret({
|
|
|
55
55
|
}), -1, true);
|
|
56
56
|
return () => cancelAnimation(opacity);
|
|
57
57
|
}, [opacity]);
|
|
58
|
-
const animatedStyle = useAnimatedStyle(function
|
|
59
|
-
|
|
58
|
+
const animatedStyle = useAnimatedStyle(function chunkN4UJYDOWJs1Factory({
|
|
59
|
+
_worklet_16954378841596_init_data,
|
|
60
60
|
opacity
|
|
61
61
|
}) {
|
|
62
62
|
const _e = [new global.Error(), -2, -27];
|
|
63
|
-
const
|
|
63
|
+
const chunkN4UJYDOWJs1 = () => ({
|
|
64
64
|
opacity: opacity.value
|
|
65
65
|
});
|
|
66
|
-
|
|
66
|
+
chunkN4UJYDOWJs1.__closure = {
|
|
67
67
|
opacity
|
|
68
68
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
69
|
+
chunkN4UJYDOWJs1.__workletHash = 16954378841596;
|
|
70
|
+
chunkN4UJYDOWJs1.__pluginVersion = "0.7.4";
|
|
71
|
+
chunkN4UJYDOWJs1.__initData = _worklet_16954378841596_init_data;
|
|
72
|
+
chunkN4UJYDOWJs1.__stackDetails = _e;
|
|
73
|
+
return chunkN4UJYDOWJs1;
|
|
74
74
|
}({
|
|
75
|
-
|
|
75
|
+
_worklet_16954378841596_init_data,
|
|
76
76
|
opacity
|
|
77
77
|
}));
|
|
78
78
|
return /* @__PURE__ */jsx(Animated.View, {
|
|
@@ -235,40 +235,7 @@ import { forwardRef as forwardRef6, useImperativeHandle, useMemo as useMemo3 } f
|
|
|
235
235
|
import { TextInput, View as View5 } from "react-native";
|
|
236
236
|
|
|
237
237
|
// src/components/input-otp/input-otp.hook.ts
|
|
238
|
-
import { useCallback
|
|
239
|
-
|
|
240
|
-
// src/hooks/use-controllable-state.ts
|
|
241
|
-
import { useCallback, useRef, useState } from "react";
|
|
242
|
-
function useControllableState({
|
|
243
|
-
value,
|
|
244
|
-
defaultValue,
|
|
245
|
-
onChange
|
|
246
|
-
}) {
|
|
247
|
-
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
248
|
-
const isControlled = value !== void 0;
|
|
249
|
-
const current = isControlled ? value : uncontrolled;
|
|
250
|
-
useControlWarning(isControlled);
|
|
251
|
-
const latest = useRef(current);
|
|
252
|
-
latest.current = current;
|
|
253
|
-
const onChangeRef = useRef(onChange);
|
|
254
|
-
onChangeRef.current = onChange;
|
|
255
|
-
const controlled = useRef(isControlled);
|
|
256
|
-
controlled.current = isControlled;
|
|
257
|
-
const set = useCallback(next => {
|
|
258
|
-
const resolved = typeof next === "function" ? next(latest.current) : next;
|
|
259
|
-
if (resolved === latest.current) return;
|
|
260
|
-
if (!controlled.current) setUncontrolled(resolved);
|
|
261
|
-
onChangeRef.current?.(resolved);
|
|
262
|
-
}, []);
|
|
263
|
-
return [current, set];
|
|
264
|
-
}
|
|
265
|
-
function useControlWarning(isControlled) {
|
|
266
|
-
const wasControlled = useRef(isControlled);
|
|
267
|
-
if (wasControlled.current !== isControlled) {
|
|
268
|
-
warnDev(`a component switched from ${wasControlled.current ? "controlled" : "uncontrolled"} to ${isControlled ? "controlled" : "uncontrolled"}. Decide for the life of the component: pass \`value\` always, or never. Passing \`undefined\` for a value you do control reads as "uncontrolled" here.`);
|
|
269
|
-
wasControlled.current = isControlled;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
238
|
+
import { useCallback, useMemo as useMemo2, useRef, useState } from "react";
|
|
272
239
|
|
|
273
240
|
// src/components/input-otp/input-otp.utils.ts
|
|
274
241
|
function buildSlots({
|
|
@@ -322,8 +289,8 @@ function useInputOTPState({
|
|
|
322
289
|
defaultValue,
|
|
323
290
|
onChange: onChangeTextProp
|
|
324
291
|
});
|
|
325
|
-
const [isFocused, setIsFocused] =
|
|
326
|
-
const inputRef =
|
|
292
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
293
|
+
const inputRef = useRef(null);
|
|
327
294
|
const regexp = useMemo2(() => {
|
|
328
295
|
if (!pattern) return null;
|
|
329
296
|
return typeof pattern === "string" ? new RegExp(pattern) : pattern;
|
|
@@ -334,7 +301,7 @@ function useInputOTPState({
|
|
|
334
301
|
isFocused,
|
|
335
302
|
placeholder
|
|
336
303
|
}), [value, maxLength, isFocused, placeholder]);
|
|
337
|
-
const latest =
|
|
304
|
+
const latest = useRef({
|
|
338
305
|
value,
|
|
339
306
|
maxLength,
|
|
340
307
|
regexp,
|
|
@@ -348,7 +315,7 @@ function useInputOTPState({
|
|
|
348
315
|
onComplete,
|
|
349
316
|
setValue
|
|
350
317
|
};
|
|
351
|
-
const onChangeText =
|
|
318
|
+
const onChangeText = useCallback(text => {
|
|
352
319
|
const current = latest.current;
|
|
353
320
|
const candidate = isPaste(text, current.value) ? extractPastedCode(text, current.maxLength) : text;
|
|
354
321
|
const next = candidate.slice(0, current.maxLength);
|
|
@@ -356,8 +323,8 @@ function useInputOTPState({
|
|
|
356
323
|
current.setValue(next);
|
|
357
324
|
if (next.length === current.maxLength) current.onComplete?.(next);
|
|
358
325
|
}, []);
|
|
359
|
-
const onFocus =
|
|
360
|
-
const onBlur =
|
|
326
|
+
const onFocus = useCallback(() => setIsFocused(true), []);
|
|
327
|
+
const onBlur = useCallback(() => setIsFocused(false), []);
|
|
361
328
|
const handle = useMemo2(() => ({
|
|
362
329
|
focus: () => inputRef.current?.focus(),
|
|
363
330
|
blur: () => inputRef.current?.blur(),
|
|
@@ -728,4 +695,4 @@ var InputOTP2 = Object.assign(InputOTPRoot, {
|
|
|
728
695
|
Caret: InputOTPCaret,
|
|
729
696
|
Separator: InputOTPSeparator
|
|
730
697
|
});
|
|
731
|
-
export { useInputOTP, useInputOTPBox,
|
|
698
|
+
export { useInputOTP, useInputOTPBox, buildSlots, extractPastedCode, OTP_DIGITS, OTP_LETTERS, OTP_ALPHANUMERIC, inputOTPRecipe, InputOTP2 as InputOTP };
|