@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
@@ -1,28 +1,32 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useMemo, useRef, useState } from 'react';
4
- import { createAnimatedNumberModel, createAnimatedNumberTransitions } from './animated-number-model.js';
5
- import { useHIG } from './provider.js';
4
+ import { createAnimatedNumberModel, createAnimatedNumberTransitions, createFormattedAnimatedNumberModel } from './animated-number-model.js';
5
+ import { useHIG, useNumberLocale } from './provider.js';
6
6
  import { tokens as higTokens } from '@bloxwap/hig/tokens';
7
7
  import * as en from '@bloxwap/hig/contracts/messages';
8
- export function AnimatedNumberReadout({ duration = 180, trend, ...props }) {
9
- const { locale, direction, reducedMotion, messages } = useHIG();
8
+ import { presentNumberFormat } from '@bloxwap/hig/contracts';
9
+ export function AnimatedNumberReadout({ duration = 180, trend, options: requested, formattedValue, animateFormatted = false, ...rest }) {
10
+ const locale = useNumberLocale();
11
+ const { direction, reducedMotion, messages, numberFormat } = useHIG();
12
+ const props = { ...rest, options: presentNumberFormat(requested, numberFormat) };
10
13
  const element = useRef(null);
11
14
  const previous = useRef(null);
12
15
  const generation = useRef(0);
13
16
  const active = useRef([]);
14
- const signature = JSON.stringify([locale, direction, props.options ?? {}]);
17
+ const known = props.value != null && Number.isFinite(props.value), own = known && !!formattedValue;
18
+ const signature = JSON.stringify([locale, direction, props.options ?? {}, own, own && animateFormatted]);
15
19
  const frame = useMemo(() => {
16
- const model = createAnimatedNumberModel(props.value, locale, props.options), prior = previous.current, changed = !!prior && prior.signature === signature && !Object.is(prior.value, props.value);
20
+ const model = own ? createFormattedAnimatedNumberModel(formattedValue, locale, animateFormatted) : createAnimatedNumberModel(props.value, locale, props.options), prior = previous.current, changed = !!prior && prior.signature === signature && !Object.is(prior.value, props.value);
17
21
  let movement = 0;
18
22
  if (changed && prior && model.animatable && prior.model.animatable && Number.isFinite(prior.value) && Number.isFinite(props.value)) {
19
23
  const requested = typeof trend === 'function' ? trend(prior.value, props.value) : trend ?? Math.sign(props.value - prior.value);
20
24
  movement = requested === -1 || requested === 1 ? requested : 0;
21
25
  }
22
26
  return { model, changed, movement, tokens: createAnimatedNumberTransitions(changed ? prior?.model ?? null : null, model) };
23
- }, [props.value, signature]);
27
+ }, [props.value, signature, formattedValue]);
24
28
  const [settled, setSettled] = useState(null);
25
- const known = props.value != null && Number.isFinite(props.value), reading = known ? `${props.prefix ?? ''}${frame.model.reading}${props.suffix ?? ''}` : frame.model.reading, staleText = messages.stale ?? en.stale, accessible = `${props.label ? `${props.label}: ` : ''}${reading}${props.stale ? ` ${staleText}` : ''}`;
29
+ const reading = known ? `${props.prefix ?? ''}${frame.model.reading}${props.suffix ?? ''}` : frame.model.reading, staleText = messages.stale ?? en.stale, accessible = `${props.label ? `${props.label}: ` : ''}${reading}${props.stale ? ` ${staleText}` : ''}`;
26
30
  useEffect(() => {
27
31
  const id = ++generation.current;
28
32
  const cancel = () => { const running = active.current; active.current = []; for (const animation of running) {
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ /** Artwork for an asset: an image URL, or an element the host draws. */
3
+ export type AssetArtwork = string | React.ReactElement;
4
+ export interface AssetBalanceRowProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onSelect'> {
5
+ name: string;
6
+ symbol: string;
7
+ /** A missing icon falls back to the first letters of the symbol. */
8
+ icon?: AssetArtwork;
9
+ /** Dollar value of the holding. `null` reads as unknown. */
10
+ value?: number | null;
11
+ /** The holding in token units, shown under the value. Omit it to show the value alone, as for a dollar stablecoin. */
12
+ balance?: number | null;
13
+ /** Format of the units line. Defaults to at most six fraction digits. */
14
+ balanceOptions?: Intl.NumberFormatOptions;
15
+ /** Host text after the units figure, such as ` HYPE`. Drawn only when the units are known. */
16
+ unitsSuffix?: string;
17
+ /** `units` puts the units on the headline line in place of the value and draws no second line, for a holding with no dollar value. Defaults to `value`. */
18
+ headline?: 'value' | 'units';
19
+ /** `false` draws no figures at all, for a row that is just an item to pick, such as a method or a chain. Defaults to `true`. */
20
+ amounts?: boolean;
21
+ /** Short muted host text under the figures, such as the ledger a holding sits in. Read after them. */
22
+ tag?: string;
23
+ /** Host content on the trailing edge, after the figures. Inside a pressable row it must not be interactive. It is read in place, last. */
24
+ trailing?: React.ReactNode;
25
+ /** What assistive technology reads for `trailing`, in place of its content, for an icon or a figure whose text is not what should be heard. */
26
+ trailingLabel?: string;
27
+ /** Marks the row in use: a check on the trailing edge, and `aria-current` for assistive technology. */
28
+ selected?: boolean;
29
+ /** Dims the row and ignores presses. */
30
+ disabled?: boolean;
31
+ /** Makes the whole row a button. */
32
+ onSelect?: () => void;
33
+ }
34
+ /** One holding in a list: round artwork, the asset's name over its symbol, and its dollar value over its units. Both numbers update place by place. */
35
+ export declare function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions, unitsSuffix, headline, amounts, tag, trailing, trailingLabel, selected, disabled, onSelect, className, ...rest }: AssetBalanceRowProps): React.JSX.Element;
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { AnimatedNumberReadout } from './animated-number.js';
4
+ import { PressDecoration } from './provider.js';
5
+ const usd = { style: 'currency', currency: 'USD' }, units = { maximumFractionDigits: 6 };
6
+ const check = _jsx("svg", { className: 'hig-asset-row-check', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '20', height: '20', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', children: _jsx("path", { d: 'm4.5 10.5 3.5 3.5 7.5-8' }) });
7
+ /** One holding in a list: round artwork, the asset's name over its symbol, and its dollar value over its units. Both numbers update place by place. */
8
+ export function AssetBalanceRow({ name, symbol, icon, value, balance, balanceOptions = units, unitsSuffix, headline = 'value', amounts = true, tag, trailing, trailingLabel, selected, disabled, onSelect, className, ...rest }) {
9
+ const unitsFirst = headline === 'units';
10
+ const figures = amounts && _jsxs(_Fragment, { children: [_jsx("strong", { children: unitsFirst ? _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions, suffix: unitsSuffix }) : _jsx(AnimatedNumberReadout, { value: value, options: usd }) }), !unitsFirst && balance !== undefined && _jsx("span", { children: _jsx(AnimatedNumberReadout, { value: balance, options: balanceOptions, suffix: unitsSuffix }) })] });
11
+ const content = _jsxs(_Fragment, { children: [_jsx("span", { className: 'hig-asset-row-icon', "aria-hidden": 'true', children: typeof icon === 'string' ? _jsx("img", { src: icon, alt: '' }) : icon ?? symbol.slice(0, 3) }), _jsxs("span", { className: 'hig-asset-row-identity', children: [_jsx("strong", { children: name }), _jsx("span", { children: symbol })] }), (amounts || tag) && _jsxs("span", { className: 'hig-asset-row-amounts', children: [figures, tag && _jsx("small", { className: 'hig-asset-row-tag', children: tag })] }), trailing != null && trailing !== false && _jsx("span", { className: 'hig-asset-row-trailing', "aria-hidden": trailingLabel !== undefined || undefined, children: trailing }), trailingLabel !== undefined && trailing != null && trailing !== false && _jsx("span", { className: 'hig-sr-only hig-asset-row-trailing-label', children: trailingLabel }), selected && check] });
12
+ const classes = `hig-asset-row${className ? ` ${className}` : ''}`;
13
+ const state = { 'aria-current': selected ? 'true' : undefined, 'data-selected': selected || undefined };
14
+ return onSelect
15
+ ? _jsxs("button", { type: 'button', ...rest, ...state, className: classes, disabled: disabled, onClick: onSelect, children: [content, _jsx(PressDecoration, { kind: 'row', disabled: disabled })] })
16
+ // A static row is a generic div, where aria-disabled is not read; disabled, it becomes a group, which carries the state.
17
+ : _jsx("div", { role: disabled ? 'group' : undefined, ...rest, ...state, "aria-disabled": disabled || undefined, className: classes, children: content });
18
+ }
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import { type Figure } from './figure.js';
3
+ /** Colour roles a segment can take. They follow the token palette (and a host's market colours) like any other role. */
4
+ export type BarMarkTone = 'positive' | 'info' | 'warning' | 'negative' | 'muted' | 'faint';
5
+ /** The order segments take tones in when they name neither a `tone` nor a `color`. */
6
+ export declare const barMarkTones: readonly BarMarkTone[];
7
+ /** A legend amount that can change while the bar is shown: formatted with `options` between `prefix` and `suffix`, and updated place by place. `null` reads as unknown. */
8
+ export type BarMarkFigure = Figure;
9
+ /** One part of the bar. `value` is in the host's own unit; only its share of the whole is drawn. `detail` is shown after the label: host-formatted text, such as `12.4 GB`, or a live figure. `color` is a host hex for a category outside the tone roles. */
10
+ export interface BarMarkElement {
11
+ id?: string;
12
+ label: string;
13
+ value: number;
14
+ tone?: BarMarkTone;
15
+ color?: string;
16
+ detail?: string | BarMarkFigure;
17
+ }
18
+ export interface BarMarkProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
19
+ title: string;
20
+ /** A line on the trailing edge of the title row, such as `59.2 GB of 64 GB used`. */
21
+ description?: React.ReactNode;
22
+ elements: readonly BarMarkElement[];
23
+ /** The whole the elements are parts of. When it is larger than their sum the remainder stays empty track. Defaults to the sum. */
24
+ total?: number;
25
+ /** Set false to hide the legend; the labels and shares stay available to assistive technology. */
26
+ legend?: boolean;
27
+ /** `small` draws a 12-unit bar for a secondary breakdown under a main one. */
28
+ size?: 'default' | 'small';
29
+ /** Set false to draw no card: no surface fill, padding or radius. The title row, bar and legend keep their spacing. Default `true`. */
30
+ surface?: boolean;
31
+ }
32
+ /** Shares of the whole for each element, and the empty remainder, as fractions of 1. Negative and non-finite values count as nothing. */
33
+ export declare function barMarkShares(elements: readonly BarMarkElement[], total?: number): {
34
+ shares: number[];
35
+ rest: number;
36
+ };
37
+ /** A one-dimensional stacked bar: a titled card whose single bar is divided among its elements, with a legend naming each part. */
38
+ export declare function BarMark({ title, description, elements, total, legend, size, surface, className, ...rest }: BarMarkProps): React.JSX.Element;
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import { formatNumber } from '@bloxwap/hig/contracts';
5
+ import { useNumberLocale } from './provider.js';
6
+ import { AnimatedNumberReadout } from './animated-number.js';
7
+ import { figureProps } from './figure.js';
8
+ /** The order segments take tones in when they name neither a `tone` nor a `color`. */
9
+ export const barMarkTones = ['positive', 'info', 'warning', 'negative', 'muted', 'faint'];
10
+ const amount = (value) => Number.isFinite(value) && value > 0 ? value : 0;
11
+ /** Shares of the whole for each element, and the empty remainder, as fractions of 1. Negative and non-finite values count as nothing. */
12
+ export function barMarkShares(elements, total) {
13
+ const values = elements.map(element => amount(element.value)), sum = values.reduce((a, b) => a + b, 0), whole = Math.max(amount(total ?? 0), sum);
14
+ return whole > 0 ? { shares: values.map(value => value / whole), rest: (whole - sum) / whole } : { shares: values.map(() => 0), rest: 1 };
15
+ }
16
+ /** A one-dimensional stacked bar: a titled card whose single bar is divided among its elements, with a legend naming each part. */
17
+ export function BarMark({ title, description, elements, total, legend = true, size = 'default', surface = true, className, ...rest }) {
18
+ const locale = useNumberLocale();
19
+ const id = useId();
20
+ const { shares, rest: remainder } = barMarkShares(elements, total);
21
+ const paint = (element, index) => element.color ? { style: { '--hig-bar-mark-color': element.color } } : { 'data-tone': element.tone ?? barMarkTones[index % barMarkTones.length] };
22
+ return _jsxs("section", { ...rest, className: `${surface ? 'hig-surface ' : ''}hig-bar-mark${className ? ` ${className}` : ''}`, "data-surface": surface ? undefined : 'false', "data-size": size === 'small' ? size : undefined, "aria-labelledby": id, children: [_jsxs("div", { className: 'hig-bar-mark-header', children: [_jsx("strong", { id: id, className: 'hig-bar-mark-title', children: title }), description != null && _jsx("span", { className: 'hig-bar-mark-description', children: description })] }), _jsxs("div", { className: 'hig-bar-mark-bar', "aria-hidden": 'true', children: [elements.map((element, index) => shares[index] > 0 && _jsx("span", { className: 'hig-bar-mark-segment', ...paint(element, index), style: { ...paint(element, index).style, flexGrow: shares[index] } }, element.id ?? index)), remainder > 0 && _jsx("span", { className: 'hig-bar-mark-rest', style: { flexGrow: remainder } })] }), _jsx("ul", { className: legend ? 'hig-bar-mark-legend' : 'hig-sr-only', children: elements.map((element, index) => _jsxs("li", { children: [_jsx("span", { className: 'hig-bar-mark-dot', "aria-hidden": 'true', ...paint(element, index) }), _jsx("span", { children: element.label }), element.detail && _jsx("span", { className: 'hig-bar-mark-detail', children: typeof element.detail === 'string' ? element.detail : _jsx(AnimatedNumberReadout, { ...figureProps(element.detail) }) }), _jsx("span", { className: 'hig-sr-only', children: formatNumber(shares[index], locale, { style: 'percent', maximumFractionDigits: 1 }) })] }, element.id ?? index)) })] });
23
+ }
@@ -0,0 +1,49 @@
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 extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
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
+ /** A line on the trailing edge of the title row, such as the profit or loss in dollars. */
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
+ }
29
+ /** 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. */
30
+ export declare function barPnlCompactOptions(value: number | null | undefined, base?: Intl.NumberFormatOptions): Intl.NumberFormatOptions;
31
+ /**
32
+ * Where each price sits on the bar, as a fraction of its width from the low-price edge, the readouts in price order, and
33
+ * whether the position is in profit. With a liquidation price the bar runs from it to the same distance on the other side
34
+ * of entry, so entry sits in the middle; a mark beyond either end stretches the bar. Without one the bar is centred on entry.
35
+ */
36
+ export declare function barPnlLayout({ entry, mark, liquidation, side, fit }: {
37
+ entry: number;
38
+ mark?: number | null;
39
+ liquidation?: number | null;
40
+ side?: BarPnlSide;
41
+ fit?: boolean;
42
+ }): {
43
+ side: BarPnlSide;
44
+ result: BarPnlResult;
45
+ positions: Partial<Record<BarPnlKind, number>>;
46
+ order: BarPnlKind[];
47
+ };
48
+ /** 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. */
49
+ export declare function BarPnl({ entry, mark, liquidation, side, labels, title, description, priceOptions, compact, fit, surface, className, ...rest }: BarPnlProps): React.JSX.Element;
@@ -0,0 +1,45 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import { AnimatedNumberReadout } from './animated-number.js';
5
+ const usd = { style: 'currency', currency: 'USD' };
6
+ const finite = (value) => typeof value === 'number' && Number.isFinite(value);
7
+ /** 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. */
8
+ export function barPnlCompactOptions(value, base = usd) {
9
+ const size = finite(value) ? Math.abs(value) : 0;
10
+ return size > 0 && size < 1 ? { ...base, minimumFractionDigits: undefined, maximumFractionDigits: undefined, maximumSignificantDigits: 4 } : { ...base, minimumFractionDigits: 0, maximumFractionDigits: size >= 1000 ? 0 : 2 };
11
+ }
12
+ /**
13
+ * Where each price sits on the bar, as a fraction of its width from the low-price edge, the readouts in price order, and
14
+ * whether the position is in profit. With a liquidation price the bar runs from it to the same distance on the other side
15
+ * of entry, so entry sits in the middle; a mark beyond either end stretches the bar. Without one the bar is centred on entry.
16
+ */
17
+ export function barPnlLayout({ entry, mark, liquidation, side, fit }) {
18
+ const liq = finite(liquidation) ? liquidation : null;
19
+ const direction = side ?? (liq !== null && liq > entry ? 'short' : 'long');
20
+ const result = !finite(entry) || !finite(mark) || mark === entry ? 'flat' : (mark > entry) === (direction === 'long') ? 'profit' : 'loss';
21
+ if (!finite(entry))
22
+ return { side: direction, result, positions: {}, order: [] };
23
+ const price = finite(mark) ? mark : entry;
24
+ const reach = liq !== null ? Math.abs(entry - liq) : Math.max(Math.abs(price - entry) * 2, Math.abs(entry) * 0.01, Number.MIN_VALUE);
25
+ // `fit` scales the bar to the prices themselves, so the stretch from entry to mark fills it.
26
+ const points = liq !== null ? [entry, price, liq] : [entry, price];
27
+ const low = fit ? Math.min(...points) : Math.min(entry - reach, price), high = fit ? Math.max(...points) : Math.max(entry + reach, price), span = high - low;
28
+ const at = (value) => span > 0 ? Math.min(1, Math.max(0, (value - low) / span)) : 0.5;
29
+ const positions = { entry: at(entry), mark: at(price) };
30
+ if (liq !== null)
31
+ positions.liquidation = at(liq);
32
+ // Ties keep liquidation outermost and put mark on the side it would move to next.
33
+ const rank = { liquidation: direction === 'long' ? 0 : 2, entry: 1, mark: direction === 'long' ? (result === 'loss' ? 0.5 : 1.5) : (result === 'loss' ? 1.5 : 0.5) };
34
+ const values = { liquidation: liq ?? 0, entry, mark: price };
35
+ const order = Object.keys(positions).sort((a, b) => values[a] - values[b] || rank[a] - rank[b]);
36
+ return { side: direction, result, positions, order };
37
+ }
38
+ /** 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. */
39
+ export function BarPnl({ entry, mark, liquidation, side, labels, title, description, priceOptions = usd, compact = false, fit = false, surface = true, className, ...rest }) {
40
+ const id = useId();
41
+ const { result, positions, order } = barPnlLayout({ entry, mark, liquidation, side, fit });
42
+ const from = Math.min(positions.entry ?? 0.5, positions.mark ?? 0.5), to = Math.max(positions.entry ?? 0.5, positions.mark ?? 0.5);
43
+ const values = { liquidation, mark, entry };
44
+ return _jsxs("section", { ...rest, className: `${surface ? 'hig-surface ' : ''}hig-bar-pnl${className ? ` ${className}` : ''}`, "data-surface": surface ? undefined : 'false', "data-result": result, "aria-labelledby": title ? id : undefined, children: [(title || description != null) && _jsxs("div", { className: 'hig-bar-mark-header', children: [title && _jsx("strong", { id: id, className: 'hig-bar-mark-title', children: title }), description != null && _jsx("span", { className: 'hig-bar-mark-description', children: description })] }), _jsxs("div", { className: 'hig-bar-pnl-bar', "aria-hidden": 'true', children: [_jsx("span", { className: 'hig-bar-pnl-rest', style: { flexGrow: from } }), _jsx("span", { className: 'hig-bar-pnl-move', "data-lead": (positions.mark ?? 0) < (positions.entry ?? 0) ? 'mark' : 'entry', style: { flexGrow: to - from } }), _jsx("span", { className: 'hig-bar-pnl-rest', style: { flexGrow: 1 - to } }), positions.liquidation !== undefined && _jsx("span", { className: 'hig-bar-pnl-liquidation', style: { insetInlineStart: `${positions.liquidation * 100}%` } })] }), _jsx("dl", { className: 'hig-bar-pnl-readouts', children: order.map(kind => _jsxs("div", { "data-kind": kind, children: [_jsx("dt", { children: labels[kind] }), _jsx("dd", { children: _jsx(AnimatedNumberReadout, { value: values[kind], options: compact ? barPnlCompactOptions(values[kind], priceOptions) : priceOptions }) })] }, kind)) })] });
45
+ }
@@ -0,0 +1,92 @@
1
+ import React from 'react';
2
+ import { type AssetArtwork } from '../asset-balance-row.js';
3
+ export { AssetBalanceRow, type AssetArtwork, type AssetBalanceRowProps } from '../asset-balance-row.js';
4
+ /** One holding of the account. The host supplies every figure; HIG sorts, formats and lays it out. */
5
+ export interface AccountAsset {
6
+ id: string;
7
+ name: string;
8
+ symbol: string;
9
+ icon?: AssetArtwork;
10
+ /** Holding in token units. */
11
+ balance?: number | null;
12
+ /** USD per unit, when the host knows it. */
13
+ price?: number | null;
14
+ /** Dollar value of the holding. Defaults to `balance × price`. */
15
+ value?: number | null;
16
+ /** Set false to draw no units line, for a holding whose units are the same figure as its value. */
17
+ units?: boolean;
18
+ /** Set false to draw this row plain even when the block has `onAssetSelect`. */
19
+ selectable?: boolean;
20
+ /** Format of the units figure. Defaults to at most six fraction digits. */
21
+ unitsOptions?: Intl.NumberFormatOptions;
22
+ /** Host text after the units figure, such as ` PAPER`. */
23
+ unitsSuffix?: string;
24
+ /** Short muted host text under the figures, such as the ledger the holding sits in (Perp, Spot, Staked). */
25
+ tag?: string;
26
+ /** When the value is unknown but the balance is known: `units` (the default) headlines the units; `dash` shows the unknown dash over the units, for a value that is still loading. */
27
+ unknownValue?: 'units' | 'dash';
28
+ }
29
+ /** Row order after the pinned asset: `value` (largest first, the default) or `given` (the order the host passed). */
30
+ export type AccountOrder = 'value' | 'given';
31
+ /** How `accountRows` picks and orders: `order` after the pinned asset, and `pinnedId`, an asset id pinned in place of the symbol match. */
32
+ export interface AccountRowsOptions {
33
+ order?: AccountOrder;
34
+ pinnedId?: string;
35
+ }
36
+ /** A titled group of holdings with its own total, such as one ledger of the account. */
37
+ export interface AccountSection {
38
+ id: string;
39
+ /** Heading over the group. */
40
+ title: string;
41
+ /** The group's total in dollars, on the trailing edge of its heading. Defaults to the sum of its asset values; `null` reads as unknown. */
42
+ total?: number | null;
43
+ assets: readonly AccountAsset[];
44
+ /** Row order in this group; defaults to the block's `order`. */
45
+ order?: AccountOrder;
46
+ /** Id of the asset that leads this group; defaults to the block's `pinnedId`, then the `pinnedSymbol` match. */
47
+ pinnedId?: string;
48
+ }
49
+ export interface AccountBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
50
+ /** Heading. Defaults to the built-in “Account”. */
51
+ title?: string;
52
+ /** Shows Back on the leading edge of the header. */
53
+ onBack?: () => void;
54
+ /** Shows a QR button on the trailing edge of the header, above the deposit action. The host shows the account address, for example with `WalletAddress`. */
55
+ onShowAddress?: () => void;
56
+ /** A control on the trailing edge of the header, usually an `IconButton`. Replaces the QR button. */
57
+ headerAction?: React.ReactNode;
58
+ /** Total in dollars. Defaults to the sum of the asset values (with `sections`, the sum of the totals of the sections that are drawn, which is unknown when any of those totals is); `null` reads as unknown. */
59
+ balance?: number | null;
60
+ /** Every holding as one list: the pinned asset, then the rest by value. Ignored when `sections` is set. */
61
+ assets?: readonly AccountAsset[];
62
+ /** Titled groups, each with its own total, drawn in the order given in place of the flat `assets` list. */
63
+ sections?: readonly AccountSection[];
64
+ /** Symbol of the asset that is always first. Defaults to `USDC`. */
65
+ pinnedSymbol?: string;
66
+ /** Id of the asset that is always first, in place of the `pinnedSymbol` match, for a holding whose symbol is not unique. */
67
+ pinnedId?: string;
68
+ /** Order of the rows after the pinned one: `value` (largest first, the default) or `given` (the order passed). */
69
+ order?: AccountOrder;
70
+ /** Shows the deposit action beside the total. */
71
+ onDeposit?: () => void;
72
+ /** Text of the deposit action. Defaults to the built-in “Deposit”. */
73
+ depositLabel?: string;
74
+ /** Makes each row a button that reports its asset, and with `sections` the section it is in. */
75
+ onAssetSelect?: (asset: AccountAsset, section?: AccountSection) => void;
76
+ }
77
+ /** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
78
+ export declare const assetValue: (asset: AccountAsset) => number | null;
79
+ /** The account's rows in display order: the pinned asset (the one with `options.pinnedId`, else the first with `pinnedSymbol`, else a zero placeholder), then every other asset by dollar value, largest first, unknown values last and ties by name, or with `options.order` `given` in the order passed. */
80
+ export declare function accountRows(assets: readonly AccountAsset[], pinnedSymbol?: string, options?: AccountRowsOptions): {
81
+ pinned: AccountAsset;
82
+ rest: AccountAsset[];
83
+ };
84
+ /** A section's total: its own `total`, or the sum of its asset values. */
85
+ export declare const accountSectionTotal: (section: AccountSection) => number | null;
86
+ /** A section's rows in display order: the pinned asset first when the section holds it (no placeholder), then the rest by dollar value as in `accountRows`. */
87
+ export declare function accountSectionRows(assets: readonly AccountAsset[], pinnedSymbol?: string, options?: AccountRowsOptions): {
88
+ pinned: AccountAsset | null;
89
+ rest: AccountAsset[];
90
+ };
91
+ /** An account at a glance: a header, the total with a deposit action, the pinned dollar balance, then every other holding by value. */
92
+ export declare function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets, sections, pinnedSymbol, pinnedId, order, onDeposit, depositLabel, onAssetSelect, className, ...rest }: AccountBlockProps): React.JSX.Element;
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import * as en from '@bloxwap/hig/contracts/messages';
5
+ import { PressDecoration, useHIG } from '../provider.js';
6
+ import { Button } from '../button.js';
7
+ import { AnimatedNumberReadout } from '../animated-number.js';
8
+ import { AssetBalanceRow } from '../asset-balance-row.js';
9
+ import { ScreenHeader, qrIcon } from './screen-header.js';
10
+ export { AssetBalanceRow } from '../asset-balance-row.js';
11
+ const usdCoin = 'USD Coin', usd = { style: 'currency', currency: 'USD' };
12
+ /** Dollar value of a holding: its `value`, or `balance × price` when both are known. */
13
+ export const assetValue = (asset) => asset.value !== undefined ? asset.value : asset.balance != null && asset.price != null ? asset.balance * asset.price : null;
14
+ /** The account's rows in display order: the pinned asset (the one with `options.pinnedId`, else the first with `pinnedSymbol`, else a zero placeholder), then every other asset by dollar value, largest first, unknown values last and ties by name, or with `options.order` `given` in the order passed. */
15
+ export function accountRows(assets, pinnedSymbol = 'USDC', options = {}) {
16
+ const byId = options.pinnedId === undefined ? -1 : assets.findIndex(asset => asset.id === options.pinnedId);
17
+ const index = byId >= 0 ? byId : assets.findIndex(asset => asset.symbol.toUpperCase() === pinnedSymbol.toUpperCase());
18
+ const pinned = index >= 0 ? assets[index] : { id: pinnedSymbol, name: pinnedSymbol === 'USDC' ? usdCoin : pinnedSymbol, symbol: pinnedSymbol, balance: 0, value: 0 };
19
+ const others = assets.filter((_, position) => position !== index);
20
+ const rest = options.order === 'given' ? others : others.sort((a, b) => { const left = assetValue(a), right = assetValue(b); return left === right ? a.name.localeCompare(b.name) : left === null ? 1 : right === null ? -1 : right - left || a.name.localeCompare(b.name); });
21
+ return { pinned, rest };
22
+ }
23
+ const sum = (assets) => assets.reduce((total, asset) => total + (assetValue(asset) ?? 0), 0);
24
+ /** A section's total: its own `total`, or the sum of its asset values. */
25
+ export const accountSectionTotal = (section) => section.total !== undefined ? section.total : sum(section.assets);
26
+ /** The block total for `sections`: the sum of the section totals, or unknown (`null`) when any of them is unknown. Pass only the sections that are drawn. */
27
+ const accountSectionsTotal = (sections) => { let all = 0; for (const section of sections) {
28
+ const total = accountSectionTotal(section);
29
+ if (total === null)
30
+ return null;
31
+ all += total;
32
+ } return all; };
33
+ /** A section's rows in display order: the pinned asset first when the section holds it (no placeholder), then the rest by dollar value as in `accountRows`. */
34
+ export function accountSectionRows(assets, pinnedSymbol = 'USDC', options = {}) {
35
+ const { pinned, rest } = accountRows(assets, pinnedSymbol, options);
36
+ return { pinned: assets.includes(pinned) ? pinned : null, rest };
37
+ }
38
+ /** An account at a glance: a header, the total with a deposit action, the pinned dollar balance, then every other holding by value. */
39
+ export function AccountBlock({ title, onBack, onShowAddress, headerAction, balance, assets = [], sections, pinnedSymbol = 'USDC', pinnedId, order, onDeposit, depositLabel, onAssetSelect, className, ...rest }) {
40
+ const { messages } = useHIG();
41
+ const id = useId();
42
+ const shown = sections?.filter(section => section.assets.length > 0);
43
+ const total = balance !== undefined ? balance : shown ? accountSectionsTotal(shown) : sum(assets);
44
+ const row = (asset, pin, pinId, section) => {
45
+ // A row pinned by symbol is the dollar balance, so its units would repeat its value; a row pinned by id keeps its own units setting.
46
+ const value = assetValue(asset), units = (!pin || asset.id === pinId) && asset.units !== false;
47
+ const select = onAssetSelect && asset.selectable !== false ? (section ? () => onAssetSelect(asset, section) : () => onAssetSelect(asset)) : undefined;
48
+ return _jsx("li", { "data-pinned": pin || undefined, children: _jsx(AssetBalanceRow, { name: asset.name, symbol: asset.symbol, icon: asset.icon, value: value, balance: units ? asset.balance ?? null : undefined, balanceOptions: asset.unitsOptions, unitsSuffix: asset.unitsSuffix, tag: asset.tag, headline: units && value === null && asset.balance != null && asset.unknownValue !== 'dash' ? 'units' : undefined, onSelect: select }) }, asset.id);
49
+ };
50
+ let list;
51
+ if (shown)
52
+ list = _jsx("div", { className: 'hig-account-sections', children: shown.map((section, index) => {
53
+ const pinId = section.pinnedId ?? pinnedId;
54
+ const { pinned, rest: others } = accountSectionRows(section.assets, pinnedSymbol, { order: section.order ?? order, pinnedId: pinId }), heading = `${id}-section-${index}`;
55
+ return _jsxs("section", { className: 'hig-account-section', "aria-labelledby": heading, children: [_jsxs("div", { className: 'hig-account-section-header', children: [_jsx("h3", { id: heading, children: section.title }), _jsx("span", { className: 'hig-account-section-total', children: _jsx(AnimatedNumberReadout, { value: accountSectionTotal(section), options: usd }) })] }), _jsxs("ul", { className: 'hig-account-assets', children: [pinned && row(pinned, true, pinId, section), others.map(asset => row(asset, false, pinId, section))] })] }, section.id);
56
+ }) });
57
+ else {
58
+ const { pinned, rest: others } = accountRows(assets, pinnedSymbol, { order, pinnedId });
59
+ list = _jsxs("ul", { className: 'hig-account-assets', children: [row(pinned, true, pinnedId), others.map(asset => row(asset, false, pinnedId))] });
60
+ }
61
+ return _jsxs("section", { ...rest, className: `hig-account-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title ?? messages.account ?? en.account, onBack: onBack, action: headerAction ?? (onShowAddress && _jsxs("button", { type: 'button', className: 'hig-swap-back hig-account-address', "aria-label": messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: [qrIcon, _jsx(PressDecoration, { kind: 'back' })] })) }), _jsxs("div", { className: 'hig-account-summary', children: [_jsx("div", { className: 'hig-account-balance', children: _jsx(AnimatedNumberReadout, { value: total, label: messages.accountBalance ?? en.accountBalance, options: usd }) }), onDeposit && _jsx(Button, { onClick: onDeposit, children: depositLabel ?? messages.deposit ?? en.deposit })] }), list] });
62
+ }
@@ -0,0 +1,36 @@
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 extends Omit<React.HTMLAttributes<HTMLElement>, 'title' | 'onSelect'> {
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
+ /** Dims the rows and ignores presses, for example while a change is being applied. */
25
+ disabled?: boolean;
26
+ /** A muted line under the header that explains the screen: Choose the language used throughout the app. */
27
+ description?: string;
28
+ /** Set false to leave out the search field, for a short list. Default `true`. */
29
+ search?: boolean;
30
+ /** With a hardware pointer, focus the search field on mount so typing filters at once. */
31
+ autoFocus?: boolean;
32
+ }
33
+ /** 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. */
34
+ export declare function filterLanguages(languages: readonly LanguageOption[], query: string): LanguageOption[];
35
+ /** Choose the app's language: 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. */
36
+ export declare function LanguageBlock({ title, onBack, headerAction, languages, value, onSelect, search, autoFocus, disabled, description, className, ...rest }: LanguageBlockProps): React.JSX.Element;
@@ -0,0 +1,52 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useMemo, useRef, useState } from 'react';
4
+ import * as en from '@bloxwap/hig/contracts/messages';
5
+ import { PressDecoration, useHIG } from '../provider.js';
6
+ import { SearchInput } from '../field.js';
7
+ import { ScreenHeader } from './screen-header.js';
8
+ const fold = (text) => text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
9
+ /** 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. */
10
+ export function filterLanguages(languages, query) {
11
+ const needle = fold(query.trim());
12
+ return needle === '' ? [...languages] : languages.filter(language => fold(`${language.name} ${language.description ?? ''} ${language.code}`).includes(needle));
13
+ }
14
+ const check = _jsx("svg", { className: 'hig-language-check', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '20', height: '20', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round', children: _jsx("path", { d: 'm4.5 10.5 3.5 3.5 7.5-8' }) });
15
+ /** Choose the app's language: 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. */
16
+ export function LanguageBlock({ title, onBack, headerAction, languages, value = null, onSelect, search = true, autoFocus, disabled, description, className, ...rest }) {
17
+ const { messages } = useHIG();
18
+ const heading = title ?? messages.language ?? en.language;
19
+ const [query, setQuery] = useState('');
20
+ const [active, setActive] = useState(-1);
21
+ const field = useRef(null), list = useRef(null);
22
+ useEffect(() => { if (autoFocus && window.matchMedia?.('(pointer: fine)').matches)
23
+ field.current?.focus(); }, []);
24
+ const rows = useMemo(() => filterLanguages(languages, query), [languages, query]);
25
+ useEffect(() => { setActive(-1); }, [query]);
26
+ useEffect(() => { if (active >= 0)
27
+ list.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({ block: 'nearest' }); }, [active]);
28
+ // From the search field, the arrow keys move through the matches and Enter chooses one: the only match, or the one the arrows reached.
29
+ const onKeyDown = (event) => {
30
+ if (event.key === 'ArrowDown') {
31
+ event.preventDefault();
32
+ setActive(index => Math.min(index + 1, rows.length - 1));
33
+ }
34
+ else if (event.key === 'ArrowUp') {
35
+ event.preventDefault();
36
+ setActive(index => Math.max(index - 1, 0));
37
+ }
38
+ else if (event.key === 'Enter') {
39
+ const choice = rows[active] ?? (rows.length === 1 ? rows[0] : undefined);
40
+ if (choice) {
41
+ event.preventDefault();
42
+ if (!disabled)
43
+ onSelect(choice);
44
+ }
45
+ }
46
+ };
47
+ const label = messages.searchLanguages ?? en.searchLanguages;
48
+ return _jsxs("section", { ...rest, className: `hig-language-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: heading, onBack: onBack, action: headerAction }), description && _jsx("p", { className: 'hig-settings-description', children: description }), search && _jsx(SearchInput, { ref: field, "aria-label": label, placeholder: label, value: query, onChange: event => setQuery(event.target.value), onKeyDown: onKeyDown, enterKeyHint: 'search', autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false }), rows.length === 0 && _jsx("p", { className: 'hig-swap-empty', role: 'status', children: messages.noResults ?? en.noResults }), rows.length > 0 && _jsx("div", { ref: list, className: 'hig-language-list', role: 'radiogroup', "aria-label": heading, "aria-disabled": disabled || undefined, children: rows.map((language, index) => {
49
+ const selected = language.code === value;
50
+ return _jsxs("button", { type: 'button', role: 'radio', "aria-checked": selected, lang: language.code, className: 'hig-language-row', "data-active": index === active || undefined, disabled: disabled, onClick: () => onSelect(language), children: [_jsx("span", { className: 'hig-language-flag', "aria-hidden": 'true', children: typeof language.flag === 'string' ? _jsx("img", { src: language.flag, alt: '' }) : language.flag ?? language.code.slice(0, 2).toUpperCase() }), _jsxs("span", { className: 'hig-language-text', children: [_jsx("strong", { children: language.name }), language.description && _jsx("span", { lang: '', children: language.description })] }), selected && check, _jsx(PressDecoration, { kind: 'row', disabled: !!disabled })] }, language.code);
51
+ }) })] });
52
+ }
@@ -0,0 +1,93 @@
1
+ import React from 'react';
2
+ import { type Figure } from '../figure.js';
3
+ import type { AssetArtwork } from '../asset-balance-row.js';
4
+ /** The words of the block. They are trading terms, so the host supplies them in its own vocabulary and language; HIG ships none. */
5
+ export interface ManagePositionBlockLabels {
6
+ title: string;
7
+ margin: string;
8
+ notional: string;
9
+ liquidation: string;
10
+ /** `99.8% to liquidation`: receives the formatted percent. */
11
+ toLiquidation: (percent: string) => string;
12
+ mark: string;
13
+ entry: string;
14
+ /** Accessible words for the direction arrow. */
15
+ long: string;
16
+ short: string;
17
+ }
18
+ /** A number the host supplies as a number so it updates place by place: `{value:66000,options:{style:'currency',currency:'USD'}}`. `null` reads as unknown. */
19
+ export type ManagePositionBlockFigure = Figure;
20
+ /** The position's artwork: an image URL, a host element, or a function that draws a host element and receives `failed`, to call when that element cannot draw (an SVG that did not load); the row then shows `iconFallback` or the initials. */
21
+ export type ManagePositionIcon = AssetArtwork | ((failed: () => void) => React.ReactNode);
22
+ export interface ManagePositionBlockAction {
23
+ id: string;
24
+ label: string;
25
+ onSelect: () => void;
26
+ disabled?: boolean;
27
+ /** Trailing value of the row, before the chevron: host text or a live figure, such as the price a resting trigger is set at. */
28
+ value?: string | ManagePositionBlockFigure;
29
+ /** Colours `value`. The default is the muted value colour. */
30
+ tone?: 'positive' | 'negative' | 'muted';
31
+ }
32
+ /** The position being managed, shown as the row under the actions. */
33
+ export interface ManagePositionBlockSummary {
34
+ name: string;
35
+ /** An image URL, a host element, or a function that draws one and reports its failure. An image or element that fails shows `iconFallback`, else the initials. */
36
+ icon?: ManagePositionIcon;
37
+ /** A host element drawn in place of an `icon` that failed to draw. Without it the row shows the initials. */
38
+ iconFallback?: React.ReactNode;
39
+ /** Short ticker for the initials when there is no artwork: BTC. Without it the first letters of the name are shown. */
40
+ symbol?: string;
41
+ /** Host text after the name, drawn as a small `Badge`, such as a venue. */
42
+ badge?: string;
43
+ /** One line under the row, such as that the profit and loss is stale or estimated. */
44
+ caption?: string;
45
+ /** Makes the whole row a button, for example one that opens the market. Needs `label`. */
46
+ onSelect?: () => void;
47
+ /** Accessible name of the row when it is a button, read before what the row shows: View Bitcoin. The caption is its description. */
48
+ label?: string;
49
+ /** 40 reads `40×`. */
50
+ leverage?: number;
51
+ /** Size in asset units. */
52
+ size?: number | null;
53
+ /** Profit and loss in dollars. */
54
+ pnl?: number | null;
55
+ /** Profit and loss as a fraction: -0.0025 reads -0.25%. */
56
+ pnlPercent?: number | null;
57
+ }
58
+ export interface ManagePositionBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
59
+ labels: ManagePositionBlockLabels;
60
+ /** Margin mode, the title of the first card: Demo, Cross, Isolated. Without it the title is the margin label. */
61
+ mode?: string;
62
+ side: 'long' | 'short';
63
+ entry: number;
64
+ mark?: number | null;
65
+ liquidation?: number | null;
66
+ margin: number;
67
+ notional: number;
68
+ /** Format of the three prices, such as another currency. They are drawn compact: no extra zeros. */
69
+ priceOptions?: Intl.NumberFormatOptions;
70
+ actions: readonly ManagePositionBlockAction[];
71
+ position?: ManagePositionBlockSummary;
72
+ /** Format of the position's profit and loss, merged over the default: signed US dollars with up to four decimals. */
73
+ pnlOptions?: Intl.NumberFormatOptions;
74
+ onBack?: () => void;
75
+ /** A control on the trailing edge of the header, usually an `IconButton`. */
76
+ headerAction?: React.ReactNode;
77
+ /** `id` of the heading, so a dialog or sheet can name itself with `aria-labelledby`. */
78
+ headingId?: string;
79
+ }
80
+ /** Distance left before liquidation. `total` is the span from entry to liquidation, `buffer` what remains of it between the mark and liquidation (the whole span while in profit, nothing once past liquidation), `drawdown` the rest, and `share` the buffer as a fraction. Unknown prices, or a liquidation price on the wrong side of entry, give an empty corridor. */
81
+ export declare function positionCorridor({ side, entry, mark, liquidation }: {
82
+ side: 'long' | 'short';
83
+ entry: number;
84
+ mark?: number | null;
85
+ liquidation?: number | null;
86
+ }): {
87
+ total: number;
88
+ buffer: number;
89
+ drawdown: number;
90
+ share: number | null;
91
+ };
92
+ /** Manage one open position: margin against notional (with the share left before liquidation) as a `BarMark` and the liquidation, mark and entry prices as a `BarPnl`, both drawn without a card because they are read-only, the host's actions as one `ListGroup` of rows, and the position itself underneath. */
93
+ export declare function ManagePositionBlock({ labels, mode, side, entry, mark, liquidation, margin, notional, priceOptions, actions, position, pnlOptions, onBack, headerAction, headingId, className, ...rest }: ManagePositionBlockProps): React.JSX.Element;