@bloxwap/hig 0.6.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/chart/README.md +13 -2
- package/chart/dist/altimeter-burst.d.ts +4 -0
- package/chart/dist/altimeter-burst.js +43 -0
- package/chart/dist/altimeter-chart.d.ts +52 -0
- package/chart/dist/altimeter-chart.js +275 -0
- package/chart/dist/altimeter-model.d.ts +43 -0
- package/chart/dist/altimeter-model.js +148 -0
- package/chart/dist/altimeter-targets.d.ts +33 -0
- package/chart/dist/altimeter-targets.js +88 -0
- package/chart/dist/bitcoin-price.d.ts +8 -0
- package/chart/dist/bitcoin-price.js +41 -0
- package/chart/dist/champions-league.d.ts +19 -0
- package/chart/dist/champions-league.js +104 -0
- package/chart/dist/index.d.ts +6 -0
- package/chart/dist/index.js +5 -0
- package/chart/dist/outcome-chart.d.ts +37 -0
- package/chart/dist/outcome-chart.js +212 -0
- package/chart/dist/outcome-model.d.ts +43 -0
- package/chart/dist/outcome-model.js +71 -0
- package/chart/dist/plus-grid.d.ts +6 -0
- package/chart/dist/plus-grid.js +29 -0
- package/contracts/README.md +1 -1
- package/contracts/dist/avatar.d.ts +68 -0
- package/contracts/dist/avatar.js +93 -0
- package/contracts/dist/confetti.d.ts +174 -0
- package/contracts/dist/confetti.js +138 -0
- package/contracts/dist/decimal.d.ts +7 -0
- package/contracts/dist/decimal.js +35 -0
- package/contracts/dist/index.d.ts +45 -2
- package/contracts/dist/index.js +145 -4
- package/contracts/dist/invariants.d.ts +17 -0
- package/contracts/dist/invariants.js +24 -0
- package/contracts/dist/messages.d.ts +62 -2
- package/contracts/dist/messages.js +22 -2
- package/contracts/dist/number-flow.d.ts +90 -0
- package/contracts/dist/number-flow.js +150 -0
- package/contracts/dist/qr.d.ts +151 -0
- package/contracts/dist/qr.js +581 -0
- package/contracts/dist/toast.d.ts +168 -0
- package/contracts/dist/toast.js +171 -0
- package/feedback/README.md +1 -1
- package/feedback/dist/contract.js +1 -1
- package/feedback/dist/react.js +2 -4
- package/native/README.md +6 -1
- package/native/dist/account-block.d.ts +62 -7
- package/native/dist/account-block.js +54 -11
- package/native/dist/animated-number-model.d.ts +47 -1
- package/native/dist/animated-number-model.js +248 -21
- package/native/dist/animated-number.d.ts +41 -1
- package/native/dist/animated-number.js +165 -17
- package/native/dist/announce.d.ts +2 -0
- package/native/dist/announce.js +10 -0
- package/native/dist/asset-balance-row.d.ts +19 -1
- package/native/dist/asset-balance-row.js +24 -8
- package/native/dist/assets-block.d.ts +115 -0
- package/native/dist/assets-block.js +87 -0
- package/native/dist/async-result.d.ts +2 -0
- package/native/dist/async-result.js +11 -0
- package/native/dist/avatar-frame.d.ts +29 -0
- package/native/dist/avatar-frame.js +56 -0
- package/native/dist/avatar.d.ts +21 -0
- package/native/dist/avatar.js +31 -0
- package/native/dist/bar-mark.d.ts +16 -2
- package/native/dist/bar-mark.js +23 -7
- package/native/dist/bar-pnl.js +7 -5
- package/native/dist/blocks.d.ts +13 -14
- package/native/dist/blocks.js +10 -6
- package/native/dist/brand.js +2 -1
- package/native/dist/button.d.ts +7 -2
- package/native/dist/button.js +16 -4
- package/native/dist/checkbox.js +2 -1
- package/native/dist/confetti.d.ts +33 -0
- package/native/dist/confetti.js +143 -0
- package/native/dist/confirm-block.d.ts +98 -0
- package/native/dist/confirm-block.js +48 -0
- package/native/dist/data.d.ts +1 -1
- package/native/dist/data.js +8 -4
- package/native/dist/explainer-block.d.ts +91 -0
- package/native/dist/explainer-block.js +34 -0
- package/native/dist/field.d.ts +19 -5
- package/native/dist/field.js +56 -9
- package/native/dist/figure.d.ts +23 -0
- package/native/dist/figure.js +10 -0
- package/native/dist/gesture-sheet-model.d.ts +50 -0
- package/native/dist/gesture-sheet-model.js +105 -0
- package/native/dist/gesture-sheet-next.d.ts +82 -0
- package/native/dist/gesture-sheet-next.js +315 -0
- package/native/dist/gesture-sheet.d.ts +5 -1
- package/native/dist/gesture-sheet.js +13 -6
- package/native/dist/icons.d.ts +9 -6
- package/native/dist/icons.js +25 -24
- package/native/dist/language-block.d.ts +14 -1
- package/native/dist/language-block.js +11 -4
- package/native/dist/list-group.d.ts +44 -8
- package/native/dist/list-group.js +84 -13
- package/native/dist/manage-position-block.d.ts +35 -2
- package/native/dist/manage-position-block.js +41 -11
- package/native/dist/market-row.d.ts +46 -0
- package/native/dist/market-row.js +41 -0
- package/native/dist/navigation.js +5 -3
- package/native/dist/notifications-block.d.ts +30 -2
- package/native/dist/notifications-block.js +16 -8
- package/native/dist/number-format.d.ts +6 -0
- package/native/dist/number-format.js +9 -0
- package/native/dist/pickers.d.ts +32 -2
- package/native/dist/pickers.js +17 -9
- package/native/dist/position-block.d.ts +66 -10
- package/native/dist/position-block.js +45 -11
- package/native/dist/preset-group.d.ts +31 -0
- package/native/dist/preset-group.js +39 -0
- package/native/dist/preset-picker-block.d.ts +107 -0
- package/native/dist/preset-picker-block.js +43 -0
- package/native/dist/profile-block.d.ts +38 -5
- package/native/dist/profile-block.js +31 -6
- package/native/dist/provider.d.ts +14 -5
- package/native/dist/provider.js +32 -6
- package/native/dist/qr-code.d.ts +33 -0
- package/native/dist/qr-code.js +29 -0
- package/native/dist/radio-group.d.ts +23 -5
- package/native/dist/radio-group.js +40 -12
- package/native/dist/recipes.d.ts +6 -0
- package/native/dist/recipes.js +6 -0
- package/native/dist/reward-block.d.ts +55 -13
- package/native/dist/reward-block.js +37 -14
- package/native/dist/screen-header.d.ts +59 -0
- package/native/dist/screen-header.js +37 -0
- package/native/dist/select.js +4 -2
- package/native/dist/selection.d.ts +3 -2
- package/native/dist/selection.js +1 -0
- package/native/dist/setting-header.d.ts +2 -8
- package/native/dist/setting-header.js +2 -11
- package/native/dist/setting-switch.d.ts +15 -2
- package/native/dist/setting-switch.js +11 -4
- package/native/dist/signals-block.d.ts +26 -2
- package/native/dist/signals-block.js +14 -4
- package/native/dist/slider.js +5 -1
- package/native/dist/sound-haptics-block.d.ts +29 -2
- package/native/dist/sound-haptics-block.js +19 -8
- package/native/dist/status.d.ts +47 -14
- package/native/dist/status.js +39 -22
- package/native/dist/sticky-header.d.ts +28 -0
- package/native/dist/sticky-header.js +29 -0
- package/native/dist/surface.d.ts +3 -1
- package/native/dist/surface.js +2 -1
- package/native/dist/swap-amount-card.d.ts +57 -0
- package/native/dist/swap-amount-card.js +31 -0
- package/native/dist/swap-panel-block.d.ts +11 -4
- package/native/dist/swap-panel-block.js +67 -38
- package/native/dist/swap-parts.d.ts +5 -10
- package/native/dist/swap-parts.js +22 -24
- package/native/dist/swap-shared.d.ts +8 -2
- package/native/dist/swap-shared.js +10 -6
- package/native/dist/swap-views.js +6 -4
- package/native/dist/switch-row.d.ts +3 -2
- package/native/dist/switch-row.js +5 -3
- package/native/dist/switch.d.ts +4 -2
- package/native/dist/switch.js +3 -3
- package/native/dist/target-block.d.ts +40 -7
- package/native/dist/target-block.js +31 -11
- package/native/dist/toast.d.ts +47 -0
- package/native/dist/toast.js +386 -0
- package/native/dist/token-action-block.d.ts +26 -9
- package/native/dist/token-action-block.js +21 -8
- package/native/dist/trade-history-detail-block.d.ts +26 -1
- package/native/dist/trade-history-detail-block.js +17 -9
- package/native/dist/trade-history-list-block.d.ts +71 -5
- package/native/dist/trade-history-list-block.js +55 -17
- package/native/dist/wallet-address-core.d.ts +25 -0
- package/native/dist/wallet-address-core.js +34 -0
- package/native/dist/wallet-address.d.ts +6 -10
- package/native/dist/wallet-address.js +16 -20
- package/native-fonts/README.md +1 -1
- package/og-fonts/README.md +1 -1
- package/package.json +131 -2
- package/react/README.md +3 -1
- package/react/dist/animated-number-flow.d.ts +72 -0
- package/react/dist/animated-number-flow.js +316 -0
- package/react/dist/animated-number-model.d.ts +24 -0
- package/react/dist/animated-number-model.js +106 -3
- package/react/dist/animated-number.d.ts +49 -1
- package/react/dist/animated-number.js +146 -11
- package/react/dist/asset-balance-row.d.ts +19 -1
- package/react/dist/asset-balance-row.js +17 -3
- package/react/dist/async-result.d.ts +2 -0
- package/react/dist/async-result.js +11 -0
- package/react/dist/avatar.d.ts +25 -0
- package/react/dist/avatar.js +50 -0
- package/react/dist/bar-mark.d.ts +5 -2
- package/react/dist/bar-mark.js +5 -3
- package/react/dist/blocks/account-block.d.ts +57 -7
- package/react/dist/blocks/account-block.js +51 -11
- package/react/dist/blocks/assets-block.d.ts +106 -0
- package/react/dist/blocks/assets-block.js +135 -0
- package/react/dist/blocks/confirm-block.d.ts +91 -0
- package/react/dist/blocks/confirm-block.js +31 -0
- package/react/dist/blocks/explainer-block.d.ts +80 -0
- package/react/dist/blocks/explainer-block.js +20 -0
- package/react/dist/blocks/install-command.js +3 -1
- package/react/dist/blocks/language-block.d.ts +9 -1
- package/react/dist/blocks/language-block.js +8 -6
- package/react/dist/blocks/manage-position-block.d.ts +30 -2
- package/react/dist/blocks/manage-position-block.js +23 -4
- package/react/dist/blocks/market-row.d.ts +20 -9
- package/react/dist/blocks/market-row.js +17 -4
- package/react/dist/blocks/notifications-block.d.ts +27 -2
- package/react/dist/blocks/notifications-block.js +11 -2
- package/react/dist/blocks/pickers.d.ts +30 -1
- package/react/dist/blocks/pickers.js +32 -10
- package/react/dist/blocks/position-block.d.ts +34 -11
- package/react/dist/blocks/position-block.js +16 -5
- package/react/dist/blocks/preset-picker-block.d.ts +85 -0
- package/react/dist/blocks/preset-picker-block.js +19 -0
- package/react/dist/blocks/profile-block.d.ts +33 -6
- package/react/dist/blocks/profile-block.js +31 -6
- package/react/dist/blocks/reward-block.d.ts +65 -21
- package/react/dist/blocks/reward-block.js +24 -11
- package/react/dist/blocks/screen-header.d.ts +34 -2
- package/react/dist/blocks/screen-header.js +17 -6
- package/react/dist/blocks/setting-switch.d.ts +14 -1
- package/react/dist/blocks/setting-switch.js +11 -4
- package/react/dist/blocks/signals-block.d.ts +23 -2
- package/react/dist/blocks/signals-block.js +6 -5
- package/react/dist/blocks/sound-haptics-block.d.ts +27 -3
- package/react/dist/blocks/sound-haptics-block.js +11 -7
- package/react/dist/blocks/sticky-header.d.ts +19 -0
- package/react/dist/blocks/sticky-header.js +103 -0
- package/react/dist/blocks/swap/amount-card.js +2 -1
- package/react/dist/blocks/swap/settings.js +4 -3
- package/react/dist/blocks/swap/shared.d.ts +29 -23
- package/react/dist/blocks/swap/shared.js +36 -32
- package/react/dist/blocks/swap-panel-block.d.ts +12 -3
- package/react/dist/blocks/swap-panel-block.js +72 -37
- package/react/dist/blocks/target-block.d.ts +35 -7
- package/react/dist/blocks/target-block.js +26 -12
- package/react/dist/blocks/token-action-block.d.ts +21 -8
- package/react/dist/blocks/token-action-block.js +9 -6
- package/react/dist/blocks/trade-history-detail-block.d.ts +23 -1
- package/react/dist/blocks/trade-history-detail-block.js +5 -4
- package/react/dist/blocks/trade-history-list-block.d.ts +31 -5
- package/react/dist/blocks/trade-history-list-block.js +20 -10
- package/react/dist/blocks.d.ts +12 -8
- package/react/dist/blocks.js +6 -2
- package/react/dist/brand.js +2 -1
- package/react/dist/button.d.ts +9 -3
- package/react/dist/button.js +12 -5
- package/react/dist/confetti.d.ts +27 -0
- package/react/dist/confetti.js +240 -0
- package/react/dist/data.js +11 -4
- package/react/dist/field.d.ts +20 -5
- package/react/dist/field.js +30 -8
- package/react/dist/figure.d.ts +23 -0
- package/react/dist/figure.js +12 -0
- package/react/dist/gesture-sheet.d.ts +15 -1
- package/react/dist/gesture-sheet.js +53 -8
- package/react/dist/list-group.d.ts +41 -8
- package/react/dist/list-group.js +49 -13
- package/react/dist/navigation.js +11 -3
- package/react/dist/overlay.d.ts +28 -3
- package/react/dist/overlay.js +29 -3
- package/react/dist/preset-group.d.ts +30 -0
- package/react/dist/preset-group.js +13 -0
- package/react/dist/provider.d.ts +42 -5
- package/react/dist/provider.js +84 -10
- package/react/dist/qr-code.d.ts +32 -0
- package/react/dist/qr-code.js +28 -0
- package/react/dist/select.js +10 -3
- package/react/dist/selection.d.ts +18 -4
- package/react/dist/selection.js +20 -10
- package/react/dist/slider.js +5 -1
- package/react/dist/status.d.ts +14 -10
- package/react/dist/status.js +17 -9
- package/react/dist/styles.css +380 -150
- package/react/dist/surface.d.ts +5 -1
- package/react/dist/surface.js +1 -1
- package/react/dist/toast.d.ts +19 -12
- package/react/dist/toast.js +29 -7
- package/react/dist/wallet-address-core.d.ts +27 -0
- package/react/dist/wallet-address-core.js +29 -0
- package/react/dist/wallet-address.d.ts +6 -12
- package/react/dist/wallet-address.js +5 -16
- package/tokens/README.md +2 -2
- package/tokens/dist/index.d.ts +16 -0
- package/tokens/dist/index.js +16 -0
- package/tokens/dist/manifest.json +8 -0
- package/tokens/dist/tokens.css +6 -0
package/react/dist/overlay.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useId, useRef } from 'react';
|
|
3
|
+
import { useEffect, useId, useRef } from 'react';
|
|
4
4
|
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
-
import { useHIG, useThemeStyle } from './provider.js';
|
|
5
|
+
import { useControllable, useHIG, useThemeStyle } from './provider.js';
|
|
6
6
|
import * as Drop from '@radix-ui/react-dropdown-menu';
|
|
7
7
|
import * as Pop from '@radix-ui/react-popover';
|
|
8
8
|
import * as Tip from '@radix-ui/react-tooltip';
|
|
@@ -14,5 +14,31 @@ export function Menu({ label, items }) { const { feedback, direction, locale, de
|
|
|
14
14
|
feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent: 'selection', origin: origin.current });
|
|
15
15
|
}
|
|
16
16
|
catch { /* Optional feedback cannot alter the action. */ } }, children: item.label }, i)) }) })] }); }
|
|
17
|
-
|
|
17
|
+
/** How long the pointer may be off the trigger and the popover before a hover-opened popover closes, so it can cross the gap between them. */
|
|
18
|
+
const hoverCloseDelay = 150;
|
|
19
|
+
export function Popover({ label, children, closeLabel, hideClose, open, defaultOpen = false, onOpenChange, trigger, openOnHover, testID, tone, className, style }) {
|
|
20
|
+
const { messages, direction, locale, density } = useHIG();
|
|
21
|
+
const themeStyle = useThemeStyle();
|
|
22
|
+
const [current, set] = useControllable(open, defaultOpen, onOpenChange, null);
|
|
23
|
+
const timer = useRef(undefined), hovered = useRef(false), pinned = useRef(false);
|
|
24
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
25
|
+
// Hover handlers only for a mouse: a touch's pointerenter comes just before its click, which toggles. A hover opens without moving focus into the popover.
|
|
26
|
+
const hover = openOnHover ? {
|
|
27
|
+
onPointerEnter: (event) => { if (event.pointerType !== 'mouse')
|
|
28
|
+
return; clearTimeout(timer.current); if (!current) {
|
|
29
|
+
hovered.current = true;
|
|
30
|
+
set(true);
|
|
31
|
+
} },
|
|
32
|
+
onPointerLeave: (event) => { if (event.pointerType !== 'mouse' || pinned.current)
|
|
33
|
+
return; clearTimeout(timer.current); timer.current = setTimeout(() => set(false), hoverCloseDelay); },
|
|
34
|
+
} : undefined;
|
|
35
|
+
// A click on the trigger of a hover-opened popover pins it open instead of toggling it shut: the pointer always hovers before it clicks.
|
|
36
|
+
const pin = openOnHover ? { onClick: (event) => { if (!hovered.current)
|
|
37
|
+
return; event.preventDefault(); clearTimeout(timer.current); hovered.current = false; pinned.current = true; } } : undefined;
|
|
38
|
+
return _jsxs(Pop.Root, { open: current, onOpenChange: next => { clearTimeout(timer.current); if (!next) {
|
|
39
|
+
hovered.current = false;
|
|
40
|
+
pinned.current = false;
|
|
41
|
+
} set(next); }, children: [_jsx(Pop.Trigger, { asChild: true, ...hover, ...pin, children: trigger ?? _jsx(Button, { intent: 'secondary', suppressFeedback: true, children: label }) }), _jsx(Pop.Portal, { children: _jsxs(Pop.Content, { ...hover, className: `hig-popover${className ? ` ${className}` : ''}`, "data-tone": tone, sideOffset: 6, collisionPadding: 16, style: style ? { ...themeStyle, ...style } : themeStyle, dir: direction, lang: locale, "data-hig-density": density, "aria-label": trigger ? label : undefined, "data-testid": testID, onOpenAutoFocus: event => { if (hovered.current)
|
|
42
|
+
event.preventDefault(); }, children: [children, hideClose ? null : _jsx(Pop.Close, { asChild: true, children: _jsx(Button, { intent: 'ghost', suppressFeedback: true, children: closeLabel ?? messages.close ?? en.close }) })] }) })] });
|
|
43
|
+
}
|
|
18
44
|
export function Tooltip({ content, children }) { const { direction, locale, density } = useHIG(); const themeStyle = useThemeStyle(); return _jsx(Tip.Provider, { children: _jsxs(Tip.Root, { children: [_jsx(Tip.Trigger, { asChild: true, children: children }), _jsx(Tip.Portal, { children: _jsx(Tip.Content, { className: 'hig-popover hig-tooltip', sideOffset: 6, collisionPadding: 16, style: themeStyle, dir: direction, lang: locale, "data-hig-density": density, children: content }) })] }) }); }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** One quick choice. `testID` becomes the chip's `data-testid`. */
|
|
3
|
+
export interface PresetOption<T extends string | number = string> {
|
|
4
|
+
value: T;
|
|
5
|
+
label: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
testID?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PresetGroupProps<T extends string | number = string> {
|
|
10
|
+
/** Accessible name of the group; not drawn, so a heading or row above it names it on screen. */
|
|
11
|
+
label?: string;
|
|
12
|
+
options: readonly PresetOption<T>[];
|
|
13
|
+
/** The selected choice; `null` selects none. Omit it, with `defaultValue`, to let the group keep its own selection. */
|
|
14
|
+
value?: T | null;
|
|
15
|
+
defaultValue?: T | null;
|
|
16
|
+
/** Called with the choice taken. A press on the selected chip, or on a dimmed one, does nothing. */
|
|
17
|
+
onValueChange?: (value: T) => void;
|
|
18
|
+
/** Chips per row. Defaults to every option in one row; with fewer columns the chips wrap onto equal-width rows. */
|
|
19
|
+
columns?: number;
|
|
20
|
+
/** Fill of the selected chip. Defaults to `primary`; TargetBlock passes `destructive` for a stop loss. */
|
|
21
|
+
selectedIntent?: 'primary' | 'destructive' | 'up' | 'down';
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/** Keeps the provider's `selection` feedback off this group, for a host that plays its own cue. By default a new choice plays it like a SegmentedControl. */
|
|
24
|
+
suppressFeedback?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
/** The group's `data-testid`. */
|
|
27
|
+
testID?: string;
|
|
28
|
+
}
|
|
29
|
+
/** A set of quick choices as chips in an equal-width grid, such as order sizes or leverage steps. Single choice, or none; each chip is a toggle button that reads pressed when selected, at least 44px tall, in the interface face. TargetBlock draws its presets with it. */
|
|
30
|
+
export declare function PresetGroup<T extends string | number = string>({ label, options, value, defaultValue, onValueChange, columns, selectedIntent, disabled, suppressFeedback, className, testID }: PresetGroupProps<T>): React.JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { assertUniqueKeys } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { useControllable } from './provider.js';
|
|
5
|
+
import { Button } from './button.js';
|
|
6
|
+
/** A set of quick choices as chips in an equal-width grid, such as order sizes or leverage steps. Single choice, or none; each chip is a toggle button that reads pressed when selected, at least 44px tall, in the interface face. TargetBlock draws its presets with it. */
|
|
7
|
+
export function PresetGroup({ label, options, value, defaultValue = null, onValueChange, columns, selectedIntent = 'primary', disabled, suppressFeedback, className, testID }) {
|
|
8
|
+
assertUniqueKeys(options, option => option.value, 'Choices');
|
|
9
|
+
const [current, set] = useControllable(value, defaultValue, onValueChange, suppressFeedback ? null : 'selection');
|
|
10
|
+
const count = Math.max(1, Math.floor(columns ?? options.length) || 1);
|
|
11
|
+
return _jsx("div", { role: 'group', "aria-label": label, "aria-disabled": disabled || undefined, className: `hig-preset-group${className ? ` ${className}` : ''}`, "data-testid": testID, style: { '--hig-preset-columns': count }, children: options.map(option => { const selected = current !== null && Object.is(current, option.value), blocked = !!disabled || !!option.disabled; return _jsx(Button, { "data-testid": option.testID, fullWidth: true, intent: selected ? selectedIntent : 'secondary', "aria-pressed": selected, disabled: blocked, suppressFeedback: true, onClick: () => { if (!blocked && !selected)
|
|
12
|
+
set(option.value); }, children: option.label }, String(option.value)); }) });
|
|
13
|
+
}
|
package/react/dist/provider.d.ts
CHANGED
|
@@ -1,25 +1,62 @@
|
|
|
1
1
|
import type { FeedbackSink, FeedbackIntent } from '@bloxwap/hig/contracts/feedback';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { type Environment } from '@bloxwap/hig/contracts';
|
|
3
|
+
import { type Environment, type NumberFormatPresentation } from '@bloxwap/hig/contracts';
|
|
4
4
|
import { type HIGMessages } from '@bloxwap/hig/contracts/messages';
|
|
5
5
|
import { nativeSrgb } from '@bloxwap/hig/tokens';
|
|
6
6
|
export type { HIGMessages } from '@bloxwap/hig/contracts/messages';
|
|
7
|
+
export type { NumberFormatPresentation } from '@bloxwap/hig/contracts';
|
|
8
|
+
/** The kind of pressable HIG control a press decoration is drawn in: `button` (Button, the block action buttons and a ListGroup heading action), `icon-button` (IconButton and the SearchInput clear button), `row` (a pressable ListRow, AssetBalanceRow, the WalletAddress copy button or a block row), `switch` (Switch, a switch ListRow and the setting switch rows), `segment` (each SegmentedControl segment) and `back` (the block header's Back, Close and address controls). */
|
|
9
|
+
export type PressDecorationKind = 'button' | 'icon-button' | 'row' | 'switch' | 'segment' | 'back';
|
|
10
|
+
export interface PressDecorationInfo {
|
|
11
|
+
kind: PressDecorationKind; /** The control is disabled or busy and will not act on a press. */
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
}
|
|
7
14
|
export interface HIGContext extends Environment {
|
|
8
15
|
onAccepted?: (id: string) => void;
|
|
9
16
|
feedback?: FeedbackSink; /** Brand accent as opaque sRGB hex (#RGB or #RRGGBB). Nested providers inherit it; omitted at the root, Bloxwap green applies. */
|
|
10
17
|
primaryColor?: string; /** Host translations of built-in copy, merged through nested providers. Components fall back to the English export per key; read the full resolved catalog with `useMessages()`. */
|
|
11
18
|
messages: Readonly<Partial<HIGMessages>>;
|
|
19
|
+
/** Host content drawn inside every pressable HIG control, such as a native switch input that gives iOS Safari a haptic. It sits in an absolutely positioned layer over the control that changes no layout and catches no pointer events itself; its children do. Nested providers inherit it. Omitted, nothing is drawn. */
|
|
20
|
+
pressDecoration?: (info: PressDecorationInfo) => React.ReactNode;
|
|
21
|
+
/** Money presentation merged under every currency format HIG draws: the blocks, BarMark, BarPnl, AssetBalanceRow, the swap pieces and the number readouts. Options a format sets itself win. Nested providers inherit it. */
|
|
22
|
+
numberFormat?: NumberFormatPresentation;
|
|
23
|
+
/** Market-direction colours: `up` (rising, long, gain) and `down` (falling, short, loss), as CSS colours. They default to `--hig-buy` and `--hig-sell`; the provider sets `--hig-up` and `--hig-down` on its wrapper. Nested providers inherit them. */
|
|
24
|
+
marketColors?: HIGMarketColors;
|
|
25
|
+
}
|
|
26
|
+
/** Host colours for the market-direction roles. An omitted, empty or non-string role keeps `buy`/`sell`. */
|
|
27
|
+
export interface HIGMarketColors {
|
|
28
|
+
up?: string;
|
|
29
|
+
down?: string;
|
|
12
30
|
}
|
|
13
31
|
export interface HIGProviderProps extends Partial<Omit<HIGContext, 'messages'>> {
|
|
14
32
|
messages?: Partial<HIGMessages>;
|
|
15
33
|
}
|
|
16
|
-
export declare function HIGProvider({ children, density, locale, direction, reducedMotion, onAccepted, feedback, primaryColor, messages }: React.PropsWithChildren<HIGProviderProps>): React.JSX.Element;
|
|
34
|
+
export declare function HIGProvider({ children, density, locale, direction, reducedMotion, onAccepted, feedback, primaryColor, messages, pressDecoration, numberFormat, marketColors }: React.PropsWithChildren<HIGProviderProps>): React.JSX.Element;
|
|
17
35
|
export declare const useHIG: () => HIGContext;
|
|
18
|
-
/**
|
|
36
|
+
/** Number options with the nearest provider's `numberFormat` merged under them; only currency formats change. */
|
|
37
|
+
export declare function usePresentNumber(): <T extends Intl.NumberFormatOptions | undefined>(options: T) => T;
|
|
38
|
+
/** The locale numbers are formatted in: the nearest provider's `numberFormat.locale`, else its `locale`. */
|
|
39
|
+
export declare function useNumberLocale(): string;
|
|
40
|
+
/**
|
|
41
|
+
* The provider's press decoration for one control: the host content in an absolutely positioned layer that is the control's last
|
|
42
|
+
* child, or nothing without a `pressDecoration`. Place it inside a host control to give it the same treatment as HIG's own.
|
|
43
|
+
* A press on an interactive element in the layer makes that element the activation target (the HTML activation rules), so the
|
|
44
|
+
* control around it would skip its own default action: a submit or reset button would not submit, a link would not navigate and
|
|
45
|
+
* a label would not toggle its input. The layer therefore stops that click and sends the control one click of its own, which
|
|
46
|
+
* runs the control's handlers and its default action once. For a control drawn as a `<label>` around its `input`, pass that
|
|
47
|
+
* input and the click goes to it. A host `<label>` that names a control is left alone, because the click it then sends to that
|
|
48
|
+
* control comes through next. A disabled control gets nothing.
|
|
49
|
+
*/
|
|
50
|
+
export declare function PressDecoration({ kind, disabled, input }: {
|
|
51
|
+
kind: PressDecorationKind;
|
|
52
|
+
disabled?: boolean;
|
|
53
|
+
input?: React.RefObject<HTMLInputElement | null>;
|
|
54
|
+
}): React.JSX.Element | null;
|
|
55
|
+
/** Scoped primary and market colour variables for host-owned portals outside the provider's DOM. */
|
|
19
56
|
export declare function useThemeStyle(): React.CSSProperties | undefined;
|
|
20
57
|
/** Resolved sRGB roles for canvas and host-drawn content. CSS retains the default wide-gamut palette. */
|
|
21
58
|
export declare function useColors(): Readonly<Record<keyof typeof nativeSrgb, string>>;
|
|
22
59
|
/** Complete built-in copy for the nearest HIGProvider: host translations over the English defaults. */
|
|
23
60
|
export declare function useMessages(): HIGMessages;
|
|
24
|
-
/** Controlled values never silently switch to internal state. */
|
|
25
|
-
export declare function useControllable<T>(value: T | undefined, initial: T, onChange?: (value: T) => void, intent?: FeedbackIntent): [T, (next: T) => void];
|
|
61
|
+
/** Controlled values never silently switch to internal state. `intent: null` commits without provider feedback. */
|
|
62
|
+
export declare function useControllable<T>(value: T | undefined, initial: T, onChange?: (value: T) => void, intent?: FeedbackIntent | null): [T, (next: T) => void];
|
package/react/dist/provider.js
CHANGED
|
@@ -1,50 +1,124 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext, useEffect, useMemo, useState, useRef, useId } from 'react';
|
|
4
|
-
import { defaultEnvironment } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { defaultEnvironment, numberLocale, presentNumberFormat } from '@bloxwap/hig/contracts';
|
|
5
5
|
import { defaultMessages, resolveMessages } from '@bloxwap/hig/contracts/messages';
|
|
6
6
|
import { nativeSrgb, resolvePrimaryColor } from '@bloxwap/hig/tokens';
|
|
7
7
|
const Context = createContext({ ...defaultEnvironment, messages: {} });
|
|
8
|
-
|
|
8
|
+
const marketColor = (value) => typeof value === 'string' && value !== '' ? value : undefined;
|
|
9
|
+
export function HIGProvider({ children, density, locale, direction, reducedMotion, onAccepted, feedback, primaryColor, messages, pressDecoration, numberFormat, marketColors }) {
|
|
9
10
|
const parent = useContext(Context);
|
|
11
|
+
density ??= parent.density;
|
|
12
|
+
locale ??= parent.locale;
|
|
13
|
+
direction ??= parent.direction;
|
|
14
|
+
onAccepted ??= parent.onAccepted;
|
|
15
|
+
feedback ??= parent.feedback;
|
|
10
16
|
const inherited = parent.messages;
|
|
11
17
|
const resolved = useMemo(() => resolveMessages(inherited, messages), [inherited, messages]);
|
|
18
|
+
const market = marketColors ?? parent.marketColors;
|
|
19
|
+
const up = marketColor(market?.up), down = marketColor(market?.down);
|
|
20
|
+
const inheritedMarket = useMemo(() => up === undefined && down === undefined ? undefined : { up, down }, [up, down]);
|
|
12
21
|
const accent = primaryColor ?? parent.primaryColor;
|
|
13
|
-
const theme = useMemo(() => primaryStyle(accent), [accent]);
|
|
22
|
+
const theme = useMemo(() => marketStyle(primaryStyle(accent), up, down), [accent, up, down]);
|
|
23
|
+
const decorate = pressDecoration ?? parent.pressDecoration;
|
|
24
|
+
const drawPress = useMemo(() => decorate ? pressLayer(decorate) : undefined, [decorate]);
|
|
14
25
|
const [osReduced, setOSReduced] = useState(false);
|
|
15
26
|
useEffect(() => { const query = window.matchMedia?.('(prefers-reduced-motion: reduce)'); if (!query)
|
|
16
27
|
return; const update = () => setOSReduced(query.matches); update(); query.addEventListener('change', update); return () => query.removeEventListener('change', update); }, []);
|
|
17
|
-
|
|
28
|
+
const reduced = reducedMotion ?? (parent.provided ? parent.reducedMotion : osReduced), format = numberFormat ?? parent.numberFormat;
|
|
29
|
+
// One context value for as long as nothing in it changes. A provider that renders again (a host state change above it) then
|
|
30
|
+
// re-renders no component that reads the context: measured over 500 generated avatars, 25,000 face renders per 50 provider renders became none.
|
|
31
|
+
const value = useMemo(() => ({ provided: true, density, locale, direction, reducedMotion: reduced, onAccepted, feedback, primaryColor: accent, messages: resolved, pressDecoration: decorate, numberFormat: format, marketColors: inheritedMarket, drawPress }), [density, locale, direction, reduced, onAccepted, feedback, accent, resolved, decorate, format, inheritedMarket, drawPress]);
|
|
32
|
+
return _jsx(Context.Provider, { value: value, children: _jsx("div", { style: theme, "data-hig-density": density, "data-hig-motion": reduced ? 'reduced' : 'full', dir: direction, lang: locale, children: children }) });
|
|
18
33
|
}
|
|
19
34
|
export const useHIG = () => useContext(Context);
|
|
35
|
+
/** Number options with the nearest provider's `numberFormat` merged under them; only currency formats change. */
|
|
36
|
+
export function usePresentNumber() { const { numberFormat } = useContext(Context); return useMemo(() => (options) => presentNumberFormat(options, numberFormat), [numberFormat]); }
|
|
37
|
+
/** The locale numbers are formatted in: the nearest provider's `numberFormat.locale`, else its `locale`. */
|
|
38
|
+
export function useNumberLocale() { const { locale, numberFormat } = useContext(Context); return numberLocale(locale, numberFormat); }
|
|
39
|
+
const interactive = 'a[href],button,input,select,textarea,label';
|
|
40
|
+
/**
|
|
41
|
+
* The provider's press decoration for one control: the host content in an absolutely positioned layer that is the control's last
|
|
42
|
+
* child, or nothing without a `pressDecoration`. Place it inside a host control to give it the same treatment as HIG's own.
|
|
43
|
+
* A press on an interactive element in the layer makes that element the activation target (the HTML activation rules), so the
|
|
44
|
+
* control around it would skip its own default action: a submit or reset button would not submit, a link would not navigate and
|
|
45
|
+
* a label would not toggle its input. The layer therefore stops that click and sends the control one click of its own, which
|
|
46
|
+
* runs the control's handlers and its default action once. For a control drawn as a `<label>` around its `input`, pass that
|
|
47
|
+
* input and the click goes to it. A host `<label>` that names a control is left alone, because the click it then sends to that
|
|
48
|
+
* control comes through next. A disabled control gets nothing.
|
|
49
|
+
*/
|
|
50
|
+
export function PressDecoration({ kind, disabled = false, input }) {
|
|
51
|
+
const draw = useContext(Context).drawPress;
|
|
52
|
+
return draw ? draw(kind, disabled, input) : null;
|
|
53
|
+
}
|
|
54
|
+
function pressLayer(decorate) {
|
|
55
|
+
return (kind, disabled, input) => {
|
|
56
|
+
const content = decorate({ kind, disabled });
|
|
57
|
+
if (content == null || content === false)
|
|
58
|
+
return null;
|
|
59
|
+
return _jsx("span", { className: 'hig-press-decoration', "data-kind": kind, onClick: event => forwardPress(event, input), children: content });
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function forwardPress(event, input) {
|
|
63
|
+
const layer = event.currentTarget;
|
|
64
|
+
for (let node = event.target; node && node !== layer; node = node.parentElement) {
|
|
65
|
+
if (!node.matches(interactive))
|
|
66
|
+
continue;
|
|
67
|
+
if (node instanceof HTMLLabelElement && node.control)
|
|
68
|
+
return;
|
|
69
|
+
const control = input ? input.current : layer.parentElement;
|
|
70
|
+
if (!control)
|
|
71
|
+
return;
|
|
72
|
+
event.stopPropagation();
|
|
73
|
+
if (control.matches(':disabled'))
|
|
74
|
+
return;
|
|
75
|
+
const { detail, screenX, screenY, clientX, clientY, ctrlKey, shiftKey, altKey, metaKey, button } = event;
|
|
76
|
+
control.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, composed: true, view: event.nativeEvent.view, detail, screenX, screenY, clientX, clientY, ctrlKey, shiftKey, altKey, metaKey, button }));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
20
80
|
function primaryStyle(primaryColor) {
|
|
21
81
|
if (primaryColor === undefined)
|
|
22
82
|
return undefined;
|
|
23
83
|
const colors = resolvePrimaryColor(primaryColor);
|
|
24
84
|
return { '--hig-action': colors.action, '--hig-focus': colors.focus, '--hig-onAction': colors.onAction };
|
|
25
85
|
}
|
|
26
|
-
/**
|
|
27
|
-
|
|
86
|
+
/** Adds `--hig-up` / `--hig-down` for a market colour override; without one the style is returned unchanged. */
|
|
87
|
+
function marketStyle(style, up, down) {
|
|
88
|
+
if (up === undefined && down === undefined)
|
|
89
|
+
return style;
|
|
90
|
+
return { ...style, ...(up !== undefined ? { '--hig-up': up } : {}), ...(down !== undefined ? { '--hig-down': down } : {}) };
|
|
91
|
+
}
|
|
92
|
+
/** Scoped primary and market colour variables for host-owned portals outside the provider's DOM. */
|
|
93
|
+
export function useThemeStyle() { const { primaryColor, marketColors } = useHIG(); return useMemo(() => marketStyle(primaryStyle(primaryColor), marketColors?.up, marketColors?.down), [primaryColor, marketColors]); }
|
|
28
94
|
/** Resolved sRGB roles for canvas and host-drawn content. CSS retains the default wide-gamut palette. */
|
|
29
95
|
export function useColors() { const { primaryColor } = useHIG(); return useMemo(() => primaryColor === undefined ? nativeSrgb : { ...nativeSrgb, ...resolvePrimaryColor(primaryColor) }, [primaryColor]); }
|
|
30
96
|
/** Complete built-in copy for the nearest HIGProvider: host translations over the English defaults. */
|
|
31
97
|
export function useMessages() { const overrides = useContext(Context).messages; return useMemo(() => resolveMessages({ ...defaultMessages }, overrides), [overrides]); }
|
|
32
|
-
/** Controlled values never silently switch to internal state. */
|
|
98
|
+
/** Controlled values never silently switch to internal state. `intent: null` commits without provider feedback. */
|
|
33
99
|
export function useControllable(value, initial, onChange, intent = 'selection') {
|
|
34
100
|
const [internal, setInternal] = useState(initial);
|
|
35
|
-
const
|
|
101
|
+
const controlled = useRef(value !== undefined).current, last = useRef(initial), warned = useRef(false);
|
|
102
|
+
if (controlled && value !== undefined)
|
|
103
|
+
last.current = value;
|
|
104
|
+
const current = controlled ? last.current : internal;
|
|
105
|
+
useEffect(() => { if ((value !== undefined) !== controlled && !warned.current) {
|
|
106
|
+
warned.current = true;
|
|
107
|
+
if (process.env.NODE_ENV !== 'production')
|
|
108
|
+
console.warn('HIG controlled state cannot change ownership after mount. Remount to reset it.');
|
|
109
|
+
} }, [controlled, value]);
|
|
36
110
|
const { feedback } = useHIG();
|
|
37
111
|
const id = useId();
|
|
38
112
|
const sequence = useRef(0);
|
|
39
113
|
const pending = useRef(null);
|
|
40
114
|
useEffect(() => { const request = pending.current; if (!request)
|
|
41
|
-
return; pending.current = null; if (Object.is(current, request.value)) {
|
|
115
|
+
return; pending.current = null; if (intent && Object.is(current, request.value)) {
|
|
42
116
|
try {
|
|
43
117
|
feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent, origin: 'programmatic' });
|
|
44
118
|
}
|
|
45
119
|
catch { /* Effects remain optional. */ }
|
|
46
120
|
} });
|
|
47
121
|
return [current, (next) => { if (Object.is(current, next))
|
|
48
|
-
return; pending.current = { value: next }; if (
|
|
122
|
+
return; pending.current = { value: next }; if (!controlled)
|
|
49
123
|
setInternal(next); onChange?.(next); }];
|
|
50
124
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type QRErrorCorrection } from '@bloxwap/hig/contracts/qr';
|
|
3
|
+
export type { QRErrorCorrection } from '@bloxwap/hig/contracts/qr';
|
|
4
|
+
export interface QRCodeProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, 'children' | 'color'> {
|
|
5
|
+
/** The text to encode: an address, a payment URI, a link. Digits pack tightest, then upper-case alphanumerics, then UTF-8. A value too long for a QR code draws an empty square. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Edge of the square in CSS pixels, quiet zone included; default 196. It sets `--hig-qr-code-size`, the element's width, so host CSS may resize the element: the drawing and the arena's box scale with it. */
|
|
8
|
+
size?: number;
|
|
9
|
+
/** Drawn over the centre, which is cleared of modules: an image URL, or a node such as a token mark laid out in the arena's box. */
|
|
10
|
+
arena?: React.ReactNode;
|
|
11
|
+
/** Error correction level. Defaults to `high` with an arena, which covers part of the code, and `medium` without. With an arena, `low` and `medium` are raised to `quartile` so the code still reads. */
|
|
12
|
+
errorCorrection?: QRErrorCorrection;
|
|
13
|
+
/** Colour of the modules. Defaults to the text role, `var(--hig-text)`. */
|
|
14
|
+
color?: string;
|
|
15
|
+
/** Colour of the tile behind the code. Defaults to the background role, `var(--hig-background)`; `'none'` draws no tile, for a code that sits on the host's own surface. */
|
|
16
|
+
background?: string;
|
|
17
|
+
/** Clear modules kept on every side, inside `size`; default 4, the margin scanners expect. Pass 0 only where the host keeps that margin itself. */
|
|
18
|
+
quietZone?: number;
|
|
19
|
+
/** Accessible name. Defaults to the built-in “QR code”. */
|
|
20
|
+
label?: string;
|
|
21
|
+
/** Hides the code from assistive technology, for a host that names it on an element of its own. */
|
|
22
|
+
decorative?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A QR code in the Cuer style: round modules, rounded finder patterns and an optional arena in the centre. HIG encodes the
|
|
26
|
+
* value itself, so no package is needed, and the whole code is one path in one inline SVG. The value is encoded once per
|
|
27
|
+
* `value`, `errorCorrection` and arena; `size`, the colours and the quiet zone only change attributes.
|
|
28
|
+
*
|
|
29
|
+
* The arena is an HTML box over the SVG, not a `foreignObject` inside it: WebKit paints positioned, transformed or
|
|
30
|
+
* translucent content of a `foreignObject` at the SVG's corner, where it would cover a finder pattern.
|
|
31
|
+
*/
|
|
32
|
+
export declare function QRCode({ value, size, arena, errorCorrection, color, background, quietZone, label, decorative, className, style, ...rest }: QRCodeProps): React.JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { QR_QUIET_ZONE, qrCodeGeometry, qrFrame } from '@bloxwap/hig/contracts/qr';
|
|
6
|
+
import { useHIG } from './provider.js';
|
|
7
|
+
const drawn = (node) => node != null && node !== false && node !== true && node !== '';
|
|
8
|
+
const percent = (fraction) => `${Math.round(fraction * 1e6) / 1e4}%`;
|
|
9
|
+
/**
|
|
10
|
+
* A QR code in the Cuer style: round modules, rounded finder patterns and an optional arena in the centre. HIG encodes the
|
|
11
|
+
* value itself, so no package is needed, and the whole code is one path in one inline SVG. The value is encoded once per
|
|
12
|
+
* `value`, `errorCorrection` and arena; `size`, the colours and the quiet zone only change attributes.
|
|
13
|
+
*
|
|
14
|
+
* The arena is an HTML box over the SVG, not a `foreignObject` inside it: WebKit paints positioned, transformed or
|
|
15
|
+
* translucent content of a `foreignObject` at the SVG's corner, where it would cover a finder pattern.
|
|
16
|
+
*/
|
|
17
|
+
export function QRCode({ value, size = 196, arena, errorCorrection, color, background, quietZone = QR_QUIET_ZONE, label, decorative = false, className, style, ...rest }) {
|
|
18
|
+
const { messages } = useHIG();
|
|
19
|
+
const withArena = drawn(arena);
|
|
20
|
+
const geometry = useMemo(() => qrCodeGeometry(value, { errorCorrection, arena: withArena }), [value, errorCorrection, withArena]);
|
|
21
|
+
const frame = useMemo(() => geometry ? qrFrame(geometry, size, quietZone) : null, [geometry, size, quietZone]);
|
|
22
|
+
const tile = background === 'none' || background === 'transparent' ? null : background ?? 'var(--hig-background,transparent)';
|
|
23
|
+
const named = !decorative && geometry !== null;
|
|
24
|
+
const box = frame?.arena;
|
|
25
|
+
// Percentages of the square, so the box stays over the cleared modules when host CSS resizes the code. Physical `left`: a right-to-left page does not mirror a QR code.
|
|
26
|
+
const boxStyle = box ? { left: percent(box.inset), top: percent(box.inset), width: percent(box.extent), height: percent(box.extent), borderRadius: percent(box.radius / box.size) } : undefined;
|
|
27
|
+
return _jsxs("span", { ...rest, className: `hig-qr-code${className ? ` ${className}` : ''}`, style: { '--hig-qr-code-size': `${size}px`, ...style }, role: named ? 'img' : undefined, "aria-label": named ? label ?? messages.qrCode ?? en.qrCode : undefined, "aria-hidden": named ? undefined : true, "data-empty": geometry ? undefined : '', children: [_jsxs("svg", { "aria-hidden": 'true', focusable: 'false', width: size, height: size, viewBox: frame?.viewBox, children: [tile && frame && _jsx("rect", { x: -frame.quietZone, y: -frame.quietZone, width: frame.span, height: frame.span, rx: frame.tileRadius, style: { fill: tile } }), geometry && _jsx("path", { d: geometry.path, style: { fill: color ?? 'var(--hig-text,currentColor)' } })] }), box && _jsx("span", { className: 'hig-qr-code-arena', style: boxStyle, children: typeof arena === 'string' ? _jsx("img", { className: 'hig-qr-code-image', src: arena, alt: '', draggable: false }) : arena })] });
|
|
28
|
+
}
|
package/react/dist/select.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Check } from '@bloxwap/icons/react/check';
|
|
4
|
+
import { ChevronDown } from '@bloxwap/icons/react/chevron-down';
|
|
5
|
+
import { assertUniqueKeys } from '@bloxwap/hig/contracts';
|
|
3
6
|
import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
4
7
|
import { useControllable, useHIG } from './provider.js';
|
|
5
8
|
/** A select-only combobox. DOM focus stays on the trigger while its active option is announced. */
|
|
6
9
|
export function Select({ label, options, value, defaultValue, disabled, onValueChange }) {
|
|
10
|
+
assertUniqueKeys(options, option => option.value, 'Select');
|
|
11
|
+
const controlled = useRef(value !== undefined).current;
|
|
7
12
|
const id = useId();
|
|
8
13
|
const { direction, locale } = useHIG();
|
|
9
14
|
const [current, setCurrent] = useControllable(value, defaultValue ?? options.find(option => !option.disabled)?.value ?? '', onValueChange);
|
|
@@ -13,7 +18,9 @@ export function Select({ label, options, value, defaultValue, disabled, onValueC
|
|
|
13
18
|
const list = useRef(null);
|
|
14
19
|
const search = useRef({ text: '', time: 0 });
|
|
15
20
|
const match = options.findIndex(option => option.value === current);
|
|
16
|
-
const selected = match >= 0 ? match : options.findIndex(option => !option.disabled);
|
|
21
|
+
const selected = match >= 0 && !options[match].disabled ? match : controlled ? -1 : options.findIndex(option => !option.disabled);
|
|
22
|
+
useEffect(() => { if (!controlled && selected >= 0 && current !== options[selected].value)
|
|
23
|
+
setCurrent(options[selected].value); }, [controlled, current, selected, options]);
|
|
17
24
|
const expanded = open && !disabled && options.length > 0;
|
|
18
25
|
const activeOption = active >= 0 && !options[active]?.disabled ? options[active] : undefined;
|
|
19
26
|
const optionId = (index) => `${id}-option-${index}`;
|
|
@@ -169,6 +176,6 @@ export function Select({ label, options, value, defaultValue, disabled, onValueC
|
|
|
169
176
|
else if (option.offsetTop + option.offsetHeight > popup.scrollTop + popup.clientHeight)
|
|
170
177
|
popup.scrollTop = option.offsetTop + option.offsetHeight - popup.clientHeight;
|
|
171
178
|
}, [expanded, active, activeOption, id]);
|
|
172
|
-
return _jsxs("div", { className: 'hig-field', children: [_jsx("label", { id: `${id}-label`, htmlFor: id, children: label }), _jsxs("div", { className: 'hig-select', children: [_jsxs("button", { ref: trigger, id: id, type: 'button', role: 'combobox', className: 'hig-input hig-select-trigger', disabled: disabled, "aria-labelledby": `${id}-label`, "aria-haspopup": 'listbox', "aria-expanded": expanded, "aria-controls": expanded ? `${id}-list` : undefined, "aria-activedescendant": expanded && activeOption ? optionId(active) : undefined, onClick: () => expanded ? setOpen(false) : show(), onKeyDown: onKeyDown, onBlur: () => setOpen(false), children: [_jsx("span", { className: 'hig-select-value', children: options[selected]?.label ?? '' }), _jsx(
|
|
173
|
-
setActive(index); }, onClick: () => choose(index), children: [_jsx("span", { children: option.label }), _jsx(
|
|
179
|
+
return _jsxs("div", { className: 'hig-field', children: [_jsx("label", { id: `${id}-label`, htmlFor: id, children: label }), _jsxs("div", { className: 'hig-select', children: [_jsxs("button", { ref: trigger, id: id, type: 'button', role: 'combobox', className: 'hig-input hig-select-trigger', disabled: disabled, "aria-labelledby": `${id}-label`, "aria-haspopup": 'listbox', "aria-expanded": expanded, "aria-controls": expanded ? `${id}-list` : undefined, "aria-activedescendant": expanded && activeOption ? optionId(active) : undefined, onClick: () => expanded ? setOpen(false) : show(), onKeyDown: onKeyDown, onBlur: () => setOpen(false), children: [_jsx("span", { className: 'hig-select-value', children: options[selected]?.label ?? '' }), _jsx(ChevronDown, { size: 20, className: 'hig-select-chevron' })] }), expanded && _jsx("div", { ref: list, id: `${id}-list`, className: 'hig-select-list', role: 'listbox', "aria-labelledby": `${id}-label`, popover: 'manual', onPointerDown: event => event.preventDefault(), children: options.map((option, index) => _jsxs("div", { id: optionId(index), role: 'option', className: 'hig-select-option', "aria-selected": index === selected, "aria-disabled": option.disabled || undefined, "data-active": index === active || undefined, onPointerMove: () => { if (!option.disabled)
|
|
180
|
+
setActive(index); }, onClick: () => choose(index), children: [_jsx("span", { children: option.label }), _jsx(Check, { size: 20, className: 'hig-select-check' })] }, option.value)) })] })] });
|
|
174
181
|
}
|
|
@@ -12,7 +12,10 @@ interface CheckedProps {
|
|
|
12
12
|
onCheckedChange?: (value: boolean) => void;
|
|
13
13
|
}
|
|
14
14
|
export declare function Checkbox({ label, checked, defaultChecked, disabled, onCheckedChange }: CheckedProps): React.JSX.Element;
|
|
15
|
-
export
|
|
15
|
+
export interface SwitchProps extends CheckedProps {
|
|
16
|
+
hideLabel?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function Switch({ label, checked, defaultChecked, disabled, hideLabel, onCheckedChange }: SwitchProps): React.JSX.Element;
|
|
16
19
|
export interface ChoicesProps {
|
|
17
20
|
label: string;
|
|
18
21
|
options: readonly Choice[];
|
|
@@ -21,8 +24,17 @@ export interface ChoicesProps {
|
|
|
21
24
|
disabled?: boolean;
|
|
22
25
|
onValueChange?: (value: string) => void;
|
|
23
26
|
}
|
|
27
|
+
/** One segment. `testID` becomes the `data-testid` of the segment's radio, in place of `<group testID>-<value>`. */
|
|
28
|
+
export interface SegmentedControlOption extends Choice {
|
|
29
|
+
testID?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface SegmentedControlProps extends Omit<ChoicesProps, 'options'> {
|
|
32
|
+
options: readonly SegmentedControlOption[]; /** Keeps `label` as the group's accessible name but does not draw it, for a control whose heading or row already names it. */
|
|
33
|
+
hideLabel?: boolean; /** The group's `data-testid`; each segment's radio then takes `<testID>-<value>` unless the option sets its own `testID`, as on native. Omitted, only options with a `testID` set one. */
|
|
34
|
+
testID?: string;
|
|
35
|
+
}
|
|
24
36
|
export declare function RadioGroup({ label, options, value, defaultValue, disabled, onValueChange }: ChoicesProps): React.JSX.Element;
|
|
25
|
-
export declare function SegmentedControl({ label, options, value, defaultValue, disabled, onValueChange }:
|
|
37
|
+
export declare function SegmentedControl({ label, options, value, defaultValue, disabled, hideLabel, testID, onValueChange }: SegmentedControlProps): React.JSX.Element;
|
|
26
38
|
export interface FilterOption extends Choice {
|
|
27
39
|
icon?: string;
|
|
28
40
|
}
|
|
@@ -32,9 +44,11 @@ export interface FilterProps {
|
|
|
32
44
|
value?: string;
|
|
33
45
|
defaultValue?: string;
|
|
34
46
|
disabled?: boolean;
|
|
35
|
-
onValueChange?: (value: string) => void;
|
|
47
|
+
onValueChange?: (value: string) => void; /** Pixels the row scrolls out past its container on each side (`--hig-filter-bleed`), so the capsules are cut by the container's edge, while the first and last capsule rest this far in: pass the container's side padding. Default 0, or what an ancestor sets in `--hig-filter-bleed`. */
|
|
48
|
+
bleed?: number;
|
|
36
49
|
}
|
|
37
50
|
/** One row of filter capsules that scrolls sideways. Single choice with radio semantics; the chosen capsule inverts and a check draws into its circle. */
|
|
38
|
-
export declare function Filter({ label, options, value, defaultValue, disabled, onValueChange }: FilterProps): React.JSX.Element;
|
|
51
|
+
export declare function Filter({ label, options, value, defaultValue, disabled, onValueChange, bleed }: FilterProps): React.JSX.Element;
|
|
39
52
|
export { Select } from './select.js';
|
|
40
53
|
export { Slider } from './slider.js';
|
|
54
|
+
export { PresetGroup, type PresetGroupProps, type PresetOption } from './preset-group.js';
|
package/react/dist/selection.js
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Check } from '@bloxwap/icons/react/check';
|
|
4
|
+
import { assertUniqueKeys } from '@bloxwap/hig/contracts';
|
|
5
|
+
import { useId, useRef } from 'react';
|
|
6
|
+
import { PressDecoration, useControllable } from './provider.js';
|
|
5
7
|
export function Checkbox({ label, checked, defaultChecked = false, disabled, onCheckedChange }) { const [value, set] = useControllable(checked, defaultChecked, onCheckedChange); return _jsxs("label", { className: 'hig-choice', children: [_jsx("input", { type: 'checkbox', checked: value, disabled: disabled, onChange: e => set(e.target.checked) }), _jsx("span", { children: label })] }); }
|
|
6
|
-
export function Switch({ label, checked, defaultChecked = false, disabled, onCheckedChange }) { const [value, set] = useControllable(checked, defaultChecked, onCheckedChange); return _jsxs("label", { className: 'hig-choice hig-switch', children: [_jsx("input", { role: 'switch', type: 'checkbox', checked: value, disabled: disabled, onChange: e => set(e.target.checked) }), _jsx("span", { children: label })] }); }
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
export function Switch({ label, checked, defaultChecked = false, disabled, hideLabel, onCheckedChange }) { const [value, set] = useControllable(checked, defaultChecked, onCheckedChange); const input = useRef(null); return _jsxs("label", { className: 'hig-choice hig-switch', children: [_jsx("input", { ref: input, role: 'switch', type: 'checkbox', checked: value, disabled: disabled, onChange: e => set(e.target.checked) }), _jsx("span", { className: hideLabel ? 'hig-sr-only' : undefined, children: label }), _jsx(PressDecoration, { kind: 'switch', disabled: !!disabled, input: input })] }); }
|
|
9
|
+
/** One segment: a label around its radio, with the provider's press decoration aimed at that radio. */
|
|
10
|
+
function Segment({ name, option, checked, blocked, testID, onSelect }) {
|
|
11
|
+
const input = useRef(null);
|
|
12
|
+
return _jsxs("label", { className: 'hig-segment', children: [_jsx("input", { ref: input, type: 'radio', name: name, value: option.value, checked: checked, disabled: option.disabled, "data-testid": testID, onChange: () => { if (!blocked)
|
|
13
|
+
onSelect(); } }), _jsx("span", { children: option.label }), _jsx(PressDecoration, { kind: 'segment', disabled: blocked, input: input })] });
|
|
14
|
+
}
|
|
15
|
+
export function RadioGroup({ label, options, value, defaultValue = '', disabled, onValueChange }) { assertUniqueKeys(options, option => option.value, 'Choices'); const name = useId(); const [current, set] = useControllable(value, defaultValue, onValueChange); return _jsxs("fieldset", { className: 'hig-group', disabled: disabled, children: [_jsx("legend", { children: label }), options.map(o => _jsxs("label", { className: 'hig-choice', children: [_jsx("input", { type: 'radio', name: name, value: o.value, checked: current === o.value, disabled: o.disabled, onChange: () => set(o.value) }), _jsx("span", { children: o.label })] }, o.value))] }); }
|
|
16
|
+
export function SegmentedControl({ label, options, value, defaultValue = '', disabled, hideLabel, testID, onValueChange }) {
|
|
17
|
+
assertUniqueKeys(options, option => option.value, 'Choices');
|
|
9
18
|
const name = useId();
|
|
10
19
|
const [current, set] = useControllable(value, defaultValue, onValueChange);
|
|
11
20
|
const selected = options.findIndex(option => option.value === current);
|
|
12
|
-
return _jsxs("fieldset", { className: 'hig-group hig-segmented-control', disabled: disabled, children: [_jsx("legend", { children: label }), _jsxs("div", { className: 'hig-segments', style: { '--hig-segment-count': Math.max(1, options.length), '--hig-segment-index': selected }, children: [selected >= 0 && _jsx("span", { className: 'hig-segment-indicator', "aria-hidden": 'true', "data-disabled": disabled || options[selected].disabled || undefined }), options.map(o =>
|
|
13
|
-
set(o.value); } }), _jsx("span", { children: o.label })] }, o.value))] })] });
|
|
21
|
+
return _jsxs("fieldset", { className: 'hig-group hig-segmented-control', disabled: disabled, "data-testid": testID, children: [_jsx("legend", { className: hideLabel ? 'hig-sr-only' : undefined, children: label }), _jsxs("div", { className: 'hig-segments', style: { '--hig-segment-count': Math.max(1, options.length), '--hig-segment-index': selected }, children: [selected >= 0 && _jsx("span", { className: 'hig-segment-indicator', "aria-hidden": 'true', "data-disabled": disabled || options[selected].disabled || undefined }), options.map(o => _jsx(Segment, { name: name, option: o, checked: current === o.value, blocked: !!disabled || !!o.disabled, testID: o.testID ?? (testID === undefined ? undefined : `${testID}-${o.value}`), onSelect: () => set(o.value) }, o.value))] })] });
|
|
14
22
|
}
|
|
15
23
|
/** One row of filter capsules that scrolls sideways. Single choice with radio semantics; the chosen capsule inverts and a check draws into its circle. */
|
|
16
|
-
export function Filter({ label, options, value, defaultValue = '', disabled, onValueChange }) {
|
|
24
|
+
export function Filter({ label, options, value, defaultValue = '', disabled, onValueChange, bleed }) {
|
|
25
|
+
assertUniqueKeys(options, option => option.value, 'Choices');
|
|
17
26
|
const name = useId();
|
|
18
27
|
const [current, set] = useControllable(value, defaultValue, onValueChange);
|
|
19
|
-
return _jsx("div", { className: 'hig-filter', role: 'radiogroup', "aria-label": label, "aria-disabled": disabled || undefined, children: options.map(o => _jsxs("label", { className: 'hig-filter-chip', children: [_jsx("input", { type: 'radio', name: name, value: o.value, checked: current === o.value, disabled: disabled || o.disabled, onChange: () => { if (!disabled && !o.disabled)
|
|
20
|
-
set(o.value); } }), _jsxs("span", { className: 'hig-filter-mark', "aria-hidden": 'true', children: [o.icon && _jsx("img", { src: o.icon, alt: '', loading: 'lazy' }), _jsx(
|
|
28
|
+
return _jsx("div", { className: 'hig-filter', role: 'radiogroup', "aria-label": label, "aria-disabled": disabled || undefined, style: bleed == null ? undefined : { '--hig-filter-bleed': `${bleed}px` }, children: options.map(o => _jsxs("label", { className: 'hig-filter-chip', children: [_jsx("input", { type: 'radio', name: name, value: o.value, checked: current === o.value, disabled: disabled || o.disabled, onChange: () => { if (!disabled && !o.disabled)
|
|
29
|
+
set(o.value); } }), _jsxs("span", { className: 'hig-filter-mark', "aria-hidden": 'true', children: [o.icon && _jsx("img", { src: o.icon, alt: '', loading: 'lazy' }), _jsx(Check, { size: 16 })] }), _jsx("span", { children: o.label })] }, o.value)) });
|
|
21
30
|
}
|
|
22
31
|
export { Select } from './select.js';
|
|
23
32
|
export { Slider } from './slider.js';
|
|
33
|
+
export { PresetGroup } from './preset-group.js';
|
package/react/dist/slider.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { numericRange } from '@bloxwap/hig/contracts';
|
|
3
4
|
import { useId } from 'react';
|
|
4
5
|
import { useControllable } from './provider.js';
|
|
5
6
|
export function Slider({ label, value, defaultValue = 0, min = 0, max = 100, step = 1, disabled, onValueChange }) {
|
|
6
7
|
const id = useId();
|
|
7
|
-
const
|
|
8
|
+
const range = numericRange(min, max, step);
|
|
9
|
+
const [stored, commit] = useControllable(value, defaultValue, onValueChange);
|
|
10
|
+
const current = range.clamp(stored);
|
|
11
|
+
const set = (next) => commit(range.clamp(next));
|
|
8
12
|
const fill = max > min ? Math.min(100, Math.max(0, (current - min) / (max - min) * 100)) : 0;
|
|
9
13
|
return _jsxs("div", { className: 'hig-field hig-slider', children: [_jsxs("label", { htmlFor: id, children: [label, ": ", current] }), _jsx("input", { id: id, className: 'hig-range', style: { '--hig-range-fill': `${fill}%` }, type: 'range', min: min, max: max, step: step, disabled: disabled, value: current, onChange: e => set(e.target.valueAsNumber) })] });
|
|
10
14
|
}
|
package/react/dist/status.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export type BadgeTone = 'neutral' | 'positive' | 'negative' | 'warning' | 'info';
|
|
3
3
|
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
4
|
-
tone?: BadgeTone;
|
|
4
|
+
tone?: BadgeTone; /** A 6px status dot in the label colour on the leading edge, hidden from assistive technology. */
|
|
5
|
+
dot?: boolean;
|
|
5
6
|
}
|
|
6
7
|
/** A quiet status label. The host owns announcements and may supply typography or an accessible name. */
|
|
7
8
|
export declare const Badge: React.ForwardRefExoticComponent<BadgeProps & React.RefAttributes<HTMLSpanElement>>;
|
|
@@ -21,9 +22,10 @@ export interface Notice {
|
|
|
21
22
|
severity: 'info' | 'success' | 'warning' | 'error';
|
|
22
23
|
action?: React.ReactNode;
|
|
23
24
|
}
|
|
24
|
-
/** One notice as a single capsule row: severity symbol on the leading edge, message, optional action, close on the trailing edge. Shared by `Toast` and the Sonner-backed `toast()`; it announces nothing itself. */
|
|
25
|
-
export declare function ToastNotice({ message, severity, action, dismissName, onDismiss }: {
|
|
26
|
-
message: React.ReactNode;
|
|
25
|
+
/** One notice as a single capsule row: severity symbol on the leading edge, message with an optional description under it, optional action, close on the trailing edge. Shared by `Toast` and the Sonner-backed `toast()`; it announces nothing itself. */
|
|
26
|
+
export declare function ToastNotice({ message, description, severity, action, dismissName, onDismiss }: {
|
|
27
|
+
message: React.ReactNode; /** A second line under the message, in regular weight. With one the capsule keeps a fixed corner radius, not a full pill. */
|
|
28
|
+
description?: React.ReactNode;
|
|
27
29
|
severity?: Notice['severity'];
|
|
28
30
|
action?: React.ReactNode; /** Accessible name of the close button. */
|
|
29
31
|
dismissName: string;
|
|
@@ -40,9 +42,13 @@ export declare function Progress({ label, value, max }: {
|
|
|
40
42
|
value?: number;
|
|
41
43
|
max?: number;
|
|
42
44
|
}): React.JSX.Element;
|
|
43
|
-
export
|
|
45
|
+
export interface SpinnerProps {
|
|
46
|
+
/** What is loading; defaults to HIGProvider `messages.loading`. */
|
|
44
47
|
label?: string;
|
|
45
|
-
|
|
48
|
+
/** Draws the ring alone, for a tight spot such as a row or a button-sized slot: the label is not drawn but stays the status's accessible text. */
|
|
49
|
+
hideLabel?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export declare function Spinner({ label, hideLabel }: SpinnerProps): React.JSX.Element;
|
|
46
52
|
export declare function Skeleton({ label }: {
|
|
47
53
|
label?: string;
|
|
48
54
|
}): React.JSX.Element;
|
|
@@ -53,10 +59,8 @@ export declare function EmptyState({ title, description, action, illustration }:
|
|
|
53
59
|
action?: React.ReactNode;
|
|
54
60
|
illustration?: React.ReactNode;
|
|
55
61
|
}): React.JSX.Element;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
src?: string;
|
|
59
|
-
}): React.JSX.Element;
|
|
62
|
+
/** `Avatar` is its own entry, `@bloxwap/hig/react/avatar`; this entry keeps exporting it for the imports that predate that one. */
|
|
63
|
+
export { Avatar, type AvatarProps } from './avatar.js';
|
|
60
64
|
export declare function StatusIndicator({ label, state }: {
|
|
61
65
|
label: string;
|
|
62
66
|
state: 'online' | 'offline' | 'stale';
|