@xaui/native 0.9.1-alpha.4 → 0.9.1-alpha.40

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.
Files changed (203) hide show
  1. package/dist/chunk-2EGR4LWD.js +145 -0
  2. package/dist/chunk-2NRZKJG7.js +531 -0
  3. package/dist/chunk-2PMXMKS5.js +67 -0
  4. package/dist/chunk-2XPG2243.js +586 -0
  5. package/dist/chunk-36PRYGAM.js +13 -0
  6. package/dist/chunk-3E7CDKFO.cjs +696 -0
  7. package/dist/chunk-3GFRSZYR.js +54 -0
  8. package/dist/chunk-423RQBOX.js +21 -0
  9. package/dist/chunk-4CUZZWFW.js +92 -0
  10. package/dist/chunk-4GTAZM2C.js +174 -0
  11. package/dist/chunk-4KFKWBN5.cjs +89 -0
  12. package/dist/{chunk-3QBT3Q65.cjs → chunk-57SJ4LJF.cjs} +7 -2
  13. package/dist/chunk-5R26NM4M.cjs +402 -0
  14. package/dist/chunk-5VKYNBNA.js +607 -0
  15. package/dist/chunk-64MXEVT3.js +66 -0
  16. package/dist/chunk-6DOLGZVV.cjs +147 -0
  17. package/dist/chunk-6L2TS2R3.cjs +92 -0
  18. package/dist/chunk-6UEZJRVI.js +669 -0
  19. package/dist/chunk-734MFAX4.js +27 -0
  20. package/dist/chunk-73RKQC5X.js +104 -0
  21. package/dist/chunk-7DPL3ZDS.cjs +21 -0
  22. package/dist/chunk-7EIHHOHP.cjs +42 -0
  23. package/dist/chunk-7GHM4GKL.cjs +119 -0
  24. package/dist/chunk-7YF5NAHQ.cjs +74 -0
  25. package/dist/{chunk-X2K2FX3W.js → chunk-A3EGFI6T.js} +6 -1
  26. package/dist/chunk-ABAGZTXZ.cjs +736 -0
  27. package/dist/{chunk-AW63PTQ4.cjs → chunk-ACAPTWE3.cjs} +85 -81
  28. package/dist/chunk-AMCSSOJT.cjs +104 -0
  29. package/dist/chunk-BA2DBSAN.js +102 -0
  30. package/dist/chunk-BRRXFOBY.js +431 -0
  31. package/dist/chunk-C5YLPCFC.cjs +293 -0
  32. package/dist/chunk-DA3OKXHV.cjs +700 -0
  33. package/dist/chunk-DD4276RF.js +366 -0
  34. package/dist/chunk-DG2I4PJG.js +701 -0
  35. package/dist/chunk-DHGLGSH6.js +661 -0
  36. package/dist/chunk-DIBUQ46Y.js +346 -0
  37. package/dist/chunk-EGLLDKN6.js +9 -0
  38. package/dist/chunk-EJQCQPET.cjs +9 -0
  39. package/dist/chunk-EKS3W46M.cjs +66 -0
  40. package/dist/chunk-EZEYMLO3.js +402 -0
  41. package/dist/chunk-F6CQ6CBI.cjs +112 -0
  42. package/dist/chunk-F6W3JQ7K.js +42 -0
  43. package/dist/chunk-FHUYHV6J.js +89 -0
  44. package/dist/chunk-FNEUOBCV.cjs +174 -0
  45. package/dist/chunk-G7P3ERYF.cjs +478 -0
  46. package/dist/chunk-GA6PBWNT.js +147 -0
  47. package/dist/chunk-GFUZ3MUT.cjs +455 -0
  48. package/dist/chunk-GGW43Q37.cjs +1 -0
  49. package/dist/chunk-GTR5X65M.cjs +27 -0
  50. package/dist/chunk-H4E4HDEP.cjs +13 -0
  51. package/dist/chunk-H7DS4IO7.js +198 -0
  52. package/dist/chunk-HDVVZG4S.cjs +198 -0
  53. package/dist/chunk-IKJVLJKT.js +151 -0
  54. package/dist/chunk-J3MB4PI5.cjs +531 -0
  55. package/dist/chunk-K72UDPVN.js +119 -0
  56. package/dist/chunk-KCMYU7WF.js +86 -0
  57. package/dist/chunk-LRN3RNDO.js +940 -0
  58. package/dist/chunk-LTX6TB5I.js +124 -0
  59. package/dist/chunk-LUPCPLND.cjs +145 -0
  60. package/dist/chunk-M63GFNKV.js +194 -0
  61. package/dist/chunk-N3KTZMPG.js +293 -0
  62. package/dist/chunk-NCTOTTVW.js +13 -0
  63. package/dist/chunk-NWGLP6JX.cjs +410 -0
  64. package/dist/chunk-R73XQK7X.cjs +314 -0
  65. package/dist/chunk-RU7JCMWC.cjs +881 -0
  66. package/dist/chunk-SNIHUKDA.cjs +184 -0
  67. package/dist/chunk-T5FV5F7A.cjs +607 -0
  68. package/dist/chunk-TDTUAIFF.cjs +153 -0
  69. package/dist/chunk-TJ74XVZN.cjs +431 -0
  70. package/dist/chunk-TK44VBIE.cjs +194 -0
  71. package/dist/chunk-UAWBAD4E.cjs +346 -0
  72. package/dist/chunk-UFTCTTKK.js +381 -0
  73. package/dist/chunk-WDDXU3OH.cjs +67 -0
  74. package/dist/chunk-WFEMJCXO.cjs +13 -0
  75. package/dist/chunk-WHJTBTYM.js +0 -0
  76. package/dist/{chunk-2KXQATVL.js → chunk-WKCQ6VGW.js} +59 -55
  77. package/dist/chunk-XFPQFCEK.js +455 -0
  78. package/dist/chunk-XSQPVDFH.cjs +60 -0
  79. package/dist/chunk-XTC2SLFT.js +153 -0
  80. package/dist/chunk-XV735BSA.cjs +366 -0
  81. package/dist/chunk-XWNG2U4K.cjs +124 -0
  82. package/dist/chunk-YGYYJ3LQ.js +314 -0
  83. package/dist/chunk-YVHT2UVW.js +74 -0
  84. package/dist/chunk-ZFOOJK37.cjs +86 -0
  85. package/dist/close-button.type-BUYuoSt2.d.ts +36 -0
  86. package/dist/close-button.type-CHsgZ3wO.d.cts +36 -0
  87. package/dist/components/accordion/index.cjs +35 -0
  88. package/dist/components/accordion/index.d.cts +299 -0
  89. package/dist/components/accordion/index.d.ts +299 -0
  90. package/dist/components/accordion/index.js +35 -0
  91. package/dist/components/alert/index.cjs +20 -0
  92. package/dist/components/alert/index.d.cts +169 -0
  93. package/dist/components/alert/index.d.ts +169 -0
  94. package/dist/components/alert/index.js +20 -0
  95. package/dist/components/avatar/index.cjs +16 -0
  96. package/dist/components/avatar/index.d.cts +131 -0
  97. package/dist/components/avatar/index.d.ts +131 -0
  98. package/dist/components/avatar/index.js +16 -0
  99. package/dist/components/badge/index.cjs +15 -0
  100. package/dist/components/badge/index.d.cts +157 -0
  101. package/dist/components/badge/index.d.ts +157 -0
  102. package/dist/components/badge/index.js +15 -0
  103. package/dist/components/button/index.cjs +22 -0
  104. package/dist/components/button/index.d.cts +613 -0
  105. package/dist/components/button/index.d.ts +613 -0
  106. package/dist/components/button/index.js +22 -0
  107. package/dist/components/card/index.cjs +22 -0
  108. package/dist/components/card/index.d.cts +620 -0
  109. package/dist/components/card/index.d.ts +620 -0
  110. package/dist/components/card/index.js +22 -0
  111. package/dist/components/checkbox/index.cjs +26 -0
  112. package/dist/components/checkbox/index.d.cts +1136 -0
  113. package/dist/components/checkbox/index.d.ts +1136 -0
  114. package/dist/components/checkbox/index.js +26 -0
  115. package/dist/components/chip/index.cjs +20 -0
  116. package/dist/components/chip/index.d.cts +608 -0
  117. package/dist/components/chip/index.d.ts +608 -0
  118. package/dist/components/chip/index.js +20 -0
  119. package/dist/components/divider/index.cjs +13 -0
  120. package/dist/components/divider/index.d.cts +117 -0
  121. package/dist/components/divider/index.d.ts +117 -0
  122. package/dist/components/divider/index.js +13 -0
  123. package/dist/components/field-group/index.cjs +27 -0
  124. package/dist/components/field-group/index.d.cts +270 -0
  125. package/dist/components/field-group/index.d.ts +270 -0
  126. package/dist/components/field-group/index.js +27 -0
  127. package/dist/components/input-otp/index.cjs +29 -0
  128. package/dist/components/input-otp/index.d.cts +325 -0
  129. package/dist/components/input-otp/index.d.ts +325 -0
  130. package/dist/components/input-otp/index.js +29 -0
  131. package/dist/components/menu/index.cjs +49 -0
  132. package/dist/components/menu/index.d.cts +351 -0
  133. package/dist/components/menu/index.d.ts +351 -0
  134. package/dist/components/menu/index.js +49 -0
  135. package/dist/components/popover/index.cjs +38 -0
  136. package/dist/components/popover/index.d.cts +254 -0
  137. package/dist/components/popover/index.d.ts +254 -0
  138. package/dist/components/popover/index.js +38 -0
  139. package/dist/components/radio/index.cjs +26 -0
  140. package/dist/components/radio/index.d.cts +1102 -0
  141. package/dist/components/radio/index.d.ts +1102 -0
  142. package/dist/components/radio/index.js +26 -0
  143. package/dist/components/select/index.cjs +50 -0
  144. package/dist/components/select/index.d.cts +498 -0
  145. package/dist/components/select/index.d.ts +498 -0
  146. package/dist/components/select/index.js +50 -0
  147. package/dist/components/skeleton/index.cjs +11 -0
  148. package/dist/components/skeleton/index.d.cts +111 -0
  149. package/dist/components/skeleton/index.d.ts +111 -0
  150. package/dist/components/skeleton/index.js +11 -0
  151. package/dist/components/spinner/index.cjs +17 -0
  152. package/dist/components/spinner/index.d.cts +104 -0
  153. package/dist/components/spinner/index.d.ts +104 -0
  154. package/dist/components/spinner/index.js +17 -0
  155. package/dist/components/switch/index.cjs +27 -0
  156. package/dist/components/switch/index.d.cts +1154 -0
  157. package/dist/components/switch/index.d.ts +1154 -0
  158. package/dist/components/switch/index.js +27 -0
  159. package/dist/components/text-area/index.cjs +14 -0
  160. package/dist/components/text-area/index.d.cts +73 -0
  161. package/dist/components/text-area/index.d.ts +73 -0
  162. package/dist/components/text-area/index.js +14 -0
  163. package/dist/components/text-field/index.cjs +25 -0
  164. package/dist/components/text-field/index.d.cts +205 -0
  165. package/dist/components/text-field/index.d.ts +205 -0
  166. package/dist/components/text-field/index.js +25 -0
  167. package/dist/components/typography/index.cjs +15 -0
  168. package/dist/components/typography/index.d.cts +116 -0
  169. package/dist/components/typography/index.d.ts +116 -0
  170. package/dist/components/typography/index.js +15 -0
  171. package/dist/components/view/index.cjs +17 -0
  172. package/dist/components/view/index.d.cts +152 -0
  173. package/dist/components/view/index.d.ts +152 -0
  174. package/dist/components/view/index.js +17 -0
  175. package/dist/create-recipe-BdVd2ffi.d.ts +114 -0
  176. package/dist/create-recipe-dC7wMfnj.d.cts +114 -0
  177. package/dist/icon.type-Kml72iSz.d.ts +73 -0
  178. package/dist/icon.type-d_i9ma-i.d.cts +73 -0
  179. package/dist/index.cjs +400 -4
  180. package/dist/index.d.cts +118 -4
  181. package/dist/index.d.ts +118 -4
  182. package/dist/index.js +423 -27
  183. package/dist/placement-DHa0Rrh1.d.cts +38 -0
  184. package/dist/placement-DHa0Rrh1.d.ts +38 -0
  185. package/dist/pressable-feedback.type-BA2C9sSz.d.cts +127 -0
  186. package/dist/pressable-feedback.type-Bs4dQlGj.d.ts +127 -0
  187. package/dist/style-props.type-CfnoGEP7.d.cts +31 -0
  188. package/dist/style-props.type-CfnoGEP7.d.ts +31 -0
  189. package/dist/system/index.cjs +73 -4
  190. package/dist/system/index.d.cts +379 -193
  191. package/dist/system/index.d.ts +379 -193
  192. package/dist/system/index.js +87 -18
  193. package/dist/text-field.type-0l73acce.d.ts +167 -0
  194. package/dist/text-field.type-DBh06DU5.d.cts +167 -0
  195. package/dist/theme/index.cjs +5 -3
  196. package/dist/theme/index.d.cts +55 -24
  197. package/dist/theme/index.d.ts +55 -24
  198. package/dist/theme/index.js +4 -2
  199. package/dist/{theme.type-C9bFJKFm.d.cts → theme.type-C2gNHpEx.d.cts} +1 -1
  200. package/dist/{theme.type-C9bFJKFm.d.ts → theme.type-C2gNHpEx.d.ts} +1 -1
  201. package/package.json +254 -18
  202. package/dist/chunk-ECDWSSHJ.js +0 -688
  203. package/dist/chunk-IYFGO523.cjs +0 -688
@@ -0,0 +1,145 @@
1
+ import {
2
+ PortalContext
3
+ } from "./chunk-2PMXMKS5.js";
4
+
5
+ // src/hooks/use-anchored-position.ts
6
+ import { useCallback, useContext, useState } from "react";
7
+ import { useWindowDimensions } from "react-native";
8
+
9
+ // src/utils/placement.ts
10
+ var OPPOSITE = {
11
+ top: "bottom",
12
+ bottom: "top",
13
+ start: "end",
14
+ end: "start"
15
+ };
16
+ function axisOf(placement) {
17
+ return placement === "top" || placement === "bottom" ? "vertical" : "horizontal";
18
+ }
19
+ function resolvePlacement(input) {
20
+ const { anchor, content, window, offset, alignOffset, insets } = input;
21
+ const available = window.width - insets.start - insets.end;
22
+ const width = Math.min(resolveWidth(input), Math.max(available, 0));
23
+ const placement = choosePlacement(input);
24
+ const room = Math.max(roomFor(placement, input), 0);
25
+ const vertical = axisOf(placement) === "vertical";
26
+ const maxHeight = vertical ? room : Math.max(window.height - insets.top - insets.bottom, 0);
27
+ const height = Math.min(content.height, maxHeight);
28
+ const top = clamp(
29
+ vertical ? placement === "bottom" ? anchor.y + anchor.height + offset : anchor.y - offset - height : alignedCross(input, height) + alignOffset,
30
+ insets.top,
31
+ Math.max(window.height - insets.bottom - height, insets.top)
32
+ );
33
+ const start = clamp(
34
+ vertical ? alignedCross(input, width) + alignOffset : placement === "end" ? anchor.x + anchor.width + offset : anchor.x - offset - width,
35
+ insets.start,
36
+ Math.max(window.width - insets.end - width, insets.start)
37
+ );
38
+ return { top, start, width, maxHeight, placement };
39
+ }
40
+ function resolveWidth(input) {
41
+ const { width, anchor, content, placement, window, insets } = input;
42
+ if (width === "trigger") {
43
+ return axisOf(placement) === "vertical" ? anchor.width : content.width;
44
+ }
45
+ if (width === "full") return Math.max(window.width - insets.start - insets.end, 0);
46
+ if (width === "content-fit") return content.width;
47
+ return width;
48
+ }
49
+ function choosePlacement(input) {
50
+ const { placement, avoidCollisions, content } = input;
51
+ if (!avoidCollisions) return placement;
52
+ const wanted = axisOf(placement) === "vertical" ? content.height : content.width;
53
+ if (roomFor(placement, input) >= wanted) return placement;
54
+ const other = OPPOSITE[placement];
55
+ return roomFor(other, input) > roomFor(placement, input) ? other : placement;
56
+ }
57
+ function roomFor(placement, input) {
58
+ const { anchor, window, offset, insets } = input;
59
+ switch (placement) {
60
+ case "bottom":
61
+ return window.height - insets.bottom - (anchor.y + anchor.height) - offset;
62
+ case "top":
63
+ return anchor.y - insets.top - offset;
64
+ case "end":
65
+ return window.width - insets.end - (anchor.x + anchor.width) - offset;
66
+ case "start":
67
+ return anchor.x - insets.start - offset;
68
+ }
69
+ }
70
+ function alignedCross({ align, anchor, placement }, size) {
71
+ const vertical = axisOf(placement) === "vertical";
72
+ const origin = vertical ? anchor.x : anchor.y;
73
+ const extent = vertical ? anchor.width : anchor.height;
74
+ if (align === "start") return origin;
75
+ if (align === "end") return origin + extent - size;
76
+ return origin + (extent - size) / 2;
77
+ }
78
+ function clamp(value, min, max) {
79
+ return Math.min(Math.max(value, min), max);
80
+ }
81
+
82
+ // src/hooks/use-anchored-position.ts
83
+ function useAnchoredPosition({
84
+ anchor,
85
+ isOpen,
86
+ onLayout,
87
+ ...options
88
+ }) {
89
+ const window = useWindowDimensions();
90
+ const origin = useContext(PortalContext)?.origin ?? ZERO;
91
+ const [measured, setMeasured] = useState(null);
92
+ const onContentLayout = useCallback(
93
+ (event) => {
94
+ onLayout?.(event);
95
+ const { width, height } = event.nativeEvent.layout;
96
+ setMeasured(
97
+ (current) => current !== null && current.width === width && current.height === height ? current : { width, height }
98
+ );
99
+ },
100
+ [onLayout]
101
+ );
102
+ if (!isOpen && measured !== null) setMeasured(null);
103
+ const local = anchor && {
104
+ ...anchor,
105
+ x: anchor.x - origin.x,
106
+ y: anchor.y - origin.y
107
+ };
108
+ const position = local && measured ? resolvePlacement({
109
+ anchor: local,
110
+ content: measured,
111
+ window: {
112
+ width: window.width - origin.x,
113
+ height: window.height - origin.y
114
+ },
115
+ ...options
116
+ }) : null;
117
+ return {
118
+ position,
119
+ onContentLayout,
120
+ measuringStyle: {
121
+ // Invisible, and at the start of the host, so the reader never sees the panel at
122
+ // the wrong place during the frame it is being measured in.
123
+ opacity: 0,
124
+ top: 0,
125
+ start: 0,
126
+ ...measuringWidth(options, local?.width, window)
127
+ }
128
+ };
129
+ }
130
+ function measuringWidth({
131
+ width,
132
+ maxWidth,
133
+ insets
134
+ }, anchorWidth, window) {
135
+ const screen = Math.max(window.width - insets.start - insets.end, 0);
136
+ if (width === "trigger") return { width: anchorWidth };
137
+ if (width === "full") return { width: screen };
138
+ if (typeof width === "number") return { width };
139
+ return { maxWidth: Math.min(maxWidth ?? Number.POSITIVE_INFINITY, screen) };
140
+ }
141
+ var ZERO = { x: 0, y: 0 };
142
+
143
+ export {
144
+ useAnchoredPosition
145
+ };
@@ -0,0 +1,531 @@
1
+ import {
2
+ createRecipe,
3
+ radiusAxis
4
+ } from "./chunk-4GTAZM2C.js";
5
+ import {
6
+ useXAUITheme
7
+ } from "./chunk-A3EGFI6T.js";
8
+ import {
9
+ Slot,
10
+ createSlotContext
11
+ } from "./chunk-K72UDPVN.js";
12
+ import {
13
+ useStyleProps
14
+ } from "./chunk-M63GFNKV.js";
15
+
16
+ // src/components/text-field/text-field-description.tsx
17
+ import { forwardRef } from "react";
18
+ import { Text } from "react-native";
19
+
20
+ // src/components/text-field/text-field.context.ts
21
+ var [TextFieldProvider, useTextField] = createSlotContext("TextField");
22
+
23
+ // src/components/text-field/text-field-description.tsx
24
+ import { jsx } from "react/jsx-runtime";
25
+ var TextFieldDescription = forwardRef(
26
+ function TextFieldDescription2({ children, style, nativeID, ...props }, ref) {
27
+ const { descriptionStyle, descriptionId } = useTextField();
28
+ const [styleProps, rest] = useStyleProps(props);
29
+ return /* @__PURE__ */ jsx(
30
+ Text,
31
+ {
32
+ ref,
33
+ nativeID: nativeID ?? descriptionId,
34
+ style: [descriptionStyle, styleProps, style],
35
+ ...rest,
36
+ children
37
+ }
38
+ );
39
+ }
40
+ );
41
+ TextFieldDescription.displayName = "XAUI.TextField.Description";
42
+
43
+ // src/components/text-field/text-field-error.tsx
44
+ import { forwardRef as forwardRef2 } from "react";
45
+ import { Text as Text2 } from "react-native";
46
+ import { jsx as jsx2 } from "react/jsx-runtime";
47
+ var TextFieldError = forwardRef2(
48
+ function TextFieldError2({ children, style, ...props }, ref) {
49
+ const { errorStyle } = useTextField();
50
+ const [styleProps, rest] = useStyleProps(props);
51
+ return /* @__PURE__ */ jsx2(Text2, { ref, style: [errorStyle, styleProps, style], ...rest, children });
52
+ }
53
+ );
54
+ TextFieldError.displayName = "XAUI.TextField.Error";
55
+
56
+ // src/components/text-field/text-field-field.tsx
57
+ import { forwardRef as forwardRef3, useCallback } from "react";
58
+ import { TextInput } from "react-native";
59
+ import { jsx as jsx3 } from "react/jsx-runtime";
60
+ var TextFieldField = forwardRef3(
61
+ function TextFieldField2({ style, onFocus, onBlur, placeholderTextColor, ...props }, ref) {
62
+ const {
63
+ fieldStyle,
64
+ placeholderTextColor: resolvedPlaceholder,
65
+ onFieldFocus,
66
+ onFieldBlur,
67
+ labelId,
68
+ descriptionId,
69
+ isDisabled,
70
+ isInvalid
71
+ } = useTextField();
72
+ const [styleProps, rest] = useStyleProps(props);
73
+ const handleFocus = useCallback(
74
+ (event) => {
75
+ onFieldFocus(event);
76
+ onFocus?.(event);
77
+ },
78
+ [onFieldFocus, onFocus]
79
+ );
80
+ const handleBlur = useCallback(
81
+ (event) => {
82
+ onFieldBlur(event);
83
+ onBlur?.(event);
84
+ },
85
+ [onFieldBlur, onBlur]
86
+ );
87
+ return /* @__PURE__ */ jsx3(
88
+ TextInput,
89
+ {
90
+ ref,
91
+ "aria-labelledby": labelId,
92
+ "aria-describedby": descriptionId,
93
+ "aria-invalid": isInvalid,
94
+ editable: !isDisabled,
95
+ accessibilityState: { disabled: isDisabled },
96
+ placeholderTextColor: placeholderTextColor ?? resolvedPlaceholder,
97
+ ...rest,
98
+ style: [fieldStyle, styleProps, style],
99
+ onFocus: handleFocus,
100
+ onBlur: handleBlur
101
+ }
102
+ );
103
+ }
104
+ );
105
+ TextFieldField.displayName = "XAUI.TextField.Field";
106
+
107
+ // src/components/text-field/text-field-label.tsx
108
+ import { forwardRef as forwardRef4 } from "react";
109
+ import { Text as Text3 } from "react-native";
110
+ import { jsx as jsx4 } from "react/jsx-runtime";
111
+ var TextFieldLabel = forwardRef4(
112
+ function TextFieldLabel2({ children, style, nativeID, ...props }, ref) {
113
+ const { labelStyle, labelId } = useTextField();
114
+ const [styleProps, rest] = useStyleProps(props);
115
+ return /* @__PURE__ */ jsx4(
116
+ Text3,
117
+ {
118
+ ref,
119
+ nativeID: nativeID ?? labelId,
120
+ style: [labelStyle, styleProps, style],
121
+ ...rest,
122
+ children
123
+ }
124
+ );
125
+ }
126
+ );
127
+ TextFieldLabel.displayName = "XAUI.TextField.Label";
128
+
129
+ // src/components/text-field/text-field.tsx
130
+ import { forwardRef as forwardRef5, useCallback as useCallback2, useId, useMemo, useState } from "react";
131
+ import { StyleSheet, View } from "react-native";
132
+
133
+ // src/components/text-field/text-field.recipe.ts
134
+ var SLOTS = [
135
+ "root",
136
+ "label",
137
+ "field",
138
+ "textArea",
139
+ "placeholder",
140
+ "description",
141
+ "error",
142
+ "prefix",
143
+ "suffix",
144
+ "icon"
145
+ ];
146
+ var VARIANT_TOKENS = {
147
+ primary: {
148
+ bg: "fieldBackground",
149
+ border: "fieldBorder",
150
+ borderFocus: "fieldBorderFocus",
151
+ fg: "fieldForeground"
152
+ },
153
+ // `bg: 'default'` is the neutral *token*, not this variant's name — the two namespaces
154
+ // meet here and nowhere else. It is also what keeps a field visible on a card, where
155
+ // `fieldBackground` is the card's own colour.
156
+ secondary: {
157
+ bg: "default",
158
+ border: "fieldBorder",
159
+ borderFocus: "fieldBorderFocus",
160
+ fg: "fieldForeground"
161
+ },
162
+ tertiary: {
163
+ border: "fieldBorder",
164
+ borderFocus: "fieldBorderFocus",
165
+ fg: "fieldForeground"
166
+ },
167
+ ghost: { borderFocus: "fieldBorderFocus", fg: "fieldForeground" }
168
+ };
169
+ function sizeAxis(step) {
170
+ const { control, padding, gap, field, label, help, glyph, textAreaPadding } = step;
171
+ return (theme) => {
172
+ const inset = { paddingHorizontal: theme.spacing(LABEL_INSET) };
173
+ const helpType = {
174
+ fontSize: theme.fontSizes[help],
175
+ lineHeight: theme.lineHeights[help]
176
+ };
177
+ const decorator = {
178
+ paddingHorizontal: theme.spacing(padding),
179
+ gap: theme.spacing(padding)
180
+ };
181
+ return {
182
+ root: { gap: theme.spacing(gap) },
183
+ label: {
184
+ ...inset,
185
+ fontSize: theme.fontSizes[label],
186
+ lineHeight: theme.lineHeights[label]
187
+ },
188
+ field: {
189
+ minHeight: theme.controlHeights[control],
190
+ paddingHorizontal: theme.spacing(padding),
191
+ fontSize: theme.fontSizes[field]
192
+ },
193
+ // Only what a multiline field *adds* — `TextField.TextArea` layers this over the field's
194
+ // own style rather than restating it, so the colours, the border and the radius are
195
+ // resolved once for both. The height is not here: `rows` is a raw value, and the
196
+ // slot computes it from the two numbers below.
197
+ textArea: {
198
+ lineHeight: theme.lineHeights[field],
199
+ paddingTop: theme.spacing(textAreaPadding),
200
+ paddingBottom: theme.spacing(textAreaPadding)
201
+ },
202
+ description: { ...inset, ...helpType },
203
+ error: { ...inset, ...helpType },
204
+ prefix: decorator,
205
+ suffix: decorator,
206
+ icon: { fontSize: theme.fontSizes[glyph] }
207
+ };
208
+ };
209
+ }
210
+ var LABEL_INSET = 1.5;
211
+ var DECORATOR = {
212
+ position: "absolute",
213
+ top: 0,
214
+ bottom: 0,
215
+ flexDirection: "row",
216
+ alignItems: "center",
217
+ justifyContent: "center",
218
+ zIndex: 10
219
+ };
220
+ var SIZES = {
221
+ xs: {
222
+ control: "xs",
223
+ padding: 2.5,
224
+ gap: 0.75,
225
+ field: "sm",
226
+ label: "sm",
227
+ help: "xs",
228
+ glyph: "md",
229
+ labelInside: "xs",
230
+ textAreaPadding: 1.5
231
+ },
232
+ sm: {
233
+ control: "sm",
234
+ padding: 3,
235
+ gap: 0.75,
236
+ field: "md",
237
+ label: "sm",
238
+ help: "xs",
239
+ glyph: "lg",
240
+ labelInside: "xs",
241
+ textAreaPadding: 2
242
+ },
243
+ md: {
244
+ control: "md",
245
+ padding: 3,
246
+ gap: 1.25,
247
+ field: "md",
248
+ label: "md",
249
+ help: "sm",
250
+ glyph: "lg",
251
+ labelInside: "xs",
252
+ textAreaPadding: 2
253
+ },
254
+ lg: {
255
+ control: "lg",
256
+ padding: 4,
257
+ gap: 1.75,
258
+ field: "lg",
259
+ label: "lg",
260
+ help: "md",
261
+ glyph: "xl",
262
+ labelInside: "sm",
263
+ textAreaPadding: 2.5
264
+ }
265
+ };
266
+ function insideLabel(step) {
267
+ const { control, padding, field, labelInside } = step;
268
+ return (theme) => {
269
+ const top = theme.spacing(LABEL_INSIDE_TOP);
270
+ const block = top + theme.lineHeights[labelInside];
271
+ return {
272
+ label: {
273
+ position: "absolute",
274
+ top,
275
+ // `start`, never `left` (R13): RTL mirrors the logical property and only it.
276
+ start: theme.spacing(padding),
277
+ paddingHorizontal: 0,
278
+ fontSize: theme.fontSizes[labelInside],
279
+ lineHeight: theme.lineHeights[labelInside]
280
+ },
281
+ // The height is built from the two lines it now holds rather than added to the
282
+ // control height: `controlHeights` already pays for centring one line, so adding
283
+ // the label's block to it would pay for that room twice. It is floored at the
284
+ // control height all the same, so a theme that raises `controlHeights` does not end
285
+ // up with an inside field shorter than the outside one beside it.
286
+ field: {
287
+ minHeight: Math.max(
288
+ block + theme.lineHeights[field] + top,
289
+ theme.controlHeights[control]
290
+ ),
291
+ paddingTop: block,
292
+ paddingBottom: top
293
+ },
294
+ // The same room, because `TextField.TextArea` layers its own padding over the field's
295
+ // and would otherwise put the first line back under the label.
296
+ textArea: { paddingTop: block, paddingBottom: top }
297
+ };
298
+ };
299
+ }
300
+ var LABEL_INSIDE_TOP = 1.5;
301
+ var textFieldRecipe = createRecipe({
302
+ slots: SLOTS,
303
+ base: (theme) => ({
304
+ root: { flexDirection: "column" },
305
+ label: {
306
+ fontFamily: theme.fontFamilies.body,
307
+ fontWeight: theme.fontWeights.medium
308
+ },
309
+ field: {
310
+ fontFamily: theme.fontFamilies.body,
311
+ // `regular`, not `medium`: what the user typed is content, not a control's label,
312
+ // and a heavier weight makes a filled field read as a button.
313
+ fontWeight: theme.fontWeights.regular,
314
+ borderWidth: theme.borderWidth.field,
315
+ // The theme has a radius named for this component, so every size uses it and the
316
+ // `radius` axis is what overrides it — the same shape a `Chip` takes from `full`.
317
+ // It is HeroUI's twelve points since the scale was aligned on theirs; it was 21,
318
+ // which put a 48-tall field at 87% of its geometric maximum.
319
+ borderRadius: theme.radius.field,
320
+ borderCurve: "continuous",
321
+ // RN centres a single line inside `minHeight` on iOS and pins it to the top on
322
+ // Android. Saying it removes a difference nobody chose.
323
+ textAlignVertical: "center"
324
+ },
325
+ // Several lines start at the top; only a single line is centred in its box.
326
+ textArea: { textAlignVertical: "top" },
327
+ // Not a node — the root flattens this one into `placeholderTextColor`, which is a
328
+ // `TextInput` prop rather than a style.
329
+ placeholder: { color: theme.colors.fieldPlaceholder },
330
+ description: {
331
+ fontFamily: theme.fontFamilies.body,
332
+ color: theme.colors.muted
333
+ },
334
+ error: {
335
+ fontFamily: theme.fontFamilies.body,
336
+ color: theme.colors.danger
337
+ },
338
+ prefix: { ...DECORATOR, start: 0 },
339
+ suffix: { ...DECORATOR, end: 0 },
340
+ // The glyph sits with the placeholder rather than with the value: a search mark or a
341
+ // lock is decoration for the text, not text. `paint` leaves it alone, so a tinted
342
+ // filled field is the one case where the caller names a colour on the icon itself.
343
+ icon: { color: theme.colors.fieldPlaceholder }
344
+ }),
345
+ variantTokens: VARIANT_TOKENS,
346
+ /**
347
+ * Where the variant's colours land. The border width follows the *presence* of the
348
+ * border role, so `ghost` needs no rule of its own to say it has no edge.
349
+ *
350
+ * The label is **not** painted from the variant: it sits outside the box, on the screen
351
+ * behind it, so it takes `foreground` and not the field's own text colour. That is also
352
+ * why a tinted input does not tint its label — the tint is the field's, not the form's.
353
+ */
354
+ paint: (theme, colors) => ({
355
+ field: {
356
+ backgroundColor: colors.bg,
357
+ borderColor: colors.border,
358
+ borderWidth: colors.border ? theme.borderWidth.field : 0,
359
+ color: colors.fg
360
+ },
361
+ label: { color: theme.colors.foreground }
362
+ }),
363
+ /**
364
+ * Declaration order is application order, and it is load-bearing here: `isInvalid`
365
+ * comes after `size` so its border wins, and it must also outrank focus — which is why
366
+ * the root passes `focused` only when the field is *not* invalid, rather than relying
367
+ * on an order that states cannot express.
368
+ */
369
+ variants: {
370
+ size: {
371
+ xs: sizeAxis(SIZES.xs),
372
+ sm: sizeAxis(SIZES.sm),
373
+ md: sizeAxis(SIZES.md),
374
+ lg: sizeAxis(SIZES.lg)
375
+ },
376
+ radius: radiusAxis("field"),
377
+ /**
378
+ * `outside` is the base behaviour, so it adds nothing — it is declared because an
379
+ * axis needs both of its values for the selection to be typed, and because a reader
380
+ * looking for "what does outside do" should find the answer here rather than infer it
381
+ * from an absence. The size-dependent half of `inside` is in `compoundVariants`.
382
+ */
383
+ labelPlacement: {
384
+ outside: () => ({}),
385
+ inside: () => ({})
386
+ },
387
+ isInvalid: {
388
+ true: (theme) => ({
389
+ field: { borderColor: theme.colors.danger },
390
+ // The label and the description turn with it: on a long form the field that is
391
+ // wrong has to be findable without reading every message.
392
+ label: { color: theme.colors.danger },
393
+ description: { color: theme.colors.danger }
394
+ })
395
+ }
396
+ },
397
+ /**
398
+ * The focus treatment is the border darkening towards the mode's ink — the theme's
399
+ * `fieldBorderFocus`, which is `fieldBorder` mixed 26% towards `fieldForeground`. No
400
+ * ring and no accent: a form where every focused field flashes the brand colour is a
401
+ * form where the accent has stopped meaning "the action".
402
+ *
403
+ * `borderFocus` is a role rather than a token named here, so a raw `color` follows the
404
+ * field into focus the same way it follows a `Button` into its pressed state.
405
+ */
406
+ /**
407
+ * What `primary` adds to a filled field, and the four halves of the inside label that
408
+ * need to know the size — a compound is how the engine expresses a rule that depends on
409
+ * two axes at once.
410
+ */
411
+ compoundVariants: [
412
+ {
413
+ when: { variant: "primary" },
414
+ style: (theme) => ({ field: theme.shadows.field })
415
+ },
416
+ { when: { size: "xs", labelPlacement: "inside" }, style: insideLabel(SIZES.xs) },
417
+ { when: { size: "sm", labelPlacement: "inside" }, style: insideLabel(SIZES.sm) },
418
+ { when: { size: "md", labelPlacement: "inside" }, style: insideLabel(SIZES.md) },
419
+ { when: { size: "lg", labelPlacement: "inside" }, style: insideLabel(SIZES.lg) }
420
+ ],
421
+ states: {
422
+ focused: (_theme, colors) => ({ field: { borderColor: colors.borderFocus } }),
423
+ disabled: (theme) => ({ root: { opacity: theme.opacity.disabled } })
424
+ },
425
+ defaultVariants: { variant: "secondary", size: "md", labelPlacement: "outside" }
426
+ });
427
+
428
+ // src/components/text-field/text-field.tsx
429
+ import { jsx as jsx5 } from "react/jsx-runtime";
430
+ var TextFieldRoot = forwardRef5(function TextField({
431
+ children,
432
+ variant,
433
+ size,
434
+ radius,
435
+ labelPlacement,
436
+ color,
437
+ isInvalid = false,
438
+ isDisabled = false,
439
+ asChild = false,
440
+ style,
441
+ ...props
442
+ }, ref) {
443
+ const theme = useXAUITheme();
444
+ const [styleProps, rest] = useStyleProps(props);
445
+ const [isFocused, setIsFocused] = useState(false);
446
+ const onFieldFocus = useCallback2(() => setIsFocused(true), []);
447
+ const onFieldBlur = useCallback2(() => setIsFocused(false), []);
448
+ const id = useId();
449
+ const labelId = `${id}-label`;
450
+ const descriptionId = `${id}-description`;
451
+ const selection = {
452
+ variant,
453
+ size,
454
+ radius,
455
+ labelPlacement,
456
+ isInvalid: isInvalid ? "true" : void 0
457
+ };
458
+ const states = { focused: isFocused && !isInvalid, disabled: isDisabled };
459
+ const styles = textFieldRecipe.resolve({ theme, selection, states });
460
+ const tint = color ? textFieldRecipe.tint({ theme, color, selection, states }) : void 0;
461
+ const context = useMemo(() => {
462
+ const placeholder = StyleSheet.flatten(styles.placeholder);
463
+ const icon = StyleSheet.flatten(styles.icon);
464
+ const textArea = StyleSheet.flatten(styles.textArea);
465
+ return {
466
+ labelStyle: tint ? [styles.label, tint.label] : styles.label,
467
+ fieldStyle: tint ? [styles.field, tint.field] : styles.field,
468
+ textAreaStyle: styles.textArea,
469
+ textArea: {
470
+ lineHeight: textArea.lineHeight ?? 0,
471
+ // `DimensionValue` also covers a percentage and `auto`, neither of which can be
472
+ // multiplied by a number of rows. The recipe only ever writes points here.
473
+ paddingVertical: typeof textArea.paddingBottom === "number" ? textArea.paddingBottom : 0
474
+ },
475
+ descriptionStyle: styles.description,
476
+ errorStyle: styles.error,
477
+ prefixStyle: styles.prefix,
478
+ suffixStyle: styles.suffix,
479
+ icon: {
480
+ size: icon.fontSize,
481
+ // `ColorValue` also covers the platform's opaque colours, which an icon component
482
+ // takes as a `string` and nothing else.
483
+ color: typeof icon.color === "string" ? icon.color : void 0
484
+ },
485
+ // `ColorValue` also covers the platform's opaque colours, which `TextInput` cannot
486
+ // take for a placeholder.
487
+ placeholderTextColor: typeof placeholder.color === "string" ? placeholder.color : void 0,
488
+ onFieldFocus,
489
+ onFieldBlur,
490
+ labelId,
491
+ descriptionId,
492
+ isDisabled,
493
+ isInvalid
494
+ };
495
+ }, [
496
+ styles,
497
+ tint,
498
+ onFieldFocus,
499
+ onFieldBlur,
500
+ labelId,
501
+ descriptionId,
502
+ isDisabled,
503
+ isInvalid
504
+ ]);
505
+ const rootStyle = [styles.root, tint?.root, styleProps, style];
506
+ const surface = asChild ? (
507
+ // R12 — the caller's element *is* the column.
508
+ /* @__PURE__ */ jsx5(Slot, { ref, ...rest, style: rootStyle, children })
509
+ ) : /* @__PURE__ */ jsx5(View, { ref, ...rest, style: rootStyle, children });
510
+ return /* @__PURE__ */ jsx5(TextFieldProvider, { value: context, children: surface });
511
+ });
512
+ TextFieldRoot.displayName = "XAUI.TextField.Root";
513
+
514
+ // src/components/text-field/index.ts
515
+ var TextField2 = Object.assign(TextFieldRoot, {
516
+ Label: TextFieldLabel,
517
+ Field: TextFieldField,
518
+ Description: TextFieldDescription,
519
+ Error: TextFieldError
520
+ });
521
+
522
+ export {
523
+ useTextField,
524
+ TextFieldDescription,
525
+ TextFieldError,
526
+ TextFieldField,
527
+ TextFieldLabel,
528
+ textFieldRecipe,
529
+ TextFieldRoot,
530
+ TextField2 as TextField
531
+ };