@bloxwap/hig 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/README.md +2 -2
  2. package/chart/README.md +13 -2
  3. package/chart/dist/altimeter-burst.d.ts +4 -0
  4. package/chart/dist/altimeter-burst.js +43 -0
  5. package/chart/dist/altimeter-chart.d.ts +52 -0
  6. package/chart/dist/altimeter-chart.js +275 -0
  7. package/chart/dist/altimeter-model.d.ts +43 -0
  8. package/chart/dist/altimeter-model.js +148 -0
  9. package/chart/dist/altimeter-targets.d.ts +33 -0
  10. package/chart/dist/altimeter-targets.js +88 -0
  11. package/chart/dist/bitcoin-price.d.ts +8 -0
  12. package/chart/dist/bitcoin-price.js +41 -0
  13. package/chart/dist/champions-league.d.ts +19 -0
  14. package/chart/dist/champions-league.js +104 -0
  15. package/chart/dist/index.d.ts +6 -0
  16. package/chart/dist/index.js +5 -0
  17. package/chart/dist/outcome-chart.d.ts +37 -0
  18. package/chart/dist/outcome-chart.js +212 -0
  19. package/chart/dist/outcome-model.d.ts +43 -0
  20. package/chart/dist/outcome-model.js +71 -0
  21. package/chart/dist/plus-grid.d.ts +6 -0
  22. package/chart/dist/plus-grid.js +29 -0
  23. package/contracts/README.md +1 -1
  24. package/contracts/dist/avatar.d.ts +68 -0
  25. package/contracts/dist/avatar.js +93 -0
  26. package/contracts/dist/confetti.d.ts +174 -0
  27. package/contracts/dist/confetti.js +138 -0
  28. package/contracts/dist/decimal.d.ts +7 -0
  29. package/contracts/dist/decimal.js +35 -0
  30. package/contracts/dist/index.d.ts +29 -2
  31. package/contracts/dist/index.js +123 -4
  32. package/contracts/dist/invariants.d.ts +17 -0
  33. package/contracts/dist/invariants.js +24 -0
  34. package/contracts/dist/login.d.ts +34 -0
  35. package/contracts/dist/login.js +43 -0
  36. package/contracts/dist/messages.d.ts +57 -3
  37. package/contracts/dist/messages.js +20 -2
  38. package/contracts/dist/number-flow.d.ts +90 -0
  39. package/contracts/dist/number-flow.js +150 -0
  40. package/contracts/dist/qr.d.ts +151 -0
  41. package/contracts/dist/qr.js +581 -0
  42. package/contracts/dist/toast.d.ts +168 -0
  43. package/contracts/dist/toast.js +171 -0
  44. package/feedback/README.md +1 -1
  45. package/feedback/dist/contract.js +1 -1
  46. package/feedback/dist/react.js +2 -4
  47. package/native/README.md +6 -1
  48. package/native/dist/account-block.d.ts +10 -1
  49. package/native/dist/account-block.js +17 -7
  50. package/native/dist/animated-number-model.d.ts +41 -1
  51. package/native/dist/animated-number-model.js +201 -23
  52. package/native/dist/animated-number.d.ts +39 -1
  53. package/native/dist/animated-number.js +164 -17
  54. package/native/dist/announce.d.ts +2 -0
  55. package/native/dist/announce.js +10 -0
  56. package/native/dist/asset-balance-row.d.ts +3 -1
  57. package/native/dist/asset-balance-row.js +15 -4
  58. package/native/dist/assets-block.d.ts +115 -0
  59. package/native/dist/assets-block.js +87 -0
  60. package/native/dist/async-result.d.ts +2 -0
  61. package/native/dist/async-result.js +11 -0
  62. package/native/dist/avatar-frame.d.ts +29 -0
  63. package/native/dist/avatar-frame.js +56 -0
  64. package/native/dist/avatar.d.ts +21 -0
  65. package/native/dist/avatar.js +31 -0
  66. package/native/dist/bar-mark.d.ts +2 -0
  67. package/native/dist/bar-mark.js +4 -2
  68. package/native/dist/bar-pnl.js +2 -1
  69. package/native/dist/blocks.d.ts +9 -2
  70. package/native/dist/blocks.js +8 -1
  71. package/native/dist/brand.js +2 -1
  72. package/native/dist/button.d.ts +7 -2
  73. package/native/dist/button.js +13 -3
  74. package/native/dist/checkbox.js +2 -1
  75. package/native/dist/confetti.d.ts +33 -0
  76. package/native/dist/confetti.js +143 -0
  77. package/native/dist/confirm-block.d.ts +98 -0
  78. package/native/dist/confirm-block.js +48 -0
  79. package/native/dist/data.d.ts +1 -1
  80. package/native/dist/data.js +5 -1
  81. package/native/dist/deposit-block.d.ts +19 -0
  82. package/native/dist/deposit-block.js +17 -0
  83. package/native/dist/explainer-block.d.ts +91 -0
  84. package/native/dist/explainer-block.js +34 -0
  85. package/native/dist/field.d.ts +5 -1
  86. package/native/dist/field.js +27 -6
  87. package/native/dist/gesture-sheet-model.d.ts +50 -0
  88. package/native/dist/gesture-sheet-model.js +105 -0
  89. package/native/dist/gesture-sheet-next.d.ts +82 -0
  90. package/native/dist/gesture-sheet-next.js +315 -0
  91. package/native/dist/gesture-sheet.d.ts +5 -1
  92. package/native/dist/gesture-sheet.js +13 -6
  93. package/native/dist/icons.d.ts +9 -6
  94. package/native/dist/icons.js +25 -24
  95. package/native/dist/language-block.d.ts +10 -1
  96. package/native/dist/language-block.js +11 -4
  97. package/native/dist/list-group.d.ts +3 -1
  98. package/native/dist/list-group.js +26 -13
  99. package/native/dist/login-block.d.ts +4 -0
  100. package/native/dist/login-block.js +22 -0
  101. package/native/dist/manage-position-block.d.ts +8 -1
  102. package/native/dist/manage-position-block.js +7 -2
  103. package/native/dist/market-row.js +19 -8
  104. package/native/dist/navigation.js +5 -3
  105. package/native/dist/number-format.d.ts +6 -0
  106. package/native/dist/number-format.js +9 -0
  107. package/native/dist/pickers.d.ts +8 -0
  108. package/native/dist/pickers.js +3 -3
  109. package/native/dist/position-block.d.ts +5 -5
  110. package/native/dist/preset-group.d.ts +31 -0
  111. package/native/dist/preset-group.js +39 -0
  112. package/native/dist/preset-picker-block.d.ts +107 -0
  113. package/native/dist/preset-picker-block.js +43 -0
  114. package/native/dist/profile-block.d.ts +10 -1
  115. package/native/dist/profile-block.js +8 -3
  116. package/native/dist/provider.d.ts +5 -2
  117. package/native/dist/provider.js +27 -5
  118. package/native/dist/qr-code.d.ts +33 -0
  119. package/native/dist/qr-code.js +29 -0
  120. package/native/dist/radio-group.d.ts +19 -7
  121. package/native/dist/radio-group.js +39 -10
  122. package/native/dist/reward-block.d.ts +10 -7
  123. package/native/dist/reward-block.js +9 -4
  124. package/native/dist/screen-header.d.ts +13 -3
  125. package/native/dist/screen-header.js +12 -4
  126. package/native/dist/select.js +4 -2
  127. package/native/dist/selection.d.ts +2 -1
  128. package/native/dist/selection.js +1 -0
  129. package/native/dist/setting-switch.d.ts +1 -1
  130. package/native/dist/setting-switch.js +7 -3
  131. package/native/dist/slider.js +5 -1
  132. package/native/dist/sound-haptics-block.js +1 -1
  133. package/native/dist/status.d.ts +41 -9
  134. package/native/dist/status.js +34 -17
  135. package/native/dist/sticky-header.js +9 -1
  136. package/native/dist/swap-amount-card.d.ts +57 -0
  137. package/native/dist/swap-amount-card.js +31 -0
  138. package/native/dist/{swap-panel-block.d.ts → swap-block.d.ts} +18 -8
  139. package/native/dist/{swap-panel-block.js → swap-block.js} +63 -35
  140. package/native/dist/swap-parts.d.ts +3 -10
  141. package/native/dist/swap-parts.js +22 -24
  142. package/native/dist/swap-shared.d.ts +2 -2
  143. package/native/dist/swap-shared.js +10 -6
  144. package/native/dist/swap-sheet.d.ts +3 -3
  145. package/native/dist/swap-sheet.js +3 -3
  146. package/native/dist/swap-views.js +1 -1
  147. package/native/dist/target-block.d.ts +7 -1
  148. package/native/dist/target-block.js +13 -6
  149. package/native/dist/toast.d.ts +47 -0
  150. package/native/dist/toast.js +386 -0
  151. package/native/dist/token-action-block.d.ts +11 -2
  152. package/native/dist/token-action-block.js +10 -4
  153. package/native/dist/trade-history-list-block.js +7 -4
  154. package/native/dist/wallet-address-core.js +6 -3
  155. package/native-fonts/README.md +1 -1
  156. package/og-fonts/README.md +1 -1
  157. package/package.json +155 -11
  158. package/react/README.md +3 -1
  159. package/react/dist/animated-number-flow.d.ts +72 -0
  160. package/react/dist/animated-number-flow.js +316 -0
  161. package/react/dist/animated-number-model.d.ts +18 -0
  162. package/react/dist/animated-number-model.js +75 -5
  163. package/react/dist/animated-number.d.ts +45 -1
  164. package/react/dist/animated-number.js +137 -6
  165. package/react/dist/asset-balance-row.d.ts +3 -1
  166. package/react/dist/asset-balance-row.js +10 -4
  167. package/react/dist/async-result.d.ts +2 -0
  168. package/react/dist/async-result.js +11 -0
  169. package/react/dist/avatar.d.ts +25 -0
  170. package/react/dist/avatar.js +50 -0
  171. package/react/dist/blocks/account-block.d.ts +5 -1
  172. package/react/dist/blocks/account-block.js +11 -6
  173. package/react/dist/blocks/assets-block.d.ts +106 -0
  174. package/react/dist/blocks/assets-block.js +135 -0
  175. package/react/dist/blocks/confirm-block.d.ts +91 -0
  176. package/react/dist/blocks/confirm-block.js +31 -0
  177. package/react/dist/blocks/deposit-block.d.ts +19 -0
  178. package/react/dist/blocks/deposit-block.js +15 -0
  179. package/react/dist/blocks/explainer-block.d.ts +80 -0
  180. package/react/dist/blocks/explainer-block.js +20 -0
  181. package/react/dist/blocks/install-command.js +3 -1
  182. package/react/dist/blocks/language-block.d.ts +5 -1
  183. package/react/dist/blocks/language-block.js +4 -3
  184. package/react/dist/blocks/login-block.d.ts +4 -0
  185. package/react/dist/blocks/login-block.js +14 -0
  186. package/react/dist/blocks/manage-position-block.d.ts +3 -1
  187. package/react/dist/blocks/manage-position-block.js +2 -2
  188. package/react/dist/blocks/market-row.js +8 -3
  189. package/react/dist/blocks/notifications-block.d.ts +3 -1
  190. package/react/dist/blocks/notifications-block.js +2 -2
  191. package/react/dist/blocks/pickers.d.ts +9 -0
  192. package/react/dist/blocks/pickers.js +4 -2
  193. package/react/dist/blocks/position-block.d.ts +3 -3
  194. package/react/dist/blocks/preset-picker-block.d.ts +85 -0
  195. package/react/dist/blocks/preset-picker-block.js +19 -0
  196. package/react/dist/blocks/profile-block.d.ts +5 -1
  197. package/react/dist/blocks/profile-block.js +12 -13
  198. package/react/dist/blocks/reward-block.d.ts +13 -8
  199. package/react/dist/blocks/reward-block.js +7 -4
  200. package/react/dist/blocks/screen-header.d.ts +10 -2
  201. package/react/dist/blocks/screen-header.js +7 -4
  202. package/react/dist/blocks/setting-switch.js +6 -3
  203. package/react/dist/blocks/signals-block.d.ts +3 -1
  204. package/react/dist/blocks/signals-block.js +4 -3
  205. package/react/dist/blocks/sound-haptics-block.d.ts +3 -1
  206. package/react/dist/blocks/sound-haptics-block.js +2 -2
  207. package/react/dist/blocks/sticky-header.d.ts +14 -4
  208. package/react/dist/blocks/sticky-header.js +68 -8
  209. package/react/dist/blocks/swap/settings.js +2 -1
  210. package/react/dist/blocks/swap/shared.d.ts +22 -22
  211. package/react/dist/blocks/swap/shared.js +30 -28
  212. package/react/dist/blocks/{swap-panel-block.d.ts → swap-block.d.ts} +19 -8
  213. package/react/dist/blocks/swap-block.js +215 -0
  214. package/react/dist/blocks/swap-sheet.d.ts +3 -3
  215. package/react/dist/blocks/swap-sheet.js +3 -3
  216. package/react/dist/blocks/target-block.d.ts +7 -1
  217. package/react/dist/blocks/target-block.js +10 -4
  218. package/react/dist/blocks/token-action-block.d.ts +6 -2
  219. package/react/dist/blocks/token-action-block.js +3 -2
  220. package/react/dist/blocks/trade-history-detail-block.d.ts +3 -1
  221. package/react/dist/blocks/trade-history-detail-block.js +2 -2
  222. package/react/dist/blocks/trade-history-list-block.d.ts +3 -1
  223. package/react/dist/blocks/trade-history-list-block.js +7 -4
  224. package/react/dist/blocks.d.ts +8 -2
  225. package/react/dist/blocks.js +7 -1
  226. package/react/dist/brand.js +2 -1
  227. package/react/dist/button.d.ts +9 -3
  228. package/react/dist/button.js +8 -3
  229. package/react/dist/confetti.d.ts +27 -0
  230. package/react/dist/confetti.js +240 -0
  231. package/react/dist/data.js +8 -1
  232. package/react/dist/field.d.ts +6 -1
  233. package/react/dist/field.js +18 -9
  234. package/react/dist/gesture-sheet.d.ts +15 -1
  235. package/react/dist/gesture-sheet.js +53 -8
  236. package/react/dist/list-group.js +11 -7
  237. package/react/dist/navigation.js +11 -3
  238. package/react/dist/overlay.d.ts +1 -4
  239. package/react/dist/overlay.js +1 -3
  240. package/react/dist/popover.d.ts +30 -0
  241. package/react/dist/popover.js +34 -0
  242. package/react/dist/preset-group.d.ts +30 -0
  243. package/react/dist/preset-group.js +13 -0
  244. package/react/dist/provider.d.ts +2 -2
  245. package/react/dist/provider.js +23 -6
  246. package/react/dist/qr-code.d.ts +32 -0
  247. package/react/dist/qr-code.js +28 -0
  248. package/react/dist/select.js +10 -3
  249. package/react/dist/selection.d.ts +13 -5
  250. package/react/dist/selection.js +13 -8
  251. package/react/dist/slider.js +5 -1
  252. package/react/dist/status.d.ts +14 -10
  253. package/react/dist/status.js +17 -9
  254. package/react/dist/styles.css +260 -165
  255. package/react/dist/toast.d.ts +19 -12
  256. package/react/dist/toast.js +29 -7
  257. package/react/dist/wallet-address-core.d.ts +8 -4
  258. package/react/dist/wallet-address-core.js +10 -5
  259. package/tokens/README.md +2 -2
  260. package/tokens/assets/onramps/apple-pay.svg +33 -0
  261. package/tokens/assets/onramps/bank.svg +98 -0
  262. package/tokens/assets/onramps/blink.svg +37 -0
  263. package/tokens/assets/onramps/cashapp.svg +33 -0
  264. package/tokens/assets/onramps/crypto.svg +121 -0
  265. package/tokens/assets/onramps/exchange.svg +105 -0
  266. package/tokens/dist/deposit-icons.d.ts +1 -0
  267. package/tokens/dist/deposit-icons.js +28 -0
  268. package/tokens/dist/index.d.ts +16 -0
  269. package/tokens/dist/index.js +16 -0
  270. package/tokens/dist/manifest.json +8 -0
  271. package/tokens/dist/tokens.css +6 -0
  272. package/react/dist/blocks/swap-panel-block.js +0 -178
@@ -0,0 +1,34 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { View } from 'react-native';
3
+ import { withAlpha } from '@bloxwap/hig/tokens';
4
+ import { useColors, useFills, useHIG } from './provider.js';
5
+ import { Text } from './surface.js';
6
+ import * as en from '@bloxwap/hig/contracts/messages';
7
+ import { Button, busyAccessibilityLabel } from './button.js';
8
+ import { ScreenHeader } from './screen-header.js';
9
+ import { StickyHeaderLayout } from './sticky-header.js';
10
+ const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
11
+ /** Test ID parts, which double as the actions' default intents. */
12
+ const primaryPart = 'primary', secondaryPart = 'secondary', descriptionPart = 'description', caveatPart = 'caveat';
13
+ /**
14
+ * How something works, or how to finish a task, as a screen: an optional header, a lead paragraph, titled sections (each with an optional
15
+ * icon and tone, a heading, media, a body and a caveat), numbered steps, a closing note, then one or two actions. Draws the "How Swing
16
+ * works" and "How Trend works" sheets and short task dialogs such as inviting a friend.
17
+ */
18
+ export function ExplainerBlock({ title, eyebrow, badge, titleRef, hero, description, sections = [], steps = [], caveat, children, primaryAction, secondaryAction, suppressFeedback, onBack, backProps, headerAction, headingId, stickyHeader, stickyHeaderBackground, scrollComponent, testID = 'explainer' }) {
19
+ const colors = useColors(), fills = useFills(), { direction, messages } = useHIG();
20
+ const id = (part) => `${testID}-${part}`;
21
+ const muted = { fontSize: 14, lineHeight: 20, color: colors.muted };
22
+ // Host text is drawn as muted Text; host nodes are drawn as given.
23
+ const prose = (content, part) => typeof content === 'string' || typeof content === 'number' ? _jsx(Text, { testID: id(part), style: muted, children: content }) : _jsx(View, { testID: id(part), children: content });
24
+ const shown = (content) => content != null && content !== false;
25
+ const action = (entry, fallback) => { const button = entry.testID ?? id(fallback); /* With an icon, the label alone names the button (and its busy reading), so a Text glyph is never read into it. */ /* With an icon, the label alone names the button (and its busy reading), so a Text glyph is never read into it. */ const named = shown(entry.icon) ? { accessibilityLabel: entry.busy ? busyAccessibilityLabel(entry.label, messages.busy ?? en.busy) : entry.label } : {}; return _jsxs(Button, { ...entry.pressProps, ...named, testID: button, intent: entry.intent ?? fallback, disabled: entry.disabled, busy: entry.busy, suppressFeedback: suppressFeedback, onPress: entry.onSelect, style: { flex: 1, alignSelf: 'auto' }, children: [entry.label, shown(entry.icon) ? _jsx(View, { ...hidden, testID: `${button}-icon`, children: entry.icon }, 'icon') : null] }); };
26
+ const header = title !== undefined ? _jsx(ScreenHeader, { title: title, eyebrow: eyebrow, badge: badge, titleRef: titleRef, onBack: onBack, backProps: backProps, action: headerAction, headingId: headingId, testID: testID }) : null;
27
+ const body = _jsxs(_Fragment, { children: [header === null && eyebrow ? _jsx(Text, { testID: id('eyebrow'), style: { fontSize: 12, lineHeight: 16, letterSpacing: 1.5, textTransform: 'uppercase', color: colors.muted }, children: eyebrow }) : null, shown(hero) ? _jsx(View, { testID: id('hero'), style: { alignItems: 'center' }, children: hero }) : null, shown(description) ? prose(description, descriptionPart) : null, sections.length > 0 ? _jsx(View, { testID: id('sections'), style: { gap: 12 }, children: sections.map(section => {
28
+ const part = `section-${section.id}`, bodyPart = `${part}-body`, sectionCaveatPart = `${part}-caveat`, tone = section.tone ? colors[section.tone] : undefined;
29
+ return _jsxs(View, { testID: section.testID ?? id(part), style: { direction, flexDirection: 'row', alignItems: section.icon != null ? 'flex-start' : 'center', gap: 12, padding: 12, borderRadius: section.icon != null ? 32 : 16, backgroundColor: tone ? withAlpha(tone, 0.1) : fills.well }, children: [section.icon != null ? _jsx(View, { ...hidden, testID: id(`${part}-icon`), style: { width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center', backgroundColor: withAlpha(tone ?? colors.text, 0.15) }, children: section.icon }) : null, _jsxs(View, { style: { flex: 1, minWidth: 0, gap: 4 }, children: [section.title !== undefined ? _jsxs(Text, { testID: id(`${part}-title`), accessibilityRole: 'header', style: { fontSize: 16, lineHeight: 24, fontWeight: '700', color: tone ?? colors.text }, children: [section.title, section.meaning ? _jsx(Text, { style: { color: colors.muted }, children: ` ${section.meaning}` }) : null] }) : null, section.media != null ? _jsx(View, { testID: id(`${part}-media`), style: { alignItems: 'center', gap: 8, marginVertical: 12 }, children: section.media }) : null, shown(section.body) ? prose(section.body, bodyPart) : null, shown(section.caveat) ? prose(section.caveat, sectionCaveatPart) : null] })] }, section.id);
30
+ }) }) : null, steps.length > 0 ? _jsx(View, { testID: id('steps'), style: { gap: 8 }, children: steps.map((step, index) => _jsxs(View, { testID: id(`step-${index}`), accessible: typeof step === 'string' || typeof step === 'number', style: { direction, flexDirection: 'row', gap: 8 }, children: [_jsx(Text, { style: { ...muted, minWidth: 16, fontVariant: ['tabular-nums'] }, children: `${index + 1}.` }), typeof step === 'string' || typeof step === 'number' ? _jsx(Text, { style: { ...muted, flexShrink: 1 }, children: step }) : _jsx(View, { style: { flexShrink: 1 }, children: step })] }, index)) }) : null, shown(caveat) ? prose(caveat, caveatPart) : null, children, primaryAction || secondaryAction ? _jsxs(View, { testID: id('actions'), style: { direction, flexDirection: 'row', gap: 8 }, children: [secondaryAction ? action(secondaryAction, secondaryPart) : null, primaryAction ? action(primaryAction, primaryPart) : null] }) : null] });
31
+ if (stickyHeader && header)
32
+ return _jsx(StickyHeaderLayout, { testID: testID, headerTestID: id('sticky-header'), header: header, background: stickyHeaderBackground, scrollComponent: scrollComponent, bodyStyle: { direction, gap: 16, paddingTop: 16 }, children: body });
33
+ return _jsxs(View, { testID: testID, style: { direction, padding: 16, gap: 16 }, children: [header, body] });
34
+ }
@@ -12,7 +12,11 @@ export interface FieldProps {
12
12
  export declare function Field({ label, description, descriptionTone, error, required, disabled, children }: React.PropsWithChildren<FieldProps>): React.JSX.Element;
13
13
  export declare const Label: typeof Text;
14
14
  /** No resting stroke: the fill separates the field (one step lighter inside a Surface, Dialog or sheet). The ring appears only for focus and for an invalid value. */
15
- export declare const Input: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
15
+ export interface InputProps extends TextInputProps {
16
+ /** Host text on the leading edge inside the field, before what is typed, such as `@` for a handle or `$` for an amount (test ID `<testID>-prefix`). Drawn muted and not part of the value; it leads the input's accessibility hint, before the field's description and error, so it is read after the label. The text starts after it. */
17
+ prefix?: string;
18
+ }
19
+ export declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
16
20
  export declare const TextArea: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
17
21
  export interface SearchInputProps extends TextInputProps {
18
22
  /** Host content on the trailing edge inside the field, such as a filter button. The text stops 48dp short of the edge; wider content sets the input's end padding through `style`. */
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { createContext, useContext, forwardRef, useEffect, useId, useRef, useState } from 'react';
2
+ import { createContext, useContext, forwardRef, useEffect, useId, useRef, useCallback, useState } from 'react';
3
3
  import { AccessibilityInfo, Platform, Pressable, TextInput, View } from 'react-native';
4
4
  import { CloseIcon, SearchIcon } from './icons.js';
5
5
  import { Text } from './surface.js';
@@ -24,8 +24,26 @@ export function Field({ label, description, descriptionTone, error, required, di
24
24
  return _jsx(Context.Provider, { value: { label: marked, hint: [description, error].filter(Boolean).join('. '), disabled, invalid: !!error }, children: _jsxs(View, { style: { gap: 8 }, children: [_jsx(Text, { nativeID: id, children: marked }), children, description && _jsx(Text, { ...(positive ? { accessibilityLiveRegion: 'polite' } : {}), style: { color: positive ? colors.positive : colors.muted }, children: description }), error && _jsx(Text, { accessibilityLiveRegion: 'polite', style: { color: colors.negative }, children: error })] }) });
25
25
  }
26
26
  export const Label = Text;
27
- /** No resting stroke: the fill separates the field (one step lighter inside a Surface, Dialog or sheet). The ring appears only for focus and for an invalid value. */
28
- export const Input = forwardRef(function Input({ style, onFocus, onBlur, ...props }, ref) { const field = useContext(Context); const colors = useColors(); const fills = useFills(); const env = useHIG(); const [focused, setFocused] = useState(false); return _jsx(TextInput, { ...props, ref: ref, accessibilityLabel: props.accessibilityLabel ?? field.label, accessibilityHint: props.accessibilityHint ?? field.hint, accessibilityState: { ...props.accessibilityState, disabled: !!field.disabled || !!props.accessibilityState?.disabled }, editable: field.disabled ? false : props.editable, onChangeText: field.disabled ? undefined : props.onChangeText, onChange: field.disabled ? undefined : props.onChange, onFocus: event => { setFocused(true); onFocus?.(event); }, onBlur: event => { setFocused(false); onBlur?.(event); }, placeholderTextColor: props.placeholderTextColor ?? colors.muted, style: [{ color: colors.text, backgroundColor: fills.well, minHeight: 48, borderWidth: 1.5, borderColor: field.invalid ? colors.negative : focused ? colors.faint : 'transparent', borderRadius: props.multiline ? 14 : 9999, paddingVertical: 12, paddingHorizontal: 20, fontSize: 16, fontFamily: env.fontFamilies?.[400] ?? env.fontFamily, opacity: field.disabled ? 0.5 : 1 }, style] }); });
27
+ export const Input = forwardRef(function Input({ style, onFocus, onBlur, prefix, ...props }, ref) {
28
+ const field = useContext(Context);
29
+ const colors = useColors();
30
+ const fills = useFills();
31
+ const env = useHIG();
32
+ const [focused, setFocused] = useState(false);
33
+ // The prefix is measured once laid out, so the text starts just after it; until then a width is estimated from its length.
34
+ const [lead, setLead] = useState(null);
35
+ const rtl = env.direction === 'rtl', web = Platform.OS === 'web';
36
+ const hint = props.accessibilityHint ?? ([prefix, field.hint].filter(Boolean).join('. ') || undefined);
37
+ const start = prefix ? 20 + (lead ?? prefix.length * 10) + 4 : undefined;
38
+ const inset = start === undefined ? null : web ? (rtl ? { paddingRight: start } : { paddingLeft: start }) : { paddingStart: start };
39
+ const input = _jsx(TextInput, { ...props, ref: ref, accessibilityLabel: props.accessibilityLabel ?? field.label, accessibilityHint: hint, accessibilityState: { ...props.accessibilityState, disabled: !!field.disabled || !!props.accessibilityState?.disabled }, editable: field.disabled ? false : props.editable, onChangeText: field.disabled ? undefined : props.onChangeText, onChange: field.disabled ? undefined : props.onChange, onFocus: event => { setFocused(true); onFocus?.(event); }, onBlur: event => { setFocused(false); onBlur?.(event); }, placeholderTextColor: props.placeholderTextColor ?? colors.muted, style: [{ color: colors.text, backgroundColor: fills.well, minHeight: 48, borderWidth: 1.5, borderColor: field.invalid ? colors.negative : focused ? colors.faint : 'transparent', borderRadius: props.multiline ? 14 : 9999, paddingVertical: 12, paddingHorizontal: 20, fontSize: 16, fontFamily: env.fontFamilies?.[400] ?? env.fontFamily, opacity: field.disabled ? 0.5 : 1 }, inset, style] });
40
+ if (!prefix)
41
+ return input;
42
+ const edge = web ? (rtl ? { right: 20 } : { left: 20 }) : { start: 20 };
43
+ return _jsxs(View, { style: { direction: env.direction, justifyContent: 'center' }, children: [input, _jsx(View, { ...hiddenPrefix, pointerEvents: 'none', style: { position: 'absolute', ...edge }, children: _jsx(Text, { testID: props.testID ? `${props.testID}-prefix` : undefined, onLayout: event => { const width = Math.ceil(event.nativeEvent.layout.width); if (width !== lead)
44
+ setLead(width); }, style: { fontSize: 16, color: colors.muted, opacity: field.disabled ? 0.5 : 1 }, children: prefix }) })] });
45
+ });
46
+ const hiddenPrefix = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
29
47
  export const TextArea = forwardRef(function TextArea(props, ref) { return _jsx(Input, { ...props, ref: ref, multiline: true, textAlignVertical: 'top' }); });
30
48
  /** The magnifying glass sits inset on the leading edge and the text starts past it. */
31
49
  /** A search box is as tall as a button, 44dp, not a 48dp form field. */
@@ -41,10 +59,13 @@ export const SearchInput = forwardRef(function SearchInput({ style, trailing, on
41
59
  const extra = trailing != null && trailing !== false, reserve = extra || onClear != null;
42
60
  const end = web ? (rtl ? { left: 0 } : { right: 0 }) : { end: 0 };
43
61
  const endInset = reserve ? (web ? (rtl ? { paddingLeft: 48 } : { paddingRight: 48 }) : { paddingEnd: 48 }) : null;
44
- const attach = (node) => { inner.current = node; if (typeof ref === 'function')
45
- ref(node);
62
+ const attach = useCallback((node) => { inner.current = node; const cleanup = typeof ref === 'function' ? ref(node) : undefined; if (ref && typeof ref !== 'function')
63
+ ref.current = node; return () => { inner.current = null; if (typeof cleanup === 'function')
64
+ cleanup();
65
+ else if (typeof ref === 'function')
66
+ ref(null);
46
67
  else if (ref)
47
- ref.current = node; };
68
+ ref.current = null; }; }, [ref]);
48
69
  const off = props.editable === false || !!useContext(Context).disabled;
49
70
  const clear = onClear && props.value != null && props.value !== '' ? _jsx(Pressable, { testID: props.testID ? `${props.testID}-clear` : undefined, accessibilityRole: 'button', accessibilityLabel: clearLabel ?? messages.clearSearch ?? en.clearSearch, accessibilityState: off ? { disabled: true } : undefined, disabled: off, hitSlop: 2, onPress: () => { onClear(); inner.current?.focus(); }, style: ({ pressed }) => ({ width: 44, height: 44, borderRadius: 22, alignItems: 'center', justifyContent: 'center', opacity: off ? 0.5 : pressed ? 0.6 : 1 }), children: _jsx(CloseIcon, { color: colors.muted }) }) : null;
50
71
  return _jsxs(View, { style: { direction, justifyContent: 'center' }, children: [_jsx(Input, { ...props, ref: onClear ? attach : ref, returnKeyType: props.returnKeyType ?? 'search', style: [searchSize, inset, endInset, style] }), _jsx(View, { pointerEvents: 'none', style: { position: 'absolute', ...edge }, children: _jsx(SearchIcon, { color: colors.muted }) }), extra || clear ? _jsxs(View, { style: { position: 'absolute', top: 0, bottom: 0, ...end, flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [trailing, clear] }) : null] });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The arithmetic of HIG's own sheet, kept apart from React so it runs on the UI thread as worklets and is tested as plain
3
+ * functions. Positions are the sheet's `translateY` in points: 0 is the sheet at its full height, `height` is closed.
4
+ */
5
+ export type SheetSnapPoint = number | `${number}%`;
6
+ /** A detent as visible height in points, from points or a percentage of the room the sheet has. Invalid input reads as 0. */
7
+ export declare function detentHeight(point: SheetSnapPoint, room: number): number;
8
+ /** Detent heights for fixed snap points: clamped to the room, sorted increasing, without duplicates or empty detents. */
9
+ export declare function detentHeights(points: readonly SheetSnapPoint[], room: number): number[];
10
+ /**
11
+ * Resistance past the sheet's limit: the further the finger goes, the less the sheet follows, and it never passes `limit`
12
+ * points. The same curve UIScrollView uses.
13
+ */
14
+ export declare function rubberBand(overshoot: number, limit: number): number;
15
+ /** Where a drag puts the sheet: 1:1 between the top detent and closed, resisting above the top detent, and resisting below the lowest detent when it cannot be dismissed. */
16
+ export declare function dragPosition(raw: number, top: number, lowest: number, closed: number, dismissible: boolean): number;
17
+ /** How far ahead of the finger a release is read, in seconds: a flick lands where its momentum would carry it. */
18
+ export declare const SHEET_PROJECTION = 0.18;
19
+ /** A release slower than this (points per second) is a placement, not a flick. */
20
+ export declare const SHEET_FLICK = 500;
21
+ /**
22
+ * The detent a release settles on, as an index into `positions` (increasing translateY, so index 0 is the tallest), or -1 to
23
+ * close. A flick moves one detent in its direction, or closes from the lowest; a slow release takes the nearest detent, or
24
+ * closes when the sheet is more than half way from the lowest detent to closed.
25
+ */
26
+ export declare function releaseTarget(position: number, velocity: number, positions: readonly number[], closed: number, dismissible: boolean): number;
27
+ /**
28
+ * The spring every settle uses: critically damped (damping = 2·√(stiffness·mass)), so the sheet lands without a bounce and
29
+ * without a slow tail, in about a third of a second. An overdamped spring creeps to rest and keeps drawing frames long
30
+ * after the sheet looks still (measured on a Seeker: animating almost a second per settle).
31
+ */
32
+ export declare const SHEET_SPRING: {
33
+ readonly damping: 36;
34
+ readonly stiffness: 320;
35
+ readonly mass: 1;
36
+ readonly overshootClamping: true;
37
+ };
38
+ /** Backdrop strength for a position: full at the lowest detent and above, fading to none at closed. */
39
+ export declare function backdropProgress(position: number, lowest: number, closed: number): number;
40
+ /**
41
+ * How a content-sized sheet moves when its content changes height while it rests: one curve with no spring and no
42
+ * overshoot, a short ease in and a long ease out, the values of Vaul's Dynamic Drawer. Drag releases, opening and closing
43
+ * use the spring.
44
+ */
45
+ export declare const SHEET_RESIZE: {
46
+ readonly duration: 270;
47
+ readonly curve: readonly [0.26, 0.08, 0.25, 1];
48
+ };
49
+ /** Invalid fixed detents are programmer errors, before they reach either sheet backend. */
50
+ export declare function validateSnapPoints(points: readonly SheetSnapPoint[], initialIndex?: number): void;
@@ -0,0 +1,105 @@
1
+ /** A detent as visible height in points, from points or a percentage of the room the sheet has. Invalid input reads as 0. */
2
+ export function detentHeight(point, room) {
3
+ 'worklet';
4
+ const raw = typeof point === 'number' ? point : parseFloat(point) / 100 * room;
5
+ return Number.isFinite(raw) ? Math.max(0, Math.min(raw, room)) : 0;
6
+ }
7
+ /** Detent heights for fixed snap points: clamped to the room, sorted increasing, without duplicates or empty detents. */
8
+ export function detentHeights(points, room) {
9
+ 'worklet';
10
+ const heights = [];
11
+ for (const point of points) {
12
+ const height = detentHeight(point, room);
13
+ if (height > 0 && !heights.includes(height))
14
+ heights.push(height);
15
+ }
16
+ return heights.sort((a, b) => a - b);
17
+ }
18
+ /**
19
+ * Resistance past the sheet's limit: the further the finger goes, the less the sheet follows, and it never passes `limit`
20
+ * points. The same curve UIScrollView uses.
21
+ */
22
+ export function rubberBand(overshoot, limit) {
23
+ 'worklet';
24
+ if (overshoot <= 0 || limit <= 0)
25
+ return 0;
26
+ return (1 - 1 / (overshoot * 0.55 / limit + 1)) * limit;
27
+ }
28
+ /** Where a drag puts the sheet: 1:1 between the top detent and closed, resisting above the top detent, and resisting below the lowest detent when it cannot be dismissed. */
29
+ export function dragPosition(raw, top, lowest, closed, dismissible) {
30
+ 'worklet';
31
+ if (raw < top)
32
+ return top - rubberBand(top - raw, Math.max(top, 64));
33
+ const floor = dismissible ? closed : lowest;
34
+ if (raw > floor)
35
+ return dismissible ? closed : floor + rubberBand(raw - floor, Math.max(closed - floor, 64));
36
+ return raw;
37
+ }
38
+ /** How far ahead of the finger a release is read, in seconds: a flick lands where its momentum would carry it. */
39
+ export const SHEET_PROJECTION = 0.18;
40
+ /** A release slower than this (points per second) is a placement, not a flick. */
41
+ export const SHEET_FLICK = 500;
42
+ /**
43
+ * The detent a release settles on, as an index into `positions` (increasing translateY, so index 0 is the tallest), or -1 to
44
+ * close. A flick moves one detent in its direction, or closes from the lowest; a slow release takes the nearest detent, or
45
+ * closes when the sheet is more than half way from the lowest detent to closed.
46
+ */
47
+ export function releaseTarget(position, velocity, positions, closed, dismissible) {
48
+ 'worklet';
49
+ if (positions.length === 0)
50
+ return -1;
51
+ const lowestIndex = positions.length - 1, lowest = positions[lowestIndex];
52
+ let nearest = 0;
53
+ for (let index = 1; index < positions.length; index++)
54
+ if (Math.abs(positions[index] - position) < Math.abs(positions[nearest] - position))
55
+ nearest = index;
56
+ if (Math.abs(velocity) >= SHEET_FLICK) {
57
+ const projected = position + velocity * SHEET_PROJECTION;
58
+ if (velocity > 0) {
59
+ // Downward: the next detent below where the finger let go, or closed.
60
+ for (let index = 0; index < positions.length; index++)
61
+ if (positions[index] > position + 1)
62
+ return index;
63
+ return dismissible && projected > lowest ? -1 : lowestIndex;
64
+ }
65
+ for (let index = lowestIndex; index >= 0; index--)
66
+ if (positions[index] < position - 1)
67
+ return index;
68
+ return 0;
69
+ }
70
+ if (dismissible && position > lowest + (closed - lowest) / 2)
71
+ return -1;
72
+ return nearest;
73
+ }
74
+ /**
75
+ * The spring every settle uses: critically damped (damping = 2·√(stiffness·mass)), so the sheet lands without a bounce and
76
+ * without a slow tail, in about a third of a second. An overdamped spring creeps to rest and keeps drawing frames long
77
+ * after the sheet looks still (measured on a Seeker: animating almost a second per settle).
78
+ */
79
+ export const SHEET_SPRING = { damping: 36, stiffness: 320, mass: 1, overshootClamping: true };
80
+ /** Backdrop strength for a position: full at the lowest detent and above, fading to none at closed. */
81
+ export function backdropProgress(position, lowest, closed) {
82
+ 'worklet';
83
+ if (closed <= lowest)
84
+ return position >= closed ? 0 : 1;
85
+ return Math.max(0, Math.min(1, (closed - position) / (closed - lowest)));
86
+ }
87
+ /**
88
+ * How a content-sized sheet moves when its content changes height while it rests: one curve with no spring and no
89
+ * overshoot, a short ease in and a long ease out, the values of Vaul's Dynamic Drawer. Drag releases, opening and closing
90
+ * use the spring.
91
+ */
92
+ export const SHEET_RESIZE = { duration: 270, curve: [0.26, 0.08, 0.25, 1] };
93
+ /** Invalid fixed detents are programmer errors, before they reach either sheet backend. */
94
+ export function validateSnapPoints(points, initialIndex = 0) {
95
+ if (!points.length)
96
+ throw new Error('GestureSheet requires at least one snap point.');
97
+ if (!Number.isInteger(initialIndex) || initialIndex < 0)
98
+ throw new RangeError('GestureSheet initialIndex must be a nonnegative integer.');
99
+ for (const point of points) {
100
+ const percent = typeof point === 'string';
101
+ const value = percent ? Number(point.slice(0, -1)) : point;
102
+ if ((percent && !/^\d+(?:\.\d+)?%$/.test(point)) || !Number.isFinite(value) || value <= 0 || (percent && value > 100))
103
+ throw new RangeError('GestureSheet snap points must be positive finite points or percentages up to 100%.');
104
+ }
105
+ }
@@ -0,0 +1,82 @@
1
+ import React from 'react';
2
+ import { Text as RNText, TextInput, View, type StyleProp, type ViewStyle } from 'react-native';
3
+ import Reanimated from 'react-native-reanimated';
4
+ import { type SheetSnapPoint } from './gesture-sheet-model.js';
5
+ export type { SheetSnapPoint } from './gesture-sheet-model.js';
6
+ type FocusTarget = React.ComponentRef<typeof View> | React.ComponentRef<typeof RNText> | React.ComponentRef<typeof TextInput> | null;
7
+ interface SheetCommonProps {
8
+ open: boolean;
9
+ onOpenChange: (open: boolean) => void;
10
+ /** Names the sheet. Drawn as the heading in default mode; in custom mode it is read by assistive technology unless `titleRef` points at the host's own heading. */
11
+ title: string;
12
+ description?: string;
13
+ children: React.ReactNode;
14
+ /** Default anatomy scrolls the title, description, content and a Close action. Custom content owns layout, scrolling and its own way out. */
15
+ contentMode?: 'default' | 'custom';
16
+ /** In custom mode, the host's accessible title. It takes accessibility focus when the sheet opens. */
17
+ titleRef?: React.RefObject<FocusTarget>;
18
+ /** Takes accessibility focus back when the sheet has closed. */
19
+ returnFocusRef?: React.RefObject<FocusTarget>;
20
+ /** `nativeID` of a heading inside the sheet that names it (Android `accessibilityLabelledBy`). Same prop as web. */
21
+ labelledBy?: string;
22
+ /** Close button text and accessible name; defaults to HIGProvider `messages.close`. */
23
+ closeLabel?: string;
24
+ /** `false` blocks every dismissal the user can start: drag, backdrop press, Android Back and the accessibility escape. Default `true`. */
25
+ dismissible?: boolean;
26
+ /** Modal draws in the nearest `GestureSheetHost`, above the screen. Inline draws where it is rendered and keeps its children mounted while closed. */
27
+ presentation?: 'modal' | 'inline';
28
+ /** Called once after an accepted dismissal has finished moving. */
29
+ onDismiss?: () => void;
30
+ /** Called with the detent index (0 is the lowest) each time the sheet settles on one. */
31
+ onChange?: (index: number) => void;
32
+ /** Return true to consume Android Back, or false to leave it to another handler. Omit for default dismissal. */
33
+ onHardwareBackPress?: () => boolean;
34
+ /** Room kept clear above the sheet, and padding under its content so nothing sits behind the home indicator. Default to the safe-area insets; pass `bottomInset={0}` for content that runs to the edge. */
35
+ topInset?: number;
36
+ bottomInset?: number;
37
+ /** Draws the drag handle. Default `true`. The whole sheet drags either way. */
38
+ handle?: boolean;
39
+ /** Merged over the sheet's fill, radius and clipping. */
40
+ backgroundStyle?: StyleProp<ViewStyle>;
41
+ /** Content sits one elevation up, so wells and rows step up a shade on the `overlay` fill. Pass `false` when `backgroundStyle` paints the page background. Default `true`. */
42
+ raised?: boolean;
43
+ /** Scales the modal scrim behind the sheet (the same scrim as Dialog), 0 to 1. Default 1; 0 draws none and lets presses through. */
44
+ backdropOpacity?: number;
45
+ /** Prefix of the test IDs: `<testID>`, `-backdrop`, `-surface`, `-handle` and `-content`. */
46
+ testID?: string;
47
+ }
48
+ export type GestureSheetProps = SheetCommonProps & (
49
+ /** Fixed detents, as points or a percentage of the room under `topInset`. Sorted for you; `initialIndex` counts from the lowest. */
50
+ {
51
+ enableDynamicSizing?: false;
52
+ snapPoints: readonly SheetSnapPoint[];
53
+ initialIndex?: number;
54
+ maxDynamicContentSize?: never;
55
+ }
56
+ /** One detent as tall as the content, up to `maxDynamicContentSize` points (default: all the room). */
57
+ | {
58
+ enableDynamicSizing: true;
59
+ snapPoints?: never;
60
+ initialIndex?: never;
61
+ maxDynamicContentSize?: number;
62
+ });
63
+ /**
64
+ * Where modal sheets draw: wrap the screen (inside GestureHandlerRootView and SafeAreaProvider) once. Sheets render in a
65
+ * layer over its children, so they cover the tab bar and anything else inside it. Without a host a modal sheet draws in place.
66
+ */
67
+ export declare function GestureSheetHost({ children, style }: {
68
+ children: React.ReactNode;
69
+ style?: StyleProp<ViewStyle>;
70
+ }): React.JSX.Element;
71
+ /**
72
+ * A ScrollView that shares the drag with its sheet: at the top detent it scrolls, and a pull down from the top of the
73
+ * content moves the sheet; below the top detent the drag moves the sheet and the content stays put. Outside a sheet it is a
74
+ * plain ScrollView. Bounce and overscroll are off so the content cannot move while the sheet does.
75
+ */
76
+ export declare const GestureSheetScrollView: React.ForwardRefExoticComponent<Omit<import("react-native-reanimated").AnimatedScrollViewProps, "ref"> & React.RefAttributes<Reanimated.ScrollView>>;
77
+ /**
78
+ * HIG's own sheet, one engine for iOS and Android: Reanimated moves it and Gesture Handler reads the finger, both on the UI
79
+ * thread. While it moves only a transform and the backdrop's opacity change, so content of any weight costs no layout per frame.
80
+ * Host supplies GestureHandlerRootView, SafeAreaProvider and, for modal sheets, GestureSheetHost.
81
+ */
82
+ export declare const GestureSheet: React.MemoExoticComponent<(props: GestureSheetProps) => React.JSX.Element | null>;