@xaui/native 0.9.1-alpha.22 → 0.9.1-alpha.23

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.
@@ -0,0 +1,451 @@
1
+ import {
2
+ createRecipe,
3
+ radiusAxis
4
+ } from "./chunk-3JATAB7S.js";
5
+ import {
6
+ useXAUITheme
7
+ } from "./chunk-A3EGFI6T.js";
8
+ import {
9
+ Slot,
10
+ createSlotContext,
11
+ useStyleProps
12
+ } from "./chunk-PMO62QK4.js";
13
+
14
+ // src/components/input/input-description.tsx
15
+ import { forwardRef } from "react";
16
+ import { Text } from "react-native";
17
+
18
+ // src/components/input/input.context.ts
19
+ var [InputProvider, useInput] = createSlotContext("Input");
20
+
21
+ // src/components/input/input-description.tsx
22
+ import { jsx } from "react/jsx-runtime";
23
+ var InputDescription = forwardRef(
24
+ function InputDescription2({ children, style, nativeID, ...props }, ref) {
25
+ const { descriptionStyle, descriptionId } = useInput();
26
+ const [styleProps, rest] = useStyleProps(props);
27
+ return /* @__PURE__ */ jsx(
28
+ Text,
29
+ {
30
+ ref,
31
+ nativeID: nativeID ?? descriptionId,
32
+ style: [descriptionStyle, styleProps, style],
33
+ ...rest,
34
+ children
35
+ }
36
+ );
37
+ }
38
+ );
39
+ InputDescription.displayName = "XAUI.Input.Description";
40
+
41
+ // src/components/input/input-error.tsx
42
+ import { forwardRef as forwardRef2 } from "react";
43
+ import { Text as Text2 } from "react-native";
44
+ import { jsx as jsx2 } from "react/jsx-runtime";
45
+ var InputError = forwardRef2(function InputError2({ children, style, ...props }, ref) {
46
+ const { errorStyle } = useInput();
47
+ const [styleProps, rest] = useStyleProps(props);
48
+ return /* @__PURE__ */ jsx2(Text2, { ref, style: [errorStyle, styleProps, style], ...rest, children });
49
+ });
50
+ InputError.displayName = "XAUI.Input.Error";
51
+
52
+ // src/components/input/input-field.tsx
53
+ import { forwardRef as forwardRef3, useCallback } from "react";
54
+ import { TextInput } from "react-native";
55
+ import { jsx as jsx3 } from "react/jsx-runtime";
56
+ var InputField = forwardRef3(function InputField2({ style, onFocus, onBlur, placeholderTextColor, ...props }, ref) {
57
+ const {
58
+ fieldStyle,
59
+ placeholderTextColor: resolvedPlaceholder,
60
+ onFieldFocus,
61
+ onFieldBlur,
62
+ labelId,
63
+ descriptionId,
64
+ isDisabled,
65
+ isInvalid
66
+ } = useInput();
67
+ const [styleProps, rest] = useStyleProps(props);
68
+ const handleFocus = useCallback(
69
+ (event) => {
70
+ onFieldFocus(event);
71
+ onFocus?.(event);
72
+ },
73
+ [onFieldFocus, onFocus]
74
+ );
75
+ const handleBlur = useCallback(
76
+ (event) => {
77
+ onFieldBlur(event);
78
+ onBlur?.(event);
79
+ },
80
+ [onFieldBlur, onBlur]
81
+ );
82
+ return /* @__PURE__ */ jsx3(
83
+ TextInput,
84
+ {
85
+ ref,
86
+ "aria-labelledby": labelId,
87
+ "aria-describedby": descriptionId,
88
+ "aria-invalid": isInvalid,
89
+ editable: !isDisabled,
90
+ accessibilityState: { disabled: isDisabled },
91
+ placeholderTextColor: placeholderTextColor ?? resolvedPlaceholder,
92
+ ...rest,
93
+ style: [fieldStyle, styleProps, style],
94
+ onFocus: handleFocus,
95
+ onBlur: handleBlur
96
+ }
97
+ );
98
+ });
99
+ InputField.displayName = "XAUI.Input.Field";
100
+
101
+ // src/components/input/input-label.tsx
102
+ import { forwardRef as forwardRef4 } from "react";
103
+ import { Text as Text3 } from "react-native";
104
+ import { jsx as jsx4 } from "react/jsx-runtime";
105
+ var InputLabel = forwardRef4(function InputLabel2({ children, style, nativeID, ...props }, ref) {
106
+ const { labelStyle, labelId } = useInput();
107
+ const [styleProps, rest] = useStyleProps(props);
108
+ return /* @__PURE__ */ jsx4(
109
+ Text3,
110
+ {
111
+ ref,
112
+ nativeID: nativeID ?? labelId,
113
+ style: [labelStyle, styleProps, style],
114
+ ...rest,
115
+ children
116
+ }
117
+ );
118
+ });
119
+ InputLabel.displayName = "XAUI.Input.Label";
120
+
121
+ // src/components/input/input.tsx
122
+ import { forwardRef as forwardRef5, useCallback as useCallback2, useId, useMemo, useState } from "react";
123
+ import { StyleSheet, View } from "react-native";
124
+
125
+ // src/components/input/input.recipe.ts
126
+ var SLOTS = [
127
+ "root",
128
+ "label",
129
+ "field",
130
+ "placeholder",
131
+ "description",
132
+ "error"
133
+ ];
134
+ var VARIANT_TOKENS = {
135
+ primary: {
136
+ bg: "fieldBackground",
137
+ border: "fieldBorder",
138
+ borderFocus: "fieldBorderFocus",
139
+ fg: "fieldForeground"
140
+ },
141
+ // `bg: 'default'` is the neutral *token*, not this variant's name — the two namespaces
142
+ // meet here and nowhere else. It is also what keeps a field visible on a card, where
143
+ // `fieldBackground` is the card's own colour.
144
+ secondary: {
145
+ bg: "default",
146
+ border: "fieldBorder",
147
+ borderFocus: "fieldBorderFocus",
148
+ fg: "fieldForeground"
149
+ },
150
+ tertiary: {
151
+ border: "fieldBorder",
152
+ borderFocus: "fieldBorderFocus",
153
+ fg: "fieldForeground"
154
+ },
155
+ ghost: { borderFocus: "fieldBorderFocus", fg: "fieldForeground" }
156
+ };
157
+ function sizeAxis(step) {
158
+ const { control, padding, gap, field, label, help } = step;
159
+ return (theme) => {
160
+ const inset = { paddingHorizontal: theme.spacing(LABEL_INSET) };
161
+ const helpType = {
162
+ fontSize: theme.fontSizes[help],
163
+ lineHeight: theme.lineHeights[help]
164
+ };
165
+ return {
166
+ root: { gap: theme.spacing(gap) },
167
+ label: {
168
+ ...inset,
169
+ fontSize: theme.fontSizes[label],
170
+ lineHeight: theme.lineHeights[label]
171
+ },
172
+ field: {
173
+ minHeight: theme.controlHeights[control],
174
+ paddingHorizontal: theme.spacing(padding),
175
+ fontSize: theme.fontSizes[field]
176
+ },
177
+ description: { ...inset, ...helpType },
178
+ error: { ...inset, ...helpType }
179
+ };
180
+ };
181
+ }
182
+ var LABEL_INSET = 1.5;
183
+ var SIZES = {
184
+ xs: {
185
+ control: "xs",
186
+ padding: 2.5,
187
+ gap: 1,
188
+ field: "sm",
189
+ label: "sm",
190
+ help: "xs",
191
+ labelInside: "xs"
192
+ },
193
+ sm: {
194
+ control: "sm",
195
+ padding: 3,
196
+ gap: 1,
197
+ field: "md",
198
+ label: "sm",
199
+ help: "xs",
200
+ labelInside: "xs"
201
+ },
202
+ md: {
203
+ control: "md",
204
+ padding: 3,
205
+ gap: 1.5,
206
+ field: "md",
207
+ label: "md",
208
+ help: "sm",
209
+ labelInside: "xs"
210
+ },
211
+ lg: {
212
+ control: "lg",
213
+ padding: 4,
214
+ gap: 2,
215
+ field: "lg",
216
+ label: "lg",
217
+ help: "md",
218
+ labelInside: "sm"
219
+ }
220
+ };
221
+ function insideLabel(step) {
222
+ const { control, padding, field, labelInside } = step;
223
+ return (theme) => {
224
+ const top = theme.spacing(LABEL_INSIDE_TOP);
225
+ const block = top + theme.lineHeights[labelInside];
226
+ return {
227
+ label: {
228
+ position: "absolute",
229
+ top,
230
+ // `start`, never `left` (R13): RTL mirrors the logical property and only it.
231
+ start: theme.spacing(padding),
232
+ paddingHorizontal: 0,
233
+ fontSize: theme.fontSizes[labelInside],
234
+ lineHeight: theme.lineHeights[labelInside]
235
+ },
236
+ // The height is built from the two lines it now holds rather than added to the
237
+ // control height: `controlHeights` already pays for centring one line, so adding
238
+ // the label's block to it would pay for that room twice. It is floored at the
239
+ // control height all the same, so a theme that raises `controlHeights` does not end
240
+ // up with an inside field shorter than the outside one beside it.
241
+ field: {
242
+ minHeight: Math.max(
243
+ block + theme.lineHeights[field] + top,
244
+ theme.controlHeights[control]
245
+ ),
246
+ paddingTop: block,
247
+ paddingBottom: top
248
+ }
249
+ };
250
+ };
251
+ }
252
+ var LABEL_INSIDE_TOP = 1.5;
253
+ var inputRecipe = createRecipe({
254
+ slots: SLOTS,
255
+ base: (theme) => ({
256
+ root: { flexDirection: "column" },
257
+ label: {
258
+ fontFamily: theme.fontFamilies.body,
259
+ fontWeight: theme.fontWeights.medium
260
+ },
261
+ field: {
262
+ fontFamily: theme.fontFamilies.body,
263
+ // `regular`, not `medium`: what the user typed is content, not a control's label,
264
+ // and a heavier weight makes a filled field read as a button.
265
+ fontWeight: theme.fontWeights.regular,
266
+ borderWidth: theme.borderWidth.field,
267
+ // The theme has a radius named for this component, so every size uses it and the
268
+ // `radius` axis is what overrides it — the same shape a `Chip` takes from `full`.
269
+ borderRadius: theme.radius.field,
270
+ borderCurve: "continuous",
271
+ // RN centres a single line inside `minHeight` on iOS and pins it to the top on
272
+ // Android. Saying it removes a difference nobody chose.
273
+ textAlignVertical: "center"
274
+ },
275
+ // Not a node — the root flattens this one into `placeholderTextColor`, which is a
276
+ // `TextInput` prop rather than a style.
277
+ placeholder: { color: theme.colors.fieldPlaceholder },
278
+ description: {
279
+ fontFamily: theme.fontFamilies.body,
280
+ color: theme.colors.muted
281
+ },
282
+ error: {
283
+ fontFamily: theme.fontFamilies.body,
284
+ color: theme.colors.danger
285
+ }
286
+ }),
287
+ variantTokens: VARIANT_TOKENS,
288
+ /**
289
+ * Where the variant's colours land. The border width follows the *presence* of the
290
+ * border role, so `ghost` needs no rule of its own to say it has no edge.
291
+ *
292
+ * The label is **not** painted from the variant: it sits outside the box, on the screen
293
+ * behind it, so it takes `foreground` and not the field's own text colour. That is also
294
+ * why a tinted input does not tint its label — the tint is the field's, not the form's.
295
+ */
296
+ paint: (theme, colors) => ({
297
+ field: {
298
+ backgroundColor: colors.bg,
299
+ borderColor: colors.border,
300
+ borderWidth: colors.border ? theme.borderWidth.field : 0,
301
+ color: colors.fg
302
+ },
303
+ label: { color: theme.colors.foreground }
304
+ }),
305
+ /**
306
+ * Declaration order is application order, and it is load-bearing here: `isInvalid`
307
+ * comes after `size` so its border wins, and it must also outrank focus — which is why
308
+ * the root passes `focused` only when the field is *not* invalid, rather than relying
309
+ * on an order that states cannot express.
310
+ */
311
+ variants: {
312
+ size: {
313
+ xs: sizeAxis(SIZES.xs),
314
+ sm: sizeAxis(SIZES.sm),
315
+ md: sizeAxis(SIZES.md),
316
+ lg: sizeAxis(SIZES.lg)
317
+ },
318
+ radius: radiusAxis("field"),
319
+ /**
320
+ * `outside` is the base behaviour, so it adds nothing — it is declared because an
321
+ * axis needs both of its values for the selection to be typed, and because a reader
322
+ * looking for "what does outside do" should find the answer here rather than infer it
323
+ * from an absence. The size-dependent half of `inside` is in `compoundVariants`.
324
+ */
325
+ labelPlacement: {
326
+ outside: () => ({}),
327
+ inside: () => ({})
328
+ },
329
+ isInvalid: {
330
+ true: (theme) => ({
331
+ field: { borderColor: theme.colors.danger },
332
+ // The label and the description turn with it: on a long form the field that is
333
+ // wrong has to be findable without reading every message.
334
+ label: { color: theme.colors.danger },
335
+ description: { color: theme.colors.danger }
336
+ })
337
+ }
338
+ },
339
+ /**
340
+ * The focus treatment is the border darkening towards the mode's ink — the theme's
341
+ * `fieldBorderFocus`, which is `fieldBorder` mixed 26% towards `fieldForeground`. No
342
+ * ring and no accent: a form where every focused field flashes the brand colour is a
343
+ * form where the accent has stopped meaning "the action".
344
+ *
345
+ * `borderFocus` is a role rather than a token named here, so a raw `color` follows the
346
+ * field into focus the same way it follows a `Button` into its pressed state.
347
+ */
348
+ /**
349
+ * What `primary` adds to a filled field, and the four halves of the inside label that
350
+ * need to know the size — a compound is how the engine expresses a rule that depends on
351
+ * two axes at once.
352
+ */
353
+ compoundVariants: [
354
+ {
355
+ when: { variant: "primary" },
356
+ style: (theme) => ({ field: theme.shadows.field })
357
+ },
358
+ { when: { size: "xs", labelPlacement: "inside" }, style: insideLabel(SIZES.xs) },
359
+ { when: { size: "sm", labelPlacement: "inside" }, style: insideLabel(SIZES.sm) },
360
+ { when: { size: "md", labelPlacement: "inside" }, style: insideLabel(SIZES.md) },
361
+ { when: { size: "lg", labelPlacement: "inside" }, style: insideLabel(SIZES.lg) }
362
+ ],
363
+ states: {
364
+ focused: (_theme, colors) => ({ field: { borderColor: colors.borderFocus } }),
365
+ disabled: (theme) => ({ root: { opacity: theme.opacity.disabled } })
366
+ },
367
+ defaultVariants: { variant: "secondary", size: "md", labelPlacement: "outside" }
368
+ });
369
+
370
+ // src/components/input/input.tsx
371
+ import { jsx as jsx5 } from "react/jsx-runtime";
372
+ var InputRoot = forwardRef5(function Input({
373
+ children,
374
+ variant,
375
+ size,
376
+ radius,
377
+ labelPlacement,
378
+ color,
379
+ isInvalid = false,
380
+ isDisabled = false,
381
+ asChild = false,
382
+ style,
383
+ ...props
384
+ }, ref) {
385
+ const theme = useXAUITheme();
386
+ const [styleProps, rest] = useStyleProps(props);
387
+ const [isFocused, setIsFocused] = useState(false);
388
+ const onFieldFocus = useCallback2(() => setIsFocused(true), []);
389
+ const onFieldBlur = useCallback2(() => setIsFocused(false), []);
390
+ const id = useId();
391
+ const labelId = `${id}-label`;
392
+ const descriptionId = `${id}-description`;
393
+ const selection = {
394
+ variant,
395
+ size,
396
+ radius,
397
+ labelPlacement,
398
+ isInvalid: isInvalid ? "true" : void 0
399
+ };
400
+ const states = { focused: isFocused && !isInvalid, disabled: isDisabled };
401
+ const styles = inputRecipe.resolve({ theme, selection, states });
402
+ const tint = color ? inputRecipe.tint({ theme, color, selection, states }) : void 0;
403
+ const context = useMemo(() => {
404
+ const placeholder = StyleSheet.flatten(styles.placeholder);
405
+ return {
406
+ labelStyle: tint ? [styles.label, tint.label] : styles.label,
407
+ fieldStyle: tint ? [styles.field, tint.field] : styles.field,
408
+ descriptionStyle: styles.description,
409
+ errorStyle: styles.error,
410
+ // `ColorValue` also covers the platform's opaque colours, which `TextInput` cannot
411
+ // take for a placeholder.
412
+ placeholderTextColor: typeof placeholder.color === "string" ? placeholder.color : void 0,
413
+ onFieldFocus,
414
+ onFieldBlur,
415
+ labelId,
416
+ descriptionId,
417
+ isDisabled,
418
+ isInvalid
419
+ };
420
+ }, [
421
+ styles,
422
+ tint,
423
+ onFieldFocus,
424
+ onFieldBlur,
425
+ labelId,
426
+ descriptionId,
427
+ isDisabled,
428
+ isInvalid
429
+ ]);
430
+ const rootStyle = [styles.root, tint?.root, styleProps, style];
431
+ const surface = asChild ? (
432
+ // R12 — the caller's element *is* the column.
433
+ /* @__PURE__ */ jsx5(Slot, { ref, ...rest, style: rootStyle, children })
434
+ ) : /* @__PURE__ */ jsx5(View, { ref, ...rest, style: rootStyle, children });
435
+ return /* @__PURE__ */ jsx5(InputProvider, { value: context, children: surface });
436
+ });
437
+ InputRoot.displayName = "XAUI.Input.Root";
438
+
439
+ // src/components/input/index.ts
440
+ var Input2 = Object.assign(InputRoot, {
441
+ Label: InputLabel,
442
+ Field: InputField,
443
+ Description: InputDescription,
444
+ Error: InputError
445
+ });
446
+
447
+ export {
448
+ useInput,
449
+ inputRecipe,
450
+ Input2 as Input
451
+ };