@bloxwap/hig 0.6.0 → 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 (167) hide show
  1. package/chart/README.md +1 -1
  2. package/contracts/README.md +1 -1
  3. package/contracts/dist/index.d.ts +16 -0
  4. package/contracts/dist/index.js +22 -0
  5. package/contracts/dist/messages.d.ts +6 -0
  6. package/contracts/dist/messages.js +3 -1
  7. package/feedback/README.md +1 -1
  8. package/native/README.md +1 -1
  9. package/native/dist/account-block.d.ts +53 -7
  10. package/native/dist/account-block.js +42 -9
  11. package/native/dist/animated-number-model.d.ts +7 -1
  12. package/native/dist/animated-number-model.js +50 -1
  13. package/native/dist/animated-number.d.ts +3 -1
  14. package/native/dist/animated-number.js +8 -5
  15. package/native/dist/asset-balance-row.d.ts +17 -1
  16. package/native/dist/asset-balance-row.js +13 -8
  17. package/native/dist/bar-mark.d.ts +14 -2
  18. package/native/dist/bar-mark.js +19 -5
  19. package/native/dist/bar-pnl.js +5 -4
  20. package/native/dist/blocks.d.ts +8 -14
  21. package/native/dist/blocks.js +5 -6
  22. package/native/dist/button.js +3 -1
  23. package/native/dist/data.d.ts +1 -1
  24. package/native/dist/data.js +6 -4
  25. package/native/dist/field.d.ts +14 -4
  26. package/native/dist/field.js +33 -7
  27. package/native/dist/figure.d.ts +23 -0
  28. package/native/dist/figure.js +10 -0
  29. package/native/dist/language-block.d.ts +5 -1
  30. package/native/dist/language-block.js +3 -3
  31. package/native/dist/list-group.d.ts +42 -8
  32. package/native/dist/list-group.js +71 -13
  33. package/native/dist/manage-position-block.d.ts +28 -2
  34. package/native/dist/manage-position-block.js +36 -11
  35. package/native/dist/market-row.d.ts +46 -0
  36. package/native/dist/market-row.js +30 -0
  37. package/native/dist/notifications-block.d.ts +30 -2
  38. package/native/dist/notifications-block.js +16 -8
  39. package/native/dist/pickers.d.ts +24 -2
  40. package/native/dist/pickers.js +16 -8
  41. package/native/dist/position-block.d.ts +66 -10
  42. package/native/dist/position-block.js +45 -11
  43. package/native/dist/profile-block.d.ts +29 -5
  44. package/native/dist/profile-block.js +25 -5
  45. package/native/dist/provider.d.ts +9 -3
  46. package/native/dist/provider.js +7 -3
  47. package/native/dist/radio-group.d.ts +9 -3
  48. package/native/dist/radio-group.js +4 -5
  49. package/native/dist/recipes.d.ts +6 -0
  50. package/native/dist/recipes.js +6 -0
  51. package/native/dist/reward-block.d.ts +45 -6
  52. package/native/dist/reward-block.js +30 -12
  53. package/native/dist/screen-header.d.ts +49 -0
  54. package/native/dist/screen-header.js +29 -0
  55. package/native/dist/selection.d.ts +2 -2
  56. package/native/dist/setting-header.d.ts +2 -8
  57. package/native/dist/setting-header.js +2 -11
  58. package/native/dist/setting-switch.d.ts +14 -1
  59. package/native/dist/setting-switch.js +5 -2
  60. package/native/dist/signals-block.d.ts +26 -2
  61. package/native/dist/signals-block.js +14 -4
  62. package/native/dist/sound-haptics-block.d.ts +29 -2
  63. package/native/dist/sound-haptics-block.js +18 -7
  64. package/native/dist/status.d.ts +6 -5
  65. package/native/dist/status.js +5 -5
  66. package/native/dist/sticky-header.d.ts +28 -0
  67. package/native/dist/sticky-header.js +21 -0
  68. package/native/dist/surface.d.ts +3 -1
  69. package/native/dist/surface.js +2 -1
  70. package/native/dist/swap-panel-block.d.ts +2 -1
  71. package/native/dist/swap-panel-block.js +9 -6
  72. package/native/dist/swap-parts.d.ts +5 -3
  73. package/native/dist/swap-parts.js +2 -2
  74. package/native/dist/swap-shared.d.ts +6 -0
  75. package/native/dist/swap-views.js +5 -3
  76. package/native/dist/switch-row.d.ts +3 -2
  77. package/native/dist/switch-row.js +5 -3
  78. package/native/dist/switch.d.ts +4 -2
  79. package/native/dist/switch.js +3 -3
  80. package/native/dist/target-block.d.ts +33 -6
  81. package/native/dist/target-block.js +19 -6
  82. package/native/dist/token-action-block.d.ts +17 -9
  83. package/native/dist/token-action-block.js +14 -6
  84. package/native/dist/trade-history-detail-block.d.ts +26 -1
  85. package/native/dist/trade-history-detail-block.js +17 -9
  86. package/native/dist/trade-history-list-block.d.ts +71 -5
  87. package/native/dist/trade-history-list-block.js +50 -15
  88. package/native/dist/wallet-address-core.d.ts +25 -0
  89. package/native/dist/wallet-address-core.js +31 -0
  90. package/native/dist/wallet-address.d.ts +6 -10
  91. package/native/dist/wallet-address.js +16 -20
  92. package/native-fonts/README.md +1 -1
  93. package/og-fonts/README.md +1 -1
  94. package/package.json +21 -1
  95. package/react/README.md +1 -1
  96. package/react/dist/animated-number-model.d.ts +6 -0
  97. package/react/dist/animated-number-model.js +33 -0
  98. package/react/dist/animated-number.d.ts +5 -1
  99. package/react/dist/animated-number.js +12 -8
  100. package/react/dist/asset-balance-row.d.ts +17 -1
  101. package/react/dist/asset-balance-row.js +11 -3
  102. package/react/dist/bar-mark.d.ts +5 -2
  103. package/react/dist/bar-mark.js +5 -3
  104. package/react/dist/blocks/account-block.d.ts +53 -7
  105. package/react/dist/blocks/account-block.js +45 -10
  106. package/react/dist/blocks/language-block.d.ts +5 -1
  107. package/react/dist/blocks/language-block.js +6 -5
  108. package/react/dist/blocks/manage-position-block.d.ts +28 -2
  109. package/react/dist/blocks/manage-position-block.js +23 -4
  110. package/react/dist/blocks/market-row.d.ts +20 -9
  111. package/react/dist/blocks/market-row.js +12 -4
  112. package/react/dist/blocks/notifications-block.d.ts +25 -2
  113. package/react/dist/blocks/notifications-block.js +11 -2
  114. package/react/dist/blocks/pickers.d.ts +21 -1
  115. package/react/dist/blocks/pickers.js +30 -10
  116. package/react/dist/blocks/position-block.d.ts +34 -11
  117. package/react/dist/blocks/position-block.js +16 -5
  118. package/react/dist/blocks/profile-block.d.ts +29 -6
  119. package/react/dist/blocks/profile-block.js +31 -5
  120. package/react/dist/blocks/reward-block.d.ts +53 -14
  121. package/react/dist/blocks/reward-block.js +20 -10
  122. package/react/dist/blocks/screen-header.d.ts +26 -2
  123. package/react/dist/blocks/screen-header.js +13 -5
  124. package/react/dist/blocks/setting-switch.d.ts +14 -1
  125. package/react/dist/blocks/setting-switch.js +8 -4
  126. package/react/dist/blocks/signals-block.d.ts +21 -2
  127. package/react/dist/blocks/signals-block.js +5 -5
  128. package/react/dist/blocks/sound-haptics-block.d.ts +25 -3
  129. package/react/dist/blocks/sound-haptics-block.js +11 -7
  130. package/react/dist/blocks/sticky-header.d.ts +9 -0
  131. package/react/dist/blocks/sticky-header.js +43 -0
  132. package/react/dist/blocks/swap/amount-card.js +2 -1
  133. package/react/dist/blocks/swap/settings.js +2 -2
  134. package/react/dist/blocks/swap/shared.d.ts +7 -1
  135. package/react/dist/blocks/swap/shared.js +6 -4
  136. package/react/dist/blocks/swap-panel-block.d.ts +2 -0
  137. package/react/dist/blocks/swap-panel-block.js +6 -6
  138. package/react/dist/blocks/target-block.d.ts +28 -6
  139. package/react/dist/blocks/target-block.js +17 -9
  140. package/react/dist/blocks/token-action-block.d.ts +17 -8
  141. package/react/dist/blocks/token-action-block.js +9 -6
  142. package/react/dist/blocks/trade-history-detail-block.d.ts +21 -1
  143. package/react/dist/blocks/trade-history-detail-block.js +5 -4
  144. package/react/dist/blocks/trade-history-list-block.d.ts +29 -5
  145. package/react/dist/blocks/trade-history-list-block.js +15 -8
  146. package/react/dist/blocks.d.ts +8 -8
  147. package/react/dist/blocks.js +2 -2
  148. package/react/dist/button.js +6 -4
  149. package/react/dist/data.js +3 -3
  150. package/react/dist/field.d.ts +14 -4
  151. package/react/dist/field.js +19 -6
  152. package/react/dist/figure.d.ts +23 -0
  153. package/react/dist/figure.js +12 -0
  154. package/react/dist/list-group.d.ts +41 -8
  155. package/react/dist/list-group.js +44 -12
  156. package/react/dist/provider.d.ts +40 -3
  157. package/react/dist/provider.js +63 -6
  158. package/react/dist/selection.d.ts +8 -2
  159. package/react/dist/selection.js +11 -6
  160. package/react/dist/styles.css +164 -9
  161. package/react/dist/surface.d.ts +5 -1
  162. package/react/dist/surface.js +1 -1
  163. package/react/dist/wallet-address-core.d.ts +23 -0
  164. package/react/dist/wallet-address-core.js +24 -0
  165. package/react/dist/wallet-address.d.ts +6 -12
  166. package/react/dist/wallet-address.js +5 -16
  167. package/tokens/README.md +1 -1
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { type SettingAction } from './setting-switch.js';
2
3
  /** One kind of notification. Every word is host text. */
3
4
  export interface NotificationsItem {
4
5
  id: string;
@@ -7,17 +8,39 @@ export interface NotificationsItem {
7
8
  checked: boolean;
8
9
  onCheckedChange: (checked: boolean) => void;
9
10
  disabled?: boolean;
11
+ /** Always on and not changeable: shown on at full strength and read as unavailable. */
12
+ locked?: boolean;
13
+ /** Host content after the label, such as a badge. It is part of the switch's name. */
14
+ labelAccessory?: React.ReactNode;
15
+ /** Host words for the `labelAccessory`, read after the label and a pause in place of its content: `Push, New`. */
16
+ labelAccessoryLabel?: string;
17
+ /** A neutral line under the card, announced when it changes, for progress or a hint: Registering this device. */
18
+ hint?: string;
10
19
  /** Why turning it on failed, under the card: Push request timed out. It is announced when it appears. */
11
20
  error?: string;
21
+ /** A secondary action under the card, such as Open Settings after the permission was refused. `feedback: false` keeps the provider's press feedback off it. */
22
+ action?: SettingAction;
23
+ }
24
+ /** Notifications under one optional heading: Alert types. */
25
+ export interface NotificationsGroup {
26
+ id: string;
27
+ title?: string;
28
+ items: readonly NotificationsItem[];
12
29
  }
13
30
  export interface NotificationsBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
14
31
  /** Heading: Notifications. */
15
32
  title: string;
33
+ /** A muted line under the header that explains the screen. */
34
+ description?: string;
16
35
  /** One card each, in order. */
17
- items: readonly NotificationsItem[];
36
+ items?: readonly NotificationsItem[];
37
+ /** More cards under the items, in groups with an optional heading, 24 units apart. */
38
+ groups?: readonly NotificationsGroup[];
18
39
  onBack?: () => void;
19
40
  /** A control on the trailing edge of the header, usually an `IconButton`. */
20
41
  headerAction?: React.ReactNode;
42
+ /** Pins the header to the top of the nearest scrolling container, transparent at rest and filled with `--hig-sticky-header-background` once content scrolls under it. */
43
+ stickyHeader?: boolean;
21
44
  }
22
45
  /** The notifications the viewer receives: each kind is a card with a switch and a line of explanation, and a failure to turn one on reads under its card. */
23
- export declare function NotificationsBlock({ title, items, onBack, headerAction, className, ...rest }: NotificationsBlockProps): React.JSX.Element;
46
+ export declare function NotificationsBlock({ title, description, items, groups, onBack, headerAction, stickyHeader, className, ...rest }: NotificationsBlockProps): React.JSX.Element;
@@ -1,8 +1,17 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from 'react';
4
+ import { Button } from '../button.js';
3
5
  import { ScreenHeader } from './screen-header.js';
4
6
  import { SettingSwitch } from './setting-switch.js';
7
+ function Item({ item }) {
8
+ return _jsxs("div", { className: 'hig-notifications-item', children: [_jsx("div", { className: 'hig-setting-card', children: _jsx(SettingSwitch, { label: item.label, description: item.description, checked: item.checked, disabled: item.disabled, locked: item.locked, labelAccessory: item.labelAccessory, labelAccessoryLabel: item.labelAccessoryLabel, onCheckedChange: item.onCheckedChange }) }), item.hint && _jsx("p", { role: 'status', className: 'hig-setting-hint', children: item.hint }), item.error && _jsx("p", { role: 'alert', className: 'hig-setting-error', children: item.error }), item.action && _jsx(Button, { className: 'hig-notifications-action', intent: 'secondary', fullWidth: true, disabled: item.action.disabled, suppressFeedback: item.action.feedback === false, onClick: item.action.onSelect, children: item.action.label })] });
9
+ }
10
+ function Group({ group }) {
11
+ const id = useId();
12
+ return _jsxs("section", { className: 'hig-notifications-group', "aria-labelledby": group.title ? id : undefined, children: [group.title && _jsx("div", { className: 'hig-signals-group-header', children: _jsx("h3", { id: id, children: group.title }) }), group.items.length > 0 && _jsx("div", { className: 'hig-setting-cards', children: group.items.map(item => _jsx(Item, { item: item }, item.id)) })] });
13
+ }
5
14
  /** The notifications the viewer receives: each kind is a card with a switch and a line of explanation, and a failure to turn one on reads under its card. */
6
- export function NotificationsBlock({ title, items, onBack, headerAction, className, ...rest }) {
7
- return _jsxs("section", { ...rest, className: `hig-settings-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, action: headerAction }), items.length > 0 && _jsx("div", { className: 'hig-setting-cards', children: items.map(item => _jsxs("div", { className: 'hig-notifications-item', children: [_jsx("div", { className: 'hig-setting-card', children: _jsx(SettingSwitch, { label: item.label, description: item.description, checked: item.checked, disabled: item.disabled, onCheckedChange: item.onCheckedChange }) }), item.error && _jsx("p", { role: 'alert', className: 'hig-setting-error', children: item.error })] }, item.id)) })] });
15
+ export function NotificationsBlock({ title, description, items = [], groups, onBack, headerAction, stickyHeader, className, ...rest }) {
16
+ return _jsxs("section", { ...rest, className: `hig-settings-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, action: headerAction, stickyHeader: stickyHeader }), description && _jsx("p", { className: 'hig-settings-description', children: description }), items.length > 0 && _jsx("div", { className: 'hig-setting-cards', children: items.map(item => _jsx(Item, { item: item }, item.id)) }), groups?.map(group => _jsx(Group, { group: group }, group.id))] });
8
17
  }
@@ -21,7 +21,21 @@ export interface PickerListProps {
21
21
  loading?: boolean;
22
22
  /** With a hardware pointer, focus the search field on mount so typing filters at once. */
23
23
  autoFocus?: boolean;
24
+ /** `false` leaves out the search field, for a short list. Defaults to `true`. */
25
+ search?: boolean;
26
+ /** Shows a token's balance when it is zero, where by default only a balance above zero is drawn. */
27
+ zeroBalances?: boolean;
28
+ /** A visible label over the search field, which then names it in place of the built-in hidden label. */
29
+ searchLabel?: string;
30
+ /** A ref to the search input, for example to focus it or register it with a host sheet. */
31
+ searchRef?: React.Ref<HTMLInputElement>;
32
+ /** Attributes for the search input, such as `name`, `autoComplete`, `data-1p-ignore` or `onFocus`/`onBlur`. The value and its change handler stay HIG's; a host `onKeyDown` runs before the list's arrow keys. */
33
+ searchInputProps?: PickerInputProps;
24
34
  }
35
+ /** Host attributes for a picker's input: anything an `<input>` takes, including `data-*`, except the value and its change handler. */
36
+ export type PickerInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'defaultValue' | 'onChange' | 'type' | 'children'> & {
37
+ [attribute: `data-${string}`]: string | number | boolean | undefined;
38
+ };
25
39
  export interface FromPickerBlockProps extends PickerListProps {
26
40
  /** The connected wallet. Omit for a list with no wallet row at all. */
27
41
  wallet?: SwapWallet;
@@ -48,13 +62,19 @@ export interface ToPickerBlockProps extends Partial<PickerListProps> {
48
62
  addressPlaceholder?: string;
49
63
  /** Shows the scan button. HIG ships no scanner: the host opens its own and writes the result to `address`. */
50
64
  onScan?: () => void;
65
+ /** A visible label over the address field, which then names it in place of the built-in hidden “Recipient”. */
66
+ addressLabel?: string;
67
+ /** A ref to the address input, for example to focus it or register it with a host sheet. */
68
+ addressRef?: React.Ref<HTMLInputElement>;
69
+ /** Attributes for the address input, such as `name='recipient'`, `data-1p-ignore`, `data-lpignore`, a mono `className` or `onFocus`/`onBlur`. The value and its change handler stay HIG's. */
70
+ addressInputProps?: PickerInputProps;
51
71
  className?: string;
52
72
  }
53
73
  /**
54
74
  * Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
55
75
  * searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
56
76
  */
57
- export declare function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, className, tokens, onSelect, ...list }: ToPickerBlockProps): React.JSX.Element;
77
+ export declare function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, addressLabel, addressRef, addressInputProps, className, tokens, onSelect, ...list }: ToPickerBlockProps): React.JSX.Element;
58
78
  /** @deprecated Renamed `FromPickerBlock`. The old name keeps working until the next major release. */
59
79
  export declare const FromPicker: typeof FromPickerBlock;
60
80
  /** @deprecated Renamed `FromPickerBlockProps`. */
@@ -1,20 +1,34 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useEffect, useId, useMemo, useRef, useState } from 'react';
3
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
4
4
  import * as en from '@bloxwap/hig/contracts/messages';
5
- import { useHIG } from '../provider.js';
5
+ import { PressDecoration, useHIG } from '../provider.js';
6
6
  import { Button, IconButton } from '../button.js';
7
- import { Input, SearchInput } from '../field.js';
7
+ import { Field, Input, SearchInput } from '../field.js';
8
8
  import { Filter } from '../selection.js';
9
9
  import { SwapIcon, SwapNumber, TokenIcon, usdNumber, addressGradient, chainsOf, fuzzyMatch, shortAddress } from './swap/shared.js';
10
- function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected = null, onSelect, loading, autoFocus, label }) {
10
+ /** A row shows a known balance above zero, or a zero one when the host asks for it. */
11
+ const showBalance = (token, zero) => token.balance != null && Number.isFinite(token.balance) && (token.balance > 0 || (!!zero && token.balance === 0));
12
+ /** One callback ref that sets each given ref. */
13
+ function useMergedRef(...refs) {
14
+ const latest = useRef(refs);
15
+ latest.current = refs;
16
+ return useCallback((node) => { for (const ref of latest.current) {
17
+ if (typeof ref === 'function')
18
+ ref(node);
19
+ else if (ref)
20
+ ref.current = node;
21
+ } }, []);
22
+ }
23
+ function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected = null, onSelect, loading, autoFocus, search: searchable = true, zeroBalances, searchLabel, searchRef, searchInputProps, label }) {
11
24
  const { messages } = useHIG();
12
25
  const id = useId();
13
26
  const [query, setQuery] = useState('');
14
27
  const [chainId, setChainId] = useState(null);
15
- const [active, setActive] = useState(0);
28
+ const [active, setActive] = useState(searchable ? 0 : -1);
16
29
  const list = useRef(null);
17
30
  const search = useRef(null);
31
+ const searchInput = useMergedRef(search, searchRef);
18
32
  useEffect(() => { if (autoFocus && window.matchMedia?.('(pointer: fine)').matches)
19
33
  search.current?.focus(); }, []);
20
34
  const options = useMemo(() => chains ?? chainsOf(tokens), [chains, tokens]);
@@ -29,7 +43,8 @@ function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected =
29
43
  return { rows: filtered, hotCount: 0 };
30
44
  return { rows: [...hot, ...filtered.filter(token => !hot.includes(token))], hotCount: hot.length };
31
45
  }, [tokens, hotTokenIds, query, chainId]);
32
- useEffect(() => { setActive(0); }, [query, chainId]);
46
+ // Without a search field there is no arrow-key cursor, so no row is highlighted until the pointer moves over one.
47
+ useEffect(() => { setActive(searchable ? 0 : -1); }, [query, chainId, searchable]);
33
48
  useEffect(() => { list.current?.querySelector('[data-active="true"]')?.scrollIntoView?.({ block: 'nearest' }); }, [active]);
34
49
  const onKeyDown = (event) => {
35
50
  if (event.key === 'ArrowDown') {
@@ -49,9 +64,12 @@ function TokenList({ tokens, chains, chainFilter = true, hotTokenIds, selected =
49
64
  const filters = [{ value: '', label: messages.swapAllChains ?? en.swapAllChains }, ...options.map(chain => ({ value: String(chain.chainId), label: chain.name, icon: chain.icon }))];
50
65
  const row = (token, index) => {
51
66
  const isSelected = selected?.id === token.id;
52
- return _jsx("div", { role: 'listitem', children: _jsxs("button", { type: 'button', className: 'hig-swap-row', "data-active": index === active, "data-selected": isSelected || undefined, onClick: () => onSelect(token), onPointerMove: () => setActive(index), children: [_jsx(TokenIcon, { token: token }), _jsxs("span", { className: 'hig-swap-row-text', children: [_jsx("strong", { children: token.name }), _jsxs("span", { children: [token.chain, isSelected ? ' · ' + (messages.swapSelected ?? en.swapSelected) : ''] })] }), (token.balance ?? 0) > 0 && _jsxs("span", { className: 'hig-swap-row-balance', children: [_jsx("strong", { children: _jsx(SwapNumber, { value: token.balance, options: { maximumFractionDigits: 6 } }) }), (token.price ?? 0) > 0 && _jsx(SwapNumber, { ...usdNumber((token.balance ?? 0) * (token.price ?? 0)) })] })] }) }, token.id);
67
+ return _jsx("div", { role: 'listitem', children: _jsxs("button", { type: 'button', className: 'hig-swap-row', "data-active": index === active, "data-selected": isSelected || undefined, onClick: () => onSelect(token), onPointerMove: () => setActive(index), children: [_jsx(TokenIcon, { token: token }), _jsxs("span", { className: 'hig-swap-row-text', children: [_jsx("strong", { children: token.name }), _jsxs("span", { children: [token.detail ?? token.chain, isSelected ? ' · ' + (messages.swapSelected ?? en.swapSelected) : ''] })] }), showBalance(token, zeroBalances) && _jsxs("span", { className: 'hig-swap-row-balance', children: [_jsx("strong", { children: _jsx(SwapNumber, { value: token.balance, options: { maximumFractionDigits: 6 }, suffix: token.unitsSuffix }) }), (token.price ?? 0) > 0 && _jsx(SwapNumber, { ...usdNumber((token.balance ?? 0) * (token.price ?? 0)) })] }), _jsx(PressDecoration, { kind: 'row' })] }) }, token.id);
53
68
  };
54
- return _jsxs(_Fragment, { children: [_jsx(SearchInput, { ref: search, "aria-label": messages.swapSearchTokens ?? en.swapSearchTokens, placeholder: messages.swapSearchTokens ?? en.swapSearchTokens, value: query, onChange: event => setQuery(event.target.value), onKeyDown: onKeyDown, enterKeyHint: 'search', autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false }), chainFilter && options.length > 1 && _jsx(Filter, { label: messages.swapChains ?? en.swapChains, options: filters, value: chainId === null ? '' : String(chainId), onValueChange: next => setChainId(options.find(chain => String(chain.chainId) === next)?.chainId ?? null) }), _jsxs("div", { ref: list, className: 'hig-swap-list', "aria-busy": loading || undefined, children: [rows.length === 0 && _jsx("p", { className: 'hig-swap-empty', role: 'status', children: loading ? (messages.loading ?? en.loading) + '…' : messages.swapNoTokens ?? en.swapNoTokens }), hotCount > 0 && _jsxs("p", { className: 'hig-swap-section', id: `${id}-hot`, children: [_jsx(SwapIcon, { name: 'flame', size: 14 }), messages.swapHot ?? en.swapHot] }), hotCount > 0 && _jsx("div", { role: 'list', "aria-labelledby": `${id}-hot`, children: rows.slice(0, hotCount).map((token, index) => row(token, index)) }), hotCount > 0 && _jsx("p", { className: 'hig-swap-section', id: `${id}-all`, children: messages.swapAllTokens ?? en.swapAllTokens }), rows.length > hotCount && _jsx("div", { role: 'list', ...(hotCount > 0 ? { 'aria-labelledby': `${id}-all` } : { 'aria-label': label }), children: rows.slice(hotCount).map((token, index) => row(token, index + hotCount)) })] })] });
69
+ const searchName = messages.swapSearchTokens ?? en.swapSearchTokens;
70
+ const field = _jsx(SearchInput, { ref: searchInput, "aria-label": searchLabel ? undefined : searchName, placeholder: searchName, enterKeyHint: 'search', autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false, ...searchInputProps, value: query, onChange: event => setQuery(event.target.value), onKeyDown: event => { searchInputProps?.onKeyDown?.(event); if (!event.defaultPrevented)
71
+ onKeyDown(event); } });
72
+ return _jsxs(_Fragment, { children: [searchable && (searchLabel ? _jsx(Field, { label: searchLabel, children: field }) : field), chainFilter && options.length > 1 && _jsx(Filter, { label: messages.swapChains ?? en.swapChains, options: filters, value: chainId === null ? '' : String(chainId), onValueChange: next => setChainId(options.find(chain => String(chain.chainId) === next)?.chainId ?? null) }), _jsxs("div", { ref: list, className: 'hig-swap-list', "aria-busy": loading || undefined, children: [rows.length === 0 && _jsx("p", { className: 'hig-swap-empty', role: 'status', children: loading ? (messages.loading ?? en.loading) + '…' : messages.swapNoTokens ?? en.swapNoTokens }), hotCount > 0 && _jsxs("p", { className: 'hig-swap-section', id: `${id}-hot`, children: [_jsx(SwapIcon, { name: 'flame', size: 14 }), messages.swapHot ?? en.swapHot] }), hotCount > 0 && _jsx("div", { role: 'list', "aria-labelledby": `${id}-hot`, children: rows.slice(0, hotCount).map((token, index) => row(token, index)) }), hotCount > 0 && _jsx("p", { className: 'hig-swap-section', id: `${id}-all`, children: messages.swapAllTokens ?? en.swapAllTokens }), rows.length > hotCount && _jsx("div", { role: 'list', ...(hotCount > 0 ? { 'aria-labelledby': `${id}-all` } : { 'aria-label': label }), children: rows.slice(hotCount).map((token, index) => row(token, index + hotCount)) })] })] });
55
73
  }
56
74
  /**
57
75
  * Where the assets come from. A connected wallet shows its address, with a disconnect button the host can leave out, above
@@ -70,10 +88,12 @@ export function FromPickerBlock({ wallet, onConnect, onDisconnect, generateAddre
70
88
  * Where the assets go. On its own it is a destination address field with a scan button. With `tokens` it adds the
71
89
  * searchable token list, with the chain filter or, with `chainFilter={false}`, without it.
72
90
  */
73
- export function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, className, tokens, onSelect, ...list }) {
91
+ export function ToPickerBlock({ address, onAddressChange, addressPlaceholder, onScan, addressLabel, addressRef, addressInputProps, className, tokens, onSelect, ...list }) {
74
92
  const { messages } = useHIG();
75
93
  const label = messages.swapTo ?? en.swapTo;
76
- return _jsxs("div", { className: `hig-picker${className ? ` ${className}` : ''}`, role: 'group', "aria-label": label, children: [onAddressChange && _jsxs("div", { className: 'hig-swap-wallet', children: [_jsx(Input, { "aria-label": messages.swapRecipient ?? en.swapRecipient, placeholder: addressPlaceholder ?? messages.swapRecipient ?? en.swapRecipient, value: address ?? '', onChange: event => onAddressChange(event.target.value), autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false }), onScan && _jsx(IconButton, { intent: 'secondary', label: messages.swapScan ?? en.swapScan, onClick: onScan, children: _jsx(SwapIcon, { name: 'scan' }) })] }), tokens && onSelect && _jsx(TokenList, { ...list, tokens: tokens, onSelect: onSelect, label: label })] });
94
+ const recipient = messages.swapRecipient ?? en.swapRecipient;
95
+ const row = onAddressChange && _jsxs("div", { className: 'hig-swap-wallet', children: [_jsx(Input, { ref: addressRef, "aria-label": addressLabel ? undefined : recipient, placeholder: addressPlaceholder ?? recipient, autoComplete: 'off', autoCapitalize: 'none', autoCorrect: 'off', spellCheck: false, ...addressInputProps, value: address ?? '', onChange: event => onAddressChange(event.target.value) }), onScan && _jsx(IconButton, { intent: 'secondary', label: messages.swapScan ?? en.swapScan, onClick: onScan, children: _jsx(SwapIcon, { name: 'scan' }) })] });
96
+ return _jsxs("div", { className: `hig-picker${className ? ` ${className}` : ''}`, role: 'group', "aria-label": label, children: [row && (addressLabel ? _jsx(Field, { label: addressLabel, children: row }) : row), tokens && onSelect && _jsx(TokenList, { ...list, tokens: tokens, onSelect: onSelect, label: label })] });
77
97
  }
78
98
  /** @deprecated Renamed `FromPickerBlock`. The old name keeps working until the next major release. */
79
99
  export const FromPicker = FromPickerBlock;
@@ -1,25 +1,38 @@
1
1
  import React from 'react';
2
- /** A number the host supplies as a number so it updates place by place: `{value:0.53,options:{style:'currency',currency:'USD'}}`. `null` reads as unknown. */
3
- export interface PositionBlockFigure {
4
- value: number | null;
5
- options?: Intl.NumberFormatOptions;
6
- prefix?: string;
7
- suffix?: string;
8
- }
2
+ import { type Figure } from '../figure.js';
3
+ import { type ScreenHeaderControlProps } from './screen-header.js';
4
+ /** A number the host supplies as a number so it updates place by place: `{value:0.53,options:{style:'currency',currency:'USD'}}`, or Leverage as `{value:40,suffix:'×'}`. `null` reads as unknown. `formattedValue` is the host's own text for it, still moving place by place. */
5
+ export type PositionBlockFigure = Figure;
9
6
  /** One line of the summary: Notional, Fee, Liquidation. `value` is host text (`2% of profit`) or a live figure. `tone` colours the value; the default is the text colour. */
10
7
  export interface PositionBlockDetail {
11
8
  id?: string;
12
9
  label: string;
13
10
  value: string | PositionBlockFigure;
14
11
  tone?: 'positive' | 'negative' | 'muted';
12
+ /** Draws the value struck through, for a charge that does not apply, and reads this host text after it: Waived. */
13
+ struck?: string;
14
+ /** Host content right after the label, such as a badge that explains the line. It may be interactive. */
15
+ labelAccessory?: React.ReactNode;
15
16
  }
16
- /** One setting of the position: Size, Leverage, Stop Loss. With `onSelect` the row opens the host's own view and shows a chevron. */
17
+ /** One setting of the position: Size, Leverage, Stop Loss. With `onSelect` the row opens the host's own view and shows a chevron; with `onCheckedChange` the row is a switch. */
17
18
  export interface PositionBlockRow {
18
19
  id: string;
19
20
  label: string;
20
- value?: string;
21
+ /** Host text on the trailing edge, or a live figure that updates place by place. */
22
+ value?: string | PositionBlockFigure;
21
23
  onSelect?: () => void;
22
24
  disabled?: boolean;
25
+ /** With `onCheckedChange`, the row is a switch named by its label, and the whole row toggles it. */
26
+ checked?: boolean;
27
+ onCheckedChange?: (checked: boolean) => void;
28
+ }
29
+ /** An action on the paper trading row's card, under the switch, such as collecting what the paper position earned. */
30
+ export interface PositionBlockFlagAction {
31
+ label: string;
32
+ onSelect: () => void;
33
+ intent?: 'primary' | 'secondary' | 'destructive';
34
+ busy?: boolean;
35
+ disabled?: boolean;
23
36
  }
24
37
  /** The paper trading switch. The host supplies its name, because HIG ships no trading terms. */
25
38
  export interface PositionBlockFlag {
@@ -27,6 +40,8 @@ export interface PositionBlockFlag {
27
40
  checked: boolean;
28
41
  onCheckedChange: (checked: boolean) => void;
29
42
  disabled?: boolean;
43
+ /** A button on the row's card, under the switch. */
44
+ action?: PositionBlockFlagAction;
30
45
  }
31
46
  export interface PositionBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
32
47
  /** Heading: Position. */
@@ -35,7 +50,7 @@ export interface PositionBlockProps extends Omit<React.HTMLAttributes<HTMLElemen
35
50
  details: readonly PositionBlockDetail[];
36
51
  /** One sentence under the summary, such as the minimum margin. */
37
52
  note?: string;
38
- /** Shows the paper trading switch as a row of its own above the settings. */
53
+ /** Shows the paper trading switch as a row of its own above the settings. The whole row toggles it. */
39
54
  paperTrade?: PositionBlockFlag;
40
55
  /** The settings, as groups of rows. Each group is one rounded container. */
41
56
  groups: readonly (readonly PositionBlockRow[])[];
@@ -44,6 +59,14 @@ export interface PositionBlockProps extends Omit<React.HTMLAttributes<HTMLElemen
44
59
  onBack?: () => void;
45
60
  /** A control on the trailing edge of the header in place of Close. */
46
61
  headerAction?: React.ReactNode;
62
+ /** `id` of the heading, so a dialog or sheet can name itself with `aria-labelledby`. */
63
+ headingId?: string;
64
+ /** Set true to pin the header to the top of the nearest scrolling container while the rest scrolls under it. It is transparent at rest and fills with `--hig-sticky-header-background` once content scrolls under it. */
65
+ stickyHeader?: boolean;
66
+ /** Attributes for the header's Back `<button>`. */
67
+ backProps?: ScreenHeaderControlProps;
68
+ /** Attributes for the header's Close `<button>`. */
69
+ closeProps?: ScreenHeaderControlProps;
47
70
  }
48
71
  /** The position being opened or edited: a summary of what it costs and where it ends, an optional paper trading switch, and its settings as grouped rows that open the host's own views. */
49
- export declare function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, className, ...rest }: PositionBlockProps): React.JSX.Element;
72
+ export declare function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, headingId, stickyHeader, backProps, closeProps, className, ...rest }: PositionBlockProps): React.JSX.Element;
@@ -1,14 +1,25 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import * as en from '@bloxwap/hig/contracts/messages';
4
4
  import { useHIG } from '../provider.js';
5
+ import { Button } from '../button.js';
5
6
  import { Switch } from '../selection.js';
6
7
  import { ListGroup, ListRow } from '../list-group.js';
7
8
  import { AnimatedNumberReadout } from '../animated-number.js';
8
- import { ScreenHeader } from './screen-header.js';
9
- import { SwapIcon } from './swap/shared.js';
9
+ import { figureProps } from '../figure.js';
10
+ import { HeaderClose, ScreenHeader } from './screen-header.js';
11
+ const figure = (value) => typeof value === 'string' ? value : _jsx(AnimatedNumberReadout, { ...figureProps(value) });
12
+ /** A press anywhere on a switch row that is not on a control toggles the row's switch, through the switch itself so its change and feedback run once. */
13
+ function toggleRow(event) {
14
+ if (event.target.closest('a,button,input,label,select,textarea'))
15
+ return;
16
+ const input = event.currentTarget.querySelector('input[role="switch"]');
17
+ if (input && !input.disabled)
18
+ input.click();
19
+ }
10
20
  /** The position being opened or edited: a summary of what it costs and where it ends, an optional paper trading switch, and its settings as grouped rows that open the host's own views. */
11
- export function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, className, ...rest }) {
21
+ export function PositionBlock({ title, details, note, paperTrade, groups, onClose, onBack, headerAction, headingId, stickyHeader, backProps, closeProps, className, ...rest }) {
12
22
  const { messages } = useHIG();
13
- return _jsxs("section", { ...rest, className: `hig-position-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, action: headerAction ?? (onClose && _jsx("button", { type: 'button', className: 'hig-swap-back', "aria-label": messages.close ?? en.close, onClick: onClose, children: _jsx(SwapIcon, { name: 'close' }) })) }), details.length > 0 && _jsx("dl", { className: 'hig-position-details', children: details.map((detail, index) => _jsxs("div", { "data-tone": detail.tone, children: [_jsx("dt", { children: detail.label }), _jsx("dd", { className: 'hig-number', children: typeof detail.value === 'string' ? detail.value : _jsx(AnimatedNumberReadout, { ...detail.value }) })] }, detail.id ?? index)) }), note && _jsx("p", { className: 'hig-position-note', children: note }), (paperTrade || groups.some(group => group.length > 0)) && _jsxs("div", { className: 'hig-position-groups', children: [paperTrade && _jsx(ListGroup, { className: 'hig-position-flag', children: _jsx(ListRow, { label: paperTrade.label, disabled: paperTrade.disabled, trailing: _jsx(Switch, { label: paperTrade.label, checked: paperTrade.checked, disabled: paperTrade.disabled, onCheckedChange: paperTrade.onCheckedChange }) }) }), groups.map((group, index) => group.length > 0 && _jsx(ListGroup, { children: group.map(row => _jsx(ListRow, { label: row.label, value: row.value, onSelect: row.onSelect, disabled: row.disabled }, row.id)) }, index))] })] });
23
+ const flag = paperTrade && _jsx(ListRow, { label: paperTrade.label, disabled: paperTrade.disabled, onClick: toggleRow, trailing: _jsx(Switch, { label: paperTrade.label, checked: paperTrade.checked, disabled: paperTrade.disabled, onCheckedChange: paperTrade.onCheckedChange }) });
24
+ return _jsxs("section", { ...rest, className: `hig-position-block${className ? ` ${className}` : ''}`, children: [_jsx(ScreenHeader, { title: title, onBack: onBack, backProps: backProps, headingId: headingId, stickyHeader: stickyHeader, action: headerAction ?? (onClose && _jsx(HeaderClose, { onClose: onClose, label: messages.close ?? en.close, closeProps: closeProps })) }), details.length > 0 && _jsx("dl", { className: 'hig-position-details', children: details.map((detail, index) => _jsxs("div", { "data-tone": detail.tone, children: [_jsxs("dt", { children: [detail.label, detail.labelAccessory != null && _jsx("span", { className: 'hig-position-label-accessory', children: detail.labelAccessory })] }), _jsx("dd", { className: 'hig-number', children: detail.struck ? _jsxs(_Fragment, { children: [_jsx("span", { className: 'hig-position-struck', children: figure(detail.value) }), _jsxs("span", { className: 'hig-sr-only', children: [" ", detail.struck] })] }) : figure(detail.value) })] }, detail.id ?? index)) }), note && _jsx("p", { className: 'hig-position-note', children: note }), (paperTrade || groups.some(group => group.length > 0)) && _jsxs("div", { className: 'hig-position-groups', children: [paperTrade && _jsx(ListGroup, { className: 'hig-position-flag', children: paperTrade.action ? _jsxs("div", { className: 'hig-position-flag-card', children: [flag, _jsx("div", { className: 'hig-position-flag-action', children: _jsx(Button, { fullWidth: true, intent: paperTrade.action.intent ?? 'primary', busy: paperTrade.action.busy, disabled: paperTrade.action.disabled, onClick: paperTrade.action.onSelect, children: paperTrade.action.label }) })] }) : flag }), groups.map((group, index) => group.length > 0 && _jsx(ListGroup, { children: group.map(row => row.onCheckedChange ? _jsx(ListRow, { label: row.label, value: row.value == null ? undefined : figure(row.value), disabled: row.disabled, onClick: toggleRow, trailing: _jsx(Switch, { label: row.label, checked: !!row.checked, disabled: row.disabled, onCheckedChange: row.onCheckedChange }) }, row.id) : _jsx(ListRow, { label: row.label, value: row.value == null || typeof row.value === 'string' ? row.value : figure(row.value), onSelect: row.onSelect, disabled: row.disabled }, row.id)) }, index))] })] });
14
25
  }
@@ -1,18 +1,23 @@
1
1
  import React from 'react';
2
+ import { type Figure } from '../figure.js';
2
3
  import type { AssetArtwork } from '../asset-balance-row.js';
4
+ /** A row value that can change while the profile is shown, such as a balance: formatted with `options` between `prefix` and `suffix`, and updated place by place. `null` reads as unknown. */
5
+ export type ProfileFigure = Figure;
3
6
  /** One row of a profile section. With `onSelect` it opens something and shows a chevron; with `onCheckedChange` it is a switch. */
4
7
  export interface ProfileRow {
5
8
  id: string;
6
9
  label: string;
7
10
  /** Artwork before the label, such as an icon. */
8
11
  leading?: React.ReactNode;
9
- /** Short text on the trailing edge, such as a balance or `Off`. */
10
- value?: React.ReactNode;
12
+ /** Short text on the trailing edge, such as a balance or `Off`, or a live figure that updates place by place. */
13
+ value?: React.ReactNode | ProfileFigure;
14
+ /** Colours the value. Without it the value keeps the row's muted value style. */
15
+ tone?: 'positive' | 'warning' | 'negative' | 'muted';
11
16
  /** Anything richer on the trailing edge: icons or a `Badge`. */
12
17
  trailing?: React.ReactNode;
13
18
  onSelect?: () => void;
14
19
  disabled?: boolean;
15
- /** With `onCheckedChange`, the row is a switch: the track trails and the label names it. */
20
+ /** With `onCheckedChange`, the row is a switch: the track trails, the label names it, and a press anywhere on the row toggles it. */
16
21
  checked?: boolean;
17
22
  onCheckedChange?: (checked: boolean) => void;
18
23
  }
@@ -28,13 +33,27 @@ export interface ProfileStatus {
28
33
  label: string;
29
34
  tone?: 'positive' | 'warning' | 'negative' | 'info';
30
35
  }
36
+ /** The primary action under the name, such as Log in for a signed-out viewer. The host writes the label. */
37
+ export interface ProfileAction {
38
+ label: string;
39
+ onSelect: () => void;
40
+ disabled?: boolean;
41
+ /** Defaults to `primary`. */
42
+ intent?: 'primary' | 'secondary';
43
+ }
31
44
  export interface ProfileBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
32
- /** The name under the avatar: a display name or a shortened address. */
33
- name: string;
45
+ /** The name under the avatar: a display name or a shortened address. It may be left out when `action` is set, for a signed-out viewer. */
46
+ name?: string;
47
+ /** Host content beside the name, such as a badge. It stays in the accessibility tree, so give an interactive badge its own name. */
48
+ nameAccessory?: React.ReactNode;
34
49
  /** Colours the avatar when there is no artwork. */
35
50
  address?: string;
36
51
  /** An image URL or an element the host draws. */
37
52
  avatar?: AssetArtwork;
53
+ /** Makes the avatar a button, for example to choose a picture. `avatarLabel` names it. */
54
+ onAvatarPress?: () => void;
55
+ /** The accessible name of the avatar button, such as Change profile picture. Defaults to `name`, then the built-in “Change profile picture”. */
56
+ avatarLabel?: string;
38
57
  status?: ProfileStatus;
39
58
  /** Shows the edit control after the name. */
40
59
  onEditName?: () => void;
@@ -42,7 +61,11 @@ export interface ProfileBlockProps extends Omit<React.HTMLAttributes<HTMLElement
42
61
  onShowAddress?: () => void;
43
62
  /** Shows Close on the trailing edge of the top bar. */
44
63
  onClose?: () => void;
64
+ /** A full-width button under the name, such as Log in. */
65
+ action?: ProfileAction;
45
66
  sections: readonly ProfileSection[];
67
+ /** Host content under the sections, such as legal links. */
68
+ footer?: React.ReactNode;
46
69
  }
47
70
  /** A person's profile as one screen: who they are (avatar, status, name), then grouped rows that open their accounts, history, rewards and settings. */
48
- export declare function ProfileBlock({ name, address, avatar, status, onEditName, onShowAddress, onClose, sections, className, ...rest }: ProfileBlockProps): React.JSX.Element;
71
+ export declare function ProfileBlock({ name, nameAccessory, address, avatar, onAvatarPress, avatarLabel, status, onEditName, onShowAddress, onClose, action, sections, footer, className, ...rest }: ProfileBlockProps): React.JSX.Element;
@@ -1,15 +1,41 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import React, { useRef } from 'react';
3
4
  import * as en from '@bloxwap/hig/contracts/messages';
4
- import { useHIG } from '../provider.js';
5
- import { IconButton } from '../button.js';
6
- import { Switch } from '../selection.js';
5
+ import { PressDecoration, useControllable, useHIG } from '../provider.js';
6
+ import { Button, IconButton } from '../button.js';
7
7
  import { ListGroup, ListRow } from '../list-group.js';
8
+ import { AnimatedNumberReadout } from '../animated-number.js';
9
+ import { figureProps } from '../figure.js';
8
10
  import { qrIcon } from './screen-header.js';
9
11
  import { SwapIcon, addressGradient } from './swap/shared.js';
10
12
  const editIcon = _jsx("svg", { "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', width: '20', height: '20', fill: 'none', stroke: 'currentColor', strokeWidth: '1.6', strokeLinecap: 'round', strokeLinejoin: 'round', children: _jsx("path", { d: 'M12.5 4.5 15.5 7.5 7.5 15.5H4.5V12.5ZM10.5 15.5H16' }) });
13
+ /** True for a `ProfileFigure`: a plain object with a `value`, not an element, array or other node. */
14
+ const isProfileFigure = (value) => value != null && typeof value === 'object' && !React.isValidElement(value) && !Array.isArray(value) && !(Symbol.iterator in value) && 'value' in value;
15
+ function rowValue(row) {
16
+ const { value, tone } = row;
17
+ if (value == null)
18
+ return value;
19
+ if (isProfileFigure(value))
20
+ return _jsx("span", { className: 'hig-profile-value', "data-tone": tone, children: _jsx(AnimatedNumberReadout, { ...figureProps(value) }) });
21
+ return tone ? _jsx("span", { className: 'hig-profile-value', "data-tone": tone, children: value }) : value;
22
+ }
23
+ /**
24
+ * A switch row whose whole row is the target. The markup is a static `ListRow` with a `Switch` in `trailing`, so the row
25
+ * draws exactly as before; a press anywhere outside the switch toggles it, the switch input stays the one named control
26
+ * for keyboard and assistive technology, and the host's press decoration covers the whole row instead of the track.
27
+ */
28
+ function ProfileSwitchRow({ row }) {
29
+ const [checked, set] = useControllable(!!row.checked, false, row.onCheckedChange);
30
+ const input = useRef(null);
31
+ const toggle = (event) => { if (row.disabled || event.target.closest('.hig-switch'))
32
+ return; input.current?.click(); };
33
+ const value = rowValue(row);
34
+ return _jsxs("div", { className: 'hig-list-row', "aria-disabled": row.disabled || undefined, onClick: toggle, children: [row.leading != null && _jsx("span", { className: 'hig-list-row-leading', "aria-hidden": 'true', children: row.leading }), _jsx("span", { className: 'hig-list-row-label', children: row.label }), value != null && _jsx("span", { className: 'hig-list-row-value', children: value }), _jsx("span", { className: 'hig-list-row-trailing', children: _jsxs("label", { className: 'hig-choice hig-switch', children: [_jsx("input", { ref: input, role: 'switch', type: 'checkbox', checked: !!checked, disabled: row.disabled, onChange: event => set(event.target.checked) }), _jsx("span", { children: row.label })] }) }), _jsx(PressDecoration, { kind: 'switch', disabled: !!row.disabled, input: input })] });
35
+ }
11
36
  /** A person's profile as one screen: who they are (avatar, status, name), then grouped rows that open their accounts, history, rewards and settings. */
12
- export function ProfileBlock({ name, address, avatar, status, onEditName, onShowAddress, onClose, sections, className, ...rest }) {
37
+ export function ProfileBlock({ name, nameAccessory, address, avatar, onAvatarPress, avatarLabel, status, onEditName, onShowAddress, onClose, action, sections, footer, className, ...rest }) {
13
38
  const { messages } = useHIG();
14
- return _jsxs("section", { ...rest, className: `hig-profile-block${className ? ` ${className}` : ''}`, children: [_jsxs("div", { className: 'hig-profile-bar', children: [_jsx("span", { children: onShowAddress && _jsx(IconButton, { intent: 'ghost', label: messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: qrIcon }) }), _jsx("span", { children: onClose && _jsx(IconButton, { intent: 'ghost', label: messages.close ?? en.close, onClick: onClose, children: _jsx(SwapIcon, { name: 'close' }) }) })] }), _jsxs("div", { className: 'hig-profile-identity', children: [_jsxs("span", { className: 'hig-profile-avatar', style: avatar == null && address ? { background: addressGradient(address) } : undefined, children: [_jsx("span", { className: 'hig-profile-artwork', "aria-hidden": 'true', children: typeof avatar === 'string' ? _jsx("img", { src: avatar, alt: '' }) : avatar ?? (address ? null : name.slice(0, 2)) }), status && _jsx("span", { className: 'hig-profile-status', "data-tone": status.tone ?? 'warning', children: _jsx("span", { className: 'hig-sr-only', children: status.label }) })] }), _jsxs("div", { className: 'hig-profile-name', children: [_jsx("h2", { children: name }), onEditName && _jsx(IconButton, { intent: 'ghost', label: messages.editName ?? en.editName, onClick: onEditName, children: editIcon })] })] }), sections.filter(section => section.rows.length > 0).map(section => _jsx(ListGroup, { title: section.title, children: section.rows.map(row => _jsx(ListRow, { label: row.label, leading: row.leading, value: row.value, disabled: row.disabled, onSelect: row.onCheckedChange ? undefined : row.onSelect, trailing: row.onCheckedChange ? _jsx(Switch, { label: row.label, checked: !!row.checked, disabled: row.disabled, onCheckedChange: row.onCheckedChange }) : row.trailing }, row.id)) }, section.id))] });
39
+ const artwork = typeof avatar === 'string' ? _jsx("img", { src: avatar, alt: '' }) : avatar ?? (address ? null : name?.slice(0, 2));
40
+ return _jsxs("section", { ...rest, className: `hig-profile-block${className ? ` ${className}` : ''}`, children: [_jsxs("div", { className: 'hig-profile-bar', children: [_jsx("span", { children: onShowAddress && _jsx(IconButton, { intent: 'ghost', label: messages.showAddress ?? en.showAddress, onClick: onShowAddress, children: qrIcon }) }), _jsx("span", { children: onClose && _jsx(IconButton, { intent: 'ghost', label: messages.close ?? en.close, onClick: onClose, children: _jsx(SwapIcon, { name: 'close' }) }) })] }), _jsxs("div", { className: 'hig-profile-identity', children: [_jsxs("span", { className: 'hig-profile-avatar', style: avatar == null && address ? { background: addressGradient(address) } : undefined, children: [onAvatarPress ? _jsxs("button", { type: 'button', className: 'hig-profile-artwork', "aria-label": avatarLabel ?? name ?? messages.changeProfilePicture ?? en.changeProfilePicture, onClick: onAvatarPress, children: [artwork, _jsx(PressDecoration, { kind: 'icon-button' })] }) : _jsx("span", { className: 'hig-profile-artwork', "aria-hidden": 'true', children: artwork }), status && _jsx("span", { className: 'hig-profile-status', "data-tone": status.tone ?? 'warning', children: _jsx("span", { className: 'hig-sr-only', children: status.label }) })] }), name != null && _jsxs("div", { className: 'hig-profile-name', children: [_jsx("h2", { children: name }), nameAccessory != null && _jsx("span", { className: 'hig-profile-name-accessory', children: nameAccessory }), onEditName && _jsx(IconButton, { intent: 'ghost', label: messages.editName ?? en.editName, onClick: onEditName, children: editIcon })] }), action && _jsx(Button, { className: 'hig-profile-action', fullWidth: true, intent: action.intent ?? 'primary', disabled: action.disabled, onClick: action.onSelect, children: action.label })] }), sections.filter(section => section.rows.length > 0).map(section => _jsx(ListGroup, { title: section.title, children: section.rows.map(row => row.onCheckedChange ? _jsx(ProfileSwitchRow, { row: row }, row.id) : _jsx(ListRow, { label: row.label, leading: row.leading, value: rowValue(row), disabled: row.disabled, onSelect: row.onSelect, trailing: row.trailing }, row.id)) }, section.id)), footer != null && _jsx("div", { className: 'hig-profile-footer', children: footer })] });
15
41
  }
@@ -1,14 +1,24 @@
1
1
  import React from 'react';
2
+ import { type Figure } from '../figure.js';
2
3
  import type { AssetArtwork } from '../asset-balance-row.js';
4
+ /** A way onward from the promotion. `href` draws a real link (an `<a>`), with `target` such as `_blank`; `onSelect` is still called on the press. */
5
+ export type RewardLink = {
6
+ label: string;
7
+ onSelect: () => void;
8
+ href?: undefined;
9
+ target?: undefined;
10
+ } | {
11
+ label: string;
12
+ href: string;
13
+ target?: string;
14
+ onSelect?: () => void;
15
+ };
3
16
  /** The promotion above the standings: a prize pool filling towards a goal, or a draw with a top prize. Every word is host text. */
4
17
  export interface RewardPromo {
5
18
  /** The small capitals line: Season 01. */
6
19
  eyebrow: string;
7
20
  /** A text link with a chevron on the trailing edge of the eyebrow: Rules. */
8
- rules?: {
9
- label: string;
10
- onSelect: () => void;
11
- };
21
+ rules?: RewardLink;
12
22
  /** The headline figure: the pool so far, or the top prize. `null` reads as unknown. */
13
23
  amount: number | null;
14
24
  /** Format of `amount` and `goal`. Defaults to whole US dollars. */
@@ -17,16 +27,15 @@ export interface RewardPromo {
17
27
  goal?: number;
18
28
  /** The line under the figure. A function receives the formatted goal: `goal => 'of ' + goal + ' prize pool'`. A string is drawn as given: top prize. */
19
29
  caption?: string | ((goal: string) => string);
20
- /** The lead of the explaining sentence, in the text colour: Top 100 traders split the pool. */
21
- headline?: string;
30
+ /** The lead of the explaining sentence, in the text colour: Top 100 traders split the pool. Host text, or host elements for an accented word. */
31
+ headline?: React.ReactNode;
22
32
  /** Continues the sentence after the headline in the muted colour: Funded by builder fees on every trade. */
23
33
  description?: string;
24
34
  /** A quiet row under a hairline at the foot of the card, with a chevron on its trailing edge: Draws and winners. The host opens its own destination. */
25
- action?: {
26
- label: string;
27
- onSelect: () => void;
28
- };
35
+ action?: RewardLink;
29
36
  }
37
+ /** A host figure that updates place by place: `{value:1090779, options:{style:'currency',currency:'USD',maximumFractionDigits:0}, suffix:' vol'}`. */
38
+ export type RewardFigure = Figure;
30
39
  /** One trader in the standings. */
31
40
  export interface RewardEntry {
32
41
  id: string;
@@ -37,13 +46,21 @@ export interface RewardEntry {
37
46
  avatar?: AssetArtwork;
38
47
  /** Shows the verified mark after the name. */
39
48
  verified?: boolean;
40
- /** The line under the name: `$1,090,779 vol`. */
41
- detail?: string;
49
+ /** The line under the name: `$1,090,779 vol` as text, or the same as a live figure. */
50
+ detail?: string | RewardFigure;
42
51
  /** Points or entries. `null` reads as unknown. */
43
52
  score: number | null;
53
+ /** Format of this entry's score, in place of the block's `scoreOptions`, for a prize list where some amounts have cents. */
54
+ scoreOptions?: Intl.NumberFormatOptions;
44
55
  /** Marks the viewer's own row: the name and score take the action colour. */
45
56
  you?: boolean;
46
57
  }
58
+ /** One step of the paging control under the list. */
59
+ export interface RewardPageStep {
60
+ label: string;
61
+ onSelect: () => void;
62
+ disabled?: boolean;
63
+ }
47
64
  export interface RewardBlockProps extends Omit<React.HTMLAttributes<HTMLElement>, 'title'> {
48
65
  /** Heading: Leaderboard. */
49
66
  title: string;
@@ -60,22 +77,44 @@ export interface RewardBlockProps extends Omit<React.HTMLAttributes<HTMLElement>
60
77
  };
61
78
  /** The viewer's own standing, pinned above the list on a tinted row. */
62
79
  you?: RewardEntry;
80
+ /** Names the pinned row for assistive technology: Your rank. */
81
+ youLabel?: string;
82
+ /** A muted line between the pinned row and the list, announced when it changes: You're not ranked yet. */
83
+ status?: string;
63
84
  /** The column heading over the names: Top 25 by volume. */
64
85
  listTitle?: string;
65
86
  /** The column heading over the scores: Entries. */
66
87
  scoreTitle?: string;
67
88
  entries: readonly RewardEntry[];
68
- /** Format of every score. Defaults to a whole number. */
89
+ /** Format of every score. Defaults to a whole number. An entry's own `scoreOptions` wins. */
69
90
  scoreOptions?: Intl.NumberFormatOptions;
70
91
  /** Accessible name of the verified mark. The mark is decorative without it. */
71
92
  verifiedLabel?: string;
93
+ /** Host artwork in place of the built-in verified mark, drawn inside the mark's image role. */
94
+ verifiedMark?: React.ReactNode;
95
+ /** The `verifiedMark` is a control, such as a badge with a popover: it stays in the accessibility tree outside the image role, and `verifiedLabel` is read before it. */
96
+ verifiedMarkInteractive?: boolean;
97
+ /** Draws skeleton rows in place of the entries while the host loads them. */
98
+ loading?: boolean;
99
+ /** Host text that names the skeleton rows for assistive technology and announces them: Loading standings. Without it the block is only marked busy. */
100
+ loadingLabel?: string;
101
+ /** Paging under the list: Previous and Next as buttons with the host's range between them, such as 1–25. */
102
+ pagination?: {
103
+ previous?: RewardPageStep;
104
+ next?: RewardPageStep;
105
+ label?: string;
106
+ };
72
107
  /** A line under the list: Entries are provisional until audited. */
73
108
  footnote?: string;
74
109
  onBack?: () => void;
75
110
  /** A control on the trailing edge of the header, usually an `IconButton` that shares. */
76
111
  headerAction?: React.ReactNode;
112
+ /** Keeps the header pinned to the top of the scrolling container. It is transparent at rest and fills with `--hig-sticky-header-background` (`--hig-background` by default) once the standings scroll under it; inside a sheet remap it, for example `--hig-sticky-header-background: var(--hig-overlay)`. */
113
+ stickyHeader?: boolean;
114
+ /** Set false to leave the header out, when the host pins its own `ScreenHeader` above the block. */
115
+ header?: boolean;
77
116
  }
78
117
  /** The share of the goal reached, from 0 to 1. Unknown amounts and goals that are not above zero give `null`. */
79
118
  export declare function rewardProgress(amount: number | null | undefined, goal: number | null | undefined): number | null;
80
119
  /** A competition as a screen: an optional promotion (a prize pool filling towards its goal, or a draw with its top prize), an optional choice of standings, the viewer's own standing pinned on a tinted row, and the ranked list. */
81
- export declare function RewardBlock({ title, promo, tabs, you, listTitle, scoreTitle, entries, scoreOptions, verifiedLabel, footnote, onBack, headerAction, className, ...rest }: RewardBlockProps): React.JSX.Element;
120
+ export declare function RewardBlock({ title, promo, tabs, you, youLabel, status, listTitle, scoreTitle, entries, scoreOptions, verifiedLabel, verifiedMark, verifiedMarkInteractive, loading, loadingLabel, pagination, footnote, onBack, headerAction, stickyHeader, header, className, ...rest }: RewardBlockProps): React.JSX.Element;