@btndprojects/loam-ui-native 0.0.0-stage → 0.1.1

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 (269) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +55 -2
  3. package/dist/accordion/index.js +3 -0
  4. package/dist/adaptive/index.js +2 -0
  5. package/dist/alert/index.js +3 -0
  6. package/dist/analyzer/index.js +6 -0
  7. package/dist/announcement/index.js +6 -0
  8. package/dist/audio-player/index.js +3 -0
  9. package/dist/avatar/index.js +3 -0
  10. package/dist/avatar-group/index.js +3 -0
  11. package/dist/badge/index.js +5 -0
  12. package/dist/banner/index.js +2 -0
  13. package/dist/board/index.js +7 -0
  14. package/dist/button/index.js +5 -0
  15. package/dist/camera-permission/index.js +13 -0
  16. package/dist/capture-result/index.js +18 -0
  17. package/dist/card/index.js +4 -0
  18. package/dist/card-form/index.js +10 -0
  19. package/dist/carousel/index.js +2 -0
  20. package/dist/chart/index.js +6 -0
  21. package/dist/charts/index.js +7 -0
  22. package/dist/checkbox/index.js +7 -0
  23. package/dist/checklist/index.js +10 -0
  24. package/dist/checkout/index.js +13 -0
  25. package/dist/chip/index.js +7 -0
  26. package/dist/chunk-223Q2T2Q.js +229 -0
  27. package/dist/chunk-2A5NIQAK.js +254 -0
  28. package/dist/chunk-2GK6PHGE.js +363 -0
  29. package/dist/chunk-2WUTXHMU.js +1 -0
  30. package/dist/chunk-2ZZ7TDJ4.js +324 -0
  31. package/dist/chunk-35OFI3JG.js +499 -0
  32. package/dist/chunk-3ARE4TES.js +195 -0
  33. package/dist/chunk-3ECPOSKO.js +1 -0
  34. package/dist/chunk-3ENTMPQY.js +229 -0
  35. package/dist/chunk-3HJH6FF4.js +98 -0
  36. package/dist/chunk-3NMD74ZU.js +4 -0
  37. package/dist/chunk-3WPW4KUN.js +182 -0
  38. package/dist/chunk-423B7SPN.js +993 -0
  39. package/dist/chunk-47FWHGUN.js +394 -0
  40. package/dist/chunk-4BXMXBJO.js +141 -0
  41. package/dist/chunk-4DS5ZWVC.js +83 -0
  42. package/dist/chunk-4GBOGOTV.js +295 -0
  43. package/dist/chunk-4SZYY6AN.js +99 -0
  44. package/dist/chunk-4YIP3CWS.js +237 -0
  45. package/dist/chunk-4YQOR7JM.js +204 -0
  46. package/dist/chunk-4ZAHCY44.js +177 -0
  47. package/dist/chunk-52X2VYTD.js +228 -0
  48. package/dist/chunk-5P26LBDL.js +1 -0
  49. package/dist/chunk-5XLRYDAX.js +1 -0
  50. package/dist/chunk-5YNTNN5A.js +177 -0
  51. package/dist/chunk-6HT2LP62.js +504 -0
  52. package/dist/chunk-6N33LFQA.js +35 -0
  53. package/dist/chunk-6X6PQ443.js +432 -0
  54. package/dist/chunk-7CFF4HXS.js +126 -0
  55. package/dist/chunk-7O2FMUPT.js +755 -0
  56. package/dist/chunk-AI4DWZCD.js +162 -0
  57. package/dist/chunk-AWJOCGFZ.js +213 -0
  58. package/dist/chunk-AZRX6SAC.js +285 -0
  59. package/dist/chunk-B54QE2FN.js +1 -0
  60. package/dist/chunk-BC475SJH.js +1 -0
  61. package/dist/chunk-BEDBFJND.js +202 -0
  62. package/dist/chunk-BTTFCMKG.js +166 -0
  63. package/dist/chunk-BV3B2HYZ.js +1635 -0
  64. package/dist/chunk-C2NTXVWM.js +98 -0
  65. package/dist/chunk-CDRZHT42.js +424 -0
  66. package/dist/chunk-CJ5EOYZE.js +62 -0
  67. package/dist/chunk-CUMUNPXY.js +128 -0
  68. package/dist/chunk-CUS3ZSCU.js +1 -0
  69. package/dist/chunk-CYRBHQQZ.js +411 -0
  70. package/dist/chunk-DHWADYZX.js +144 -0
  71. package/dist/chunk-DKCSPATL.js +1 -0
  72. package/dist/chunk-DM5QUKKO.js +326 -0
  73. package/dist/chunk-DYBH2I6W.js +1 -0
  74. package/dist/chunk-DZ255O2F.js +1 -0
  75. package/dist/chunk-E35BPSGW.js +1 -0
  76. package/dist/chunk-EJBDRVIH.js +166 -0
  77. package/dist/chunk-F43NP42L.js +1 -0
  78. package/dist/chunk-F5XNPWS7.js +1024 -0
  79. package/dist/chunk-FMYDDECK.js +1521 -0
  80. package/dist/chunk-G3HOYSF7.js +1 -0
  81. package/dist/chunk-GDKZTW34.js +395 -0
  82. package/dist/chunk-GL7B2DOW.js +134 -0
  83. package/dist/chunk-GNNJ4GCC.js +471 -0
  84. package/dist/chunk-GNZ56EUI.js +1 -0
  85. package/dist/chunk-H6NIOQHK.js +346 -0
  86. package/dist/chunk-H6PC7RDA.js +1 -0
  87. package/dist/chunk-HET4LLMX.js +129 -0
  88. package/dist/chunk-HPPW424V.js +334 -0
  89. package/dist/chunk-HQOQIBJI.js +1 -0
  90. package/dist/chunk-HU2EQNRZ.js +44 -0
  91. package/dist/chunk-HZ6CNMAF.js +870 -0
  92. package/dist/chunk-IIQTAY3J.js +715 -0
  93. package/dist/chunk-ITTYJZWX.js +271 -0
  94. package/dist/chunk-IVNRBPGC.js +1018 -0
  95. package/dist/chunk-J4KLDGI4.js +1 -0
  96. package/dist/chunk-J7Q7VCVC.js +254 -0
  97. package/dist/chunk-JDEOITQ2.js +1 -0
  98. package/dist/chunk-JNH2TYIN.js +96 -0
  99. package/dist/chunk-JNY4ZHAR.js +634 -0
  100. package/dist/chunk-JRLTGLN4.js +1 -0
  101. package/dist/chunk-JTRJJLKL.js +1 -0
  102. package/dist/chunk-JUAMLEHX.js +379 -0
  103. package/dist/chunk-JXJB2X6M.js +131 -0
  104. package/dist/chunk-KMI5ML5I.js +262 -0
  105. package/dist/chunk-KTAC4MGE.js +4 -0
  106. package/dist/chunk-LAECSR4H.js +178 -0
  107. package/dist/chunk-LK4BCSGX.js +1 -0
  108. package/dist/chunk-LOE5YNN3.js +470 -0
  109. package/dist/chunk-LRJNDEIA.js +302 -0
  110. package/dist/chunk-LSS54GLJ.js +116 -0
  111. package/dist/chunk-LZLHELAG.js +137 -0
  112. package/dist/chunk-M2LUXGKZ.js +1 -0
  113. package/dist/chunk-MOUJOP55.js +425 -0
  114. package/dist/chunk-N32RGOA5.js +159 -0
  115. package/dist/chunk-N5ZNE2YE.js +1 -0
  116. package/dist/chunk-NBNCBML6.js +1 -0
  117. package/dist/chunk-NKB7BZYK.js +167 -0
  118. package/dist/chunk-NQYBUO3K.js +1795 -0
  119. package/dist/chunk-NY2U3PBI.js +59 -0
  120. package/dist/chunk-O4AEHWII.js +464 -0
  121. package/dist/chunk-O7AE6DAF.js +146 -0
  122. package/dist/chunk-OETCUXQP.js +134 -0
  123. package/dist/chunk-OOPPQH27.js +179 -0
  124. package/dist/chunk-OPXFZ4Y5.js +204 -0
  125. package/dist/chunk-P23EQNRQ.js +338 -0
  126. package/dist/chunk-PJXUJYS6.js +248 -0
  127. package/dist/chunk-PNWUWOBF.js +1 -0
  128. package/dist/chunk-PUPM2YGF.js +376 -0
  129. package/dist/chunk-PZXZJBMP.js +620 -0
  130. package/dist/chunk-Q72LJOVE.js +169 -0
  131. package/dist/chunk-QCDXZBC5.js +247 -0
  132. package/dist/chunk-QDYDBCFP.js +197 -0
  133. package/dist/chunk-QJJ6MADV.js +274 -0
  134. package/dist/chunk-QKXCPTFS.js +349 -0
  135. package/dist/chunk-QWCMU5B2.js +860 -0
  136. package/dist/chunk-RIBDXGUG.js +108 -0
  137. package/dist/chunk-RJQOOHT2.js +214 -0
  138. package/dist/chunk-RNGLIHFA.js +191 -0
  139. package/dist/chunk-RQ3HASCC.js +6 -0
  140. package/dist/chunk-RSOJT5YW.js +124 -0
  141. package/dist/chunk-RTIKSY6A.js +1 -0
  142. package/dist/chunk-RUZHTGKB.js +237 -0
  143. package/dist/chunk-RW6ZL2FQ.js +284 -0
  144. package/dist/chunk-S7F6XLTK.js +540 -0
  145. package/dist/chunk-SBMNWWBV.js +155 -0
  146. package/dist/chunk-SDTQPRRB.js +1 -0
  147. package/dist/chunk-SYNOJOQO.js +377 -0
  148. package/dist/chunk-T753XT36.js +1 -0
  149. package/dist/chunk-TKQYWZ5V.js +196 -0
  150. package/dist/chunk-TKVFVF5D.js +95 -0
  151. package/dist/chunk-TOXAGRDQ.js +144 -0
  152. package/dist/chunk-TUTI5HOZ.js +112 -0
  153. package/dist/chunk-U7TFM2JA.js +140 -0
  154. package/dist/chunk-UC2WGUP3.js +627 -0
  155. package/dist/chunk-UWFLYMAR.js +1126 -0
  156. package/dist/chunk-UWSZB7BJ.js +1 -0
  157. package/dist/chunk-UYG5L34B.js +87 -0
  158. package/dist/chunk-VBOXAEPI.js +336 -0
  159. package/dist/chunk-VCDBXW5H.js +188 -0
  160. package/dist/chunk-VCXPHHDS.js +1 -0
  161. package/dist/chunk-VEAYTRPX.js +414 -0
  162. package/dist/chunk-VFCUIDRT.js +1 -0
  163. package/dist/chunk-VQHPQEUH.js +273 -0
  164. package/dist/chunk-VXDZFJGP.js +874 -0
  165. package/dist/chunk-WS56BL3D.js +1 -0
  166. package/dist/chunk-WSW6ZFAQ.js +98 -0
  167. package/dist/chunk-XNUVB5OL.js +375 -0
  168. package/dist/chunk-XOSCY2CW.js +242 -0
  169. package/dist/chunk-XXXEFXY5.js +99 -0
  170. package/dist/chunk-Y5CSSPV4.js +1 -0
  171. package/dist/chunk-Y6DU4J47.js +1 -0
  172. package/dist/chunk-YC6WORFL.js +535 -0
  173. package/dist/chunk-YDGVJETP.js +60 -0
  174. package/dist/chunk-YF4NSSMT.js +366 -0
  175. package/dist/chunk-YG3ZJHGU.js +223 -0
  176. package/dist/chunk-YIJ55TBC.js +1 -0
  177. package/dist/chunk-YKZ4RZZF.js +1 -0
  178. package/dist/chunk-YLLCXTMC.js +37 -0
  179. package/dist/chunk-YTA74UZR.js +1 -0
  180. package/dist/chunk-YTFKPRUK.js +845 -0
  181. package/dist/chunk-Z7H7VSFZ.js +323 -0
  182. package/dist/chunk-ZK2H4O5P.js +1 -0
  183. package/dist/chunk-ZVFE5QGU.js +524 -0
  184. package/dist/coachmark/index.js +4 -0
  185. package/dist/code-block/index.js +4 -0
  186. package/dist/color-field/index.js +7 -0
  187. package/dist/commerce/index.js +20 -0
  188. package/dist/connectivity/index.js +2 -0
  189. package/dist/context-menu/index.js +5 -0
  190. package/dist/copy-button/index.js +3 -0
  191. package/dist/data-grid/index.js +24 -0
  192. package/dist/date-range-picker/index.js +13 -0
  193. package/dist/description-list/index.js +2 -0
  194. package/dist/dialog/index.js +3 -0
  195. package/dist/empty-state/index.js +3 -0
  196. package/dist/error-summary/index.js +3 -0
  197. package/dist/fab/index.js +2 -0
  198. package/dist/file-upload/index.js +9 -0
  199. package/dist/filter-bar/index.js +8 -0
  200. package/dist/flow-run/index.js +14 -0
  201. package/dist/form/index.js +3 -0
  202. package/dist/gallery/index.js +2 -0
  203. package/dist/header/index.js +5 -0
  204. package/dist/hold-to-confirm/index.js +4 -0
  205. package/dist/index.d.ts +22883 -0
  206. package/dist/index.js +158 -0
  207. package/dist/infinite-list/index.js +2 -0
  208. package/dist/inline-edit/index.js +5 -0
  209. package/dist/input/index.js +5 -0
  210. package/dist/interactions/index.js +2 -0
  211. package/dist/invoice/index.js +10 -0
  212. package/dist/kbd/index.js +1 -0
  213. package/dist/keyboard/index.js +3 -0
  214. package/dist/list-row/index.js +7 -0
  215. package/dist/log-viewer/index.js +2 -0
  216. package/dist/map-view/index.js +3 -0
  217. package/dist/markdown/index.js +6 -0
  218. package/dist/metric/index.js +4 -0
  219. package/dist/money/index.js +3 -0
  220. package/dist/nav-drawer/index.js +2 -0
  221. package/dist/navigation/index.js +2 -0
  222. package/dist/notification-center/index.js +16 -0
  223. package/dist/number-roll/index.js +3 -0
  224. package/dist/one-handed/index.js +5 -0
  225. package/dist/os-surfaces/index.js +3 -0
  226. package/dist/otp/index.js +7 -0
  227. package/dist/page-header/index.js +1 -0
  228. package/dist/payment-method/index.js +12 -0
  229. package/dist/payment-status/index.js +16 -0
  230. package/dist/permission/index.js +2 -0
  231. package/dist/picker/index.js +7 -0
  232. package/dist/progress/index.js +5 -0
  233. package/dist/pull-to-refresh/index.js +4 -0
  234. package/dist/radio-group/index.js +6 -0
  235. package/dist/rating/index.js +2 -0
  236. package/dist/receivables/index.js +20 -0
  237. package/dist/refund/index.js +16 -0
  238. package/dist/save-status/index.js +3 -0
  239. package/dist/scroll-area/index.js +1 -0
  240. package/dist/search-bar/index.js +5 -0
  241. package/dist/segmented-control/index.js +5 -0
  242. package/dist/sheet/index.js +4 -0
  243. package/dist/skeleton/index.js +2 -0
  244. package/dist/slider/index.js +5 -0
  245. package/dist/spinner/index.js +2 -0
  246. package/dist/split-button/index.js +7 -0
  247. package/dist/spotlight/index.js +2 -0
  248. package/dist/stage-timeline/index.js +4 -0
  249. package/dist/status-dot/index.js +2 -0
  250. package/dist/stepper/index.js +6 -0
  251. package/dist/streaming-text/index.js +3 -0
  252. package/dist/survey/index.js +19 -0
  253. package/dist/switch/index.js +5 -0
  254. package/dist/system-state/index.js +4 -0
  255. package/dist/tab-bar/index.js +2 -0
  256. package/dist/tabs/index.js +2 -0
  257. package/dist/textarea/index.js +6 -0
  258. package/dist/thinking/index.js +2 -0
  259. package/dist/timeline/index.js +4 -0
  260. package/dist/toast/index.js +2 -0
  261. package/dist/toolbar/index.js +2 -0
  262. package/dist/tour/index.js +11 -0
  263. package/dist/truncation-notice/index.js +2 -0
  264. package/dist/update-notice/index.js +11 -0
  265. package/dist/video-player/index.js +2 -0
  266. package/dist/viewfinder/index.js +5 -0
  267. package/dist/widget/index.js +4 -0
  268. package/dist/wizard/index.js +6 -0
  269. package/package.json +76 -3
@@ -0,0 +1,59 @@
1
+ import { Platform, Vibration } from 'react-native';
2
+
3
+ // src/interactions/haptics.ts
4
+ var isSupported = Platform.OS !== "web" && typeof Vibration !== "undefined" && typeof Vibration.vibrate === "function";
5
+ function buzz(pattern) {
6
+ if (!isSupported) return;
7
+ try {
8
+ Vibration.vibrate(pattern, false);
9
+ } catch {
10
+ }
11
+ }
12
+ var IMPACT_MS = {
13
+ light: 10,
14
+ medium: 20,
15
+ heavy: 35
16
+ };
17
+ var NOTIFY_PATTERN = {
18
+ success: [0, 18, 60, 18],
19
+ warning: [0, 28, 80, 28],
20
+ error: [0, 40, 60, 40, 60, 40]
21
+ };
22
+ var haptics = {
23
+ /**
24
+ * A crisp, minimal tick — for selection changes (segments, chips, pickers).
25
+ * @example
26
+ * ```ts
27
+ * haptics.selection();
28
+ * ```
29
+ */
30
+ selection() {
31
+ buzz(6);
32
+ },
33
+ /**
34
+ * A single tap whose firmness scales with `style`. Use for button presses,
35
+ * toggles and drag detents.
36
+ * @param style - Tap strength. @defaultValue `'medium'`
37
+ * @example
38
+ * ```ts
39
+ * haptics.impact(); // medium
40
+ * haptics.impact('light');
41
+ * ```
42
+ */
43
+ impact(style = "medium") {
44
+ buzz(IMPACT_MS[style]);
45
+ },
46
+ /**
47
+ * A short multi-pulse pattern signaling the outcome of an operation.
48
+ * @param type - Outcome flavor. @defaultValue `'success'`
49
+ * @example
50
+ * ```ts
51
+ * haptics.notify('error');
52
+ * ```
53
+ */
54
+ notify(type = "success") {
55
+ buzz(NOTIFY_PATTERN[type]);
56
+ }
57
+ };
58
+
59
+ export { haptics };
@@ -0,0 +1,464 @@
1
+ import { CardBrandMark } from './chunk-PUPM2YGF.js';
2
+ import { Checkbox } from './chunk-JXJB2X6M.js';
3
+ import { TextField, useColorTransition } from './chunk-ITTYJZWX.js';
4
+ import { NO_UA_FOCUS_RING } from './chunk-3NMD74ZU.js';
5
+ import { useResolvedMotion } from './chunk-6N33LFQA.js';
6
+ import { Icon } from './chunk-TKVFVF5D.js';
7
+ import * as React from 'react';
8
+ import { Text, useWindowDimensions, View, Easing, Animated, TextInput } from 'react-native';
9
+ import { createStyleSheet, useStyles, useLoamTheme } from '@btndprojects/loam-theme-native';
10
+ import { formatCard, formatExpiry, validCardNumber, CARD_COPY, validExpiry, validCvc } from '@btndprojects/loam-pay';
11
+ import { jsx, jsxs } from 'react/jsx-runtime';
12
+
13
+ var TEST_HINT = "Test with 4242 4242 4242 4242 \xB7 12/34 \xB7 any code";
14
+ var CardRunContext = React.createContext(null);
15
+ function onlyDigits(text) {
16
+ return String(text).replace(/\D/g, "");
17
+ }
18
+ function ExpiryHint({
19
+ hint,
20
+ error,
21
+ nativeID,
22
+ style,
23
+ testID
24
+ }) {
25
+ const { styles } = useStyles(sheet, { invalid: Boolean(error) });
26
+ const message = error ?? hint;
27
+ if (message === void 0 || message === "") return null;
28
+ return /* @__PURE__ */ jsx(Text, { nativeID, testID, style: [styles.message, style], children: message });
29
+ }
30
+ function DigitsField({
31
+ field,
32
+ label,
33
+ digits,
34
+ format,
35
+ normalize,
36
+ onDigits,
37
+ onBackspaceOut,
38
+ autoComplete,
39
+ placeholder,
40
+ maxLength,
41
+ hint,
42
+ error,
43
+ onBlur,
44
+ motion = "full",
45
+ testHintText,
46
+ trailing,
47
+ style,
48
+ testID
49
+ }) {
50
+ const theme = useLoamTheme();
51
+ const hasError = Boolean(error);
52
+ const { styles } = useStyles(sheet, { invalid: hasError });
53
+ const labelId = React.useId();
54
+ const messageId = React.useId();
55
+ const testId = React.useId();
56
+ const [focused, setFocused] = React.useState(false);
57
+ const run = React.useContext(CardRunContext);
58
+ const inputRef = React.useRef(null);
59
+ const focusRef = React.useRef(() => {
60
+ });
61
+ focusRef.current = () => inputRef.current?.focus();
62
+ const register = run?.register;
63
+ React.useEffect(() => register?.(field, () => focusRef.current()), [register, field]);
64
+ const tone = hasError ? { border: theme.color.danger, fill: theme.color.dangerSoft } : focused ? { border: theme.focus.ringColor, fill: theme.color.surface } : { border: theme.color.borderStrong, fill: theme.color.surface2 };
65
+ const animate = useResolvedMotion(motion) === "full";
66
+ const easing = React.useMemo(() => Easing.bezier(...theme.easing.base), [theme.easing.base]);
67
+ const borderColor = useColorTransition(tone.border, theme.duration.base, easing, animate);
68
+ const backgroundColor = useColorTransition(tone.fill, theme.duration.base, easing, animate);
69
+ const handleKeyPress = (event) => {
70
+ if (event.nativeEvent.key === "Backspace" && digits.length === 0) onBackspaceOut?.();
71
+ };
72
+ const describedBy = [hasError || hint ? messageId : null, testHintText ? testId : null].filter(Boolean).join(" ");
73
+ return /* @__PURE__ */ jsxs(View, { style: [styles.field, style], children: [
74
+ /* @__PURE__ */ jsx(Text, { nativeID: labelId, style: styles.label, children: label }),
75
+ /* @__PURE__ */ jsxs(Animated.View, { style: [styles.box, { borderColor, backgroundColor }], children: [
76
+ /* @__PURE__ */ jsx(
77
+ TextInput,
78
+ {
79
+ ref: inputRef,
80
+ testID,
81
+ value: format(digits),
82
+ onChangeText: (typed) => onDigits(normalize(typed)),
83
+ onKeyPress: handleKeyPress,
84
+ onFocus: () => setFocused(true),
85
+ onBlur: () => {
86
+ setFocused(false);
87
+ onBlur?.();
88
+ },
89
+ autoComplete,
90
+ inputMode: "numeric",
91
+ keyboardType: "number-pad",
92
+ placeholder,
93
+ placeholderTextColor: theme.color.text3,
94
+ maxLength,
95
+ "aria-labelledby": labelId,
96
+ style: [styles.input, NO_UA_FOCUS_RING],
97
+ ...{
98
+ "aria-invalid": hasError || void 0,
99
+ "aria-describedby": describedBy || void 0
100
+ }
101
+ }
102
+ ),
103
+ hasError ? /* @__PURE__ */ jsx(View, { "aria-hidden": true, children: /* @__PURE__ */ jsx(Icon, { name: "alert-triangle", size: theme.ctl.icon.lg, color: theme.color.dangerOnSoft }) }) : trailing
104
+ ] }),
105
+ /* @__PURE__ */ jsx(ExpiryHint, { nativeID: messageId, hint, error }),
106
+ testHintText ? /* @__PURE__ */ jsx(Text, { nativeID: testId, style: styles.testHint, children: testHintText }) : null
107
+ ] });
108
+ }
109
+ function CardNumberField({
110
+ value,
111
+ brand,
112
+ complete,
113
+ label = "Card number",
114
+ hint,
115
+ error,
116
+ testHint = false,
117
+ onChange,
118
+ onComplete,
119
+ onBlur,
120
+ motion,
121
+ style,
122
+ testID
123
+ }) {
124
+ const result = formatCard(value);
125
+ const resolvedBrand = brand ?? result.brand;
126
+ const isComplete = complete ?? result.complete;
127
+ const wasComplete = React.useRef(isComplete);
128
+ React.useEffect(() => {
129
+ if (isComplete && !wasComplete.current) onComplete?.();
130
+ wasComplete.current = isComplete;
131
+ }, [isComplete, onComplete]);
132
+ const testHintText = testHint === true ? TEST_HINT : testHint || void 0;
133
+ return /* @__PURE__ */ jsx(
134
+ DigitsField,
135
+ {
136
+ field: "number",
137
+ label,
138
+ digits: result.digits,
139
+ format: (d) => formatCard(d).text,
140
+ normalize: (typed) => formatCard(onlyDigits(typed)).digits,
141
+ onDigits: onChange,
142
+ hint,
143
+ error,
144
+ onBlur,
145
+ motion,
146
+ autoComplete: "cc-number",
147
+ placeholder: "1234 5678 9012 3456",
148
+ testHintText: testHintText || void 0,
149
+ trailing: /* @__PURE__ */ jsx(CardBrandMark, { brand: resolvedBrand.id }),
150
+ style,
151
+ testID
152
+ }
153
+ );
154
+ }
155
+ function ExpiryField({
156
+ value,
157
+ label = "Expiry",
158
+ hint = "MM/YY",
159
+ error,
160
+ onChange,
161
+ onComplete,
162
+ onBackspaceOut,
163
+ onBlur,
164
+ motion,
165
+ style,
166
+ testID
167
+ }) {
168
+ const digits = onlyDigits(formatExpiry(value));
169
+ const wasComplete = React.useRef(digits.length === 4);
170
+ React.useEffect(() => {
171
+ const isComplete = digits.length === 4;
172
+ if (isComplete && !wasComplete.current) onComplete?.();
173
+ wasComplete.current = isComplete;
174
+ }, [digits, onComplete]);
175
+ return /* @__PURE__ */ jsx(
176
+ DigitsField,
177
+ {
178
+ field: "expiry",
179
+ label,
180
+ digits,
181
+ format: (d) => formatExpiry(d),
182
+ normalize: (typed) => onlyDigits(formatExpiry(onlyDigits(typed))),
183
+ onDigits: onChange,
184
+ onBackspaceOut,
185
+ hint,
186
+ error,
187
+ onBlur,
188
+ motion,
189
+ autoComplete: "cc-exp",
190
+ placeholder: "MM/YY",
191
+ maxLength: 5,
192
+ style,
193
+ testID
194
+ }
195
+ );
196
+ }
197
+ function CvcField({
198
+ value,
199
+ digits = 3,
200
+ label = "Security code",
201
+ hint,
202
+ error,
203
+ onChange,
204
+ onComplete,
205
+ onBackspaceOut,
206
+ onBlur,
207
+ motion,
208
+ style,
209
+ testID
210
+ }) {
211
+ const clamp = React.useCallback(
212
+ (typed) => onlyDigits(typed).slice(0, digits),
213
+ [digits]
214
+ );
215
+ const machine = clamp(value);
216
+ const wasComplete = React.useRef(machine.length === digits);
217
+ React.useEffect(() => {
218
+ const isComplete = machine.length === digits;
219
+ if (isComplete && !wasComplete.current) onComplete?.();
220
+ wasComplete.current = isComplete;
221
+ }, [machine, digits, onComplete]);
222
+ return /* @__PURE__ */ jsx(
223
+ DigitsField,
224
+ {
225
+ field: "cvc",
226
+ label,
227
+ digits: machine,
228
+ format: (d) => d,
229
+ normalize: clamp,
230
+ onDigits: onChange,
231
+ onBackspaceOut,
232
+ hint,
233
+ error,
234
+ onBlur,
235
+ motion,
236
+ autoComplete: "cc-csc",
237
+ placeholder: digits === 4 ? "1234" : "123",
238
+ maxLength: digits,
239
+ style,
240
+ testID
241
+ }
242
+ );
243
+ }
244
+ var sheet = createStyleSheet((theme) => ({
245
+ field: { flexShrink: 1, flexGrow: 1, gap: theme.space.s2 },
246
+ label: {
247
+ fontFamily: theme.font.sans,
248
+ fontWeight: theme.fontWeight.semibold,
249
+ fontSize: theme.fontSize[12],
250
+ variants: {
251
+ // The label turns danger with the field, so the failure is carried by the
252
+ // label, the edge, the glyph and the message — never colour alone.
253
+ invalid: { true: { color: theme.color.danger }, false: { color: theme.color.text2 } }
254
+ }
255
+ },
256
+ // `borderColor` / `backgroundColor` arrive at the use site as animated values,
257
+ // so the field can travel between its resting, focused and invalid tones. The
258
+ // `lg` tier is the 44 box whose 16px text iOS will not zoom.
259
+ box: {
260
+ flexDirection: "row",
261
+ alignItems: "center",
262
+ height: theme.ctl.lg,
263
+ paddingHorizontal: theme.ctl.px.lg,
264
+ gap: theme.ctl.gap.lg,
265
+ borderRadius: theme.ctl.r.lg,
266
+ // The reference draws a 1.5px field edge — the static `thick` weight.
267
+ borderWidth: theme.borderWidth.thick,
268
+ variants: {
269
+ invalid: { true: {}, false: {} }
270
+ }
271
+ },
272
+ input: {
273
+ flexGrow: 1,
274
+ // react-native-web renders a real `<input>`, whose `min-width: auto`
275
+ // resolves to its intrinsic text-box measure and would stop the field
276
+ // shrinking inside a narrow row.
277
+ minWidth: 0,
278
+ padding: 0,
279
+ color: theme.color.text,
280
+ fontFamily: theme.font.sans,
281
+ fontSize: theme.ctl.fs.lg,
282
+ // P11: a card number is a run of figures and lines up like one.
283
+ fontVariant: ["tabular-nums"],
284
+ variants: {
285
+ invalid: { true: {}, false: {} }
286
+ }
287
+ },
288
+ message: {
289
+ fontFamily: theme.font.sans,
290
+ fontSize: theme.fontSize[12],
291
+ // Reserve the line so showing a message does not shift what sits below it.
292
+ minHeight: theme.fontSize[12] * theme.lineHeight.normal,
293
+ variants: {
294
+ invalid: {
295
+ true: { fontWeight: theme.fontWeight.bold, color: theme.color.danger },
296
+ false: { color: theme.color.text3 }
297
+ }
298
+ }
299
+ },
300
+ testHint: {
301
+ fontFamily: theme.font.mono,
302
+ fontSize: theme.fontSize[10],
303
+ color: theme.color.text3
304
+ }
305
+ }));
306
+ function validateCard(value, brand, now = 0) {
307
+ const resolved = brand ?? formatCard(value.number).brand;
308
+ const errors = {};
309
+ const number = validCardNumber(value.number);
310
+ if (!number.ok) errors.number = number.why;
311
+ if (value.expiry.length === 0) {
312
+ errors.expiry = CARD_COPY.expiryEmpty;
313
+ } else {
314
+ const expiry = validExpiry(formatExpiry(value.expiry), now);
315
+ if (!expiry.ok) errors.expiry = expiry.why;
316
+ }
317
+ const cvc = validCvc(value.cvc, resolved);
318
+ if (!cvc.ok) errors.cvc = cvc.why;
319
+ const order = ["number", "expiry", "cvc"];
320
+ const firstBlocking = order.find((field) => errors[field] !== void 0) ?? null;
321
+ return { errors, firstBlocking };
322
+ }
323
+ function CardForm({
324
+ value,
325
+ brand,
326
+ errors,
327
+ showName = false,
328
+ showSave = false,
329
+ save = false,
330
+ layout = "auto",
331
+ testHint = false,
332
+ now = 0,
333
+ saveLabel = "Save this card for next time",
334
+ onChange,
335
+ onFieldBlur,
336
+ onSaveChange,
337
+ style,
338
+ testID
339
+ }) {
340
+ const theme = useLoamTheme();
341
+ const { width } = useWindowDimensions();
342
+ const asRow = layout === "row" || layout === "auto" && width >= theme.breakpoint.tablet;
343
+ const { styles } = useStyles(sheet2, { asRow });
344
+ const resolvedBrand = brand ?? formatCard(value.number).brand;
345
+ const [shown, setShown] = React.useState([]);
346
+ const isShown = (field) => shown.includes(field);
347
+ const focusers = React.useRef(/* @__PURE__ */ new Map());
348
+ const run = React.useMemo(
349
+ () => ({
350
+ register: (field, focus2) => {
351
+ focusers.current.set(field, focus2);
352
+ return () => {
353
+ if (focusers.current.get(field) === focus2) focusers.current.delete(field);
354
+ };
355
+ }
356
+ }),
357
+ []
358
+ );
359
+ const focus = (field) => focusers.current.get(field)?.();
360
+ const own = validateCard(value, resolvedBrand, now).errors;
361
+ const errorFor = (field) => errors?.[field] ?? (isShown(field) ? own[field] : void 0);
362
+ const handleBlur = (field) => () => {
363
+ setShown((current) => {
364
+ const failing = own[field] !== void 0;
365
+ if (failing) return current.includes(field) ? current : [...current, field];
366
+ return current.includes(field) ? current.filter((f) => f !== field) : current;
367
+ });
368
+ onFieldBlur?.(field);
369
+ };
370
+ return /* @__PURE__ */ jsx(CardRunContext.Provider, { value: run, children: /* @__PURE__ */ jsxs(View, { testID, style: [styles.form, style], children: [
371
+ /* @__PURE__ */ jsxs(View, { style: styles.fields, children: [
372
+ /* @__PURE__ */ jsx(
373
+ CardNumberField,
374
+ {
375
+ value: value.number,
376
+ brand: resolvedBrand,
377
+ error: errorFor("number"),
378
+ testHint,
379
+ style: styles.numberField,
380
+ onChange: (raw) => onChange({ number: raw }),
381
+ onComplete: () => focus("expiry"),
382
+ onBlur: handleBlur("number")
383
+ }
384
+ ),
385
+ /* @__PURE__ */ jsx(
386
+ ExpiryField,
387
+ {
388
+ value: value.expiry,
389
+ error: errorFor("expiry"),
390
+ onChange: (raw) => onChange({ expiry: raw }),
391
+ onComplete: () => focus("cvc"),
392
+ onBackspaceOut: () => focus("number"),
393
+ onBlur: handleBlur("expiry")
394
+ }
395
+ ),
396
+ /* @__PURE__ */ jsx(
397
+ CvcField,
398
+ {
399
+ value: value.cvc,
400
+ digits: resolvedBrand.cvc,
401
+ error: errorFor("cvc"),
402
+ onChange: (raw) => onChange({ cvc: raw }),
403
+ onBackspaceOut: () => focus("expiry"),
404
+ onBlur: handleBlur("cvc")
405
+ }
406
+ )
407
+ ] }),
408
+ showName ? /* @__PURE__ */ jsx(
409
+ TextField,
410
+ {
411
+ label: "Name on card",
412
+ autoComplete: "cc-name",
413
+ size: "lg",
414
+ value: value.name ?? "",
415
+ error: errors?.name,
416
+ onChangeText: (next) => onChange({ name: next }),
417
+ onBlur: handleBlur("name")
418
+ }
419
+ ) : null,
420
+ showSave ? /* @__PURE__ */ jsxs(View, { style: styles.saveRow, children: [
421
+ /* @__PURE__ */ jsx(
422
+ Checkbox,
423
+ {
424
+ checked: save,
425
+ onCheckedChange: (next) => onSaveChange?.(next),
426
+ accessibilityLabel: saveLabel
427
+ }
428
+ ),
429
+ /* @__PURE__ */ jsx(Text, { style: styles.saveLabel, children: saveLabel })
430
+ ] }) : null
431
+ ] }) });
432
+ }
433
+ var sheet2 = createStyleSheet((theme) => ({
434
+ form: { gap: theme.space.s3 },
435
+ fields: {
436
+ gap: theme.space.s3,
437
+ variants: {
438
+ // Number · MM/YY · code on one line, or each on its own. Nothing else
439
+ // about the fields changes between the two.
440
+ asRow: { true: { flexDirection: "row", alignItems: "flex-start" }, false: {} }
441
+ }
442
+ },
443
+ numberField: {
444
+ variants: {
445
+ // The number is twice the width of the two short fields beside it — the
446
+ // 2:1:1 split the web grid draws with four columns.
447
+ asRow: { true: { flexGrow: 2 }, false: {} }
448
+ }
449
+ },
450
+ saveRow: {
451
+ flexDirection: "row",
452
+ alignItems: "center",
453
+ gap: theme.space.s3,
454
+ minHeight: theme.tapMin
455
+ },
456
+ saveLabel: {
457
+ flexShrink: 1,
458
+ fontFamily: theme.font.sans,
459
+ fontSize: theme.fontSize[14],
460
+ color: theme.color.text
461
+ }
462
+ }));
463
+
464
+ export { CardForm, CardNumberField, CvcField, ExpiryField, ExpiryHint, validateCard };
@@ -0,0 +1,146 @@
1
+ import * as React from 'react';
2
+ import { StyleSheet, Animated, Easing, View, Text } from 'react-native';
3
+ import { Svg, Circle } from 'react-native-svg';
4
+ import { createStyleSheet, useLoamTheme, useStyles } from '@btndprojects/loam-theme-native';
5
+ import { jsx, jsxs } from 'react/jsx-runtime';
6
+
7
+ // src/spinner/spinner.tsx
8
+ var RING = {
9
+ sm: { diameter: 16, stroke: 2 },
10
+ md: { diameter: 20, stroke: 2.5 },
11
+ lg: { diameter: 28, stroke: 3 },
12
+ xl: { diameter: 40, stroke: 4 }
13
+ };
14
+ var ARC_FRACTION = 0.7;
15
+ function Spinner({
16
+ size = "md",
17
+ color,
18
+ accessibilityLabel = "Loading",
19
+ motion = "full"
20
+ }) {
21
+ const theme = useLoamTheme();
22
+ const stroke = color ?? theme.color.accent;
23
+ const { diameter, stroke: strokeWidth } = RING[size];
24
+ const spinning = motion === "full" && !theme.reduceMotion;
25
+ const radius = (diameter - strokeWidth) / 2;
26
+ const circumference = 2 * Math.PI * radius;
27
+ const arc = circumference * ARC_FRACTION;
28
+ const rotate = React.useRef(new Animated.Value(0)).current;
29
+ React.useEffect(() => {
30
+ if (!spinning) {
31
+ rotate.setValue(0);
32
+ return;
33
+ }
34
+ const loop = Animated.loop(
35
+ Animated.sequence([
36
+ Animated.timing(rotate, {
37
+ toValue: 1,
38
+ duration: theme.loop.spin,
39
+ // A rotation that never settles has no start or end to ease, so it runs
40
+ // at a constant rate — there is no ramp token to reach for here.
41
+ easing: Easing.linear,
42
+ useNativeDriver: true
43
+ })
44
+ ])
45
+ );
46
+ loop.start();
47
+ return () => loop.stop();
48
+ }, [rotate, theme.loop.spin, spinning]);
49
+ const spin = rotate.interpolate({ inputRange: [0, 1], outputRange: ["0deg", "360deg"] });
50
+ return /* @__PURE__ */ jsx(
51
+ Animated.View,
52
+ {
53
+ accessibilityRole: "progressbar",
54
+ accessibilityLabel,
55
+ accessibilityState: { busy: true },
56
+ style: { width: diameter, height: diameter, transform: [{ rotate: spin }] },
57
+ children: /* @__PURE__ */ jsx(Svg, { width: diameter, height: diameter, viewBox: `0 0 ${diameter} ${diameter}`, fill: "none", children: /* @__PURE__ */ jsx(
58
+ Circle,
59
+ {
60
+ cx: diameter / 2,
61
+ cy: diameter / 2,
62
+ r: radius,
63
+ stroke,
64
+ strokeWidth,
65
+ strokeLinecap: "round",
66
+ strokeDasharray: `${arc} ${circumference}`
67
+ }
68
+ ) })
69
+ }
70
+ );
71
+ }
72
+ var DEFAULT_LATE_LABEL = "Still working\u2026";
73
+ function LoadingOverlay({
74
+ active = true,
75
+ size = "lg",
76
+ color,
77
+ accessibilityLabel = "Loading",
78
+ late = false,
79
+ lateLabel = DEFAULT_LATE_LABEL,
80
+ scrim = "default",
81
+ motion = "full"
82
+ }) {
83
+ const { styles } = useStyles(sheet, { scrim: scrim === "light" ? "light" : void 0 });
84
+ if (!active) return null;
85
+ return /* @__PURE__ */ jsx(
86
+ View,
87
+ {
88
+ style: styles.overlay,
89
+ "aria-busy": true,
90
+ accessibilityViewIsModal: true,
91
+ accessibilityState: { busy: true },
92
+ children: /* @__PURE__ */ jsxs(View, { style: styles.content, children: [
93
+ /* @__PURE__ */ jsx(
94
+ Spinner,
95
+ {
96
+ size,
97
+ color,
98
+ accessibilityLabel,
99
+ motion
100
+ }
101
+ ),
102
+ late ? (
103
+ // `role="status"` (polite on rn-web) announces the copy when work goes late.
104
+ /* @__PURE__ */ jsx(View, { accessibilityRole: "text", role: "status", style: styles.latePill, children: /* @__PURE__ */ jsx(Text, { style: styles.lateText, children: lateLabel }) })
105
+ ) : null
106
+ ] })
107
+ }
108
+ );
109
+ }
110
+ var sheet = createStyleSheet((theme) => ({
111
+ overlay: {
112
+ ...StyleSheet.absoluteFillObject,
113
+ alignItems: "center",
114
+ justifyContent: "center",
115
+ variants: {
116
+ scrim: {
117
+ default: { backgroundColor: theme.color.scrim },
118
+ light: { backgroundColor: theme.color.scrimLight }
119
+ }
120
+ }
121
+ },
122
+ content: {
123
+ alignItems: "center",
124
+ gap: theme.space.s3
125
+ },
126
+ latePill: {
127
+ alignSelf: "center",
128
+ flexDirection: "row",
129
+ alignItems: "center",
130
+ backgroundColor: theme.color.warnSoft,
131
+ borderColor: theme.edge.warn,
132
+ borderWidth: theme.borderWidth.base,
133
+ borderRadius: theme.radius.full,
134
+ paddingHorizontal: theme.space.s2,
135
+ paddingVertical: theme.space[2]
136
+ },
137
+ lateText: {
138
+ fontFamily: theme.font.sans,
139
+ color: theme.color.warnOnSoft,
140
+ fontSize: theme.type.caption1.fontSize,
141
+ lineHeight: theme.type.caption1.lineHeight,
142
+ letterSpacing: theme.type.caption1.letterSpacing
143
+ }
144
+ }));
145
+
146
+ export { LoadingOverlay, Spinner };