@bloxwap/hig 0.5.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/chart/README.md +1 -1
- package/contracts/README.md +1 -1
- package/contracts/dist/index.d.ts +16 -0
- package/contracts/dist/index.js +22 -0
- package/contracts/dist/messages.d.ts +37 -4
- package/contracts/dist/messages.js +13 -2
- package/feedback/README.md +1 -1
- package/native/README.md +1 -1
- package/native/dist/account-block.d.ts +92 -0
- package/native/dist/account-block.js +61 -0
- package/native/dist/animated-number-model.d.ts +7 -1
- package/native/dist/animated-number-model.js +50 -1
- package/native/dist/animated-number.d.ts +3 -1
- package/native/dist/animated-number.js +8 -5
- package/native/dist/asset-balance-row.d.ts +36 -0
- package/native/dist/asset-balance-row.js +26 -0
- package/native/dist/bar-mark.d.ts +57 -0
- package/native/dist/bar-mark.js +48 -0
- package/native/dist/bar-pnl.d.ts +50 -0
- package/native/dist/bar-pnl.js +60 -0
- package/native/dist/blocks.d.ts +38 -0
- package/native/dist/blocks.js +42 -0
- package/native/dist/button.js +3 -1
- package/native/dist/data.d.ts +1 -1
- package/native/dist/data.js +6 -4
- package/native/dist/field.d.ts +14 -5
- package/native/dist/field.js +33 -8
- package/native/dist/figure.d.ts +23 -0
- package/native/dist/figure.js +10 -0
- package/native/dist/icons.d.ts +8 -0
- package/native/dist/icons.js +4 -0
- package/native/dist/language-block.d.ts +35 -0
- package/native/dist/language-block.js +30 -0
- package/native/dist/list-group.d.ts +60 -0
- package/native/dist/list-group.js +85 -0
- package/native/dist/manage-position-block.d.ts +95 -0
- package/native/dist/manage-position-block.js +82 -0
- package/native/dist/market-row.d.ts +46 -0
- package/native/dist/market-row.js +30 -0
- package/native/dist/notifications-block.d.ts +53 -0
- package/native/dist/notifications-block.js +22 -0
- package/native/dist/pickers.d.ts +35 -5
- package/native/dist/pickers.js +21 -9
- package/native/dist/position-block.d.ts +107 -0
- package/native/dist/position-block.js +55 -0
- package/native/dist/profile-block.d.ts +66 -0
- package/native/dist/profile-block.js +48 -0
- package/native/dist/provider.d.ts +9 -3
- package/native/dist/provider.js +7 -3
- package/native/dist/radio-group.d.ts +9 -3
- package/native/dist/radio-group.js +4 -5
- package/native/dist/recipes.d.ts +6 -46
- package/native/dist/recipes.js +6 -33
- package/native/dist/reward-block.d.ts +122 -0
- package/native/dist/reward-block.js +53 -0
- package/native/dist/screen-header.d.ts +49 -0
- package/native/dist/screen-header.js +29 -0
- package/native/dist/selection.d.ts +2 -2
- package/native/dist/setting-header.d.ts +2 -0
- package/native/dist/setting-header.js +2 -0
- package/native/dist/setting-switch.d.ts +31 -0
- package/native/dist/setting-switch.js +20 -0
- package/native/dist/signals-block.d.ts +61 -0
- package/native/dist/signals-block.js +26 -0
- package/native/dist/sound-haptics-block.d.ts +66 -0
- package/native/dist/sound-haptics-block.js +32 -0
- package/native/dist/status.d.ts +6 -5
- package/native/dist/status.js +5 -5
- package/native/dist/sticky-header.d.ts +28 -0
- package/native/dist/sticky-header.js +21 -0
- package/native/dist/surface.d.ts +3 -1
- package/native/dist/surface.js +2 -1
- package/native/dist/{swap-panel.d.ts → swap-panel-block.d.ts} +8 -3
- package/native/dist/{swap-panel.js → swap-panel-block.js} +13 -8
- package/native/dist/swap-parts.d.ts +5 -3
- package/native/dist/swap-parts.js +2 -2
- package/native/dist/swap-shared.d.ts +6 -0
- package/native/dist/swap-sheet.d.ts +4 -4
- package/native/dist/swap-sheet.js +4 -4
- package/native/dist/swap-views.d.ts +1 -1
- package/native/dist/swap-views.js +9 -7
- 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 +110 -0
- package/native/dist/target-block.js +74 -0
- package/native/dist/token-action-block.d.ts +47 -0
- package/native/dist/token-action-block.js +28 -0
- package/native/dist/trade-history-detail-block.d.ts +84 -0
- package/native/dist/trade-history-detail-block.js +46 -0
- package/native/dist/trade-history-list-block.d.ts +110 -0
- package/native/dist/trade-history-list-block.js +64 -0
- package/native/dist/wallet-address-core.d.ts +25 -0
- package/native/dist/wallet-address-core.js +31 -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 +266 -41
- package/react/README.md +1 -1
- package/react/dist/animated-number-model.d.ts +6 -0
- package/react/dist/animated-number-model.js +33 -0
- package/react/dist/animated-number.d.ts +5 -1
- package/react/dist/animated-number.js +12 -8
- package/react/dist/asset-balance-row.d.ts +35 -0
- package/react/dist/asset-balance-row.js +18 -0
- package/react/dist/bar-mark.d.ts +38 -0
- package/react/dist/bar-mark.js +23 -0
- package/react/dist/bar-pnl.d.ts +49 -0
- package/react/dist/bar-pnl.js +45 -0
- package/react/dist/blocks/account-block.d.ts +92 -0
- package/react/dist/blocks/account-block.js +62 -0
- package/react/dist/blocks/language-block.d.ts +36 -0
- package/react/dist/blocks/language-block.js +52 -0
- package/react/dist/blocks/manage-position-block.d.ts +93 -0
- package/react/dist/blocks/manage-position-block.js +47 -0
- package/react/dist/blocks/market-row.d.ts +36 -0
- package/react/dist/blocks/market-row.js +16 -0
- package/react/dist/blocks/notifications-block.d.ts +46 -0
- package/react/dist/blocks/notifications-block.js +17 -0
- package/react/dist/{recipes → blocks}/pickers.d.ts +32 -4
- package/react/dist/{recipes → blocks}/pickers.js +35 -11
- package/react/dist/blocks/position-block.d.ts +72 -0
- package/react/dist/blocks/position-block.js +25 -0
- package/react/dist/blocks/profile-block.d.ts +71 -0
- package/react/dist/blocks/profile-block.js +41 -0
- package/react/dist/blocks/reward-block.d.ts +120 -0
- package/react/dist/blocks/reward-block.js +34 -0
- package/react/dist/blocks/screen-header.d.ts +33 -0
- package/react/dist/blocks/screen-header.js +20 -0
- package/react/dist/blocks/setting-switch.d.ts +23 -0
- package/react/dist/blocks/setting-switch.js +12 -0
- package/react/dist/blocks/signals-block.d.ts +54 -0
- package/react/dist/blocks/signals-block.js +15 -0
- package/react/dist/blocks/sound-haptics-block.d.ts +59 -0
- package/react/dist/blocks/sound-haptics-block.js +22 -0
- package/react/dist/blocks/sticky-header.d.ts +9 -0
- package/react/dist/blocks/sticky-header.js +43 -0
- package/react/dist/blocks/swap/amount-card.js +8 -0
- package/react/dist/{recipes → blocks}/swap/picker.d.ts +1 -1
- package/react/dist/{recipes → blocks}/swap/picker.js +4 -4
- package/react/dist/{recipes → blocks}/swap/settings.js +2 -2
- package/react/dist/{recipes → blocks}/swap/shared.d.ts +8 -1
- package/react/dist/{recipes → blocks}/swap/shared.js +7 -4
- package/react/dist/{recipes/swap-panel.d.ts → blocks/swap-panel-block.d.ts} +8 -2
- package/react/dist/{recipes/swap-panel.js → blocks/swap-panel-block.js} +9 -7
- package/react/dist/{recipes → blocks}/swap-sheet.d.ts +4 -4
- package/react/dist/{recipes → blocks}/swap-sheet.js +4 -4
- package/react/dist/blocks/target-block.d.ts +103 -0
- package/react/dist/blocks/target-block.js +73 -0
- package/react/dist/blocks/token-action-block.d.ts +46 -0
- package/react/dist/blocks/token-action-block.js +21 -0
- package/react/dist/{recipes → blocks}/trade-entry.js +2 -2
- package/react/dist/blocks/trade-history-detail-block.d.ts +78 -0
- package/react/dist/blocks/trade-history-detail-block.js +17 -0
- package/react/dist/blocks/trade-history-list-block.d.ts +67 -0
- package/react/dist/blocks/trade-history-list-block.js +28 -0
- package/react/dist/blocks.d.ts +20 -0
- package/react/dist/blocks.js +21 -0
- package/react/dist/button.js +6 -4
- package/react/dist/data.js +3 -3
- package/react/dist/field.d.ts +14 -6
- package/react/dist/field.js +19 -8
- package/react/dist/figure.d.ts +23 -0
- package/react/dist/figure.js +12 -0
- package/react/dist/list-group.d.ts +59 -0
- package/react/dist/list-group.js +52 -0
- package/react/dist/provider.d.ts +40 -3
- package/react/dist/provider.js +63 -6
- package/react/dist/selection.d.ts +8 -2
- package/react/dist/selection.js +11 -6
- package/react/dist/styles.css +425 -5
- package/react/dist/surface.d.ts +5 -1
- package/react/dist/surface.js +1 -1
- package/react/dist/wallet-address-core.d.ts +23 -0
- package/react/dist/wallet-address-core.js +24 -0
- package/react/dist/wallet-address.d.ts +6 -12
- package/react/dist/wallet-address.js +5 -16
- package/tokens/README.md +1 -1
- package/react/dist/recipes/activity-list.d.ts +0 -8
- package/react/dist/recipes/activity-list.js +0 -6
- package/react/dist/recipes/balance-card.d.ts +0 -6
- package/react/dist/recipes/balance-card.js +0 -5
- package/react/dist/recipes/code-window.d.ts +0 -4
- package/react/dist/recipes/code-window.js +0 -4
- package/react/dist/recipes/market-row.d.ts +0 -25
- package/react/dist/recipes/market-row.js +0 -8
- package/react/dist/recipes/swap/amount-card.js +0 -7
- package/react/dist/recipes.d.ts +0 -10
- package/react/dist/recipes.js +0 -11
- /package/react/dist/{recipes → blocks}/install-command.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/install-command.js +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/marketing-hero.js +0 -0
- /package/react/dist/{recipes → blocks}/swap/amount-card.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/swap/settings.d.ts +0 -0
- /package/react/dist/{recipes → blocks}/trade-entry.d.ts +0 -0
package/native/dist/status.d.ts
CHANGED
|
@@ -14,12 +14,12 @@ declare const severityRole: {
|
|
|
14
14
|
export type AlertSeverity = keyof typeof severityRole | 'default';
|
|
15
15
|
/** Neutral chip in the dark well fill (one step lighter inside a Surface, Dialog or sheet). */
|
|
16
16
|
export declare function Badge({ children }: React.PropsWithChildren): React.JSX.Element;
|
|
17
|
-
/** Severity tints the fill 10% and colours the title from a token role (info/note → info, success/tip → positive, warning, error → negative; default → 6% of `text`), with no stroke or glow; `tone` swaps in another approved token role, never a raw colour. A non-string title renders inside the Heading, so pass strings or inline Text; its visible text is announced. */
|
|
18
|
-
export declare function Alert({ title, children, severity, tone, action, announce }: React.PropsWithChildren<{
|
|
17
|
+
/** Severity tints the fill 10% and colours the title from a token role (info/note → info, success/tip → positive, warning, error → negative; default → 6% of `text`), with no stroke or glow; `tone` swaps in another approved token role, never a raw colour. A non-string title renders inside the Heading, so pass strings or inline Text; its visible text is announced. A string or number child is drawn in a HIG `Text`. `announce` (default true) speaks the title and body when they appear or change; pass `false` for guidance that is present from the start. */
|
|
18
|
+
export declare function Alert({ title, children: body, severity, tone, action, announce }: React.PropsWithChildren<{
|
|
19
19
|
title: React.ReactNode;
|
|
20
20
|
severity?: AlertSeverity;
|
|
21
21
|
tone?: AccentRole;
|
|
22
|
-
action?: React.ReactNode;
|
|
22
|
+
action?: React.ReactNode; /** Speaks the alert when it appears or changes (iOS announcement, Android live region). Defaults to true. */
|
|
23
23
|
announce?: boolean;
|
|
24
24
|
}>): React.JSX.Element;
|
|
25
25
|
export declare const Callout: typeof Alert;
|
|
@@ -52,10 +52,11 @@ export declare function useTransientNotice(duration?: number): {
|
|
|
52
52
|
export declare function Spinner({ label }: {
|
|
53
53
|
label?: string;
|
|
54
54
|
}): React.JSX.Element;
|
|
55
|
-
export declare function Progress({ label, value, max }: {
|
|
55
|
+
export declare function Progress({ label, value, max, hideValue }: {
|
|
56
56
|
label: string;
|
|
57
57
|
value?: number;
|
|
58
|
-
max?: number;
|
|
58
|
+
max?: number; /** Draws the label without the ` value/max` suffix (or the `…` while indeterminate), for a host that shows the figure itself. The value is still read. */
|
|
59
|
+
hideValue?: boolean;
|
|
59
60
|
}): React.JSX.Element;
|
|
60
61
|
/** Pulses while content is on its way; still with reduced motion. */
|
|
61
62
|
export declare function Skeleton({ label }: {
|
package/native/dist/status.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { tokens } from '@bloxwap/hig/tokens';
|
|
4
4
|
import { CloseIcon, EmptyIcon, SeverityIcon } from './icons.js';
|
|
5
5
|
import { notificationDelta } from '@bloxwap/hig/contracts/announcements';
|
|
@@ -24,8 +24,8 @@ catch { /* The visible message and navigable text remain available. */ } }
|
|
|
24
24
|
export function Badge({ children }) { const fills = useFills(); return _jsx(Text, { style: { alignSelf: 'flex-start', maxWidth: '100%', backgroundColor: fills.well, overflow: 'hidden', borderRadius: 9999, paddingVertical: 4, paddingHorizontal: 10 }, children: children }); }
|
|
25
25
|
/** Opaque sRGB blend of `tone` into `base` (both `#rrggbb`): the native counterpart of CSS `color-mix`. */
|
|
26
26
|
const tint = (tone, base, amount) => '#' + [1, 3, 5].map(i => Math.round(parseInt(base.slice(i, i + 2), 16) * (1 - amount) + parseInt(tone.slice(i, i + 2), 16) * amount).toString(16).padStart(2, '0')).join('');
|
|
27
|
-
/** Severity tints the fill 10% and colours the title from a token role (info/note → info, success/tip → positive, warning, error → negative; default → 6% of `text`), with no stroke or glow; `tone` swaps in another approved token role, never a raw colour. A non-string title renders inside the Heading, so pass strings or inline Text; its visible text is announced. */
|
|
28
|
-
export function Alert({ title, children, severity = 'info', tone, action, announce = true }) { const colors = useColors(); const neutral = severity === 'default' && tone === undefined; const accent = neutral ? colors.text : roleColor(tone, severityRole[severity] ?? 'info', colors); const message = [plainText(title), blockText(children)].filter(Boolean).join('. '); const previous = useRef(''); useEffect(() => { const key = severity + message; if (announce && key !== previous.current) {
|
|
27
|
+
/** Severity tints the fill 10% and colours the title from a token role (info/note → info, success/tip → positive, warning, error → negative; default → 6% of `text`), with no stroke or glow; `tone` swaps in another approved token role, never a raw colour. A non-string title renders inside the Heading, so pass strings or inline Text; its visible text is announced. A string or number child is drawn in a HIG `Text`. `announce` (default true) speaks the title and body when they appear or change; pass `false` for guidance that is present from the start. */
|
|
28
|
+
export function Alert({ title, children: body, severity = 'info', tone, action, announce = true }) { const children = React.Children.map(body, child => typeof child === 'string' || typeof child === 'number' ? _jsx(Text, { children: child }) : child); const colors = useColors(); const neutral = severity === 'default' && tone === undefined; const accent = neutral ? colors.text : roleColor(tone, severityRole[severity] ?? 'info', colors); const message = [plainText(title), blockText(children)].filter(Boolean).join('. '); const previous = useRef(''); useEffect(() => { const key = severity + message; if (announce && key !== previous.current) {
|
|
29
29
|
previous.current = key;
|
|
30
30
|
if (Platform.OS === 'ios')
|
|
31
31
|
speak(message, severity);
|
|
@@ -81,12 +81,12 @@ export function useTransientNotice(duration = 4000) {
|
|
|
81
81
|
return; stop(); setNotice({ id: `notice-${++sequence.current}`, message, severity }); timer.current = setTimeout(() => { timer.current = null; setNotice(null); }, duration); } };
|
|
82
82
|
}
|
|
83
83
|
export function Spinner({ label }) { const { messages } = useHIG(); const colors = useColors(); const text = label ?? messages.loading ?? en.loading; return _jsxs(View, { accessible: true, accessibilityLabel: text, children: [_jsx(ActivityIndicator, { color: colors.action }), _jsx(Text, { children: text })] }); }
|
|
84
|
-
export function Progress({ label, value, max = 100 }) {
|
|
84
|
+
export function Progress({ label, value, max = 100, hideValue }) {
|
|
85
85
|
const { locale, messages, direction } = useHIG();
|
|
86
86
|
const colors = useColors();
|
|
87
87
|
const fills = useFills();
|
|
88
88
|
const fill = value === undefined ? 35 : Math.min(100, Math.max(0, Number.isFinite(value) && max > 0 ? value / max * 100 : 0));
|
|
89
|
-
return _jsxs(View, { style: { gap: 12, direction }, accessibilityRole: 'progressbar', accessibilityLabel: label, accessibilityValue: { min: 0, max, now: value, text: value === undefined ? messages.inProgress ?? en.inProgress : (messages.progressValue ?? en.progressValue)(formatNumber(value, locale), formatNumber(max, locale)) }, children: [_jsxs(Text, { children: [label, value === undefined ? '…' : ` ${value}/${max}`] }), _jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', style: { height: 6, borderRadius: 9999, overflow: 'hidden', backgroundColor: fills.raised }, children: _jsx(View, { style: { width: `${fill}%`, height: '100%', alignSelf: value === undefined ? 'center' : 'flex-start', borderRadius: 9999, backgroundColor: colors.action } }) })] });
|
|
89
|
+
return _jsxs(View, { style: { gap: 12, direction }, accessibilityRole: 'progressbar', accessibilityLabel: label, accessibilityValue: { min: 0, max, now: value, text: value === undefined ? messages.inProgress ?? en.inProgress : (messages.progressValue ?? en.progressValue)(formatNumber(value, locale), formatNumber(max, locale)) }, children: [_jsxs(Text, { children: [label, hideValue ? null : value === undefined ? '…' : ` ${value}/${max}`] }), _jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', style: { height: 6, borderRadius: 9999, overflow: 'hidden', backgroundColor: fills.raised }, children: _jsx(View, { style: { width: `${fill}%`, height: '100%', alignSelf: value === undefined ? 'center' : 'flex-start', borderRadius: 9999, backgroundColor: colors.action } }) })] });
|
|
90
90
|
}
|
|
91
91
|
/** Pulses while content is on its way; still with reduced motion. */
|
|
92
92
|
export function Skeleton({ label }) { const { messages, reducedMotion } = useHIG(); const fills = useFills(); const pulse = useLoop(!reducedMotion, 1500); return _jsx(Animated.View, { accessible: true, accessibilityLabel: label ?? messages.loadingContent ?? en.loadingContent, style: { minHeight: 48, backgroundColor: fills.raised, borderRadius: 10, opacity: pulse.interpolate({ inputRange: [0, .5, 1], outputRange: [1, .5, 1] }) } }); }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type NativeScrollEvent, type NativeSyntheticEvent, type ScrollViewProps, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
/** What a scroller needs so a pinned header knows when content is under it. Spread `onScroll` and `scrollEventThrottle` on the scroll view and pass `scrolled` to the header. */
|
|
4
|
+
export interface StickyHeaderScroll {
|
|
5
|
+
/** True once the scroll view has moved, so content sits under the pinned header. */
|
|
6
|
+
scrolled: boolean;
|
|
7
|
+
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
8
|
+
scrollEventThrottle: number;
|
|
9
|
+
}
|
|
10
|
+
/** Tracks a scroll view's offset for a pinned header: `scrolled` turns true once it has moved and false again at the top. It re-renders only when that changes. */
|
|
11
|
+
export declare function useStickyHeaderScroll(onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void): StickyHeaderScroll;
|
|
12
|
+
/** The fill of a pinned header: transparent at rest so what the host draws behind it shows through, `background` once content has scrolled under it. */
|
|
13
|
+
export declare function stickyHeaderFill(scrolled: boolean, background: string): ViewStyle;
|
|
14
|
+
export interface StickyHeaderLayoutProps {
|
|
15
|
+
/** The header, pinned as the scroll view's first child. */
|
|
16
|
+
header: React.ReactNode;
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
/** Fill once content scrolls under the header. Defaults to the background role. */
|
|
19
|
+
background?: string;
|
|
20
|
+
scrollComponent?: React.ComponentType<ScrollViewProps>;
|
|
21
|
+
testID?: string;
|
|
22
|
+
/** Test ID of the header's container. */
|
|
23
|
+
headerTestID?: string;
|
|
24
|
+
/** Layout of the content under the header, such as its gap. Side padding is 16dp. */
|
|
25
|
+
bodyStyle?: StyleProp<ViewStyle>;
|
|
26
|
+
}
|
|
27
|
+
/** A block as its own scroll view with its header pinned: 16dp around the content as the block draws it, the header transparent until content scrolls under it. Place it in a bounded container, such as a sheet body. */
|
|
28
|
+
export declare function StickyHeaderLayout({ header, children, background, scrollComponent: Scroll, testID, headerTestID, bodyStyle }: StickyHeaderLayoutProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
import { ScrollView, View } from 'react-native';
|
|
4
|
+
import { useColors } from './provider.js';
|
|
5
|
+
/** Tracks a scroll view's offset for a pinned header: `scrolled` turns true once it has moved and false again at the top. It re-renders only when that changes. */
|
|
6
|
+
export function useStickyHeaderScroll(onScroll) {
|
|
7
|
+
const [scrolled, setScrolled] = useState(false);
|
|
8
|
+
const handle = useCallback((event) => {
|
|
9
|
+
const next = (event.nativeEvent?.contentOffset?.y ?? 0) > 0.5;
|
|
10
|
+
setScrolled(current => current === next ? current : next);
|
|
11
|
+
onScroll?.(event);
|
|
12
|
+
}, [onScroll]);
|
|
13
|
+
return { scrolled, onScroll: handle, scrollEventThrottle: 16 };
|
|
14
|
+
}
|
|
15
|
+
/** The fill of a pinned header: transparent at rest so what the host draws behind it shows through, `background` once content has scrolled under it. */
|
|
16
|
+
export function stickyHeaderFill(scrolled, background) { return { backgroundColor: scrolled ? background : 'transparent' }; }
|
|
17
|
+
/** A block as its own scroll view with its header pinned: 16dp around the content as the block draws it, the header transparent until content scrolls under it. Place it in a bounded container, such as a sheet body. */
|
|
18
|
+
export function StickyHeaderLayout({ header, children, background, scrollComponent: Scroll = ScrollView, testID, headerTestID, bodyStyle }) {
|
|
19
|
+
const colors = useColors(), { scrolled, onScroll, scrollEventThrottle } = useStickyHeaderScroll();
|
|
20
|
+
return _jsxs(Scroll, { testID: testID, stickyHeaderIndices: [0], onScroll: onScroll, scrollEventThrottle: scrollEventThrottle, contentContainerStyle: { paddingBottom: 16 }, children: [_jsx(View, { testID: headerTestID, style: [{ paddingHorizontal: 16, paddingTop: 16 }, stickyHeaderFill(scrolled, background ?? colors.background)], children: header }), _jsx(View, { style: [{ paddingHorizontal: 16 }, bodyStyle], children: children })] });
|
|
21
|
+
}
|
package/native/dist/surface.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export declare const scriptLetterSpacing: Readonly<Record<Exclude<TextScript, 'l
|
|
|
7
7
|
export declare function detectScript(text: string, locale: string): TextScript;
|
|
8
8
|
export interface HIGTextProps extends TextProps {
|
|
9
9
|
script?: TextScript; /** Caps Dynamic Type / Android font scale for dense numeric readouts (2 = 200%). Defaults to HIGProvider `maxFontSizeMultiplier`; never disable scaling. */
|
|
10
|
-
maxFontSizeMultiplier?: number;
|
|
10
|
+
maxFontSizeMultiplier?: number; /** `muted` draws secondary text, such as a note under a group, in the muted role. A `style` colour still wins. */
|
|
11
|
+
tone?: 'muted'; /** `caption` draws the 12/18 caption size instead of the 16/24 body size. A `style` size still wins. */
|
|
12
|
+
size?: 'caption';
|
|
11
13
|
}
|
|
12
14
|
export declare const Text: React.ForwardRefExoticComponent<HIGTextProps & React.RefAttributes<React.ComponentRef<typeof RNText>>>;
|
|
13
15
|
export declare const Heading: React.ForwardRefExoticComponent<HIGTextProps & React.RefAttributes<React.ComponentRef<typeof RNText>>>;
|
package/native/dist/surface.js
CHANGED
|
@@ -22,9 +22,10 @@ function scriptFont(families, weight) {
|
|
|
22
22
|
weights.sort((a, b) => Math.abs(a - Number(weight)) - Math.abs(b - Number(weight)) || a - b);
|
|
23
23
|
return weights.length ? families[weights[0]] : undefined;
|
|
24
24
|
}
|
|
25
|
-
export const Text = forwardRef(function Text({ style, script, maxFontSizeMultiplier, ...props }, ref) {
|
|
25
|
+
export const Text = forwardRef(function Text({ style: own, script, maxFontSizeMultiplier, tone, size, ...props }, ref) {
|
|
26
26
|
const env = useHIG();
|
|
27
27
|
const colors = useColors();
|
|
28
|
+
const style = tone || size ? [tone === 'muted' ? { color: colors.muted } : null, size === 'caption' ? { fontSize: 12, lineHeight: 18 } : null, own] : own;
|
|
28
29
|
const resolved = StyleSheet.flatten(style);
|
|
29
30
|
const requested = resolved?.fontWeight ?? 400;
|
|
30
31
|
const weight = requested === 'normal' ? 400 : requested === 'bold' ? 700 : requested;
|
|
@@ -26,7 +26,8 @@ export interface SwapDetail {
|
|
|
26
26
|
value: string | number;
|
|
27
27
|
options?: Intl.NumberFormatOptions;
|
|
28
28
|
prefix?: string;
|
|
29
|
-
suffix?: string;
|
|
29
|
+
suffix?: string; /** With a number `value`: host-formatted text drawn and read in place of Intl's, still moving place by place. */
|
|
30
|
+
formattedValue?: string;
|
|
30
31
|
}
|
|
31
32
|
/** The receive view: the host's address and its rendered QR code. HIG ships no QR encoder. */
|
|
32
33
|
export interface SwapReceive {
|
|
@@ -34,7 +35,7 @@ export interface SwapReceive {
|
|
|
34
35
|
qr?: React.ReactNode; /** Host clipboard adapter. When set, the whole view copies the address. */
|
|
35
36
|
onCopy?: () => Promise<void> | void;
|
|
36
37
|
}
|
|
37
|
-
export interface
|
|
38
|
+
export interface SwapPanelBlockProps {
|
|
38
39
|
/** Catalog for the To side, and for the From side unless `fromTokens` is given. */
|
|
39
40
|
tokens: readonly SwapToken[];
|
|
40
41
|
/** Assets offered on the From side, typically the connected wallet's holdings. */
|
|
@@ -137,4 +138,8 @@ export interface SwapPanelProps {
|
|
|
137
138
|
* or token units through the keypad, token pickers, settings, and one action that names itself from the chosen pair.
|
|
138
139
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
139
140
|
*/
|
|
140
|
-
export declare function
|
|
141
|
+
export declare function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains, hotTokenIds, from: fromProp, to: toProp, defaultFrom, defaultTo, onFromChange, onToChange, amount, onAmountChange, received, fee, fees, quoteLoading, slippage, onSlippageChange, denomination, onDenominationChange, wallet, onConnect, onDisconnect, recipient, onRecipientChange, onScanRecipient, receive, receiving, onReceivingChange, onSubmit, submitting, onReset, keypad, destination, details, note, noteTone, title, onBack, controls, actionIcon, lockFrom, lockTo, actionLabel, actionDisabled, actionStatus, actionIntent, limitToBalance, banner, footer, oneWay: oneWayProp, denominationSwitch, settings, view: viewProp, onViewChange, style }: SwapPanelBlockProps): React.JSX.Element;
|
|
142
|
+
/** @deprecated Renamed `SwapPanelBlock`. The old name keeps working until the next major release. */
|
|
143
|
+
export declare const SwapPanel: typeof SwapPanelBlock;
|
|
144
|
+
/** @deprecated Renamed `SwapPanelBlockProps`. */
|
|
145
|
+
export type SwapPanelProps = SwapPanelBlockProps;
|
|
@@ -2,10 +2,11 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Animated, BackHandler, Easing, Platform, Pressable, StyleSheet, View } from 'react-native';
|
|
4
4
|
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
-
import { Raised, useColors, useControllable, useHIG, useMessages } from './provider.js';
|
|
5
|
+
import { Raised, useColors, useControllable, useHIG, useMessages, useNumberLocale, usePresentNumber } from './provider.js';
|
|
6
6
|
import { Text } from './surface.js';
|
|
7
7
|
import { Button, IconButton } from './button.js';
|
|
8
8
|
import { AnimatedNumberReadout } from './animated-number.js';
|
|
9
|
+
import { figureProps } from './figure.js';
|
|
9
10
|
import { Toast, useTransientNotice } from './status.js';
|
|
10
11
|
import { VerticalAddress, addressKind } from './data.js';
|
|
11
12
|
import { withAlpha } from '@bloxwap/hig/tokens';
|
|
@@ -20,9 +21,11 @@ export { SwapHostContext } from './swap-parts.js';
|
|
|
20
21
|
* or token units through the keypad, token pickers, settings, and one action that names itself from the chosen pair.
|
|
21
22
|
* Presentation only. The host owns tokens, balances, prices, the quote, the wallet and the transaction.
|
|
22
23
|
*/
|
|
23
|
-
export function
|
|
24
|
+
export function SwapPanelBlock({ tokens, fromTokens, fromTokensLoading, chains, hotTokenIds, from: fromProp, to: toProp, defaultFrom = null, defaultTo = null, onFromChange, onToChange, amount, onAmountChange, received, fee, fees, quoteLoading, slippage = 0.005, onSlippageChange, denomination, onDenominationChange, wallet, onConnect, onDisconnect, recipient, onRecipientChange, onScanRecipient, receive, receiving, onReceivingChange, onSubmit, submitting = false, onReset, keypad = 'auto', destination, details, note, noteTone = 'muted', title, onBack, controls = true, actionIcon, lockFrom = false, lockTo = false, actionLabel, actionDisabled = false, actionStatus, actionIntent = 'primary', limitToBalance = false, banner, footer, oneWay: oneWayProp = false, denominationSwitch = true, settings, view: viewProp, onViewChange, style }) {
|
|
24
25
|
const env = useHIG();
|
|
25
|
-
const {
|
|
26
|
+
const { direction } = env;
|
|
27
|
+
const locale = useNumberLocale();
|
|
28
|
+
const present = usePresentNumber();
|
|
26
29
|
const colors = useColors();
|
|
27
30
|
const t = useMessages();
|
|
28
31
|
const [from, setFrom] = useControllable(fromProp, defaultFrom, onFromChange);
|
|
@@ -105,13 +108,13 @@ export function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTo
|
|
|
105
108
|
return chains; const seen = new Map(); for (const token of tokens)
|
|
106
109
|
if (!seen.has(token.chainId))
|
|
107
110
|
seen.set(token.chainId, { chainId: token.chainId, name: token.chain, icon: typeof token.chainIcon === 'string' ? token.chainIcon : undefined }); return [...seen.values()]; }, [chains, tokens]);
|
|
108
|
-
const usdText = (value) => formatNumber(value, locale, { style: 'currency', currency: 'USD' });
|
|
111
|
+
const usdText = (value) => formatNumber(value, locale, present({ style: 'currency', currency: 'USD' }));
|
|
109
112
|
const fraction = entry.includes('.') ? Math.min(entry.length - entry.indexOf('.') - 1, fromMode === 'usd' ? 2 : 8) : 0;
|
|
110
113
|
const smallType = { fontSize: 14, lineHeight: 19 }, small = { ...smallType, color: colors.muted };
|
|
111
114
|
// Live numbers: the fee and slippage sentences keep their translated wording around a number that updates in place.
|
|
112
115
|
const usdOptions = { style: 'currency', currency: 'USD' }, feeKnown = !quoteLoading && fee != null, feeAmount = quoteLoading ? '…' : fee != null ? usdText(fee) : '—', slippageText = formatPercent(slippage);
|
|
113
116
|
// An account (a token with a `caption`) reads name over caption beside one disc, and offers Max only.
|
|
114
|
-
const account = (side, token, locked) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', testID: `swap-account-${side}`, style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 40 }) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Text, { style: { fontWeight: '600', lineHeight: 21, flexShrink: 1 }, children: token.name }), locked ? null : _jsx(View, { testID: `swap-account-chevron-${side}`, children: _jsx(SmallChevron, { color: colors.muted }) })] }), typeof token.caption === 'object' ? _jsx(AnimatedNumberReadout, { testID: 'swap-caption', ...token.caption, tone: 'muted', style: smallType }) : _jsx(Text, { style: small, children: token.caption })] })] }), side === 'from' && (token.balance ?? 0) > 0 ? _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) }) : null] });
|
|
117
|
+
const account = (side, token, locked) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', testID: `swap-account-${side}`, style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 40 }) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Text, { style: { fontWeight: '600', lineHeight: 21, flexShrink: 1 }, children: token.name }), locked ? null : _jsx(View, { testID: `swap-account-chevron-${side}`, children: _jsx(SmallChevron, { color: colors.muted }) })] }), typeof token.caption === 'object' ? _jsx(AnimatedNumberReadout, { testID: 'swap-caption', ...figureProps(token.caption), tone: 'muted', style: smallType }) : _jsx(Text, { style: small, children: token.caption })] })] }), side === 'from' && (token.balance ?? 0) > 0 ? _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) }) : null] });
|
|
115
118
|
const header = (side, token) => _jsxs(_Fragment, { children: [_jsxs(View, { pointerEvents: 'none', style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'flex-start', gap: 12 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', style: { alignItems: 'center' }, children: [wallet?.address ? _jsx(View, { style: { width: 28, height: 28, borderRadius: 14, backgroundColor: addressColor(wallet.address), borderWidth: 2, borderColor: colors.surface } }) : null, token.chainIcon ? _jsx(TokenArt, { uri: token.chainIcon, size: 28, ring: colors.surface }) : null, _jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: 28, ring: colors.surface })].filter(Boolean).map((layer, index) => _jsx(View, { style: { marginTop: index ? -14 : 0 }, children: layer }, index)) }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [wallet?.address ? _jsx(Text, { style: small, children: shortAddress(wallet.address) }) : null, _jsx(Text, { style: small, children: token.chain }), _jsx(Text, { style: { fontWeight: '600', lineHeight: 21 }, children: token.name })] })] }), side === 'from' ? ((token.balance ?? 0) > 0 ? _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { pointerEvents: 'box-none', style: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: 8 }, children: [_jsx(SwapCapsule, { testID: 'swap-test', onPress: () => setEntry(unitsToEntry(testAmount(token), fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapTest }) }), _jsx(SwapCapsule, { testID: 'swap-max', onPress: () => setEntry(unitsToEntry(token.balance ?? 0, fromMode, fromPrice)), children: _jsx(Text, { style: small, children: t.swapMax }) })] }), _jsx(View, { pointerEvents: 'none', children: _jsx(AnimatedNumberReadout, { testID: 'swap-balance', value: token.balance, options: { maximumFractionDigits: 6 }, suffix: ` ${token.symbol}`, tone: 'muted', style: smallType }) })] }) : null)
|
|
116
119
|
: _jsxs(View, { pointerEvents: 'box-none', style: { alignItems: 'flex-end', gap: 8, maxWidth: '60%' }, children: [_jsx(SwapCapsule, { testID: 'swap-slippage', label: t.swapSlippage(slippageText), onPress: () => show(onSlippageChange ? 'slippage' : 'settings'), children: _jsx(SwapNumberText, { template: t.swapSlippage, text: slippageText, value: slippage * 100, formattedValue: slippageText.slice(0, -1), suffix: '%' }) }), _jsx(View, { pointerEvents: 'none', children: _jsx(SwapNumberText, { testID: 'swap-fee', template: t.swapFee, text: feeAmount, value: feeKnown ? fee : null, options: usdOptions }) })] })] });
|
|
117
120
|
const receiveView = (view) => {
|
|
@@ -132,15 +135,15 @@ export function SwapPanel({ tokens, fromTokens, fromTokensLoading, chains, hotTo
|
|
|
132
135
|
if (!fixed)
|
|
133
136
|
return null;
|
|
134
137
|
const art = !destination ? null : destination.icon ? _jsx(TokenArt, { uri: destination.icon, size: 40 }) : destination.address ? _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, backgroundColor: addressColor(destination.address) } }) : _jsx(View, { style: { width: 40, height: 40, borderRadius: 20, backgroundColor: colors.nested, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { fontSize: 12, lineHeight: 16, fontWeight: '600', color: colors.muted }, children: destination.title.slice(0, 2) }) });
|
|
135
|
-
const row = destination ? _jsxs(View, { pointerEvents: 'none', style: { flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 84, padding: 16 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: art }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { testID: 'swap-destination-title', style: { fontWeight: destination.pending ? '500' : '600', lineHeight: 21 }, children: destination.title }), destination.subtitle ? _jsx(Text, { style: small, children: destination.subtitle }) : null, destination.address ? _jsx(Text, { style: small, children: shortAddress(destination.address) }) : null] }), destination.detail || fee !== undefined || destination.onPress ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { style: { alignItems: 'flex-end', gap: 8, flexShrink: 1 }, children: [typeof destination.detail === 'object' ? _jsx(AnimatedNumberReadout, { testID: 'swap-destination-detail', ...destination.detail, tone: 'muted', style: { ...smallType, textAlign: 'right' } }) : destination.detail ? _jsx(Text, { style: [small, { textAlign: 'right' }], children: destination.detail }) : null, fee !== undefined ? _jsx(SwapNumberText, { testID: 'swap-destination-fee', align: 'right', template: t.swapFee, text: feeAmount, value: feeKnown ? fee : null, options: usdOptions }) : null] }), destination.onPress ? _jsx(View, { testID: 'swap-destination-chevron', children: _jsx(SmallChevron, { color: colors.muted, trailing: true }) }) : null] }) : null] }) : null;
|
|
136
|
-
const rows = details && details.length > 0 ? _jsx(View, { testID: 'swap-details', style: { gap: 12, padding: 16, paddingTop: destination ? 0 : 16 }, children: details.map(detail => _jsxs(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: [_jsx(Text, { style: { color: colors.muted, lineHeight: 21 }, children: detail.label }), typeof detail.value === 'number' ? _jsx(AnimatedNumberReadout, { value: detail.value, options: detail.options, prefix: detail.prefix, suffix: detail.suffix, style: { lineHeight: 21, textAlign: 'right' } }) : _jsx(Text, { style: { lineHeight: 21, textAlign: 'right', flexShrink: 1 }, children: detail.value })] }, detail.label)) }) : null;
|
|
138
|
+
const row = destination ? _jsxs(View, { pointerEvents: 'none', style: { flexDirection: 'row', alignItems: 'center', gap: 12, minHeight: 84, padding: 16 }, children: [_jsx(View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: art }), _jsxs(View, { style: { flex: 1, minWidth: 0 }, children: [_jsx(Text, { testID: 'swap-destination-title', style: { fontWeight: destination.pending ? '500' : '600', lineHeight: 21 }, children: destination.title }), destination.subtitle ? _jsx(Text, { style: small, children: destination.subtitle }) : null, destination.address ? _jsx(Text, { style: small, children: shortAddress(destination.address) }) : null] }), destination.detail || fee !== undefined || destination.onPress ? _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, maxWidth: '60%' }, children: [_jsxs(View, { style: { alignItems: 'flex-end', gap: 8, flexShrink: 1 }, children: [typeof destination.detail === 'object' ? _jsx(AnimatedNumberReadout, { testID: 'swap-destination-detail', ...figureProps(destination.detail), tone: 'muted', style: { ...smallType, textAlign: 'right' } }) : destination.detail ? _jsx(Text, { style: [small, { textAlign: 'right' }], children: destination.detail }) : null, fee !== undefined ? _jsx(SwapNumberText, { testID: 'swap-destination-fee', align: 'right', template: t.swapFee, text: feeAmount, value: feeKnown ? fee : null, options: usdOptions }) : null] }), destination.onPress ? _jsx(View, { testID: 'swap-destination-chevron', children: _jsx(SmallChevron, { color: colors.muted, trailing: true }) }) : null] }) : null] }) : null;
|
|
139
|
+
const rows = details && details.length > 0 ? _jsx(View, { testID: 'swap-details', style: { gap: 12, padding: 16, paddingTop: destination ? 0 : 16 }, children: details.map(detail => _jsxs(View, { style: { flexDirection: 'row', justifyContent: 'space-between', gap: 12 }, children: [_jsx(Text, { style: { color: colors.muted, lineHeight: 21 }, children: detail.label }), typeof detail.value === 'number' ? _jsx(AnimatedNumberReadout, { value: detail.value, options: detail.options, prefix: detail.prefix, suffix: detail.suffix, formattedValue: detail.formattedValue, animateFormatted: !!detail.formattedValue, style: { lineHeight: 21, textAlign: 'right' } }) : _jsx(Text, { style: { lineHeight: 21, textAlign: 'right', flexShrink: 1 }, children: detail.value })] }, detail.label)) }) : null;
|
|
137
140
|
const shape = { backgroundColor: colors.surface, borderRadius: 24, overflow: 'hidden' };
|
|
138
141
|
// With a pressable destination the whole card is the button; the rows inside it are read as part of it.
|
|
139
142
|
return destination?.onPress ? _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: destination.title, testID: 'swap-destination', onPress: destination.onPress, style: ({ pressed }) => [shape, { opacity: pressed ? 0.85 : 1 }], children: _jsxs(Raised, { children: [row, rows] }) }) : _jsx(View, { testID: 'swap-destination', style: shape, children: _jsxs(Raised, { children: [row, rows] }) });
|
|
140
143
|
};
|
|
141
144
|
const fromCard = card('from'), toCard = fixedCard() ?? card('to');
|
|
142
145
|
const tone = noteTone === 'warning' ? colors.warning : noteTone === 'negative' ? colors.negative : null;
|
|
143
|
-
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(SwapHeader, { title: title, onBack: onBack }) }) : null, banner ? _jsx(View, { testID: 'swap-banner', style: { marginBottom: 8 }, children: banner }) : null, fromCard, _jsx(View, { style: { height: 8, zIndex: 1, alignItems: 'center' }, children: _jsx(View, { style: { position: 'absolute', top: -15, width: 38, height: 38, borderRadius: 19, backgroundColor: colors.background, alignItems: 'center', justifyContent: 'center' }, children: oneWay ? _jsx(View, { testID: 'swap-one-way', style: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: colors.nested }, children: _jsx(DownIcon, { color: colors.muted }) }) : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapFlip, accessibilityState: { disabled: !from || !to }, disabled: !from || !to, testID: 'swap-flip', onPress: flip, hitSlop: 6, style: ({ pressed }) => ({ width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: !from || !to ? colors.surface : colors.nested, opacity: pressed ? 0.85 : 1 }), children: _jsx(FlipIcon, { color: !from || !to ? colors.faint : colors.muted }) }) }) }), toCard, note ? _jsx(View, { testID: 'swap-note', style: tone ? { marginTop: 8, paddingVertical: 12, paddingHorizontal: 16, borderRadius: 16, backgroundColor: withAlpha(tone, 0.
|
|
146
|
+
const main = _jsxs(View, { testID: 'swap-view-main', children: [title ? _jsx(View, { style: { marginBottom: 12 }, children: _jsx(SwapHeader, { title: title, onBack: onBack }) }) : null, banner ? _jsx(View, { testID: 'swap-banner', style: { marginBottom: 8 }, children: banner }) : null, fromCard, _jsx(View, { style: { height: 8, zIndex: 1, alignItems: 'center' }, children: _jsx(View, { style: { position: 'absolute', top: -15, width: 38, height: 38, borderRadius: 19, backgroundColor: colors.background, alignItems: 'center', justifyContent: 'center' }, children: oneWay ? _jsx(View, { testID: 'swap-one-way', style: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: colors.nested }, children: _jsx(DownIcon, { color: colors.muted }) }) : _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: t.swapFlip, accessibilityState: { disabled: !from || !to }, disabled: !from || !to, testID: 'swap-flip', onPress: flip, hitSlop: 6, style: ({ pressed }) => ({ width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', backgroundColor: !from || !to ? colors.surface : colors.nested, opacity: pressed ? 0.85 : 1 }), children: _jsx(FlipIcon, { color: !from || !to ? colors.faint : colors.muted }) }) }) }), toCard, note ? _jsx(View, { testID: 'swap-note', style: tone ? { marginTop: 8, paddingVertical: 12, paddingHorizontal: 16, borderRadius: 16, backgroundColor: withAlpha(tone, 0.1) } : { marginTop: 8, paddingHorizontal: 4 }, children: _jsx(Text, { style: { fontSize: 14, lineHeight: 21, color: tone ?? colors.muted }, children: note }) }) : null, !showReceive && keypad !== 'never' ? _jsx(SwapKeypad, { onKey: press, label: t.swapKeypad, deleteLabel: t.swapDelete }) : null, _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, marginTop: 16 }, children: [controls ? _jsx(IconButton, { intent: 'secondary', label: t.swapSettings, suppressFeedback: true, testID: 'swap-settings-button', onPress: () => show('settings'), children: _jsx(MenuIcon, { color: colors.text }) }) : null, _jsxs(Button, { intent: actionIntent, busy: submitting, disabled: !showReceive && !ready, testID: 'swap-action', onPress: submit, style: { flex: 1, alignSelf: 'auto' }, children: [actionIcon ? _jsx(View, { testID: 'swap-action-icon', accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', children: actionIcon }, 'icon') : null, actionText] }), controls ? _jsx(IconButton, { intent: 'secondary', label: t.swapReset, disabled: pristine || submitting, testID: 'swap-reset', onPress: reset, children: _jsx(ResetIcon, { color: colors.text }) }) : null] }), notice ? _jsx(View, { style: { marginTop: 8, alignItems: 'center' }, children: _jsx(Toast, { notices: [notice], onDismiss: dismissNotice }) }) : null, footer ? _jsx(View, { testID: 'swap-footer', style: { marginTop: 16 }, children: footer }) : null] });
|
|
144
147
|
const body = view === 'main' ? main
|
|
145
148
|
: view === 'from' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: fromTokens ?? tokens, loading: fromTokensLoading, chains: chainList, hotTokenIds: hotTokenIds, selected: from, onSelect: setFrom, wallet: wallet, onConnect: onConnect, onDisconnect: onDisconnect, receiving: isReceiving, onReceivingChange: receive ? setReceiving : undefined })
|
|
146
149
|
: view === 'to' ? _jsx(SwapPicker, { side: view, onBack: back, tokens: tokens, chains: chainList, hotTokenIds: hotTokenIds, selected: to, onSelect: setTo, wallet: wallet, recipient: recipient, onRecipientChange: onRecipientChange, onScanRecipient: onScanRecipient })
|
|
@@ -183,3 +186,5 @@ function SwapStage({ view, animateHeight, children }) {
|
|
|
183
186
|
const fitted = sizing && sized;
|
|
184
187
|
return _jsx(Animated.View, { testID: 'swap-stage', style: fitted ? { height, overflow: 'hidden' } : undefined, children: _jsx(Animated.View, { onLayout: onLayout, style: [fitted ? { position: 'absolute', left: 0, right: 0, top: 0 } : null, { opacity: slide, transform: [{ translateX: slide.interpolate({ inputRange: [0, 1], outputRange: [travel.current * 48, 0] }) }] }], children: children }) });
|
|
185
188
|
}
|
|
189
|
+
/** @deprecated Renamed `SwapPanelBlock`. The old name keeps working until the next major release. */
|
|
190
|
+
export const SwapPanel = SwapPanelBlock;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type FlatListProps } from 'react-native';
|
|
2
|
+
import { View, type FlatListProps, type Insets } from 'react-native';
|
|
3
3
|
import type { SwapArtwork, SwapToken } from './swap-shared.js';
|
|
4
4
|
/** What a host surface supplies to the swap views: a sheet passes its backend's list so drags hand off to the sheet, and turns off the panel's own height animation. */
|
|
5
5
|
export declare const SwapHostContext: React.Context<{
|
|
@@ -56,11 +56,13 @@ export declare function TokenIcon({ token, size }: {
|
|
|
56
56
|
size?: number;
|
|
57
57
|
}): React.JSX.Element;
|
|
58
58
|
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. 32dp tall with a 44dp target. */
|
|
59
|
-
export declare function SwapCapsule({ children, onPress, label, testID }: {
|
|
59
|
+
export declare function SwapCapsule({ children, onPress, label, testID, hitSlop, ref }: {
|
|
60
60
|
children: React.ReactNode;
|
|
61
61
|
onPress: () => void;
|
|
62
62
|
label?: string;
|
|
63
|
-
testID?: string;
|
|
63
|
+
testID?: string; /** Defaults to a 44dp target, as on the swap card. */
|
|
64
|
+
hitSlop?: Insets; /** Reaches the capsule, for example to move accessibility focus back to it. */
|
|
65
|
+
ref?: React.Ref<View>;
|
|
64
66
|
}): React.JSX.Element;
|
|
65
67
|
/** Numeric keypad: a 3 by 4 grid of 56dp keys. Emits `0`–`9`, `.` or `back`. */
|
|
66
68
|
export declare function SwapKeypad({ onKey, label, deleteLabel }: {
|
|
@@ -42,10 +42,10 @@ export function TokenArt({ uri, symbol, size, ring }) {
|
|
|
42
42
|
/** Token artwork with its chain badge. */
|
|
43
43
|
export function TokenIcon({ token, size = 44 }) { const colors = useColors(); return _jsxs(View, { ...hidden, style: { width: size, height: size }, children: [_jsx(TokenArt, { uri: token.icon, symbol: token.symbol, size: size }), token.chainIcon ? _jsx(View, { style: { position: 'absolute', end: 0, bottom: 0 }, children: _jsx(TokenArt, { uri: token.chainIcon, size: 18, ring: colors.overlay }) }) : null] }); }
|
|
44
44
|
/** Small capsule action that sits on a card: Max, Test, the slippage setting and the denomination switch. 32dp tall with a 44dp target. */
|
|
45
|
-
export function SwapCapsule({ children, onPress, label, testID }) {
|
|
45
|
+
export function SwapCapsule({ children, onPress, label, testID, hitSlop = { top: 6, bottom: 6 }, ref }) {
|
|
46
46
|
const fills = useFills();
|
|
47
47
|
const { direction } = useHIG();
|
|
48
|
-
return _jsx(Pressable, { accessibilityRole: 'button', accessibilityLabel: label, testID: testID, onPress: onPress, hitSlop:
|
|
48
|
+
return _jsx(Pressable, { ref: ref, accessibilityRole: 'button', accessibilityLabel: label, testID: testID, onPress: onPress, hitSlop: hitSlop, style: ({ pressed }) => ({ direction, flexDirection: 'row', alignItems: 'center', gap: 6, minHeight: 32, paddingVertical: 4, paddingHorizontal: 12, borderRadius: 9999, backgroundColor: pressed ? fills.raised : fills.well }), children: children });
|
|
49
49
|
}
|
|
50
50
|
const keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0', 'back'];
|
|
51
51
|
/** Numeric keypad: a 3 by 4 grid of 56dp keys. Emits `0`–`9`, `.` or `back`. */
|
|
@@ -6,6 +6,8 @@ export interface SwapFigure {
|
|
|
6
6
|
options?: Intl.NumberFormatOptions;
|
|
7
7
|
prefix?: string;
|
|
8
8
|
suffix?: string;
|
|
9
|
+
/** Host-formatted text for `value`, drawn and read in place of Intl's and still moving place by place. Never parsed back. */
|
|
10
|
+
formattedValue?: string;
|
|
9
11
|
}
|
|
10
12
|
export interface SwapToken {
|
|
11
13
|
/** Unique per asset and chain, for example `${chainId}-${address}`. */
|
|
@@ -28,6 +30,10 @@ export interface SwapToken {
|
|
|
28
30
|
caption?: string | SwapFigure;
|
|
29
31
|
/** Extra text matched by the picker search, such as the contract address. */
|
|
30
32
|
keywords?: string;
|
|
33
|
+
/** Picker rows: host text after the balance figure, such as ` HYPE`. */
|
|
34
|
+
unitsSuffix?: string;
|
|
35
|
+
/** Picker rows: the second line under the name in place of the chain, for a list that is not about chains. The search still matches the chain. */
|
|
36
|
+
detail?: string;
|
|
31
37
|
}
|
|
32
38
|
/** An image URL, or an element the host draws. */
|
|
33
39
|
export type SwapArtwork = string | React.ReactElement;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
export interface SwapSheetProps extends
|
|
2
|
+
import { type SwapPanelBlockProps } from './swap-panel-block.js';
|
|
3
|
+
export interface SwapSheetProps extends SwapPanelBlockProps {
|
|
4
4
|
open: boolean;
|
|
5
5
|
onOpenChange: (open: boolean) => void;
|
|
6
6
|
/** Accessible name of the sheet. */
|
|
7
7
|
title: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* SwapPanelBlock presented in the gesture sheet. Pickers and settings push inside the same sheet, which resizes to the view
|
|
11
11
|
* on show. A back press or a dismiss gesture pops a pushed view first and closes the sheet only from the main form;
|
|
12
|
-
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `
|
|
12
|
+
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `blocks` does not load.
|
|
13
13
|
*/
|
|
14
14
|
export declare function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewChange, style, ...panel }: SwapSheetProps): React.JSX.Element;
|
|
@@ -2,11 +2,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { BottomSheetFlatList } from '@gorhom/bottom-sheet';
|
|
4
4
|
import { GestureSheet } from './gesture-sheet.js';
|
|
5
|
-
import { SwapHostContext,
|
|
5
|
+
import { SwapHostContext, SwapPanelBlock, swapParentView } from './swap-panel-block.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* SwapPanelBlock presented in the gesture sheet. Pickers and settings push inside the same sheet, which resizes to the view
|
|
8
8
|
* on show. A back press or a dismiss gesture pops a pushed view first and closes the sheet only from the main form;
|
|
9
|
-
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `
|
|
9
|
+
* closing always returns to the main form. Needs the optional gesture-sheet backend, which `blocks` does not load.
|
|
10
10
|
*/
|
|
11
11
|
export function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewChange, style, ...panel }) {
|
|
12
12
|
const [ownView, keepView] = useState('main');
|
|
@@ -22,5 +22,5 @@ export function SwapSheet({ open, onOpenChange, title, view: viewProp, onViewCha
|
|
|
22
22
|
return false; show(swapParentView(view)); return true; };
|
|
23
23
|
return _jsx(GestureSheet, { open: open, onOpenChange: next => { if (!next && leave())
|
|
24
24
|
return; onOpenChange(next); }, title: title, contentMode: 'custom', enableDynamicSizing: true, keyboardBehavior: 'interactive', onHardwareBackPress: () => { if (!leave())
|
|
25
|
-
onOpenChange(false); return true; }, children: _jsx(SwapHostContext.Provider, { value: host, children: _jsx(
|
|
25
|
+
onOpenChange(false); return true; }, children: _jsx(SwapHostContext.Provider, { value: host, children: _jsx(SwapPanelBlock, { ...panel, view: view, onViewChange: show, style: [{ paddingHorizontal: 12, paddingBottom: 16 }, style] }) }) });
|
|
26
26
|
}
|
|
@@ -20,7 +20,7 @@ export interface SwapPickerProps {
|
|
|
20
20
|
onRecipientChange?: (address: string) => void;
|
|
21
21
|
onScanRecipient?: () => void;
|
|
22
22
|
}
|
|
23
|
-
/** The panel's pushed picker view: the sub-view header over the From or To picker
|
|
23
|
+
/** The panel's pushed picker view: the sub-view header over the From or To picker block. Choosing a token pops back; the Generate address switch does not. */
|
|
24
24
|
export declare function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }: SwapPickerProps): React.JSX.Element;
|
|
25
25
|
export type SwapSettingsView = 'settings' | 'slippage' | 'fees';
|
|
26
26
|
export interface SwapSettingsProps {
|
|
@@ -2,30 +2,32 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { Pressable, View } from 'react-native';
|
|
4
4
|
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
-
import { useColors, useFills, useHIG, useMessages } from './provider.js';
|
|
5
|
+
import { useColors, useFills, useHIG, useMessages, useNumberLocale, usePresentNumber } from './provider.js';
|
|
6
6
|
import { Text } from './surface.js';
|
|
7
7
|
import { Field, Input } from './field.js';
|
|
8
8
|
import { SegmentedControl } from './radio-group.js';
|
|
9
9
|
import { ChevronIcon } from './icons.js';
|
|
10
10
|
import { AnimatedNumberReadout } from './animated-number.js';
|
|
11
11
|
import { SwapSubview } from './swap-parts.js';
|
|
12
|
-
import {
|
|
12
|
+
import { FromPickerBlock, ToPickerBlock } from './pickers.js';
|
|
13
13
|
import { formatPercent, shortAddress, slippagePresets } from './swap-shared.js';
|
|
14
|
-
/** The panel's pushed picker view: the sub-view header over the From or To picker
|
|
14
|
+
/** The panel's pushed picker view: the sub-view header over the From or To picker block. Choosing a token pops back; the Generate address switch does not. */
|
|
15
15
|
export function SwapPicker({ side, onBack, selected, onSelect, wallet, onConnect, onDisconnect, receiving, onReceivingChange, recipient, onRecipientChange, onScanRecipient, ...list }) {
|
|
16
16
|
const t = useMessages();
|
|
17
17
|
const choose = (token) => { onSelect(token); onBack(); };
|
|
18
18
|
return _jsx(SwapSubview, { title: side === 'from' ? t.swapFrom : t.swapTo, onBack: onBack, testID: `swap-picker-${side}`, children: side === 'from'
|
|
19
|
-
? _jsx(
|
|
20
|
-
: _jsx(
|
|
19
|
+
? _jsx(FromPickerBlock, { ...list, selected: selected, onSelect: choose, wallet: wallet ?? { connected: false }, onConnect: onConnect, onDisconnect: onDisconnect, generateAddress: !!receiving, onGenerateAddressChange: onReceivingChange })
|
|
20
|
+
: _jsx(ToPickerBlock, { ...list, selected: selected, onSelect: choose, address: recipient, onAddressChange: onRecipientChange, addressPlaceholder: wallet?.address ? shortAddress(wallet.address) : undefined, onScan: onScanRecipient }) });
|
|
21
21
|
}
|
|
22
22
|
/** The settings views. Slippage and the fee breakdown push from the settings list, and Back returns to it. */
|
|
23
23
|
export function SwapSettings({ view, onViewChange, onBack, denomination, onDenominationChange, slippage, onSlippageChange, fee, fees, quoteLoading, children }) {
|
|
24
|
-
const {
|
|
24
|
+
const { direction } = useHIG();
|
|
25
|
+
const locale = useNumberLocale();
|
|
25
26
|
const colors = useColors();
|
|
26
27
|
const fills = useFills();
|
|
27
28
|
const t = useMessages();
|
|
28
|
-
const
|
|
29
|
+
const present = usePresentNumber();
|
|
30
|
+
const usd = (value) => formatNumber(value, locale, present({ style: 'currency', currency: 'USD' }));
|
|
29
31
|
const [custom, setCustom] = useState(null);
|
|
30
32
|
const title = view === 'slippage' ? t.swapSlippageTitle : view === 'fees' ? t.swapFees : t.swapSettings;
|
|
31
33
|
const feeText = quoteLoading ? '…' : fee != null ? usd(fee) : '—';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type PressableProps } from 'react-native';
|
|
2
|
+
import { View, type PressableProps } from 'react-native';
|
|
3
3
|
import type { CheckedProps } from './selection-types.js';
|
|
4
4
|
/** One named switch around a host's noninteractive label, description and track. */
|
|
5
5
|
export interface SwitchRowProps extends CheckedProps, Omit<PressableProps, 'children' | 'onPress' | 'disabled' | 'role' | 'accessibilityRole' | 'accessibilityLabel' | 'accessibilityLabelledBy' | 'aria-label' | 'aria-labelledby' | 'aria-checked' | 'aria-disabled'> {
|
|
6
6
|
/** Custom anatomy is decorative. `label` names the switch and `accessibilityHint` describes it. */ children: React.ReactNode;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
/** The ref reaches the row's Pressable. */
|
|
9
|
+
export declare const SwitchRow: React.ForwardRefExoticComponent<SwitchRowProps & React.RefAttributes<React.ComponentRef<typeof View>>>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
2
3
|
import { Platform, Pressable, View } from 'react-native';
|
|
3
4
|
import { useControllable, useHIG } from './provider.js';
|
|
4
|
-
|
|
5
|
+
/** The ref reaches the row's Pressable. */
|
|
6
|
+
export const SwitchRow = /* @__PURE__ */ forwardRef(function SwitchRow({ label, checked, defaultChecked = false, disabled, onCheckedChange, children, style, accessibilityState, ...props }, ref) {
|
|
5
7
|
const env = useHIG(), [current, set] = useControllable(checked, defaultChecked, onCheckedChange);
|
|
6
8
|
const toggle = () => { if (!disabled)
|
|
7
9
|
set(!current); };
|
|
@@ -14,5 +16,5 @@ export function SwitchRow({ label, checked, defaultChecked = false, disabled, on
|
|
|
14
16
|
toggle();
|
|
15
17
|
}
|
|
16
18
|
} } : {};
|
|
17
|
-
return _jsx(Pressable, { ...props, ...webKeys, accessible: true, accessibilityRole: 'switch', accessibilityLabel: label, accessibilityState: { ...accessibilityState, checked: current, disabled: !!disabled }, "aria-checked": current, "aria-busy": accessibilityState?.busy, disabled: disabled, onPress: toggle, style: state => [{ direction: env.direction, minHeight: 48, flexDirection: 'row' }, typeof style === 'function' ? style(state) : style], children: _jsx(View, { pointerEvents: 'none', accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', "aria-hidden": true, style: { flex: 1 }, children: children }) });
|
|
18
|
-
}
|
|
19
|
+
return _jsx(Pressable, { ...props, ...webKeys, ref: ref, accessible: true, accessibilityRole: 'switch', accessibilityLabel: label, accessibilityState: { ...accessibilityState, checked: current, disabled: !!disabled }, "aria-checked": current, "aria-busy": accessibilityState?.busy, disabled: disabled, onPress: toggle, style: state => [{ direction: env.direction, minHeight: 48, flexDirection: 'row' }, typeof style === 'function' ? style(state) : style], children: _jsx(View, { pointerEvents: 'none', accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', "aria-hidden": true, style: { flex: 1 }, children: children }) });
|
|
20
|
+
});
|
package/native/dist/switch.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import type { CheckedProps } from './selection-types.js';
|
|
|
3
3
|
import { type AccentRole } from './roles.js';
|
|
4
4
|
export type { AccentRole } from './roles.js';
|
|
5
5
|
export interface SwitchProps extends CheckedProps {
|
|
6
|
-
tone?: AccentRole;
|
|
6
|
+
tone?: AccentRole; /** Draws the track alone: `label` still names the switch but is not shown, for a switch whose row already shows its name (such as a ListRow `trailing` control). */
|
|
7
|
+
hideLabel?: boolean;
|
|
8
|
+
testID?: string;
|
|
7
9
|
}
|
|
8
10
|
/** The off track is the dark `border` grey, so it reads as off on the page and on a card. On iOS/Android the whole labeled row is one 48dp switch target; the platform track is a hidden visual indicator. */
|
|
9
|
-
export declare function Switch({ label, checked, defaultChecked, disabled, tone, onCheckedChange }: SwitchProps): React.JSX.Element;
|
|
11
|
+
export declare function Switch({ label, checked, defaultChecked, disabled, tone, hideLabel, testID, onCheckedChange }: SwitchProps): React.JSX.Element;
|
|
10
12
|
export { SwitchRow, type SwitchRowProps } from './switch-row.js';
|
package/native/dist/switch.js
CHANGED
|
@@ -7,7 +7,7 @@ import { roleColor } from './roles.js';
|
|
|
7
7
|
/** react-native-web passes CSS transitions through style. */
|
|
8
8
|
const webEase = { transitionProperty: 'transform, background-color', transitionDuration: '150ms' };
|
|
9
9
|
/** The off track is the dark `border` grey, so it reads as off on the page and on a card. On iOS/Android the whole labeled row is one 48dp switch target; the platform track is a hidden visual indicator. */
|
|
10
|
-
export function Switch({ label, checked, defaultChecked = false, disabled, tone, onCheckedChange }) {
|
|
10
|
+
export function Switch({ label, checked, defaultChecked = false, disabled, tone, hideLabel, testID, onCheckedChange }) {
|
|
11
11
|
const env = useHIG();
|
|
12
12
|
const colors = useColors();
|
|
13
13
|
const fills = useFills();
|
|
@@ -20,11 +20,11 @@ export function Switch({ label, checked, defaultChecked = false, disabled, tone,
|
|
|
20
20
|
// otherwise paints the thumb with the app theme accent, Material teal, so it takes `text`). react-native-web's own Switch draws a
|
|
21
21
|
// Material thumb wider than its track in that off-palette teal and would nest a second control, so web draws the 40×24 capsule of
|
|
22
22
|
// @bloxwap/hig/react: an 18dp thumb inset 3dp that slides and eases over 150ms. RN Web presses on Enter; Space is handled here.
|
|
23
|
-
return _jsxs(Pressable, { accessibilityRole: 'switch', accessibilityLabel: label, accessibilityState: { checked: current, disabled: !!disabled }, "aria-checked": current, "aria-disabled": !!disabled, disabled: disabled, onPress: toggle, ...(web ? { onKeyDown: (event) => { if (event.key === ' ') {
|
|
23
|
+
return _jsxs(Pressable, { testID: testID, accessibilityRole: 'switch', accessibilityLabel: label, accessibilityState: { checked: current, disabled: !!disabled }, "aria-checked": current, "aria-disabled": !!disabled, disabled: disabled, onPress: toggle, ...(web ? { onKeyDown: (event) => { if (event.key === ' ') {
|
|
24
24
|
event.preventDefault();
|
|
25
25
|
if (!event.repeat)
|
|
26
26
|
toggle();
|
|
27
|
-
} } } : null), style: { direction: env.direction, minHeight: 48, flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: tokens.space.md, opacity: web && disabled ? 0.5 : 1 }, children: [_jsx(Text, { children: label }), _jsx(View, { pointerEvents: 'none', accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', "aria-hidden": web || undefined, style: web ? [{ width: 40, height: 24, borderRadius: 12, padding: 3, backgroundColor: track[current ? 'true' : 'false'] }, webEase] : undefined, children: web ? _jsx(View, { style: [{ width: 18, height: 18, borderRadius: 9, backgroundColor: current ? colors.onAction : colors.text, transform: [{ translateX: (current ? 16 : 0) * (env.direction === 'rtl' ? -1 : 1) }] }, webEase] }) : _jsx(RNSwitch, { value: current, disabled: disabled, onValueChange: next => { if (!disabled)
|
|
27
|
+
} } } : null), style: { direction: env.direction, minHeight: 48, flexDirection: 'row', flexWrap: 'wrap', alignItems: 'center', gap: tokens.space.md, opacity: web && disabled ? 0.5 : 1 }, children: [hideLabel ? null : _jsx(Text, { children: label }), _jsx(View, { pointerEvents: 'none', accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', "aria-hidden": web || undefined, style: web ? [{ width: 40, height: 24, borderRadius: 12, padding: 3, backgroundColor: track[current ? 'true' : 'false'] }, webEase] : undefined, children: web ? _jsx(View, { style: [{ width: 18, height: 18, borderRadius: 9, backgroundColor: current ? colors.onAction : colors.text, transform: [{ translateX: (current ? 16 : 0) * (env.direction === 'rtl' ? -1 : 1) }] }, webEase] }) : _jsx(RNSwitch, { value: current, disabled: disabled, onValueChange: next => { if (!disabled)
|
|
28
28
|
set(next); }, trackColor: track, thumbColor: Platform.OS === 'android' ? colors.text : undefined, ios_backgroundColor: fills.raised }) })] });
|
|
29
29
|
}
|
|
30
30
|
export { SwitchRow } from './switch-row.js';
|