@bloxwap/hig 0.5.2 → 0.7.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 (199) hide show
  1. package/README.md +1 -1
  2. package/chart/README.md +1 -1
  3. package/contracts/README.md +1 -1
  4. package/contracts/dist/index.d.ts +16 -0
  5. package/contracts/dist/index.js +22 -0
  6. package/contracts/dist/messages.d.ts +37 -4
  7. package/contracts/dist/messages.js +13 -2
  8. package/feedback/README.md +1 -1
  9. package/native/README.md +1 -1
  10. package/native/dist/account-block.d.ts +92 -0
  11. package/native/dist/account-block.js +61 -0
  12. package/native/dist/animated-number-model.d.ts +7 -1
  13. package/native/dist/animated-number-model.js +50 -1
  14. package/native/dist/animated-number.d.ts +3 -1
  15. package/native/dist/animated-number.js +8 -5
  16. package/native/dist/asset-balance-row.d.ts +36 -0
  17. package/native/dist/asset-balance-row.js +26 -0
  18. package/native/dist/bar-mark.d.ts +57 -0
  19. package/native/dist/bar-mark.js +48 -0
  20. package/native/dist/bar-pnl.d.ts +50 -0
  21. package/native/dist/bar-pnl.js +60 -0
  22. package/native/dist/blocks.d.ts +38 -0
  23. package/native/dist/blocks.js +42 -0
  24. package/native/dist/button.js +3 -1
  25. package/native/dist/data.d.ts +1 -1
  26. package/native/dist/data.js +6 -4
  27. package/native/dist/field.d.ts +14 -5
  28. package/native/dist/field.js +33 -8
  29. package/native/dist/figure.d.ts +23 -0
  30. package/native/dist/figure.js +10 -0
  31. package/native/dist/icons.d.ts +8 -0
  32. package/native/dist/icons.js +4 -0
  33. package/native/dist/language-block.d.ts +35 -0
  34. package/native/dist/language-block.js +30 -0
  35. package/native/dist/list-group.d.ts +60 -0
  36. package/native/dist/list-group.js +85 -0
  37. package/native/dist/manage-position-block.d.ts +95 -0
  38. package/native/dist/manage-position-block.js +82 -0
  39. package/native/dist/market-row.d.ts +46 -0
  40. package/native/dist/market-row.js +30 -0
  41. package/native/dist/notifications-block.d.ts +53 -0
  42. package/native/dist/notifications-block.js +22 -0
  43. package/native/dist/pickers.d.ts +35 -5
  44. package/native/dist/pickers.js +21 -9
  45. package/native/dist/position-block.d.ts +107 -0
  46. package/native/dist/position-block.js +55 -0
  47. package/native/dist/profile-block.d.ts +66 -0
  48. package/native/dist/profile-block.js +48 -0
  49. package/native/dist/provider.d.ts +9 -3
  50. package/native/dist/provider.js +7 -3
  51. package/native/dist/radio-group.d.ts +9 -3
  52. package/native/dist/radio-group.js +4 -5
  53. package/native/dist/recipes.d.ts +6 -46
  54. package/native/dist/recipes.js +6 -33
  55. package/native/dist/reward-block.d.ts +122 -0
  56. package/native/dist/reward-block.js +53 -0
  57. package/native/dist/screen-header.d.ts +49 -0
  58. package/native/dist/screen-header.js +29 -0
  59. package/native/dist/selection.d.ts +2 -2
  60. package/native/dist/setting-header.d.ts +2 -0
  61. package/native/dist/setting-header.js +2 -0
  62. package/native/dist/setting-switch.d.ts +31 -0
  63. package/native/dist/setting-switch.js +20 -0
  64. package/native/dist/signals-block.d.ts +61 -0
  65. package/native/dist/signals-block.js +26 -0
  66. package/native/dist/sound-haptics-block.d.ts +66 -0
  67. package/native/dist/sound-haptics-block.js +32 -0
  68. package/native/dist/status.d.ts +6 -5
  69. package/native/dist/status.js +5 -5
  70. package/native/dist/sticky-header.d.ts +28 -0
  71. package/native/dist/sticky-header.js +21 -0
  72. package/native/dist/surface.d.ts +3 -1
  73. package/native/dist/surface.js +2 -1
  74. package/native/dist/{swap-panel.d.ts → swap-panel-block.d.ts} +8 -3
  75. package/native/dist/{swap-panel.js → swap-panel-block.js} +13 -8
  76. package/native/dist/swap-parts.d.ts +5 -3
  77. package/native/dist/swap-parts.js +2 -2
  78. package/native/dist/swap-shared.d.ts +6 -0
  79. package/native/dist/swap-sheet.d.ts +4 -4
  80. package/native/dist/swap-sheet.js +4 -4
  81. package/native/dist/swap-views.d.ts +1 -1
  82. package/native/dist/swap-views.js +9 -7
  83. package/native/dist/switch-row.d.ts +3 -2
  84. package/native/dist/switch-row.js +5 -3
  85. package/native/dist/switch.d.ts +4 -2
  86. package/native/dist/switch.js +3 -3
  87. package/native/dist/target-block.d.ts +110 -0
  88. package/native/dist/target-block.js +74 -0
  89. package/native/dist/token-action-block.d.ts +47 -0
  90. package/native/dist/token-action-block.js +28 -0
  91. package/native/dist/trade-history-detail-block.d.ts +84 -0
  92. package/native/dist/trade-history-detail-block.js +46 -0
  93. package/native/dist/trade-history-list-block.d.ts +110 -0
  94. package/native/dist/trade-history-list-block.js +64 -0
  95. package/native/dist/wallet-address-core.d.ts +25 -0
  96. package/native/dist/wallet-address-core.js +31 -0
  97. package/native/dist/wallet-address.d.ts +6 -10
  98. package/native/dist/wallet-address.js +16 -20
  99. package/native-fonts/README.md +1 -1
  100. package/og-fonts/README.md +1 -1
  101. package/package.json +266 -41
  102. package/react/README.md +1 -1
  103. package/react/dist/animated-number-model.d.ts +6 -0
  104. package/react/dist/animated-number-model.js +33 -0
  105. package/react/dist/animated-number.d.ts +5 -1
  106. package/react/dist/animated-number.js +12 -8
  107. package/react/dist/asset-balance-row.d.ts +35 -0
  108. package/react/dist/asset-balance-row.js +18 -0
  109. package/react/dist/bar-mark.d.ts +38 -0
  110. package/react/dist/bar-mark.js +23 -0
  111. package/react/dist/bar-pnl.d.ts +49 -0
  112. package/react/dist/bar-pnl.js +45 -0
  113. package/react/dist/blocks/account-block.d.ts +92 -0
  114. package/react/dist/blocks/account-block.js +62 -0
  115. package/react/dist/blocks/language-block.d.ts +36 -0
  116. package/react/dist/blocks/language-block.js +52 -0
  117. package/react/dist/blocks/manage-position-block.d.ts +93 -0
  118. package/react/dist/blocks/manage-position-block.js +47 -0
  119. package/react/dist/blocks/market-row.d.ts +36 -0
  120. package/react/dist/blocks/market-row.js +16 -0
  121. package/react/dist/blocks/notifications-block.d.ts +46 -0
  122. package/react/dist/blocks/notifications-block.js +17 -0
  123. package/react/dist/{recipes → blocks}/pickers.d.ts +32 -4
  124. package/react/dist/{recipes → blocks}/pickers.js +35 -11
  125. package/react/dist/blocks/position-block.d.ts +72 -0
  126. package/react/dist/blocks/position-block.js +25 -0
  127. package/react/dist/blocks/profile-block.d.ts +71 -0
  128. package/react/dist/blocks/profile-block.js +41 -0
  129. package/react/dist/blocks/reward-block.d.ts +120 -0
  130. package/react/dist/blocks/reward-block.js +34 -0
  131. package/react/dist/blocks/screen-header.d.ts +33 -0
  132. package/react/dist/blocks/screen-header.js +20 -0
  133. package/react/dist/blocks/setting-switch.d.ts +23 -0
  134. package/react/dist/blocks/setting-switch.js +12 -0
  135. package/react/dist/blocks/signals-block.d.ts +54 -0
  136. package/react/dist/blocks/signals-block.js +15 -0
  137. package/react/dist/blocks/sound-haptics-block.d.ts +59 -0
  138. package/react/dist/blocks/sound-haptics-block.js +22 -0
  139. package/react/dist/blocks/sticky-header.d.ts +9 -0
  140. package/react/dist/blocks/sticky-header.js +43 -0
  141. package/react/dist/blocks/swap/amount-card.js +8 -0
  142. package/react/dist/{recipes → blocks}/swap/picker.d.ts +1 -1
  143. package/react/dist/{recipes → blocks}/swap/picker.js +4 -4
  144. package/react/dist/{recipes → blocks}/swap/settings.js +2 -2
  145. package/react/dist/{recipes → blocks}/swap/shared.d.ts +8 -1
  146. package/react/dist/{recipes → blocks}/swap/shared.js +7 -4
  147. package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +8 -2
  148. package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +9 -7
  149. package/react/dist/{recipes → blocks}/swap-sheet.d.ts +4 -4
  150. package/react/dist/{recipes → blocks}/swap-sheet.js +4 -4
  151. package/react/dist/blocks/target-block.d.ts +103 -0
  152. package/react/dist/blocks/target-block.js +73 -0
  153. package/react/dist/blocks/token-action-block.d.ts +46 -0
  154. package/react/dist/blocks/token-action-block.js +21 -0
  155. package/react/dist/{recipes → blocks}/trade-entry.js +2 -2
  156. package/react/dist/blocks/trade-history-detail-block.d.ts +78 -0
  157. package/react/dist/blocks/trade-history-detail-block.js +17 -0
  158. package/react/dist/blocks/trade-history-list-block.d.ts +67 -0
  159. package/react/dist/blocks/trade-history-list-block.js +28 -0
  160. package/react/dist/blocks.d.ts +20 -0
  161. package/react/dist/blocks.js +21 -0
  162. package/react/dist/button.js +6 -4
  163. package/react/dist/data.js +3 -3
  164. package/react/dist/field.d.ts +14 -6
  165. package/react/dist/field.js +19 -8
  166. package/react/dist/figure.d.ts +23 -0
  167. package/react/dist/figure.js +12 -0
  168. package/react/dist/list-group.d.ts +59 -0
  169. package/react/dist/list-group.js +52 -0
  170. package/react/dist/provider.d.ts +40 -3
  171. package/react/dist/provider.js +63 -6
  172. package/react/dist/selection.d.ts +8 -2
  173. package/react/dist/selection.js +11 -6
  174. package/react/dist/styles.css +425 -5
  175. package/react/dist/surface.d.ts +5 -1
  176. package/react/dist/surface.js +1 -1
  177. package/react/dist/wallet-address-core.d.ts +23 -0
  178. package/react/dist/wallet-address-core.js +24 -0
  179. package/react/dist/wallet-address.d.ts +6 -12
  180. package/react/dist/wallet-address.js +5 -16
  181. package/tokens/README.md +1 -1
  182. package/react/dist/recipes/activity-list.d.ts +0 -8
  183. package/react/dist/recipes/activity-list.js +0 -6
  184. package/react/dist/recipes/balance-card.d.ts +0 -6
  185. package/react/dist/recipes/balance-card.js +0 -5
  186. package/react/dist/recipes/code-window.d.ts +0 -4
  187. package/react/dist/recipes/code-window.js +0 -4
  188. package/react/dist/recipes/market-row.d.ts +0 -25
  189. package/react/dist/recipes/market-row.js +0 -8
  190. package/react/dist/recipes/swap/amount-card.js +0 -7
  191. package/react/dist/recipes.d.ts +0 -10
  192. package/react/dist/recipes.js +0 -11
  193. /package/react/dist/{recipes → blocks}/install-command.d.ts +0 -0
  194. /package/react/dist/{recipes → blocks}/install-command.js +0 -0
  195. /package/react/dist/{recipes → blocks}/marketing-hero.d.ts +0 -0
  196. /package/react/dist/{recipes → blocks}/marketing-hero.js +0 -0
  197. /package/react/dist/{recipes → blocks}/swap/amount-card.d.ts +0 -0
  198. /package/react/dist/{recipes → blocks}/swap/settings.d.ts +0 -0
  199. /package/react/dist/{recipes → blocks}/trade-entry.d.ts +0 -0
@@ -0,0 +1,48 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React, { useContext } from 'react';
3
+ import { View } from 'react-native';
4
+ import { formatNumber } from '@bloxwap/hig/contracts';
5
+ import { useColors, useFills, useHIG, useNumberLocale, usePresentNumber } from './provider.js';
6
+ import { figureReading } from './figure.js';
7
+ import { Surface, Text } from './surface.js';
8
+ export const BarMarkFigureContext = React.createContext(null);
9
+ /** The order segments take their colour in when an element names neither `tone` nor `color`. */
10
+ export const barMarkTones = ['positive', 'info', 'warning', 'negative', 'muted', 'faint'];
11
+ const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
12
+ /** Each element's clamped value and its share of the whole, plus the unfilled remainder in the same unit. */
13
+ export function barMarkShares(elements, total) {
14
+ const values = elements.map(element => Number.isFinite(element.value) && element.value > 0 ? element.value : 0), sum = values.reduce((a, b) => a + b, 0);
15
+ const whole = Math.max(typeof total === 'number' && Number.isFinite(total) ? total : sum, sum);
16
+ return { values, shares: values.map(value => whole > 0 ? value / whole : 0), rest: whole > 0 ? whole - sum : 1 };
17
+ }
18
+ // A component of its own so the track reads the raised fill of whatever it sits on: one step above the card inside the Surface, one step above the page without it.
19
+ function Bar({ elements, values, rest, colors, small, testID }) {
20
+ const track = useFills().raised;
21
+ return _jsxs(View, { ...hidden, testID: testID ? `${testID}-bar` : undefined, style: { flexDirection: 'row', height: small ? 12 : 24, borderRadius: small ? 6 : 8, overflow: 'hidden', gap: 2 }, children: [elements.map((element, index) => values[index] > 0 ? _jsx(View, { testID: testID ? `${testID}-segment-${element.id ?? index}` : undefined, style: { flexGrow: values[index], flexShrink: 1, flexBasis: 0, minWidth: 3, backgroundColor: colors[index] } }, element.id ?? index) : null), rest > 0 ? _jsx(View, { testID: testID ? `${testID}-track` : undefined, style: { flexGrow: rest, flexShrink: 1, flexBasis: 0, backgroundColor: track } }) : null] });
22
+ }
23
+ /**
24
+ * One horizontally stacked bar on a card: the title leads and the description trails, the bar splits into a segment per
25
+ * element in proportion to its value, and a legend names each colour. The bar is decorative; each legend item reads its
26
+ * label, detail and share. Layout follows the provider's direction.
27
+ */
28
+ export function BarMark({ title, description, elements, total, legend = true, size = 'default', surface = true, testID }) {
29
+ const { direction } = useHIG();
30
+ const locale = useNumberLocale(), palette = useColors(), present = usePresentNumber(), renderFigure = useContext(BarMarkFigureContext);
31
+ const { values, shares, rest } = barMarkShares(elements, total);
32
+ const colors = elements.map((element, index) => element.color ?? palette[element.tone ?? barMarkTones[index % barMarkTones.length]]);
33
+ const detailText = (detail) => detail == null || typeof detail === 'string' ? detail : figureReading(detail, locale, present(detail.options));
34
+ const reading = (element, index) => [element.label, detailText(element.detail), formatNumber(shares[index], locale, { style: 'percent', maximumFractionDigits: 1 })].filter(Boolean).join(', ');
35
+ const detailStyle = { color: palette.faint, fontSize: 14, lineHeight: 21 };
36
+ const detail = (element, index) => {
37
+ const value = element.detail;
38
+ if (!value)
39
+ return null;
40
+ const id = testID ? `${testID}-detail-${element.id ?? index}` : undefined;
41
+ if (typeof value === 'string')
42
+ return _jsx(Text, { style: detailStyle, children: value });
43
+ return renderFigure ? renderFigure(value, { testID: id }) : _jsx(Text, { testID: id, style: detailStyle, children: detailText(value) });
44
+ };
45
+ const group = legend ? {} : { accessible: true, accessibilityLabel: [title, ...elements.map(reading)].join(', ') };
46
+ const content = _jsxs(_Fragment, { children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [_jsx(Text, { style: { fontSize: 16, lineHeight: 24, fontWeight: '600', flexShrink: 1 }, children: title }), description == null || description === false ? null : typeof description === 'string' || typeof description === 'number' ? _jsx(Text, { style: { color: palette.muted, fontSize: 14, lineHeight: 21, flexShrink: 1 }, children: description }) : description] }), _jsx(Bar, { elements: elements, values: values, rest: rest, colors: colors, small: size === 'small', testID: testID }), legend ? _jsx(View, { style: { flexDirection: 'row', flexWrap: 'wrap', columnGap: 16, rowGap: 8 }, children: elements.map((element, index) => _jsxs(View, { accessible: true, accessibilityLabel: reading(element, index), testID: testID ? `${testID}-legend-${element.id ?? index}` : undefined, style: { flexDirection: 'row', alignItems: 'center', gap: 6 }, children: [_jsx(View, { style: { width: 8, height: 8, borderRadius: 4, backgroundColor: colors[index] } }), _jsx(Text, { style: { color: palette.muted, fontSize: 14, lineHeight: 21 }, children: element.label }), detail(element, index)] }, element.id ?? index)) }) : null] });
47
+ return surface ? _jsx(Surface, { testID: testID, style: { gap: 12 }, ...group, children: content }) : _jsx(View, { testID: testID, style: { direction, gap: 12, minWidth: 0 }, ...group, children: content });
48
+ }
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ export type BarPnlSide = 'long' | 'short';
3
+ export type BarPnlResult = 'profit' | 'loss' | 'flat';
4
+ export type BarPnlKind = 'liquidation' | 'mark' | 'entry';
5
+ export interface BarPnlProps {
6
+ /** Price the position was opened at. */
7
+ entry: number;
8
+ /** Current mark price. `null` or omitted reads as unknown and draws no profit or loss. */
9
+ mark?: number | null;
10
+ /** Liquidation price. Omit it, or pass `null`, for a position that cannot be liquidated. */
11
+ liquidation?: number | null;
12
+ /** Direction of the position. Defaults to `long` when the liquidation price is below entry (or unknown) and `short` when it is above. */
13
+ side?: BarPnlSide;
14
+ /** Host text for the three prices, for example `{liquidation:'Liquidation',mark:'Mark',entry:'Entry'}`. HIG ships no trading terms of its own. */
15
+ labels: Record<BarPnlKind, string>;
16
+ /** Heading on the leading edge above the bar, such as `BTC Long 10×`. */
17
+ title?: string;
18
+ /** Trailing text on the title row, such as the profit or loss in dollars. A string is drawn muted; an element is rendered as given. */
19
+ description?: React.ReactNode;
20
+ /** Format of the three prices. Defaults to US dollars. */
21
+ priceOptions?: Intl.NumberFormatOptions;
22
+ /** Shortens the three prices for narrow screens: `$64,700` for `$64,700.00`, `$142.96`, `$0.4821`. Trailing zeros are dropped. Default `false`. */
23
+ compact?: boolean;
24
+ /** Scales the bar to the prices themselves, so the stretch from entry to mark fills it. For a finished trade, where the move is the whole story. Default `false`. */
25
+ fit?: boolean;
26
+ /** Set false to draw no card: no surface fill, padding or radius. The title row, bar and readouts keep their spacing. Default `true`. */
27
+ surface?: boolean;
28
+ testID?: string;
29
+ }
30
+ /** Price format for `compact`: no fraction at 1,000 and above, at most two fraction digits from 1, and four significant digits below 1, with trailing zeros dropped. Host `priceOptions` (such as the currency) are kept. */
31
+ export declare function barPnlCompactOptions(value: number | null | undefined, base?: Intl.NumberFormatOptions): Intl.NumberFormatOptions;
32
+ /**
33
+ * Where each price sits on the bar, as a fraction of its width from the low-price edge, the readouts in price order, and
34
+ * whether the position is in profit. With a liquidation price the bar runs from it to the same distance on the other side
35
+ * of entry, so entry sits in the middle; a mark beyond either end stretches the bar. Without one the bar is centred on entry.
36
+ */
37
+ export declare function barPnlLayout({ entry, mark, liquidation, side, fit }: {
38
+ entry: number;
39
+ mark?: number | null;
40
+ liquidation?: number | null;
41
+ side?: BarPnlSide;
42
+ fit?: boolean;
43
+ }): {
44
+ side: BarPnlSide;
45
+ result: BarPnlResult;
46
+ positions: Partial<Record<BarPnlKind, number>>;
47
+ order: BarPnlKind[];
48
+ };
49
+ /** A position's profit or loss as one bar: the stretch between entry and mark is filled solid in the result colour, a tick marks each price, and the liquidation, mark and entry prices read under the bar in price order, so mark and entry trade places as the position moves. The bar is decorative; each readout reads its label and price. */
50
+ export declare function BarPnl({ entry, mark, liquidation, side, labels, title, description, priceOptions, compact, fit, surface, testID }: BarPnlProps): React.JSX.Element;
@@ -0,0 +1,60 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { View } from 'react-native';
3
+ import { useColors, useFills, useHIG, useNumberLocale, usePresentNumber } from './provider.js';
4
+ import { Surface, Text } from './surface.js';
5
+ import { AnimatedNumberReadout } from './animated-number.js';
6
+ import { formatNumberReadout } from './animated-number-model.js';
7
+ const usd = { style: 'currency', currency: 'USD' };
8
+ const finite = (value) => typeof value === 'number' && Number.isFinite(value);
9
+ const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
10
+ /** Price format for `compact`: no fraction at 1,000 and above, at most two fraction digits from 1, and four significant digits below 1, with trailing zeros dropped. Host `priceOptions` (such as the currency) are kept. */
11
+ export function barPnlCompactOptions(value, base = usd) {
12
+ const size = finite(value) ? Math.abs(value) : 0;
13
+ return size > 0 && size < 1 ? { ...base, minimumFractionDigits: undefined, maximumFractionDigits: undefined, maximumSignificantDigits: 4 } : { ...base, minimumFractionDigits: 0, maximumFractionDigits: size >= 1000 ? 0 : 2 };
14
+ }
15
+ /**
16
+ * Where each price sits on the bar, as a fraction of its width from the low-price edge, the readouts in price order, and
17
+ * whether the position is in profit. With a liquidation price the bar runs from it to the same distance on the other side
18
+ * of entry, so entry sits in the middle; a mark beyond either end stretches the bar. Without one the bar is centred on entry.
19
+ */
20
+ export function barPnlLayout({ entry, mark, liquidation, side, fit }) {
21
+ const liq = finite(liquidation) ? liquidation : null;
22
+ const direction = side ?? (liq !== null && liq > entry ? 'short' : 'long');
23
+ const result = !finite(entry) || !finite(mark) || mark === entry ? 'flat' : (mark > entry) === (direction === 'long') ? 'profit' : 'loss';
24
+ if (!finite(entry))
25
+ return { side: direction, result, positions: {}, order: [] };
26
+ const price = finite(mark) ? mark : entry;
27
+ const reach = liq !== null ? Math.abs(entry - liq) : Math.max(Math.abs(price - entry) * 2, Math.abs(entry) * 0.01, Number.MIN_VALUE);
28
+ // `fit` scales the bar to the prices themselves, so the stretch from entry to mark fills it.
29
+ const points = liq !== null ? [entry, price, liq] : [entry, price];
30
+ const low = fit ? Math.min(...points) : Math.min(entry - reach, price), high = fit ? Math.max(...points) : Math.max(entry + reach, price), span = high - low;
31
+ const at = (value) => span > 0 ? Math.min(1, Math.max(0, (value - low) / span)) : 0.5;
32
+ const positions = { entry: at(entry), mark: at(price) };
33
+ if (liq !== null)
34
+ positions.liquidation = at(liq);
35
+ // Ties keep liquidation outermost and put mark on the side it would move to next.
36
+ const rank = { liquidation: direction === 'long' ? 0 : 2, entry: 1, mark: direction === 'long' ? (result === 'loss' ? 0.5 : 1.5) : (result === 'loss' ? 1.5 : 0.5) };
37
+ const values = { liquidation: liq ?? 0, entry, mark: price };
38
+ const order = Object.keys(positions).sort((a, b) => values[a] - values[b] || rank[a] - rank[b]);
39
+ return { side: direction, result, positions, order };
40
+ }
41
+ /** A position's profit or loss as one bar: the stretch between entry and mark is filled solid in the result colour, a tick marks each price, and the liquidation, mark and entry prices read under the bar in price order, so mark and entry trade places as the position moves. The bar is decorative; each readout reads its label and price. */
42
+ export function BarPnl({ entry, mark, liquidation, side, labels, title, description, priceOptions = usd, compact = false, fit = false, surface = true, testID }) {
43
+ const colors = useColors(), { direction } = useHIG(), locale = useNumberLocale(), present = usePresentNumber();
44
+ const { result, positions, order } = barPnlLayout({ entry, mark, liquidation, side, fit });
45
+ // The result follows the market direction roles (HIGProvider marketColors), which default to buy and sell.
46
+ const tone = result === 'profit' ? colors.up : result === 'loss' ? colors.down : colors.muted;
47
+ const from = Math.min(positions.entry ?? 0.5, positions.mark ?? 0.5), to = Math.max(positions.entry ?? 0.5, positions.mark ?? 0.5);
48
+ const markLeads = (positions.mark ?? 0) < (positions.entry ?? 0);
49
+ const values = { liquidation, mark, entry };
50
+ const format = (kind) => compact ? barPnlCompactOptions(values[kind], priceOptions) : priceOptions;
51
+ const align = (index) => order.length > 1 && index === order.length - 1 ? 'flex-end' : order.length === 3 && index === 1 ? 'center' : 'flex-start';
52
+ const content = _jsxs(_Fragment, { children: [title || description != null ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [title ? _jsx(Text, { accessibilityRole: 'header', style: { fontSize: 16, lineHeight: 24, fontWeight: '600', flexShrink: 1 }, children: title }) : _jsx(View, {}), description == null || description === false ? null : typeof description === 'string' || typeof description === 'number' ? _jsx(Text, { style: { color: colors.muted, fontSize: 14, lineHeight: 21, flexShrink: 1 }, children: description }) : description] }) : null, _jsx(Bar, { from: from, to: to, markLeads: markLeads, tone: tone, liquidation: positions.liquidation, testID: testID }), _jsx(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: order.map((kind, index) => _jsxs(View, { accessible: true, accessibilityLabel: `${labels[kind]}, ${formatNumberReadout(values[kind], locale, present(format(kind))).text}`, testID: testID ? `${testID}-${kind}` : undefined, style: { alignItems: align(index), flexShrink: 1, minWidth: 0 }, children: [_jsx(View, { ...hidden, children: _jsx(AnimatedNumberReadout, { value: values[kind], options: format(kind), tone: kind === 'liquidation' ? 'negative' : kind === 'mark' && result !== 'flat' ? (result === 'profit' ? 'up' : 'down') : 'text', style: { fontSize: 16, lineHeight: 24, fontWeight: '600' } }) }), _jsx(Text, { ...hidden, numberOfLines: 1, style: { color: colors.muted, fontSize: 12, lineHeight: 16 }, children: labels[kind] })] }, kind)) })] });
53
+ return surface ? _jsx(Surface, { testID: testID, style: { gap: 12 }, children: content }) : _jsx(View, { testID: testID, style: { direction, gap: 12, minWidth: 0 }, children: content });
54
+ }
55
+ // Inside the Surface, so the track takes the fill that sits one step above the card.
56
+ function Bar({ from, to, markLeads, tone, liquidation, testID }) {
57
+ const colors = useColors(), track = useFills().raised;
58
+ const part = (grow) => ({ flexGrow: grow, flexShrink: 1, flexBasis: 0, backgroundColor: track });
59
+ return _jsxs(View, { ...hidden, testID: testID ? `${testID}-bar` : undefined, style: { flexDirection: 'row', height: 24, borderRadius: 8, overflow: 'hidden' }, children: [_jsx(View, { style: part(from) }), _jsx(View, { testID: testID ? `${testID}-move` : undefined, style: { flexGrow: to - from, flexShrink: 1, flexBasis: 0, minWidth: 6, backgroundColor: tone, borderStartWidth: 3, borderEndWidth: 3, borderStartColor: markLeads ? tone : colors.text, borderEndColor: markLeads ? colors.text : tone } }), _jsx(View, { style: part(1 - to) }), liquidation === undefined ? null : _jsx(View, { testID: testID ? `${testID}-liquidation-tick` : undefined, style: { position: 'absolute', top: 0, bottom: 0, width: 3, start: `${liquidation * 100}%`, marginStart: liquidation <= 0 ? 0 : liquidation >= 1 ? -3 : -1.5, backgroundColor: colors.negative } })] });
60
+ }
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ export { MarketRow, type MarketRowProps } from './market-row.js';
3
+ export declare function TradeEntry({ asset, amount, onAmountChange, onConfirm, busy, error, available }: {
4
+ asset: string;
5
+ amount: string;
6
+ onAmountChange: (v: string) => void;
7
+ onConfirm: () => void;
8
+ busy?: boolean;
9
+ error?: string;
10
+ available: string;
11
+ }): React.JSX.Element;
12
+ /** A copy outcome shows as a transient toast capsule (about 4s, dismissible) and is announced the way Toast announces any notice. */
13
+ export declare function InstallCommand({ command, onCopy }: {
14
+ command: string;
15
+ onCopy: () => Promise<void> | void;
16
+ }): React.JSX.Element;
17
+ export declare function MarketingHero({ title, description, href, cta }: {
18
+ title: string;
19
+ description: string;
20
+ href: string;
21
+ cta: string;
22
+ }): React.JSX.Element;
23
+ export { AccountBlock, accountRows, accountSectionRows, accountSectionTotal, assetValue, AssetBalanceRow, type AccountBlockProps, type AccountAsset, type AccountSection, type AccountOrder, type AccountRowsOptions, type AssetArtwork, type AssetBalanceRowProps } from './account-block.js';
24
+ export { LanguageBlock, filterLanguages, type LanguageBlockProps, type LanguageOption } from './language-block.js';
25
+ export { TokenActionBlock, tokenActionLabel, type TokenActionBlockProps, type TokenAction, type TokenActionId } from './token-action-block.js';
26
+ export { ManagePositionBlock, positionCorridor, type ManagePositionBlockProps, type ManagePositionBlockLabels, type ManagePositionBlockAction, type ManagePositionBlockSummary, type ManagePositionBlockFigure, type ManagePositionIcon } from './manage-position-block.js';
27
+ export { TradeHistoryListBlock, tradeHistorySide, type TradeHistoryListBlockProps, type TradeHistoryListLabels, type TradeHistoryItem } from './trade-history-list-block.js';
28
+ export { TradeHistoryDetailBlock, type TradeHistoryDetailBlockProps, type TradeHistoryDetailLabels, type TradeHistoryDetail, type TradeHistoryAction } from './trade-history-detail-block.js';
29
+ export { TargetBlock, targetLayout, targetFormat, targetPresets, targetUnits, type TargetBlockProps, type TargetBlockLabels, type TargetKind, type TargetUnit, type TargetPrice, type TargetPreset, type TargetUnitOption } from './target-block.js';
30
+ export { ProfileBlock, type ProfileBlockProps, type ProfileRow, type ProfileSection, type ProfileStatus, type ProfileAction, type ProfileFigure } from './profile-block.js';
31
+ export { PositionBlock, PositionBlockHeader, type PositionBlockProps, type PositionBlockHeaderProps, type PositionBlockDetail, type PositionBlockFigure, type PositionBlockRow, type PositionBlockFlag, type PositionBlockFlagAction } from './position-block.js';
32
+ export { RewardBlock, rewardProgress, type RewardBlockProps, type RewardPromo, type RewardEntry } from './reward-block.js';
33
+ export { SoundHapticsBlock, soundLevel, type SoundHapticsBlockProps, type SoundSection, type SoundVolume, type SettingAction } from './sound-haptics-block.js';
34
+ export { SignalsBlock, type SignalsBlockProps, type SignalsGroup, type SignalsItem } from './signals-block.js';
35
+ export { NotificationsBlock, type NotificationsBlockProps, type NotificationsItem } from './notifications-block.js';
36
+ export { FromPickerBlock, ToPickerBlock, FromPicker, ToPicker, type FromPickerBlockProps, type ToPickerBlockProps, type FromPickerProps, type ToPickerProps, type PickerListProps, type PickerInputProps, SwapHostContext } from './pickers.js';
37
+ export { SwapKeypad, SwapCapsule } from './swap-parts.js';
38
+ export { SwapPanelBlock, SwapPanel, swapAction, type SwapPanelBlockProps, type SwapPanelProps, type SwapToken, type SwapArtwork, type SwapChain, type SwapAction, type SwapDenomination, type SwapWallet, type SwapFee, type SwapFigure, type SwapReceive, type SwapDestination, type SwapDetail, type SwapView } from './swap-panel-block.js';
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Platform } from 'react-native';
4
+ import * as en from '@bloxwap/hig/contracts/messages';
5
+ import { useHIG } from './provider.js';
6
+ import { Button, Link } from './button.js';
7
+ import { Surface, Stack, Heading, Text } from './surface.js';
8
+ import { Field, Input } from './field.js';
9
+ import { Dialog } from './overlay.js';
10
+ import { Toast, useTransientNotice } from './status.js';
11
+ export { MarketRow } from './market-row.js';
12
+ /** The call to action that closes a form sits a double step, 16dp, below it (the Stack gap is 12). */
13
+ const formAction = { marginTop: 4 };
14
+ /** In a dialog the confirm action is 16dp below the content and 8dp above the dialog's own closing button, which adds 4dp itself. */
15
+ const dialogAction = { marginTop: 4, marginBottom: -8 };
16
+ export function TradeEntry({ asset, amount, onAmountChange, onConfirm, busy, error, available }) { const { messages } = useHIG(); const [review, setReview] = useState(false); return _jsx(Surface, { children: _jsxs(Stack, { children: [_jsx(Heading, { children: (messages.reviewAssetOrder ?? en.reviewAssetOrder)(asset) }), _jsx(Field, { label: (messages.amountInAsset ?? en.amountInAsset)(asset), description: (messages.availableAmount ?? en.availableAmount)(available), error: error, children: _jsx(Input, { keyboardType: 'decimal-pad', value: amount, onChangeText: onAmountChange, editable: !busy }) }), _jsx(Button, { fullWidth: true, style: formAction, disabled: !amount || !!error, busy: busy, onPress: () => setReview(true), children: messages.reviewOrder ?? en.reviewOrder }), _jsxs(Dialog, { open: review, onOpenChange: setReview, title: messages.confirmOrder ?? en.confirmOrder, description: (messages.confirmOrderDescription ?? en.confirmOrderDescription)(amount, asset), children: [_jsx(Button, { busy: busy, disabled: !!error, style: dialogAction, onPress: onConfirm, children: messages.confirmOrder ?? en.confirmOrder }), error && _jsx(Text, { accessibilityLiveRegion: 'polite', children: error })] })] }) }); }
17
+ /** Code and commands stay monospace and left-to-right inside RTL roots. */
18
+ function useCodeStyle() { const env = useHIG(); return { fontFamily: env.monoFontFamily ?? Platform.select({ ios: 'Menlo', default: 'monospace' }), writingDirection: 'ltr', textAlign: 'left' }; }
19
+ /** A copy outcome shows as a transient toast capsule (about 4s, dismissible) and is announced the way Toast announces any notice. */
20
+ export function InstallCommand({ command, onCopy }) {
21
+ const { messages } = useHIG();
22
+ const { notice, show, dismiss } = useTransientNotice();
23
+ const code = useCodeStyle();
24
+ return _jsxs(Surface, { style: { gap: 12 }, children: [_jsx(Text, { selectable: true, style: code, children: command }), _jsx(Button, { intent: 'secondary', onPress: () => { Promise.resolve().then(onCopy).then(() => show(messages.copied ?? en.copied, 'success')).catch(() => show(messages.copyFailed ?? en.copyFailed, 'error')); }, children: messages.copyInstallCommand ?? en.copyInstallCommand }), notice && _jsx(Toast, { notices: [notice], onDismiss: dismiss })] });
25
+ }
26
+ export function MarketingHero({ title, description, href, cta }) { return _jsxs(Stack, { children: [_jsx(Heading, { children: title }), _jsx(Text, { children: description }), _jsx(Link, { href: href, children: cta })] }); }
27
+ export { AccountBlock, accountRows, accountSectionRows, accountSectionTotal, assetValue, AssetBalanceRow } from './account-block.js';
28
+ export { LanguageBlock, filterLanguages } from './language-block.js';
29
+ export { TokenActionBlock, tokenActionLabel } from './token-action-block.js';
30
+ export { ManagePositionBlock, positionCorridor } from './manage-position-block.js';
31
+ export { TradeHistoryListBlock, tradeHistorySide } from './trade-history-list-block.js';
32
+ export { TradeHistoryDetailBlock } from './trade-history-detail-block.js';
33
+ export { TargetBlock, targetLayout, targetFormat, targetPresets, targetUnits } from './target-block.js';
34
+ export { ProfileBlock } from './profile-block.js';
35
+ export { PositionBlock, PositionBlockHeader } from './position-block.js';
36
+ export { RewardBlock, rewardProgress } from './reward-block.js';
37
+ export { SoundHapticsBlock, soundLevel } from './sound-haptics-block.js';
38
+ export { SignalsBlock } from './signals-block.js';
39
+ export { NotificationsBlock } from './notifications-block.js';
40
+ export { FromPickerBlock, ToPickerBlock, FromPicker, ToPicker, SwapHostContext } from './pickers.js';
41
+ export { SwapKeypad, SwapCapsule } from './swap-parts.js';
42
+ export { SwapPanelBlock, SwapPanel, swapAction } from './swap-panel-block.js';
@@ -16,6 +16,8 @@ function labelRuns(children) { const runs = []; for (const child of React.Childr
16
16
  } return runs; }
17
17
  /** A 44dp control keeps a 48dp touch target. */
18
18
  const touchSlop = { top: 2, bottom: 2 };
19
+ /** An icon button is 44dp both ways, so its 48dp target reaches out on every side. */
20
+ const iconSlop = { top: 2, bottom: 2, left: 2, right: 2 };
19
21
  /** Android appends its localized busy state; including the suffix there would speak it twice. */
20
22
  export function busyAccessibilityLabel(text, busyText, os = Platform.OS) { return text ? (busyText && os !== 'android' ? `${text} · ${busyText}` : text) : undefined; }
21
23
  export const Button = /* @__PURE__ */ forwardRef(function Button({ children, contentMode = 'default', intent = 'primary', disabled, busy, busyLabel, maxFontSizeMultiplier, script, fullWidth, suppressFeedback, onPress, style, ...props }, ref) { const env = useHIG(); const colors = useColors(); const fills = useFills(); const id = useId(); const sequence = useRef(0); const busyText = busyLabel ?? env.messages.busy ?? en.busy; const filled = intent === 'primary' || intent === 'destructive'; /* Unavailable is neutral: a well fill and muted text. Busy keeps the intent colour under its spinner. */ /* Unavailable is neutral: a well fill and muted text. Busy keeps the intent colour under its spinner. */ const inert = !!disabled && !busy; const label = plainText(children); const accessibleLabel = props.accessibilityLabel ?? (busy ? busyAccessibilityLabel(label, busyText) : undefined); const labelStyle = { color: inert ? (intent === 'ghost' ? colors.faint : colors.muted) : intent === 'destructive' ? colors.background : intent === 'primary' ? colors.onAction : intent === 'ghost' ? colors.muted : colors.text, fontSize: 16, fontWeight: '600', textAlign: 'center' }; return _jsx(Pressable, { ...props, ref: ref, disabled: disabled || busy, accessibilityRole: 'button', accessibilityLabel: accessibleLabel, accessibilityState: { ...props.accessibilityState, disabled: !!disabled || !!busy, busy: !!busy }, "aria-busy": !!busy, onPress: e => { if (disabled || busy)
@@ -27,7 +29,7 @@ export const Button = /* @__PURE__ */ forwardRef(function Button({ children, con
27
29
  catch { /* Best effort only. */ }
28
30
  } }, hitSlop: props.hitSlop ?? touchSlop, style: state => [{ minHeight: 44, paddingHorizontal: 20, paddingVertical: 10, borderRadius: 9999, alignItems: 'center', justifyContent: 'center', backgroundColor: inert ? (intent === 'ghost' ? 'transparent' : fills.well) : filled ? (intent === 'destructive' ? colors.negative : colors.action) : intent === 'ghost' && !state.pressed ? 'transparent' : colors.nested, opacity: busy ? 0.7 : state.pressed && !inert ? 0.85 : 1, alignSelf: fullWidth ? 'stretch' : 'flex-start' }, typeof style === 'function' ? style(state) : style], children: contentMode === 'custom' ? children : _jsxs(View, { style: { direction: env.direction, flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'center', gap: 8 }, children: [busy ? _jsx(ActivityIndicator, { size: 'small', color: labelStyle.color, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' }) : null, labelRuns(children).map((child, i) => typeof child === 'string' ? _jsx(Text, { script: script, maxFontSizeMultiplier: maxFontSizeMultiplier, style: labelStyle, children: child }, `label-${i}`) : child)] }) }); });
29
31
  /** While busy, the spinner takes the icon's place. */
30
- export function IconButton({ label, children, style, ...props }) { return _jsx(Button, { ...props, accessibilityLabel: label, style: state => [{ minWidth: 44, paddingHorizontal: 10 }, typeof style === 'function' ? style(state) : style], children: props.busy && props.contentMode !== 'custom' ? null : children }); }
32
+ export function IconButton({ label, children, style, ...props }) { return _jsx(Button, { ...props, hitSlop: props.hitSlop ?? iconSlop, accessibilityLabel: label, style: state => [{ minWidth: 44, paddingHorizontal: 10 }, typeof style === 'function' ? style(state) : style], children: props.busy && props.contentMode !== 'custom' ? null : children }); }
31
33
  export const Link = /* @__PURE__ */ forwardRef(function Link({ href, children, onError, onPress, contentMode = 'default', disabled, style, ...props }, ref) { const colors = useColors(); const web = Platform.OS === 'web', webHref = web && !disabled ? { href } : {}; return _jsx(Pressable, { ...props, ...webHref, ref: ref, accessibilityRole: 'link', disabled: disabled, accessibilityState: { ...props.accessibilityState, disabled: !!disabled }, "aria-busy": props.accessibilityState?.busy, onPress: event => { if (disabled)
32
34
  return; if (onPress)
33
35
  onPress(event);
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { type StyleProp, type TextStyle } from 'react-native';
3
3
  /** `up`/`down` are market direction (rising/long/gain, falling/short/loss) and follow `HIGProvider marketColors`; `positive`/`negative` stay success/error. */
4
- export type NumberTone = 'text' | 'positive' | 'negative' | 'muted' | 'up' | 'down';
4
+ export type NumberTone = 'text' | 'positive' | 'negative' | 'warning' | 'muted' | 'faint' | 'up' | 'down';
5
5
  /** Typography only: semantic tone owns colour and numeric glyphs remain tabular. */
6
6
  export type NumberReadoutStyle = Pick<TextStyle, 'fontFamily' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing' | 'textAlign'>;
7
7
  export interface NumberProps {
@@ -2,19 +2,21 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
3
  import { FlatList, Platform, View, StyleSheet } from 'react-native';
4
4
  import { formatNumberReadout } from './animated-number-model.js';
5
+ import { presentNumberFormat } from '@bloxwap/hig/contracts';
5
6
  import * as en from '@bloxwap/hig/contracts/messages';
6
- import { useColors, useHIG } from './provider.js';
7
+ import { useColors, useHIG, useNumberLocale } from './provider.js';
7
8
  import { Text, Surface, Separator } from './surface.js';
8
9
  import { Button } from './button.js';
9
10
  const numberTypographyKeys = new Set(['fontFamily', 'fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'textAlign']);
10
11
  export function NumberReadout({ value, options, formattedValue, stale, label, tone = 'text', style, testID, maxFontSizeMultiplier, prefix, suffix }) {
11
- const { locale, messages } = useHIG();
12
+ const { messages, numberFormat } = useHIG();
13
+ const locale = useNumberLocale();
12
14
  const colors = useColors();
13
- const reading = formatNumberReadout(value, locale, options, formattedValue, prefix, suffix).text;
15
+ const reading = formatNumberReadout(value, locale, presentNumberFormat(options, numberFormat), formattedValue, prefix, suffix).text;
14
16
  const staleSuffix = stale ? ` ${messages.stale ?? en.stale}` : '';
15
17
  // Keep the same boundary for untyped hosts and registered/array styles: no raw colour, glyph or layout overrides.
16
18
  const typography = Object.fromEntries(Object.entries(StyleSheet.flatten(style) ?? {}).filter(([key]) => numberTypographyKeys.has(key)));
17
- const color = colors[tone === 'positive' || tone === 'negative' || tone === 'muted' || tone === 'up' || tone === 'down' ? tone : 'text'];
19
+ const color = colors[tone === 'positive' || tone === 'negative' || tone === 'warning' || tone === 'muted' || tone === 'faint' || tone === 'up' || tone === 'down' ? tone : 'text'];
18
20
  return _jsxs(Text, { accessibilityLabel: label ? `${label}: ${reading}${staleSuffix}` : undefined, testID: testID, maxFontSizeMultiplier: maxFontSizeMultiplier, style: [typography, { color, fontVariant: ['tabular-nums'] }], children: [reading, staleSuffix] });
19
21
  }
20
22
  export function Usd(props) { return _jsx(NumberReadout, { ...props, options: { style: 'currency', currency: 'USD', ...props.options } }); }
@@ -1,16 +1,25 @@
1
1
  import React from 'react';
2
2
  import { TextInput, type TextInputProps } from 'react-native';
3
3
  import { Text } from './surface.js';
4
- export declare function Field({ label, description, error, required, disabled, children }: React.PropsWithChildren<{
4
+ export interface FieldProps {
5
5
  label: string;
6
- description?: string;
6
+ description?: string; /** `positive` draws the description as a success line, such as a name that is available, and announces it when it changes. The words carry the meaning; the colour repeats it. */
7
+ descriptionTone?: 'muted' | 'positive';
7
8
  error?: string;
8
9
  required?: boolean;
9
10
  disabled?: boolean;
10
- }>): React.JSX.Element;
11
+ }
12
+ export declare function Field({ label, description, descriptionTone, error, required, disabled, children }: React.PropsWithChildren<FieldProps>): React.JSX.Element;
11
13
  export declare const Label: typeof Text;
12
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. */
13
15
  export declare const Input: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
14
16
  export declare const TextArea: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
15
- export declare const AmountInput: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
16
- export declare const SearchInput: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
17
+ export interface SearchInputProps extends TextInputProps {
18
+ /** 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`. */
19
+ trailing?: React.ReactNode;
20
+ /** Shows a clear button (44dp, reaching 48dp through `hitSlop`) on the trailing edge while the controlled `value` is not empty. It calls this and returns focus to the field. */
21
+ onClear?: () => void;
22
+ /** Accessible name of the clear button; defaults to HIGProvider `messages.clearSearch`. */
23
+ clearLabel?: string;
24
+ }
25
+ export declare const SearchInput: React.ForwardRefExoticComponent<SearchInputProps & React.RefAttributes<React.ComponentRef<typeof TextInput>>>;
@@ -1,26 +1,51 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { createContext, useContext, forwardRef, useId, useState } from 'react';
3
- import { Platform, TextInput, View } from 'react-native';
4
- import { SearchIcon } from './icons.js';
2
+ import { createContext, useContext, forwardRef, useEffect, useId, useRef, useState } from 'react';
3
+ import { AccessibilityInfo, Platform, Pressable, TextInput, View } from 'react-native';
4
+ import { CloseIcon, SearchIcon } from './icons.js';
5
5
  import { Text } from './surface.js';
6
6
  import * as en from '@bloxwap/hig/contracts/messages';
7
7
  import { useColors, useFills, useHIG } from './provider.js';
8
8
  const Context = createContext({ label: '' });
9
- export function Field({ label, description, error, required, disabled, children }) { const id = useId(); const { messages } = useHIG(); const colors = useColors(); const marked = required ? `${label} ${messages.required ?? en.required}` : label; 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, { style: { color: colors.muted }, children: description }), error && _jsx(Text, { accessibilityLiveRegion: 'polite', style: { color: colors.negative }, children: error })] }) }); }
9
+ export function Field({ label, description, descriptionTone, error, required, disabled, children }) {
10
+ const id = useId();
11
+ const { messages } = useHIG();
12
+ const colors = useColors();
13
+ const marked = required ? `${label} ${messages.required ?? en.required}` : label;
14
+ const positive = descriptionTone === 'positive';
15
+ // iOS has no live regions: a changed success line is spoken explicitly, as an Alert is. Android reads the live region.
16
+ const spoken = useRef(description);
17
+ useEffect(() => { if (spoken.current === description)
18
+ return; spoken.current = description; if (positive && description && Platform.OS === 'ios') {
19
+ try {
20
+ AccessibilityInfo.announceForAccessibility(description);
21
+ }
22
+ catch { /* The visible line remains. */ }
23
+ } }, [description, positive]);
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
+ }
10
26
  export const Label = Text;
11
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. */
12
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] }); });
13
29
  export const TextArea = forwardRef(function TextArea(props, ref) { return _jsx(Input, { ...props, ref: ref, multiline: true, textAlignVertical: 'top' }); });
14
- export const AmountInput = forwardRef(function AmountInput(props, ref) { return _jsx(Input, { ...props, ref: ref, keyboardType: props.keyboardType ?? 'decimal-pad' }); });
15
30
  /** The magnifying glass sits inset on the leading edge and the text starts past it. */
16
31
  /** A search box is as tall as a button, 44dp, not a 48dp form field. */
17
32
  const searchSize = { minHeight: 44, paddingVertical: 10 };
18
- export const SearchInput = forwardRef(function SearchInput({ style, ...props }, ref) {
33
+ export const SearchInput = forwardRef(function SearchInput({ style, trailing, onClear, clearLabel, ...props }, ref) {
19
34
  const colors = useColors();
20
- const { direction } = useHIG();
35
+ const { direction, messages } = useHIG();
36
+ const inner = useRef(null);
21
37
  // RN Web resolves `start` through its own locale context rather than this View's direction.
22
38
  const rtl = direction === 'rtl', web = Platform.OS === 'web';
23
39
  const edge = web ? (rtl ? { right: 18 } : { left: 18 }) : { start: 18 };
24
40
  const inset = web ? (rtl ? { paddingRight: 46 } : { paddingLeft: 46 }) : { paddingStart: 46 };
25
- return _jsxs(View, { style: { direction, justifyContent: 'center' }, children: [_jsx(Input, { ...props, ref: ref, returnKeyType: props.returnKeyType ?? 'search', style: [searchSize, inset, style] }), _jsx(View, { pointerEvents: 'none', style: { position: 'absolute', ...edge }, children: _jsx(SearchIcon, { color: colors.muted }) })] });
41
+ const extra = trailing != null && trailing !== false, reserve = extra || onClear != null;
42
+ const end = web ? (rtl ? { left: 0 } : { right: 0 }) : { end: 0 };
43
+ 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);
46
+ else if (ref)
47
+ ref.current = node; };
48
+ const off = props.editable === false || !!useContext(Context).disabled;
49
+ 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
+ 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] });
26
51
  });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A number the host supplies as a number so it updates place by place: `{value:0.53,options:{style:'currency',currency:'USD'}}`.
3
+ * `null` reads as unknown. `formattedValue` is the host's own text for the value, drawn and read in place of Intl's, which
4
+ * still moves place by place: use it where this runtime's Intl does not match the host's number table. Never parse it back.
5
+ */
6
+ export interface Figure {
7
+ value: number | null;
8
+ options?: Intl.NumberFormatOptions;
9
+ prefix?: string;
10
+ suffix?: string;
11
+ formattedValue?: string;
12
+ }
13
+ /** The props of an `AnimatedNumberReadout` that draws a figure: its host text, when given, moves place by place too. */
14
+ export declare function figureProps(figure: Figure): {
15
+ value: number | null;
16
+ options?: Intl.NumberFormatOptions;
17
+ prefix?: string;
18
+ suffix?: string;
19
+ formattedValue?: string;
20
+ animateFormatted?: boolean;
21
+ };
22
+ /** What a figure reads as, with the provider's money format already merged into `options` by the caller. */
23
+ export declare function figureReading(figure: Figure, locale: string, options?: Intl.NumberFormatOptions): string;
@@ -0,0 +1,10 @@
1
+ import { formatNumberReadout } from './animated-number-model.js';
2
+ /** The props of an `AnimatedNumberReadout` that draws a figure: its host text, when given, moves place by place too. */
3
+ export function figureProps(figure) {
4
+ const { value, options, prefix, suffix, formattedValue } = figure;
5
+ return formattedValue ? { value, options, prefix, suffix, formattedValue, animateFormatted: true } : { value, options, prefix, suffix };
6
+ }
7
+ /** What a figure reads as, with the provider's money format already merged into `options` by the caller. */
8
+ export function figureReading(figure, locale, options) {
9
+ return formatNumberReadout(figure.value, locale, options, figure.formattedValue, figure.prefix, figure.suffix).text;
10
+ }
@@ -6,9 +6,17 @@ export declare function SearchIcon({ color }: {
6
6
  export declare function ChevronIcon({ color }: {
7
7
  color: string;
8
8
  }): React.JSX.Element;
9
+ /** A QR glyph: three finder squares and two cells. */
10
+ export declare function QrIcon({ color }: {
11
+ color: string;
12
+ }): React.JSX.Element;
9
13
  export declare function CloseIcon({ color }: {
10
14
  color: string;
11
15
  }): React.JSX.Element;
16
+ /** A pencil: a slanted barrel over the line it writes on. */
17
+ export declare function EditIcon({ color }: {
18
+ color: string;
19
+ }): React.JSX.Element;
12
20
  export type SeverityIconKind = 'info' | 'success' | 'warning' | 'error';
13
21
  /** Shape as well as colour tells the severities apart: warning is a diamond, the others a circle with their own mark. */
14
22
  export declare function SeverityIcon({ kind, color }: {
@@ -8,7 +8,11 @@ function Bar({ length, color, angle }) { return _jsx(View, { style: { position:
8
8
  export function SearchIcon({ color }) { return _jsxs(View, { ...hidden, style: { width: 18, height: 18 }, children: [_jsx(View, { style: { width: 13, height: 13, borderRadius: 7, borderWidth: stroke, borderColor: color } }), _jsx(View, { style: { position: 'absolute', right: 1, bottom: 3, width: 6, height: stroke, borderRadius: stroke, backgroundColor: color, transform: [{ rotate: '45deg' }] } })] }); }
9
9
  /** Points down; the caller rotates it. */
10
10
  export function ChevronIcon({ color }) { return _jsx(View, { ...hidden, style: { width: 20, height: 20, ...centre }, children: _jsx(View, { style: { width: 9, height: 9, borderRightWidth: stroke, borderBottomWidth: stroke, borderColor: color, transform: [{ translateY: -2 }, { rotate: '45deg' }] } }) }); }
11
+ /** A QR glyph: three finder squares and two cells. */
12
+ export function QrIcon({ color }) { const finder = (position) => _jsx(View, { style: { position: 'absolute', width: 7, height: 7, borderRadius: 1.5, borderWidth: stroke, borderColor: color, ...position } }); const cell = (position) => _jsx(View, { style: { position: 'absolute', width: 3, height: 3, backgroundColor: color, ...position } }); return _jsxs(View, { ...hidden, style: { width: 20, height: 20 }, children: [finder({ left: 2, top: 2 }), finder({ right: 2, top: 2 }), finder({ left: 2, bottom: 2 }), cell({ right: 6, bottom: 6 }), cell({ right: 2, bottom: 2 })] }); }
11
13
  export function CloseIcon({ color }) { return _jsxs(View, { ...hidden, style: { width: 20, height: 20, ...centre }, children: [_jsx(Bar, { length: 14, color: color, angle: '45deg' }), _jsx(Bar, { length: 14, color: color, angle: '-45deg' })] }); }
14
+ /** A pencil: a slanted barrel over the line it writes on. */
15
+ export function EditIcon({ color }) { return _jsxs(View, { ...hidden, style: { width: 20, height: 20, ...centre }, children: [_jsx(View, { style: { position: 'absolute', top: 6, width: 13, height: 5, borderRadius: 1.5, borderWidth: stroke, borderColor: color, transform: [{ rotate: '-45deg' }] } }), _jsx(View, { style: { position: 'absolute', bottom: 2, start: 3, width: 14, height: stroke, borderRadius: stroke, backgroundColor: color } })] }); }
12
16
  /** Shape as well as colour tells the severities apart: warning is a diamond, the others a circle with their own mark. */
13
17
  export function SeverityIcon({ kind, color }) {
14
18
  const mark = kind === 'success' ? _jsx(View, { style: { width: 9, height: 5, borderLeftWidth: stroke, borderBottomWidth: stroke, borderColor: color, transform: [{ translateY: -1 }, { rotate: '-45deg' }] } })
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ /** One language the host offers. */
3
+ export interface LanguageOption {
4
+ /** Stable id the host switches on, usually a BCP 47 tag such as `pt-BR`. */
5
+ code: string;
6
+ /** The language in its own words: `Français`. */
7
+ name: string;
8
+ /** The language in the reader's words, shown under the name: `French`. Omit it where it would repeat the name. */
9
+ description?: string;
10
+ /** Round artwork, usually a flag: an image URL or a host element. Without it the row shows the first letters of the code. */
11
+ flag?: string | React.ReactElement;
12
+ }
13
+ export interface LanguageBlockProps {
14
+ /** Heading. Defaults to the built-in “Language”. */
15
+ title?: string;
16
+ /** Shows Back on the leading edge of the header. */
17
+ onBack?: () => void;
18
+ /** A control on the trailing edge of the header, usually an IconButton that closes the sheet. */
19
+ headerAction?: React.ReactNode;
20
+ languages: readonly LanguageOption[];
21
+ /** `code` of the language in use. */
22
+ value?: string | null;
23
+ onSelect: (language: LanguageOption) => void;
24
+ /** Set false to leave out the search field, for a short list. Default `true`. */
25
+ search?: boolean;
26
+ /** Dims the rows and ignores presses, for example while a change is being applied. */
27
+ disabled?: boolean;
28
+ /** A muted line under the header that explains the screen: Choose the language used throughout the app. */
29
+ description?: string;
30
+ testID?: string;
31
+ }
32
+ /** The languages whose name, description or code contains the query, ignoring case and accents. An empty query keeps every language, in the host's order. */
33
+ export declare function filterLanguages(languages: readonly LanguageOption[], query: string): LanguageOption[];
34
+ /** Choose the app's language as one screen: a header, a search field, then each language as a row with its flag, its own name over the reader's name for it, and a check on the one in use. */
35
+ export declare function LanguageBlock({ title, onBack, headerAction, languages, value, onSelect, search, disabled, description, testID }: LanguageBlockProps): React.JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from 'react';
3
+ import { Image, Pressable, View } from 'react-native';
4
+ import { useColors, useFills, useHIG, useMessages } from './provider.js';
5
+ import { Text } from './surface.js';
6
+ import { IconButton } from './button.js';
7
+ import { SearchInput } from './field.js';
8
+ import { ChevronIcon } from './icons.js';
9
+ const fold = (text) => text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
10
+ /** The languages whose name, description or code contains the query, ignoring case and accents. An empty query keeps every language, in the host's order. */
11
+ export function filterLanguages(languages, query) {
12
+ const needle = fold(query.trim());
13
+ return needle === '' ? [...languages] : languages.filter(language => fold(`${language.name} ${language.description ?? ''} ${language.code}`).includes(needle));
14
+ }
15
+ const hidden = { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' };
16
+ const avatar = 40;
17
+ /** Choose the app's language as one screen: a header, a search field, then each language as a row with its flag, its own name over the reader's name for it, and a check on the one in use. */
18
+ export function LanguageBlock({ title, onBack, headerAction, languages, value = null, onSelect, search = true, disabled, description, testID }) {
19
+ const colors = useColors(), fills = useFills(), t = useMessages(), { direction } = useHIG();
20
+ const [query, setQuery] = useState('');
21
+ const rows = useMemo(() => filterLanguages(languages, query), [languages, query]);
22
+ const heading = title ?? t.language;
23
+ const shape = { width: avatar, height: avatar, borderRadius: avatar / 2, backgroundColor: fills.raised, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' };
24
+ const row = (pressed) => ({ flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 56, paddingVertical: 8, paddingStart: 8, paddingEnd: 16, borderRadius: 28, backgroundColor: pressed ? fills.well : 'transparent' });
25
+ return _jsxs(View, { testID: testID, style: { direction, padding: 16, gap: 16 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', minHeight: 44 }, children: [_jsx(View, { style: { minWidth: 44, alignItems: 'flex-start' }, children: onBack ? _jsx(IconButton, { intent: 'ghost', label: t.back, suppressFeedback: true, testID: testID ? `${testID}-back` : undefined, onPress: onBack, children: _jsx(View, { style: { transform: [{ rotate: direction === 'rtl' ? '-90deg' : '90deg' }] }, children: _jsx(ChevronIcon, { color: colors.text }) }) }) : null }), _jsx(Text, { testID: testID ? `${testID}-title` : undefined, accessibilityRole: 'header', numberOfLines: 1, style: { flex: 1, textAlign: 'center', fontSize: 17, lineHeight: 24, fontWeight: '600', color: colors.text }, children: heading }), _jsx(View, { style: { minWidth: 44, alignItems: 'flex-end' }, children: headerAction })] }), description ? _jsx(Text, { testID: testID ? `${testID}-description` : undefined, style: { paddingHorizontal: 4, fontSize: 14, lineHeight: 21, color: colors.muted }, children: description }) : null, search ? _jsx(SearchInput, { testID: testID ? `${testID}-search` : undefined, accessibilityLabel: t.searchLanguages, placeholder: t.searchLanguages, value: query, onChangeText: setQuery, returnKeyType: 'search', autoCapitalize: 'none', autoCorrect: false, spellCheck: false }) : null, rows.length === 0 ? _jsx(Text, { testID: testID ? `${testID}-empty` : undefined, accessibilityLiveRegion: 'polite', style: { paddingVertical: 32, textAlign: 'center', fontSize: 14, lineHeight: 20, color: colors.muted }, children: t.noResults }) :
26
+ _jsx(View, { testID: testID ? `${testID}-list` : undefined, accessibilityRole: 'radiogroup', accessibilityLabel: heading, style: { gap: 4 }, children: rows.map(language => {
27
+ const selected = language.code === value;
28
+ return _jsxs(Pressable, { testID: testID ? `${testID}-${language.code}` : undefined, accessibilityRole: 'radio', accessibilityState: disabled ? { checked: selected, disabled: true } : { checked: selected }, accessibilityLabel: [language.name, language.description].filter(Boolean).join(', '), accessibilityLanguage: language.code, disabled: disabled, onPress: () => onSelect(language), style: disabled ? ({ pressed }) => ({ ...row(pressed), opacity: 0.5 }) : ({ pressed }) => row(pressed), children: [_jsx(View, { ...hidden, children: typeof language.flag === 'string' ? _jsx(Image, { accessible: false, accessibilityIgnoresInvertColors: true, source: { uri: language.flag }, style: shape }) : _jsx(View, { style: shape, children: language.flag ?? _jsx(Text, { accessible: false, maxFontSizeMultiplier: 1, style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: language.code.slice(0, 2).toUpperCase() }) }) }), _jsxs(View, { ...hidden, style: { flex: 1, flexShrink: 1, minWidth: 0 }, children: [_jsx(Text, { style: { fontSize: 16, lineHeight: 24, fontWeight: '600', color: colors.text }, children: language.name }), language.description ? _jsx(Text, { style: { fontSize: 14, lineHeight: 20, color: colors.muted }, children: language.description }) : null] }), selected ? _jsx(View, { ...hidden, testID: testID ? `${testID}-check` : undefined, style: { width: 20, height: 20, alignItems: 'center', justifyContent: 'center' }, children: _jsx(View, { style: { width: 6, height: 12, borderRightWidth: 2, borderBottomWidth: 2, borderColor: colors.text, transform: [{ translateY: -1 }, { rotate: '45deg' }] } }) }) : null] }, language.code);
29
+ }) })] });
30
+ }