@bloxwap/hig 0.0.0-stage → 0.5.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/LICENSE +5 -0
- package/README.md +44 -2
- package/chart/README.md +23 -0
- package/chart/dist/index.d.ts +8 -0
- package/chart/dist/index.js +12 -0
- package/contracts/README.md +3 -0
- package/contracts/dist/announcements.d.ts +12 -0
- package/contracts/dist/announcements.js +8 -0
- package/contracts/dist/feedback.d.ts +40 -0
- package/contracts/dist/feedback.js +1 -0
- package/contracts/dist/index.d.ts +41 -0
- package/contracts/dist/index.js +52 -0
- package/contracts/dist/messages.d.ts +300 -0
- package/contracts/dist/messages.js +114 -0
- package/css.d.ts +2 -0
- package/feedback/README.md +7 -0
- package/feedback/assets/error.wav +0 -0
- package/feedback/assets/manifest.json +78 -0
- package/feedback/assets/success.wav +0 -0
- package/feedback/assets/tick.wav +0 -0
- package/feedback/assets/toggle.wav +0 -0
- package/feedback/dist/browser-haptic.d.ts +23 -0
- package/feedback/dist/browser-haptic.js +41 -0
- package/feedback/dist/contract.d.ts +40 -0
- package/feedback/dist/contract.js +59 -0
- package/feedback/dist/native.d.ts +28 -0
- package/feedback/dist/native.js +63 -0
- package/feedback/dist/preferences.d.ts +8 -0
- package/feedback/dist/preferences.js +24 -0
- package/feedback/dist/presets.d.ts +57 -0
- package/feedback/dist/presets.js +1 -0
- package/feedback/dist/react.d.ts +19 -0
- package/feedback/dist/react.js +23 -0
- package/feedback/dist/web-haptic.d.ts +6 -0
- package/feedback/dist/web-haptic.js +6 -0
- package/feedback/dist/web-sound.d.ts +5 -0
- package/feedback/dist/web-sound.js +32 -0
- package/feedback/dist/web.d.ts +3 -0
- package/feedback/dist/web.js +4 -0
- package/native/README.md +16 -0
- package/native/android/build.gradle +28 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableView.java +173 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableViewManager.java +23 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGPackage.java +24 -0
- package/native/dist/animated-number-model.d.ts +24 -0
- package/native/dist/animated-number-model.js +110 -0
- package/native/dist/animated-number.d.ts +9 -0
- package/native/dist/animated-number.js +97 -0
- package/native/dist/brand.d.ts +7 -0
- package/native/dist/brand.js +7 -0
- package/native/dist/button.d.ts +30 -0
- package/native/dist/button.js +36 -0
- package/native/dist/checkbox.d.ts +3 -0
- package/native/dist/checkbox.js +11 -0
- package/native/dist/data.d.ts +57 -0
- package/native/dist/data.js +47 -0
- package/native/dist/field.d.ts +16 -0
- package/native/dist/field.js +26 -0
- package/native/dist/gesture-sheet.d.ts +73 -0
- package/native/dist/gesture-sheet.js +153 -0
- package/native/dist/icons.d.ts +21 -0
- package/native/dist/icons.js +20 -0
- package/native/dist/navigation.d.ts +48 -0
- package/native/dist/navigation.js +58 -0
- package/native/dist/overlay.d.ts +36 -0
- package/native/dist/overlay.js +65 -0
- package/native/dist/pickers.d.ts +54 -0
- package/native/dist/pickers.js +60 -0
- package/native/dist/provider.d.ts +62 -0
- package/native/dist/provider.js +67 -0
- package/native/dist/radio-group.d.ts +21 -0
- package/native/dist/radio-group.js +91 -0
- package/native/dist/recipes.d.ts +45 -0
- package/native/dist/recipes.js +32 -0
- package/native/dist/roles.d.ts +6 -0
- package/native/dist/roles.js +4 -0
- package/native/dist/select.d.ts +3 -0
- package/native/dist/select.js +9 -0
- package/native/dist/selection-types.d.ts +22 -0
- package/native/dist/selection-types.js +1 -0
- package/native/dist/selection.d.ts +8 -0
- package/native/dist/selection.js +7 -0
- package/native/dist/slider.d.ts +11 -0
- package/native/dist/slider.js +42 -0
- package/native/dist/status.d.ts +86 -0
- package/native/dist/status.js +112 -0
- package/native/dist/surface.d.ts +19 -0
- package/native/dist/surface.js +42 -0
- package/native/dist/swap-panel.d.ts +125 -0
- package/native/dist/swap-panel.js +177 -0
- package/native/dist/swap-parts.d.ts +86 -0
- package/native/dist/swap-parts.js +66 -0
- package/native/dist/swap-shared.d.ts +65 -0
- package/native/dist/swap-shared.js +76 -0
- package/native/dist/swap-sheet.d.ts +14 -0
- package/native/dist/swap-sheet.js +26 -0
- package/native/dist/swap-views.d.ts +41 -0
- package/native/dist/swap-views.js +37 -0
- package/native/dist/switch-row.d.ts +8 -0
- package/native/dist/switch-row.js +18 -0
- package/native/dist/switch.d.ts +10 -0
- package/native/dist/switch.js +30 -0
- package/native/dist/text-content.d.ts +5 -0
- package/native/dist/text-content.js +6 -0
- package/native/dist/wallet-address.d.ts +37 -0
- package/native/dist/wallet-address.js +50 -0
- package/native-fonts/README.md +17 -0
- package/native-fonts/dist/index.d.ts +164 -0
- package/native-fonts/dist/index.js +164 -0
- package/native-fonts/fonts/BloxwapMono-Bold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-ExtraBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Black.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-ExtraBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansKR-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansKR.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansSC-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansSC.ttf +0 -0
- package/native-fonts/fonts/OFL.txt +93 -0
- package/native-fonts/fonts/manifest.json +164 -0
- package/og-fonts/README.md +34 -0
- package/og-fonts/dist/index.d.ts +116 -0
- package/og-fonts/dist/index.js +102 -0
- package/og-fonts/dist/node.d.ts +11 -0
- package/og-fonts/dist/node.js +39 -0
- package/og-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Black.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans.ttf +0 -0
- package/og-fonts/fonts/OFL.txt +93 -0
- package/og-fonts/fonts/manifest.json +65 -0
- package/package.json +476 -4
- package/react/README.md +30 -0
- package/react/dist/animated-number-model.d.ts +20 -0
- package/react/dist/animated-number-model.js +92 -0
- package/react/dist/animated-number.d.ts +8 -0
- package/react/dist/animated-number.js +72 -0
- package/react/dist/base.css +9 -0
- package/react/dist/brand.d.ts +7 -0
- package/react/dist/brand.js +5 -0
- package/react/dist/button.d.ts +14 -0
- package/react/dist/button.js +20 -0
- package/react/dist/data.d.ts +78 -0
- package/react/dist/data.js +36 -0
- package/react/dist/dialog.d.ts +29 -0
- package/react/dist/dialog.js +21 -0
- package/react/dist/field.d.ts +16 -0
- package/react/dist/field.js +20 -0
- package/react/dist/gesture-sheet.d.ts +41 -0
- package/react/dist/gesture-sheet.js +128 -0
- package/react/dist/navigation.d.ts +48 -0
- package/react/dist/navigation.js +69 -0
- package/react/dist/notify.d.ts +14 -0
- package/react/dist/notify.js +6 -0
- package/react/dist/overlay.d.ts +17 -0
- package/react/dist/overlay.js +18 -0
- package/react/dist/provider.d.ts +25 -0
- package/react/dist/provider.js +50 -0
- package/react/dist/recipes/activity-list.d.ts +8 -0
- package/react/dist/recipes/activity-list.js +6 -0
- package/react/dist/recipes/balance-card.d.ts +6 -0
- package/react/dist/recipes/balance-card.js +5 -0
- package/react/dist/recipes/code-window.d.ts +4 -0
- package/react/dist/recipes/code-window.js +4 -0
- package/react/dist/recipes/install-command.d.ts +6 -0
- package/react/dist/recipes/install-command.js +15 -0
- package/react/dist/recipes/market-row.d.ts +25 -0
- package/react/dist/recipes/market-row.js +8 -0
- package/react/dist/recipes/marketing-hero.d.ts +7 -0
- package/react/dist/recipes/marketing-hero.js +5 -0
- package/react/dist/recipes/pickers.d.ts +57 -0
- package/react/dist/recipes/pickers.js +78 -0
- package/react/dist/recipes/swap/amount-card.d.ts +40 -0
- package/react/dist/recipes/swap/amount-card.js +7 -0
- package/react/dist/recipes/swap/picker.d.ts +26 -0
- package/react/dist/recipes/swap/picker.js +20 -0
- package/react/dist/recipes/swap/settings.d.ts +24 -0
- package/react/dist/recipes/swap/settings.js +25 -0
- package/react/dist/recipes/swap/shared.d.ts +98 -0
- package/react/dist/recipes/swap/shared.js +106 -0
- package/react/dist/recipes/swap-panel.d.ts +127 -0
- package/react/dist/recipes/swap-panel.js +170 -0
- package/react/dist/recipes/swap-sheet.d.ts +16 -0
- package/react/dist/recipes/swap-sheet.js +22 -0
- package/react/dist/recipes/trade-entry.d.ts +11 -0
- package/react/dist/recipes/trade-entry.js +12 -0
- package/react/dist/recipes.d.ts +10 -0
- package/react/dist/recipes.js +11 -0
- package/react/dist/select.d.ts +4 -0
- package/react/dist/select.js +174 -0
- package/react/dist/selection.d.ts +40 -0
- package/react/dist/selection.js +23 -0
- package/react/dist/slider.d.ts +11 -0
- package/react/dist/slider.js +10 -0
- package/react/dist/status.d.ts +63 -0
- package/react/dist/status.js +47 -0
- package/react/dist/styles.css +542 -0
- package/react/dist/surface.d.ts +291 -0
- package/react/dist/surface.js +9 -0
- package/react/dist/toast.d.ts +17 -0
- package/react/dist/toast.js +21 -0
- package/react/dist/wallet-address.d.ts +23 -0
- package/react/dist/wallet-address.js +24 -0
- package/tokens/README.md +17 -0
- package/tokens/assets/bloxwap-icon.svg +1 -0
- package/tokens/dist/brand.d.ts +19 -0
- package/tokens/dist/brand.js +24 -0
- package/tokens/dist/index.d.ts +437 -0
- package/tokens/dist/index.js +514 -0
- package/tokens/dist/manifest.json +200 -0
- package/tokens/dist/theme.d.ts +11 -0
- package/tokens/dist/theme.js +22 -0
- package/tokens/dist/tokens.css +120 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface AnimatedNumberToken {
|
|
2
|
+
key: string;
|
|
3
|
+
text: string;
|
|
4
|
+
digit: boolean;
|
|
5
|
+
value?: number;
|
|
6
|
+
place?: number;
|
|
7
|
+
section?: 'number' | 'exponent';
|
|
8
|
+
}
|
|
9
|
+
export interface AnimatedNumberModel {
|
|
10
|
+
reading: string;
|
|
11
|
+
tokens: readonly AnimatedNumberToken[];
|
|
12
|
+
animatable: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface AnimatedNumberTransitionToken extends AnimatedNumberToken {
|
|
15
|
+
oldText?: string;
|
|
16
|
+
oldValue?: number;
|
|
17
|
+
changed: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function createAnimatedNumberModel(value: number | null | undefined, locale: string, options?: Intl.NumberFormatOptions): AnimatedNumberModel;
|
|
20
|
+
export declare function createAnimatedNumberTransitions(previous: AnimatedNumberModel | null, next: AnimatedNumberModel): readonly AnimatedNumberTransitionToken[];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const staticModel = (reading) => ({ reading, animatable: false, tokens: [{ key: 'static:0', text: reading, digit: false }] });
|
|
2
|
+
function digitsFor(formatter) {
|
|
3
|
+
const resolved = formatter.resolvedOptions();
|
|
4
|
+
const digitFormatter = new Intl.NumberFormat(resolved.locale, { numberingSystem: resolved.numberingSystem, useGrouping: false });
|
|
5
|
+
const glyphs = Array.from({ length: 10 }, (_, digit) => { const text = digitFormatter.format(digit); const parts = digitFormatter.formatToParts(digit); return parts.length === 1 && parts[0].type === 'integer' && parts[0].value === text ? text : ''; });
|
|
6
|
+
return new Set(glyphs).size === 10 && glyphs.every(Boolean) ? glyphs : null;
|
|
7
|
+
}
|
|
8
|
+
function decodeDigits(text, glyphs) {
|
|
9
|
+
const digits = [];
|
|
10
|
+
let offset = 0;
|
|
11
|
+
while (offset < text.length) {
|
|
12
|
+
let match = -1;
|
|
13
|
+
for (let digit = 0; digit < 10; digit++)
|
|
14
|
+
if (text.startsWith(glyphs[digit], offset) && (match < 0 || glyphs[digit].length > glyphs[match].length))
|
|
15
|
+
match = digit;
|
|
16
|
+
if (match < 0)
|
|
17
|
+
return null;
|
|
18
|
+
digits.push({ text: glyphs[match], value: match });
|
|
19
|
+
offset += glyphs[match].length;
|
|
20
|
+
}
|
|
21
|
+
return digits.length ? digits : null;
|
|
22
|
+
}
|
|
23
|
+
export function createAnimatedNumberModel(value, locale, options) {
|
|
24
|
+
if (value == null || !Number.isFinite(value))
|
|
25
|
+
return staticModel('—');
|
|
26
|
+
const formatter = new Intl.NumberFormat(locale, options), reading = formatter.format(value);
|
|
27
|
+
if (Number.isInteger(value) && !Number.isSafeInteger(value))
|
|
28
|
+
return staticModel(reading);
|
|
29
|
+
const parts = formatter.formatToParts(value);
|
|
30
|
+
if (parts.map(part => part.value).join('') !== reading)
|
|
31
|
+
return staticModel(reading);
|
|
32
|
+
const glyphs = digitsFor(formatter);
|
|
33
|
+
if (!glyphs)
|
|
34
|
+
return staticModel(reading);
|
|
35
|
+
const decoded = parts.map(part => part.type === 'integer' || part.type === 'fraction' || part.type === 'exponentInteger' ? decodeDigits(part.value, glyphs) : null);
|
|
36
|
+
if (decoded.some((digits, index) => !digits && (parts[index].type === 'integer' || parts[index].type === 'fraction' || parts[index].type === 'exponentInteger')))
|
|
37
|
+
return staticModel(reading);
|
|
38
|
+
const count = (type) => decoded.reduce((total, digits, index) => total + (parts[index].type === type ? digits?.length ?? 0 : 0), 0);
|
|
39
|
+
const integerCount = count('integer'), exponentCount = count('exponentInteger');
|
|
40
|
+
let integerIndex = 0, fractionIndex = 0, exponentIndex = 0;
|
|
41
|
+
const tokens = [];
|
|
42
|
+
for (let index = 0; index < parts.length; index++) {
|
|
43
|
+
const part = parts[index], digits = decoded[index];
|
|
44
|
+
if (!digits) {
|
|
45
|
+
tokens.push({ key: `literal:${index}`, text: part.value, digit: false });
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const section = part.type === 'exponentInteger' ? 'exponent' : 'number';
|
|
49
|
+
for (const digit of digits) {
|
|
50
|
+
let place;
|
|
51
|
+
if (part.type === 'integer')
|
|
52
|
+
place = integerCount - integerIndex++ - 1;
|
|
53
|
+
else if (part.type === 'fraction')
|
|
54
|
+
place = --fractionIndex;
|
|
55
|
+
else
|
|
56
|
+
place = exponentCount - exponentIndex++ - 1;
|
|
57
|
+
tokens.push({ key: `digit:${section}:${place}`, text: digit.text, digit: true, value: digit.value, place, section });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return tokens.some(token => token.digit) ? { reading, tokens, animatable: true } : staticModel(reading);
|
|
61
|
+
}
|
|
62
|
+
export function createAnimatedNumberTransitions(previous, next) {
|
|
63
|
+
if (!previous?.animatable || !next.animatable)
|
|
64
|
+
return next.tokens.map(token => ({ ...token, changed: false }));
|
|
65
|
+
const oldDigits = new Map(previous.tokens.filter(token => token.digit).map(token => [token.key, token]));
|
|
66
|
+
const nextDigits = new Set(next.tokens.filter(token => token.digit).map(token => token.key));
|
|
67
|
+
const result = next.tokens.map(token => { const old = token.digit ? oldDigits.get(token.key) : undefined; return { ...token, oldText: old && old.text !== token.text ? old.text : undefined, oldValue: old?.value, changed: token.digit && old?.text !== token.text }; });
|
|
68
|
+
for (let index = 0; index < previous.tokens.length; index++) {
|
|
69
|
+
const old = previous.tokens[index];
|
|
70
|
+
if (!old.digit || nextDigits.has(old.key))
|
|
71
|
+
continue;
|
|
72
|
+
let insertion = -1;
|
|
73
|
+
for (let nextIndex = index + 1; nextIndex < previous.tokens.length; nextIndex++) {
|
|
74
|
+
const anchor = result.findIndex(token => token.key === previous.tokens[nextIndex].key);
|
|
75
|
+
if (anchor >= 0) {
|
|
76
|
+
insertion = anchor;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (insertion < 0)
|
|
81
|
+
for (let nextIndex = index - 1; nextIndex >= 0; nextIndex--) {
|
|
82
|
+
const anchor = result.findIndex(token => token.key === previous.tokens[nextIndex].key);
|
|
83
|
+
if (anchor >= 0) {
|
|
84
|
+
insertion = anchor + 1;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (insertion >= 0)
|
|
89
|
+
result.splice(insertion, 0, { ...old, text: '', oldText: old.text, changed: true });
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type NumberProps } from './data.js';
|
|
3
|
+
export type AnimatedNumberTrend = -1 | 0 | 1 | ((oldValue: number, newValue: number) => -1 | 0 | 1);
|
|
4
|
+
export interface AnimatedNumberProps extends NumberProps {
|
|
5
|
+
duration?: number;
|
|
6
|
+
trend?: AnimatedNumberTrend;
|
|
7
|
+
}
|
|
8
|
+
export declare function AnimatedNumberReadout({ duration, trend, ...props }: AnimatedNumberProps): React.JSX.Element;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { createAnimatedNumberModel, createAnimatedNumberTransitions } from './animated-number-model.js';
|
|
5
|
+
import { useHIG } from './provider.js';
|
|
6
|
+
import { tokens as higTokens } from '@bloxwap/hig/tokens';
|
|
7
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
8
|
+
export function AnimatedNumberReadout({ duration = 180, trend, ...props }) {
|
|
9
|
+
const { locale, direction, reducedMotion, messages } = useHIG();
|
|
10
|
+
const element = useRef(null);
|
|
11
|
+
const previous = useRef(null);
|
|
12
|
+
const generation = useRef(0);
|
|
13
|
+
const active = useRef([]);
|
|
14
|
+
const signature = JSON.stringify([locale, direction, props.options ?? {}]);
|
|
15
|
+
const frame = useMemo(() => {
|
|
16
|
+
const model = createAnimatedNumberModel(props.value, locale, props.options), prior = previous.current, changed = !!prior && prior.signature === signature && !Object.is(prior.value, props.value);
|
|
17
|
+
let movement = 0;
|
|
18
|
+
if (changed && prior && model.animatable && prior.model.animatable && Number.isFinite(prior.value) && Number.isFinite(props.value)) {
|
|
19
|
+
const requested = typeof trend === 'function' ? trend(prior.value, props.value) : trend ?? Math.sign(props.value - prior.value);
|
|
20
|
+
movement = requested === -1 || requested === 1 ? requested : 0;
|
|
21
|
+
}
|
|
22
|
+
return { model, changed, movement, tokens: createAnimatedNumberTransitions(changed ? prior?.model ?? null : null, model) };
|
|
23
|
+
}, [props.value, signature]);
|
|
24
|
+
const [settled, setSettled] = useState(null);
|
|
25
|
+
const known = props.value != null && Number.isFinite(props.value), reading = known ? `${props.prefix ?? ''}${frame.model.reading}${props.suffix ?? ''}` : frame.model.reading, staleText = messages.stale ?? en.stale, accessible = `${props.label ? `${props.label}: ` : ''}${reading}${props.stale ? ` ${staleText}` : ''}`;
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const id = ++generation.current;
|
|
28
|
+
const cancel = () => { const running = active.current; active.current = []; for (const animation of running) {
|
|
29
|
+
animation.onfinish = null;
|
|
30
|
+
animation.cancel();
|
|
31
|
+
} };
|
|
32
|
+
cancel();
|
|
33
|
+
previous.current = { value: props.value, signature, model: frame.model };
|
|
34
|
+
if (!frame.changed)
|
|
35
|
+
return;
|
|
36
|
+
if (reducedMotion || !Number.isFinite(duration) || duration <= 0 || !frame.model.animatable) {
|
|
37
|
+
setSettled(frame);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const places = element.current?.querySelectorAll('[data-hig-animated-number-change]');
|
|
41
|
+
if (!places) {
|
|
42
|
+
setSettled(frame);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const created = [], changes = frame.tokens.filter(token => token.changed);
|
|
46
|
+
for (const [index, place] of Array.from(places).entries()) {
|
|
47
|
+
const token = changes[index], movement = frame.movement || (token?.value !== undefined && token.oldValue !== undefined ? token.value > token.oldValue ? 1 : token.value < token.oldValue ? -1 : 0 : 0), old = place.querySelector('.hig-animated-number-old'), next = place.querySelector('.hig-animated-number-new'), timing = { duration: Math.min(duration, 600), easing: `cubic-bezier(${higTokens.easing.standard.join(',')})`, fill: 'forwards' };
|
|
48
|
+
const oldFrames = movement === 0 ? [{ opacity: 1 }, { opacity: 0 }] : [{ opacity: 1, transform: 'translateY(0%)' }, { opacity: 0, transform: `translateY(${-movement * 100}%)` }];
|
|
49
|
+
const newFrames = movement === 0 ? [{ opacity: 0 }, { opacity: 1 }] : [{ opacity: 0, transform: `translateY(${movement * 100}%)` }, { opacity: 1, transform: 'translateY(0%)' }];
|
|
50
|
+
const oldAnimation = old?.animate?.(oldFrames, timing), newAnimation = next?.animate?.(newFrames, timing);
|
|
51
|
+
if (oldAnimation)
|
|
52
|
+
created.push(oldAnimation);
|
|
53
|
+
if (newAnimation)
|
|
54
|
+
created.push(newAnimation);
|
|
55
|
+
}
|
|
56
|
+
active.current = created;
|
|
57
|
+
if (!created.length) {
|
|
58
|
+
setSettled(frame);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let remaining = created.length;
|
|
62
|
+
for (const animation of created)
|
|
63
|
+
animation.onfinish = () => { if (generation.current === id && --remaining === 0) {
|
|
64
|
+
active.current = [];
|
|
65
|
+
setSettled(frame);
|
|
66
|
+
} };
|
|
67
|
+
return () => { if (generation.current === id)
|
|
68
|
+
cancel(); };
|
|
69
|
+
}, [frame, reducedMotion, duration]);
|
|
70
|
+
const tokens = settled === frame || reducedMotion ? createAnimatedNumberTransitions(null, frame.model) : frame.tokens;
|
|
71
|
+
return _jsxs("span", { className: 'hig-number', children: [_jsx("span", { className: 'hig-sr-only', "aria-label": props.label ? accessible : undefined, children: accessible }), _jsxs("span", { ref: element, className: 'hig-animated-number-visual', "aria-hidden": 'true', dir: direction, children: [known && props.prefix, tokens.map(token => token.changed ? _jsxs("span", { className: 'hig-animated-number-place', "data-hig-animated-number-change": true, children: [token.oldText !== undefined && _jsx("span", { className: 'hig-animated-number-old', children: token.oldText }), token.text && _jsx("span", { className: 'hig-animated-number-new', children: token.text })] }, token.key) : _jsx("span", { children: token.text }, token.key)), known && props.suffix, props.stale && _jsxs("span", { children: [" ", staleText] })] })] });
|
|
72
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* Opt-in global base for hosts that want HIG defaults on every element, not only HIG components (#95):
|
|
2
|
+
import '@bloxwap/hig/react/css/base' next to '@bloxwap/hig/react/css'. These are the page-wide rules
|
|
3
|
+
that @bloxwap/hig/react/css shipped before it was scoped to HIG classes. Partial adopters that load
|
|
4
|
+
HIG on some routes only should not import this file. */
|
|
5
|
+
* { box-sizing: border-box; }
|
|
6
|
+
:focus-visible { outline:2px solid var(--hig-focus);outline-offset:3px; }
|
|
7
|
+
table { border-collapse:collapse;width:100%; }
|
|
8
|
+
th,td { padding:12px;text-align:start;border-bottom:1px solid var(--hig-border); }
|
|
9
|
+
input[type='range'] { accent-color:var(--hig-action); min-height:48px; width:100%; }
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** The approved mark. Geometry and fills come from the pinned SVG through `@bloxwap/hig/tokens/brand`, so it does not follow `primaryColor` or the token palette. */
|
|
3
|
+
export declare function BrandMark({ size, label }: {
|
|
4
|
+
size?: number;
|
|
5
|
+
label?: string;
|
|
6
|
+
}): React.JSX.Element;
|
|
7
|
+
export declare function CheckIcon(): React.JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { brandMark as mark } from '@bloxwap/hig/tokens/brand';
|
|
3
|
+
/** The approved mark. Geometry and fills come from the pinned SVG through `@bloxwap/hig/tokens/brand`, so it does not follow `primaryColor` or the token palette. */
|
|
4
|
+
export function BrandMark({ size = 32, label }) { return _jsxs("svg", { width: size, height: size, viewBox: mark.viewBox, role: label ? 'img' : undefined, "aria-label": label, "aria-hidden": label ? undefined : true, children: [_jsx("rect", { width: mark.size, height: mark.size, rx: mark.radius, fill: mark.fill.srgb }), _jsx("g", { fill: 'none', stroke: mark.stroke.srgb, strokeWidth: mark.strokeWidth, strokeLinecap: mark.strokeLinecap, children: mark.paths.map(d => _jsx("path", { d: d }, d)) })] }); }
|
|
5
|
+
export function CheckIcon() { return _jsx("svg", { width: '20', height: '20', viewBox: '0 0 24 24', "aria-hidden": 'true', children: _jsx("path", { d: 'm5 12 4 4 10-10', fill: 'none', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round', strokeLinejoin: 'round' }) }); }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Intent } from '@bloxwap/hig/contracts';
|
|
3
|
+
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
4
|
+
intent?: Intent; /** Shows a leading spinner and blocks activation. */
|
|
5
|
+
busy?: boolean; /** Busy text appended to the accessible name (not drawn; the spinner is the visible cue); defaults to HIGProvider `messages.busy`. `''` omits it (busy state stays exposed). */
|
|
6
|
+
busyLabel?: string;
|
|
7
|
+
fullWidth?: boolean;
|
|
8
|
+
suppressFeedback?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
11
|
+
export declare const IconButton: React.ForwardRefExoticComponent<Omit<ButtonProps, "aria-label"> & {
|
|
12
|
+
label: string;
|
|
13
|
+
} & React.RefAttributes<HTMLButtonElement>>;
|
|
14
|
+
export declare const Link: React.ForwardRefExoticComponent<React.AnchorHTMLAttributes<HTMLAnchorElement> & React.RefAttributes<HTMLAnchorElement>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useId, useRef } from 'react';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG } from './provider.js';
|
|
6
|
+
export const Button = forwardRef(function Button({ intent = 'primary', busy = false, busyLabel, disabled, fullWidth, suppressFeedback, onClick, children, type = 'button', ...props }, ref) {
|
|
7
|
+
const context = useHIG();
|
|
8
|
+
const id = useId();
|
|
9
|
+
const sequence = useRef(0);
|
|
10
|
+
const busyText = busyLabel ?? context.messages.busy ?? en.busy;
|
|
11
|
+
return _jsxs("button", { ...props, ref: ref, type: type, className: `hig-button ${props.className ?? ''}`, "data-intent": intent, "data-full": fullWidth || undefined, "data-density": context.density, disabled: disabled || busy, "aria-busy": busy || undefined, onClick: e => { e.stopPropagation(); onClick?.(e); if (!e.defaultPrevented && !disabled && !busy && !suppressFeedback) {
|
|
12
|
+
try {
|
|
13
|
+
context.onAccepted?.(id);
|
|
14
|
+
context.feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent: 'activate', origin: e.detail === 0 ? 'keyboard' : 'pointer' });
|
|
15
|
+
}
|
|
16
|
+
catch { /* Optional feedback cannot alter the action. */ }
|
|
17
|
+
} }, children: [busy && _jsx("span", { className: 'hig-button-spinner', "aria-hidden": 'true' }), children, busy && busyText ? _jsxs("span", { role: 'status', className: 'hig-busy hig-sr-only', children: [" \u00B7 ", busyText] }) : null] });
|
|
18
|
+
});
|
|
19
|
+
export const IconButton = forwardRef(function IconButton({ label, children, className, ...props }, ref) { return _jsx(Button, { ...props, ref: ref, className: `hig-icon-button ${className ?? ''}`, "aria-label": label, children: _jsx("span", { "aria-hidden": 'true', children: children }) }); });
|
|
20
|
+
export const Link = forwardRef(function Link(props, ref) { return _jsx("a", { ...props, ref: ref, className: `hig-link ${props.className ?? ''}` }); });
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface NumberProps {
|
|
3
|
+
value: number | null | undefined;
|
|
4
|
+
options?: Intl.NumberFormatOptions;
|
|
5
|
+
stale?: boolean;
|
|
6
|
+
label?: string;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
suffix?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function NumberReadout({ value, options, stale, label, prefix, suffix }: NumberProps): React.JSX.Element;
|
|
11
|
+
export declare function Usd(props: NumberProps): React.JSX.Element;
|
|
12
|
+
/** Input is percent points: 5 means 5%, not 500%. */
|
|
13
|
+
export declare function Percent(props: NumberProps): React.JSX.Element;
|
|
14
|
+
export type AddressKind = 'ethereum' | 'solana';
|
|
15
|
+
/** `0x…` is Ethereum-style (EVM); anything else lays out as Solana (base58). */
|
|
16
|
+
export declare const addressKind: (address: string) => AddressKind;
|
|
17
|
+
/** Fixed-width rows: 6 characters for Ethereum-style addresses (42 characters make 7 rows), 4 for Solana (44 make 11). */
|
|
18
|
+
export declare function addressRows(address: string, kind: AddressKind): string[];
|
|
19
|
+
/**
|
|
20
|
+
* A wallet address in HIG's vertical style: fixed-width monospace rows with the leading row and the trailing four characters
|
|
21
|
+
* emphasised, the characters people compare, and the middle dimmed. Always left to right. Selecting it copies the plain address.
|
|
22
|
+
*/
|
|
23
|
+
export declare function VerticalAddress({ address, kind, rowHeight, className }: {
|
|
24
|
+
address: string; /** Row layout; inferred from the address when omitted. */
|
|
25
|
+
kind?: AddressKind; /** Row height in CSS pixels; the type size follows it. Defaults to the surrounding line height. */
|
|
26
|
+
rowHeight?: number;
|
|
27
|
+
className?: string;
|
|
28
|
+
}): React.JSX.Element;
|
|
29
|
+
export declare function Metric({ label, value }: {
|
|
30
|
+
label: string;
|
|
31
|
+
value: React.ReactNode;
|
|
32
|
+
}): React.JSX.Element;
|
|
33
|
+
export declare const Stat: typeof Metric;
|
|
34
|
+
export interface ListProps<T> {
|
|
35
|
+
items: readonly T[];
|
|
36
|
+
keyFor: (item: T) => string;
|
|
37
|
+
render: (item: T) => React.ReactNode;
|
|
38
|
+
empty?: string;
|
|
39
|
+
label?: string;
|
|
40
|
+
loading?: boolean;
|
|
41
|
+
error?: string;
|
|
42
|
+
onRetry?: () => void;
|
|
43
|
+
onLoadMore?: () => void;
|
|
44
|
+
}
|
|
45
|
+
export declare function List<T>({ items, keyFor, render, empty, label, loading, error, onRetry, onLoadMore }: ListProps<T>): React.JSX.Element;
|
|
46
|
+
export declare function Row({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
47
|
+
export interface Column<T> {
|
|
48
|
+
key: string;
|
|
49
|
+
label: string;
|
|
50
|
+
render: (row: T) => React.ReactNode; /** Logical alignment applies to both header and data cells. */
|
|
51
|
+
align?: 'start' | 'center' | 'end';
|
|
52
|
+
sort?: 'ascending' | 'descending';
|
|
53
|
+
onSort?: () => void;
|
|
54
|
+
}
|
|
55
|
+
/** Keep native table-row semantics and HIG's cells while forwarding host highlights, data/ARIA attributes and event handlers. */
|
|
56
|
+
export type TableRowProps = Omit<React.HTMLAttributes<HTMLTableRowElement>, 'children' | 'dangerouslySetInnerHTML' | 'role'> & {
|
|
57
|
+
[name: `data-${string}`]: string | number | boolean | undefined;
|
|
58
|
+
};
|
|
59
|
+
export interface TableProps<T> {
|
|
60
|
+
caption: string;
|
|
61
|
+
rows: readonly T[];
|
|
62
|
+
columns: readonly Column<T>[];
|
|
63
|
+
keyFor: (row: T) => string;
|
|
64
|
+
rowProps?: (row: T, index: number) => TableRowProps;
|
|
65
|
+
/** Host classes/style belong to the focusable scroll region; tableClassName styles the table itself. */
|
|
66
|
+
className?: string;
|
|
67
|
+
style?: React.CSSProperties;
|
|
68
|
+
tableClassName?: string;
|
|
69
|
+
/** Keep the accessible caption when a visible section heading already names this table. */
|
|
70
|
+
captionHidden?: boolean;
|
|
71
|
+
/** Set a bounded scroll-region height through style/className for vertical sticky scrolling. */
|
|
72
|
+
stickyHeader?: boolean;
|
|
73
|
+
/** Retains existing rows and suppresses an empty message while loading. */
|
|
74
|
+
loading?: boolean;
|
|
75
|
+
/** Content of one full-width state cell, such as an empty explanation, skeleton, or error/retry UI. Supply content, not tr/td elements. null hides the default state. */
|
|
76
|
+
state?: React.ReactNode;
|
|
77
|
+
}
|
|
78
|
+
export declare function Table<T>({ caption, rows, columns, keyFor, rowProps, className, style, tableClassName, captionHidden, stickyHeader, loading, state }: TableProps<T>): React.JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { useHIG } from './provider.js';
|
|
7
|
+
export function NumberReadout({ value, options, stale, label, prefix = '', suffix = '' }) { const { locale, messages } = useHIG(); const known = value != null && Number.isFinite(value), formatted = formatNumber(value, locale, options), reading = known ? `${prefix}${formatted}${suffix}` : formatted; return _jsxs("span", { className: 'hig-number', "aria-label": label ? `${label}: ${reading}${stale ? ` ${messages.stale ?? en.stale}` : ''}` : undefined, children: [reading, stale && _jsxs("span", { children: [" ", messages.stale ?? en.stale] })] }); }
|
|
8
|
+
export function Usd(props) { return _jsx(NumberReadout, { ...props, options: { style: 'currency', currency: 'USD', ...props.options } }); }
|
|
9
|
+
/** Input is percent points: 5 means 5%, not 500%. */
|
|
10
|
+
export function Percent(props) { return _jsx(NumberReadout, { ...props, value: props.value == null ? props.value : props.value / 100, options: { maximumFractionDigits: Math.max(3, props.options?.minimumFractionDigits ?? 0), ...props.options, style: 'percent' } }); }
|
|
11
|
+
/** `0x…` is Ethereum-style (EVM); anything else lays out as Solana (base58). */
|
|
12
|
+
export const addressKind = (address) => address.startsWith('0x') ? 'ethereum' : 'solana';
|
|
13
|
+
/** Fixed-width rows: 6 characters for Ethereum-style addresses (42 characters make 7 rows), 4 for Solana (44 make 11). */
|
|
14
|
+
export function addressRows(address, kind) { const size = kind === 'ethereum' ? 6 : 4, rows = []; for (let index = 0; index < address.length; index += size)
|
|
15
|
+
rows.push(address.slice(index, index + size)); return rows; }
|
|
16
|
+
/**
|
|
17
|
+
* A wallet address in HIG's vertical style: fixed-width monospace rows with the leading row and the trailing four characters
|
|
18
|
+
* emphasised, the characters people compare, and the middle dimmed. Always left to right. Selecting it copies the plain address.
|
|
19
|
+
*/
|
|
20
|
+
export function VerticalAddress({ address, kind, rowHeight, className }) {
|
|
21
|
+
const layout = kind ?? addressKind(address), rows = addressRows(address, layout), size = layout === 'ethereum' ? 6 : 4, tail = address.length - 4;
|
|
22
|
+
return _jsxs("span", { className: `hig-vertical-address${className ? ` ${className}` : ''}`, dir: 'ltr', translate: 'no', "data-kind": layout, style: rowHeight ? { '--hig-address-row': `${rowHeight}px` } : undefined, children: [_jsx("span", { className: 'hig-sr-only', children: address }), _jsx("span", { "aria-hidden": 'true', children: rows.map((row, rowIndex) => _jsx("span", { children: Array.from(row).map((character, index) => { const position = rowIndex * size + index; return _jsx("span", { "data-anchor": position < size || position >= tail || undefined, children: character }, index); }) }, rowIndex)) })] });
|
|
23
|
+
}
|
|
24
|
+
export function Metric({ label, value }) { return _jsxs("dl", { className: 'hig-surface', children: [_jsx("dt", { children: label }), _jsx("dd", { children: value })] }); }
|
|
25
|
+
export const Stat = Metric;
|
|
26
|
+
export function List({ items, keyFor, render, empty, label, loading = false, error, onRetry, onLoadMore }) {
|
|
27
|
+
const { messages } = useHIG();
|
|
28
|
+
return _jsxs("div", { className: 'hig-data-list', "aria-busy": loading, children: [items.length ? _jsx("ul", { className: 'hig-list', "aria-label": label, children: items.map(item => _jsx("li", { children: render(item) }, keyFor(item))) }) : !loading && !error ? _jsx("p", { className: 'hig-list-message', children: empty ?? messages.noItems ?? en.noItems }) : null, loading && _jsx("p", { className: 'hig-list-message', role: 'status', children: messages.loadingItems ?? en.loadingItems }), error && _jsxs("div", { className: 'hig-list-error', role: 'alert', children: [_jsx("p", { className: 'hig-list-message', children: error }), onRetry && _jsx("button", { className: 'hig-button', "data-intent": 'secondary', type: 'button', disabled: loading, onClick: onRetry, children: messages.retry ?? en.retry })] }), onLoadMore && _jsx("button", { className: 'hig-button', "data-intent": 'secondary', type: 'button', disabled: loading, onClick: onLoadMore, children: messages.loadMore ?? en.loadMore })] });
|
|
29
|
+
}
|
|
30
|
+
export function Row({ className, ...props }) { return _jsx("div", { ...props, className: `hig-row${className ? ` ${className}` : ''}` }); }
|
|
31
|
+
function tableRowAttributes(props) { const attributes = { ...props }; delete attributes.children; delete attributes.dangerouslySetInnerHTML; delete attributes.role; return attributes; }
|
|
32
|
+
export function Table({ caption, rows, columns, keyFor, rowProps, className, style, tableClassName, captionHidden = false, stickyHeader = false, loading = false, state }) {
|
|
33
|
+
const { messages } = useHIG();
|
|
34
|
+
const status = state !== undefined ? state : loading ? _jsx("span", { role: 'status', children: messages.loading ?? en.loading }) : !rows.length ? messages.noRows ?? en.noRows : null;
|
|
35
|
+
return _jsx("div", { className: `hig-table-scroll${className ? ` ${className}` : ''}`, style: style, tabIndex: 0, role: 'region', "aria-label": caption, "aria-busy": loading || undefined, children: _jsxs("table", { className: `hig-table${tableClassName ? ` ${tableClassName}` : ''}`, "data-sticky-header": stickyHeader || undefined, children: [_jsx("caption", { className: captionHidden ? 'hig-sr-only' : undefined, children: caption }), _jsx("thead", { children: _jsx("tr", { children: columns.map(c => _jsx("th", { scope: 'col', "aria-sort": c.sort, style: c.align ? { textAlign: c.align } : undefined, children: c.onSort ? _jsxs("button", { type: 'button', className: 'hig-table-sort', onClick: c.onSort, children: [c.label, _jsxs("svg", { className: 'hig-table-sort-icon', "aria-hidden": 'true', focusable: 'false', width: '14', height: '14', viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round', children: [_jsx("path", { className: 'hig-table-sort-up', d: 'm4.5 6 3.5-3.5L11.5 6' }), _jsx("path", { className: 'hig-table-sort-down', d: 'm4.5 10 3.5 3.5 3.5-3.5' })] })] }) : c.label }, c.key)) }) }), _jsxs("tbody", { children: [rows.map((row, index) => _createElement("tr", { ...tableRowAttributes(rowProps?.(row, index)), key: keyFor(row) }, columns.map(c => _jsx("td", { style: c.align ? { textAlign: c.align } : undefined, children: c.render(row) }, c.key)))), status !== null && status !== false && _jsx("tr", { className: 'hig-table-state', children: _jsx("td", { colSpan: Math.max(1, columns.length), children: status }) })] })] }) });
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as Modal from '@radix-ui/react-dialog';
|
|
3
|
+
/** Layout, focus and dismissal events on the owned Radix content element. */
|
|
4
|
+
export type DialogContentProps = Omit<React.ComponentPropsWithoutRef<typeof Modal.Content>, 'children' | 'asChild' | 'forceMount' | 'role' | 'dir' | 'lang' | 'id' | 'aria-labelledby' | 'aria-describedby' | 'dangerouslySetInnerHTML'>;
|
|
5
|
+
export interface DialogProps {
|
|
6
|
+
open: boolean;
|
|
7
|
+
onOpenChange: (open: boolean) => void;
|
|
8
|
+
title: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
trigger?: React.ReactNode;
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
/** Keep the required accessible title while the host supplies its visible heading. */
|
|
13
|
+
titleHidden?: boolean;
|
|
14
|
+
/** Keep supporting text available to assistive technology without rendering it visibly. */
|
|
15
|
+
descriptionHidden?: boolean;
|
|
16
|
+
contentProps?: DialogContentProps;
|
|
17
|
+
contentRef?: React.Ref<HTMLDivElement>;
|
|
18
|
+
/** Undefined keeps the standard action; null omits it. A custom ref-capable button is composed with Close. */
|
|
19
|
+
closeButton?: React.ReactElement | null;
|
|
20
|
+
/** Close button text and accessible name; defaults to HIGProvider `messages.close`. */
|
|
21
|
+
closeLabel?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AlertDialogProps extends Omit<DialogProps, 'closeLabel'> {
|
|
24
|
+
cancelLabel?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function Dialog(props: DialogProps): React.JSX.Element;
|
|
27
|
+
export declare const Sheet: typeof Dialog;
|
|
28
|
+
/** Critical confirmation stays open on outside interaction and requires an explicit decision. */
|
|
29
|
+
export declare function AlertDialog({ cancelLabel, ...props }: AlertDialogProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as Modal from '@radix-ui/react-dialog';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG, useThemeStyle } from './provider.js';
|
|
6
|
+
import { Button } from './button.js';
|
|
7
|
+
const OWNED_CONTENT_PROPS = new Set(['children', 'asChild', 'forceMount', 'role', 'dir', 'lang', 'id', 'ref', 'aria-labelledby', 'aria-describedby', 'dangerouslySetInnerHTML']);
|
|
8
|
+
function DialogFrame({ open, onOpenChange, title, description, trigger, children, closeLabel, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, alert = false }) {
|
|
9
|
+
const { messages, direction, locale, density } = useHIG();
|
|
10
|
+
const themeStyle = useThemeStyle();
|
|
11
|
+
// JavaScript callers receive the same ownership guarantees as typed callers. Copy first;
|
|
12
|
+
// a host may share or freeze its props object across several modal instances.
|
|
13
|
+
const safeContent = Object.fromEntries(Object.entries(contentProps ?? {}).filter(([key]) => !OWNED_CONTENT_PROPS.has(key)));
|
|
14
|
+
const { className, onPointerDownOutside, style, ...content } = safeContent;
|
|
15
|
+
return _jsxs(Modal.Root, { open: open, onOpenChange: onOpenChange, children: [trigger && _jsx(Modal.Trigger, { asChild: true, children: trigger }), _jsxs(Modal.Portal, { children: [_jsx(Modal.Overlay, { className: 'hig-backdrop' }), _jsxs(Modal.Content, { ...content, ...(!description ? { 'aria-describedby': undefined } : {}), ref: contentRef, role: alert ? 'alertdialog' : 'dialog', className: ['hig-dialog', className].filter(Boolean).join(' '), dir: direction, lang: locale, "data-hig-density": density, style: { ...themeStyle, ...style }, onPointerDownOutside: event => { onPointerDownOutside?.(event); if (alert)
|
|
16
|
+
event.preventDefault(); }, children: [_jsx(Modal.Title, { className: titleHidden ? 'hig-sr-only' : 'hig-dialog-title', children: title }), description && _jsx(Modal.Description, { className: descriptionHidden ? 'hig-sr-only' : 'hig-dialog-description', children: description }), children, closeButton !== null && _jsx(Modal.Close, { asChild: true, children: closeButton ?? _jsx(Button, { intent: 'secondary', suppressFeedback: true, children: closeLabel ?? messages.close ?? en.close }) })] })] })] });
|
|
17
|
+
}
|
|
18
|
+
export function Dialog(props) { return _jsx(DialogFrame, { ...props }); }
|
|
19
|
+
export const Sheet = Dialog;
|
|
20
|
+
/** Critical confirmation stays open on outside interaction and requires an explicit decision. */
|
|
21
|
+
export function AlertDialog({ cancelLabel, ...props }) { const { messages } = useHIG(); return _jsx(DialogFrame, { ...props, alert: true, closeLabel: cancelLabel ?? messages.cancel ?? en.cancel }); }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function Field({ id: provided, label, description, error, required, disabled, children }: React.PropsWithChildren<{
|
|
3
|
+
id?: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}>): React.JSX.Element;
|
|
10
|
+
export declare const Label: (props: React.LabelHTMLAttributes<HTMLLabelElement>) => React.JSX.Element;
|
|
11
|
+
export declare const Input: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
|
|
12
|
+
export declare const TextArea: React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> & React.RefAttributes<HTMLTextAreaElement>>;
|
|
13
|
+
/** Raw string and selection stay untouched; host parses/validates precision on submit. */
|
|
14
|
+
export declare const AmountInput: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & React.RefAttributes<HTMLInputElement>>;
|
|
15
|
+
/** The magnifying glass sits inset on the leading edge; the input keeps the ref, class and every prop. Marked pure so a bundle that imports another field drops the icon. */
|
|
16
|
+
export declare const SearchInput: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useId, forwardRef } from 'react';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG } from './provider.js';
|
|
6
|
+
const Context = createContext({ id: '' });
|
|
7
|
+
export function Field({ id: provided, label, description, error, required, disabled, children }) {
|
|
8
|
+
const { messages } = useHIG();
|
|
9
|
+
const generated = useId();
|
|
10
|
+
const id = provided ?? generated;
|
|
11
|
+
const ids = [description && `${id}-help`, error && `${id}-error`].filter(Boolean).join(' ') || undefined;
|
|
12
|
+
return _jsx(Context.Provider, { value: { id, description: ids, invalid: !!error, disabled, required }, children: _jsxs("div", { className: 'hig-field', children: [_jsxs("label", { htmlFor: id, children: [label, required ? ` ${messages.required ?? en.required}` : ''] }), children, description && _jsx("p", { id: `${id}-help`, children: description }), error && _jsx("p", { id: `${id}-error`, role: 'alert', children: error })] }) });
|
|
13
|
+
}
|
|
14
|
+
export const Label = (props) => _jsx("label", { ...props });
|
|
15
|
+
export const Input = forwardRef(function Input(props, ref) { const field = useContext(Context); return _jsx("input", { id: field.id || undefined, "aria-describedby": field.description, "aria-invalid": field.invalid || undefined, required: field.required, ...props, disabled: !!field.disabled || props.disabled, ref: ref, className: `hig-input ${props.className ?? ''}` }); });
|
|
16
|
+
export const TextArea = forwardRef(function TextArea(props, ref) { const field = useContext(Context); return _jsx("textarea", { id: field.id || undefined, "aria-describedby": field.description, "aria-invalid": field.invalid || undefined, required: field.required, ...props, disabled: !!field.disabled || props.disabled, ref: ref, className: `hig-input ${props.className ?? ''}` }); });
|
|
17
|
+
/** Raw string and selection stay untouched; host parses/validates precision on submit. */
|
|
18
|
+
export const AmountInput = forwardRef(function AmountInput(props, ref) { return _jsx(Input, { ...props, ref: ref, type: 'text', inputMode: props.inputMode ?? 'decimal' }); });
|
|
19
|
+
/** The magnifying glass sits inset on the leading edge; the input keeps the ref, class and every prop. Marked pure so a bundle that imports another field drops the icon. */
|
|
20
|
+
export const SearchInput = /* @__PURE__ */ forwardRef(function SearchInput(props, ref) { return _jsxs("span", { className: 'hig-search-input', children: [_jsxs("svg", { className: 'hig-search-icon', "aria-hidden": 'true', focusable: 'false', viewBox: '0 0 20 20', children: [_jsx("circle", { cx: '9', cy: '9', r: '5.25' }), _jsx("path", { d: 'm13 13 3.5 3.5' })] }), _jsx(Input, { type: 'search', ...props, ref: ref })] }); });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Drawer, type DialogProps as BackendProps } from 'vaul';
|
|
3
|
+
import type { DialogProps, DialogContentProps } from './dialog.js';
|
|
4
|
+
/** Vaul owns gestures, detents, input repositioning and background scaling. HIG owns the controlled modal root. */
|
|
5
|
+
type HostBackendProps<Props> = Props extends object ? Omit<Props, 'children' | 'open' | 'defaultOpen' | 'onOpenChange' | 'modal' | 'nested' | 'onClose'> : never;
|
|
6
|
+
export type GestureSheetBackendProps = HostBackendProps<BackendProps>;
|
|
7
|
+
type SnapPointBackendProp = 'snapPoints' | 'snapPoint' | 'activeSnapPoint' | 'setActiveSnapPoint' | 'fadeFromIndex' | 'snapToSequentialPoint';
|
|
8
|
+
export type GestureSheetDynamicBackendProps = Omit<GestureSheetBackendProps, SnapPointBackendProp> & {
|
|
9
|
+
[Key in SnapPointBackendProp]?: never;
|
|
10
|
+
};
|
|
11
|
+
export type GestureSheetContentProps = DialogContentProps & {
|
|
12
|
+
[key: `data-${string}`]: string | number | boolean | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type GestureSheetHandleProps = Omit<React.ComponentPropsWithoutRef<typeof Drawer.Handle>, 'children' | 'aria-hidden' | 'dangerouslySetInnerHTML' | 'onClick' | 'onPointerDown' | 'onPointerMove' | 'onPointerCancel'>;
|
|
15
|
+
export type GestureSheetOverlayProps = Omit<React.ComponentPropsWithoutRef<typeof Drawer.Overlay>, 'children' | 'asChild' | 'forceMount' | 'dangerouslySetInnerHTML'>;
|
|
16
|
+
interface GestureSheetCommonProps extends Omit<DialogProps, 'contentProps'> {
|
|
17
|
+
contentProps?: GestureSheetContentProps;
|
|
18
|
+
/** Default anatomy pads and scrolls the card; custom anatomy leaves layout and scrolling to the host. */
|
|
19
|
+
contentMode?: 'default' | 'custom';
|
|
20
|
+
/** The real backend drag handle is included by default. */
|
|
21
|
+
handle?: boolean;
|
|
22
|
+
handleProps?: GestureSheetHandleProps;
|
|
23
|
+
handleRef?: React.Ref<HTMLDivElement>;
|
|
24
|
+
overlayProps?: GestureSheetOverlayProps;
|
|
25
|
+
}
|
|
26
|
+
export type GestureSheetProps = GestureSheetCommonProps & (
|
|
27
|
+
/** Backend defaults are retained, including autoFocus=false and repositionInputs=true. */
|
|
28
|
+
{
|
|
29
|
+
enableDynamicSizing?: false;
|
|
30
|
+
backendProps?: GestureSheetBackendProps;
|
|
31
|
+
maxDynamicContentSize?: never;
|
|
32
|
+
}
|
|
33
|
+
/** Vertical content sizing is intrinsic and cannot be combined with Vaul detents. */
|
|
34
|
+
| {
|
|
35
|
+
enableDynamicSizing: true;
|
|
36
|
+
backendProps?: GestureSheetDynamicBackendProps; /** A finite positive content-height ceiling in CSS pixels; the viewport ceiling still applies. */
|
|
37
|
+
maxDynamicContentSize?: number;
|
|
38
|
+
});
|
|
39
|
+
/** Optional web gesture backend. Install vaul separately; the core overlay entry never imports it. */
|
|
40
|
+
export declare function GestureSheet({ open, onOpenChange, title, description, trigger, children, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, closeLabel, backendProps, contentMode, handle, handleProps, handleRef, overlayProps, enableDynamicSizing, maxDynamicContentSize }: GestureSheetProps): React.JSX.Element;
|
|
41
|
+
export {};
|