@bloxwap/hig 0.0.0-stage → 0.2.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/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 +162 -0
- package/contracts/dist/messages.js +68 -0
- package/feedback/README.md +7 -0
- package/feedback/assets/error.wav +0 -0
- package/feedback/assets/manifest.json +68 -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 +96 -0
- package/feedback/dist/contract.js +58 -0
- package/feedback/dist/native.d.ts +27 -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/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 +11 -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 +93 -0
- package/native/dist/brand.d.ts +7 -0
- package/native/dist/brand.js +6 -0
- package/native/dist/button.d.ts +29 -0
- package/native/dist/button.js +34 -0
- package/native/dist/checkbox.d.ts +3 -0
- package/native/dist/checkbox.js +11 -0
- package/native/dist/data.d.ts +40 -0
- package/native/dist/data.js +27 -0
- package/native/dist/field.d.ts +15 -0
- package/native/dist/field.js +13 -0
- package/native/dist/gesture-sheet.d.ts +73 -0
- package/native/dist/gesture-sheet.js +151 -0
- package/native/dist/navigation.d.ts +47 -0
- package/native/dist/navigation.js +16 -0
- package/native/dist/overlay.d.ts +36 -0
- package/native/dist/overlay.js +65 -0
- package/native/dist/provider.d.ts +43 -0
- package/native/dist/provider.js +52 -0
- package/native/dist/radio-group.d.ts +5 -0
- package/native/dist/radio-group.js +53 -0
- package/native/dist/recipes.d.ts +42 -0
- package/native/dist/recipes.js +19 -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 +7 -0
- package/native/dist/selection.js +6 -0
- package/native/dist/slider.d.ts +11 -0
- package/native/dist/slider.js +41 -0
- package/native/dist/status.d.ts +75 -0
- package/native/dist/status.js +72 -0
- package/native/dist/surface.d.ts +18 -0
- package/native/dist/surface.js +41 -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 +23 -0
- package/native/dist/text-content.d.ts +5 -0
- package/native/dist/text-content.js +6 -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 +358 -4
- package/react/README.md +9 -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 +71 -0
- package/react/dist/base.css +9 -0
- package/react/dist/brand.d.ts +7 -0
- package/react/dist/brand.js +4 -0
- package/react/dist/button.d.ts +14 -0
- package/react/dist/button.js +20 -0
- package/react/dist/data.d.ts +63 -0
- package/react/dist/data.js +23 -0
- package/react/dist/dialog.d.ts +29 -0
- package/react/dist/dialog.js +21 -0
- package/react/dist/field.d.ts +15 -0
- package/react/dist/field.js +19 -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/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 +5 -0
- package/react/dist/recipes/install-command.js +8 -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/trade-entry.d.ts +11 -0
- package/react/dist/recipes/trade-entry.js +12 -0
- package/react/dist/recipes.d.ts +8 -0
- package/react/dist/recipes.js +9 -0
- package/react/dist/select.d.ts +4 -0
- package/react/dist/select.js +172 -0
- package/react/dist/selection.d.ts +27 -0
- package/react/dist/selection.js +16 -0
- package/react/dist/slider.d.ts +11 -0
- package/react/dist/slider.js +10 -0
- package/react/dist/status.d.ts +53 -0
- package/react/dist/status.js +43 -0
- package/react/dist/styles.css +228 -0
- package/react/dist/surface.d.ts +291 -0
- package/react/dist/surface.js +9 -0
- package/tokens/README.md +9 -0
- package/tokens/assets/bloxwap-icon.svg +1 -0
- package/tokens/dist/index.d.ts +429 -0
- package/tokens/dist/index.js +507 -0
- package/tokens/dist/manifest.json +197 -0
- package/tokens/dist/theme.d.ts +11 -0
- package/tokens/dist/theme.js +22 -0
- package/tokens/dist/tokens.css +119 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useCallback, useImperativeHandle } from 'react';
|
|
3
|
+
import { AccessibilityInfo, BackHandler, findNodeHandle, Platform, View } from 'react-native';
|
|
4
|
+
import BottomSheet, { BottomSheetModal, BottomSheetScrollView, BottomSheetBackdrop, BottomSheetView } from '@gorhom/bottom-sheet';
|
|
5
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
|
+
import { ReduceMotion } from 'react-native-reanimated';
|
|
7
|
+
import { nativeMetrics as tokens } from '@bloxwap/hig/tokens';
|
|
8
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
9
|
+
import { useColors, useHIG } from './provider.js';
|
|
10
|
+
import { Heading, Text, Stack } from './surface.js';
|
|
11
|
+
import { Button } from './button.js';
|
|
12
|
+
/** Optional backend: host supplies GestureHandlerRootView, SafeAreaProvider and BottomSheetModalProvider. */
|
|
13
|
+
export function GestureSheet({ open, onOpenChange, title, description, children, contentMode = 'default', titleRef, presentation = 'modal', sheetRef, snapPoints, enableDynamicSizing = false, maxDynamicContentSize, enableContentPanningGesture, keyboardBehavior = 'interactive', keyboardBlurBehavior = 'restore', android_keyboardInputMode = 'adjustResize', initialIndex = 0, dismissible = true, returnFocusRef, closeLabel, onDismiss, onChange, onHardwareBackPress, topInset, bottomInset, modalRef, handleComponent, handleStyle, handleIndicatorStyle, backgroundComponent, backgroundStyle, containerStyle, animateOnMount, animationConfigs, backdropComponent }) {
|
|
14
|
+
if (enableDynamicSizing && snapPoints !== undefined)
|
|
15
|
+
throw new Error('Content-sized GestureSheet does not accept fixed snapPoints.');
|
|
16
|
+
const fixedSnapPoints = snapPoints ?? [];
|
|
17
|
+
if (!enableDynamicSizing && fixedSnapPoints.length === 0)
|
|
18
|
+
throw new Error('GestureSheet requires at least one snap point.');
|
|
19
|
+
if (maxDynamicContentSize !== undefined && (!Number.isFinite(maxDynamicContentSize) || maxDynamicContentSize <= 0))
|
|
20
|
+
throw new Error('GestureSheet maxDynamicContentSize must be finite and greater than zero.');
|
|
21
|
+
const detentCount = enableDynamicSizing ? 1 : fixedSnapPoints.length;
|
|
22
|
+
const sheet = useRef(null), inline = useRef(null), heading = useRef(null), requested = useRef(false), focused = useRef(false), frame = useRef(null), requestFrame = useRef(null);
|
|
23
|
+
useImperativeHandle(modalRef, () => sheet.current);
|
|
24
|
+
useImperativeHandle(sheetRef, () => inline.current);
|
|
25
|
+
const dismissed = useRef(true);
|
|
26
|
+
const startingIndex = Math.max(0, Math.min(initialIndex, detentCount - 1));
|
|
27
|
+
const activeIndex = useRef(startingIndex), detentFrame = useRef(null), pendingSnap = useRef(false);
|
|
28
|
+
const detentKey = JSON.stringify(fixedSnapPoints);
|
|
29
|
+
const latest = useRef({ open, onOpenChange, returnFocusRef, onDismiss, onHardwareBackPress });
|
|
30
|
+
latest.current = { open, onOpenChange, returnFocusRef, onDismiss, onHardwareBackPress };
|
|
31
|
+
const env = useHIG(), colors = useColors(), insets = useSafeAreaInsets();
|
|
32
|
+
const focus = useCallback((node) => { if (!node)
|
|
33
|
+
return; try {
|
|
34
|
+
const handle = findNodeHandle(node);
|
|
35
|
+
if (handle != null) {
|
|
36
|
+
AccessibilityInfo.setAccessibilityFocus(handle);
|
|
37
|
+
if (Platform.OS === 'android')
|
|
38
|
+
AccessibilityInfo.sendAccessibilityEvent(node, 'viewHoverEnter');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch { /* Detached focus targets cannot prevent dismissal. */ } }, []);
|
|
42
|
+
const requestClose = useCallback(() => {
|
|
43
|
+
if (requested.current || !latest.current.open)
|
|
44
|
+
return;
|
|
45
|
+
requested.current = true;
|
|
46
|
+
requestFrame.current = requestAnimationFrame(() => { requestFrame.current = null; if (latest.current.open)
|
|
47
|
+
requested.current = false; });
|
|
48
|
+
latest.current.onOpenChange(false);
|
|
49
|
+
}, []);
|
|
50
|
+
// Gorhom 5 marks a never-presented modal DISMISSING on dismiss() and then skips its portal render, so the sheet
|
|
51
|
+
// never appeared on the iOS Simulator or Android emulator. Only dismiss what this component presented.
|
|
52
|
+
const presented = useRef(false);
|
|
53
|
+
useEffect(() => { requested.current = false; focused.current = false; pendingSnap.current = false; if (requestFrame.current !== null) {
|
|
54
|
+
cancelAnimationFrame(requestFrame.current);
|
|
55
|
+
requestFrame.current = null;
|
|
56
|
+
} if (open) {
|
|
57
|
+
dismissed.current = false;
|
|
58
|
+
activeIndex.current = startingIndex;
|
|
59
|
+
presented.current = true;
|
|
60
|
+
if (presentation === 'inline')
|
|
61
|
+
inline.current?.snapToIndex(startingIndex);
|
|
62
|
+
else
|
|
63
|
+
sheet.current?.present();
|
|
64
|
+
}
|
|
65
|
+
else if (presented.current) {
|
|
66
|
+
presented.current = false;
|
|
67
|
+
if (presentation === 'inline')
|
|
68
|
+
inline.current?.close();
|
|
69
|
+
else
|
|
70
|
+
sheet.current?.dismiss();
|
|
71
|
+
} }, [open, presentation]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!open)
|
|
74
|
+
return;
|
|
75
|
+
if (enableDynamicSizing) {
|
|
76
|
+
activeIndex.current = 0;
|
|
77
|
+
pendingSnap.current = false;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Gorhom reacts to changed detent positions itself. Removing the active detent also needs a valid index;
|
|
81
|
+
// wait until the new geometry has reached the backend before requesting it.
|
|
82
|
+
if (activeIndex.current >= fixedSnapPoints.length || pendingSnap.current) {
|
|
83
|
+
activeIndex.current = Math.min(activeIndex.current, fixedSnapPoints.length - 1);
|
|
84
|
+
pendingSnap.current = true;
|
|
85
|
+
const index = activeIndex.current;
|
|
86
|
+
detentFrame.current = requestAnimationFrame(() => { detentFrame.current = null; pendingSnap.current = false; if (latest.current.open) {
|
|
87
|
+
activeIndex.current = index;
|
|
88
|
+
(presentation === 'inline' ? inline.current : sheet.current)?.snapToIndex(index);
|
|
89
|
+
} });
|
|
90
|
+
}
|
|
91
|
+
return () => { if (detentFrame.current !== null) {
|
|
92
|
+
cancelAnimationFrame(detentFrame.current);
|
|
93
|
+
detentFrame.current = null;
|
|
94
|
+
} };
|
|
95
|
+
}, [open, detentKey, enableDynamicSizing, presentation]);
|
|
96
|
+
useEffect(() => { if (!open)
|
|
97
|
+
return; const subscription = BackHandler.addEventListener('hardwareBackPress', () => { if (latest.current.onHardwareBackPress)
|
|
98
|
+
return latest.current.onHardwareBackPress(); if (dismissible)
|
|
99
|
+
requestClose(); return true; }); return () => subscription.remove(); }, [open, dismissible, requestClose]);
|
|
100
|
+
useEffect(() => () => { if (frame.current !== null)
|
|
101
|
+
cancelAnimationFrame(frame.current); if (requestFrame.current !== null)
|
|
102
|
+
cancelAnimationFrame(requestFrame.current); if (detentFrame.current !== null)
|
|
103
|
+
cancelAnimationFrame(detentFrame.current); }, []);
|
|
104
|
+
const backdrop = useCallback((props) => _jsx(BottomSheetBackdrop, { ...props, appearsOnIndex: 0, disappearsOnIndex: -1, pressBehavior: dismissible ? 'close' : 'none' }), [dismissible]);
|
|
105
|
+
// BottomSheetView reports intrinsic layout to Gorhom's dynamic sizing. Fixed custom content
|
|
106
|
+
// keeps a plain View so it does not replace the caller's nested scrollable registration.
|
|
107
|
+
const CustomContent = enableDynamicSizing ? BottomSheetView : View;
|
|
108
|
+
const handleChange = useCallback((index, position, type) => { if (index >= 0) {
|
|
109
|
+
activeIndex.current = index;
|
|
110
|
+
if (latest.current.open && !focused.current) {
|
|
111
|
+
focused.current = true;
|
|
112
|
+
focus(contentMode === 'custom' ? (titleRef?.current ?? heading.current) : heading.current);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else
|
|
116
|
+
requestClose(); onChange?.(index, position, type); }, [contentMode, titleRef, focus, requestClose, onChange]);
|
|
117
|
+
const handleSettledClose = useCallback(() => {
|
|
118
|
+
// An inline sheet initially mounts closed to prepare its children. That is not a dismissal.
|
|
119
|
+
if (dismissed.current && !latest.current.open)
|
|
120
|
+
return;
|
|
121
|
+
requestClose();
|
|
122
|
+
if (requestFrame.current !== null) {
|
|
123
|
+
cancelAnimationFrame(requestFrame.current);
|
|
124
|
+
requestFrame.current = null;
|
|
125
|
+
}
|
|
126
|
+
if (frame.current !== null)
|
|
127
|
+
cancelAnimationFrame(frame.current);
|
|
128
|
+
frame.current = requestAnimationFrame(() => { frame.current = null; if (latest.current.open) {
|
|
129
|
+
requested.current = false;
|
|
130
|
+
if (presentation === 'inline')
|
|
131
|
+
inline.current?.snapToIndex(activeIndex.current);
|
|
132
|
+
else {
|
|
133
|
+
focused.current = false;
|
|
134
|
+
sheet.current?.present();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (!dismissed.current) {
|
|
138
|
+
dismissed.current = true;
|
|
139
|
+
focus(latest.current.returnFocusRef?.current ?? null);
|
|
140
|
+
latest.current.onDismiss?.();
|
|
141
|
+
} });
|
|
142
|
+
}, [focus, presentation, requestClose]);
|
|
143
|
+
const inlineAccessibility = presentation === 'inline' ? { accessibilityElementsHidden: !open, importantForAccessibility: open ? 'auto' : 'no-hide-descendants', pointerEvents: open ? 'auto' : 'none' } : {};
|
|
144
|
+
const contentAccessibility = { ...inlineAccessibility, ...(presentation === 'modal' && { accessibilityViewIsModal: true, onAccessibilityEscape: requestClose }) };
|
|
145
|
+
const content = contentMode === 'custom' ? _jsxs(CustomContent, { ...contentAccessibility, accessible: false, collapsable: false, style: { ...(!enableDynamicSizing && { flex: 1, flexShrink: 1, minHeight: 0 }), direction: env.direction }, children: [!titleRef && _jsx(Heading, { ref: heading, accessible: true, accessibilityLabel: title, style: { position: 'absolute', width: 1, height: 1, overflow: 'hidden' }, children: title }), children] }) : _jsx(BottomSheetScrollView, { ...contentAccessibility, accessible: false, keyboardShouldPersistTaps: 'handled', contentContainerStyle: { padding: tokens.space.xl, paddingBottom: tokens.space.xl + (bottomInset ?? insets.bottom) }, children: _jsxs(Stack, { children: [_jsx(Heading, { ref: heading, children: title }), description && _jsx(Text, { children: description }), children, _jsx(Button, { intent: 'secondary', onPress: requestClose, children: closeLabel ?? env.messages.close ?? en.close })] }) });
|
|
146
|
+
// Expose individual children instead of grouping the sheet as one adjustable element. Gorhom forwards only
|
|
147
|
+
// basic accessibility props, so modal escape and VoiceOver scope belong on its measured or scrolling content.
|
|
148
|
+
// Inline content keeps its native state while closed, with all descendants hidden from accessibility.
|
|
149
|
+
const backendProps = { accessible: false, accessibilityLabel: title, index: presentation === 'inline' && !open ? -1 : presented.current ? Math.max(0, Math.min(activeIndex.current, detentCount - 1)) : startingIndex, snapPoints: enableDynamicSizing ? undefined : [...fixedSnapPoints], enableDynamicSizing, maxDynamicContentSize: enableDynamicSizing ? maxDynamicContentSize : undefined, enableContentPanningGesture, enablePanDownToClose: dismissible, topInset: topInset ?? insets.top, bottomInset: bottomInset ?? insets.bottom, keyboardBehavior, keyboardBlurBehavior, android_keyboardInputMode, overrideReduceMotion: env.reducedMotion ? ReduceMotion.Always : ReduceMotion.System, animateOnMount, animationConfigs, backdropComponent: backdropComponent === undefined ? backdrop : backdropComponent, handleComponent, handleStyle, backgroundComponent, containerStyle, backgroundStyle: backgroundStyle ? [{ backgroundColor: colors.surface, borderRadius: tokens.radius.xl }, backgroundStyle] : { backgroundColor: colors.surface, borderRadius: tokens.radius.xl }, handleIndicatorStyle: handleIndicatorStyle ? [{ backgroundColor: colors.muted }, handleIndicatorStyle] : { backgroundColor: colors.muted }, onChange: handleChange };
|
|
150
|
+
return presentation === 'inline' ? _jsx(BottomSheet, { ...backendProps, ref: inline, accessibilityElementsHidden: !open, importantForAccessibility: open ? 'auto' : 'no-hide-descendants', onClose: handleSettledClose, children: content }) : _jsx(BottomSheetModal, { ...backendProps, ref: sheet, enableDismissOnClose: true, stackBehavior: 'push', onDismiss: handleSettledClose, children: content });
|
|
151
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function Tabs({ label, items, value, defaultValue, onValueChange }: {
|
|
3
|
+
label: string;
|
|
4
|
+
items: readonly {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
content: React.ReactNode;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
value?: string;
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
onValueChange?: (v: string) => void;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export declare function Accordion({ title, children, open, onOpenChange }: React.PropsWithChildren<{
|
|
15
|
+
title: string;
|
|
16
|
+
open?: boolean;
|
|
17
|
+
onOpenChange?: (v: boolean) => void;
|
|
18
|
+
}>): React.JSX.Element;
|
|
19
|
+
export declare function Navigation({ label, items }: {
|
|
20
|
+
label: string;
|
|
21
|
+
items: readonly {
|
|
22
|
+
label: string;
|
|
23
|
+
id: string;
|
|
24
|
+
active?: boolean;
|
|
25
|
+
onNavigate: () => void;
|
|
26
|
+
}[];
|
|
27
|
+
}): React.JSX.Element;
|
|
28
|
+
export declare const BottomNavigation: typeof Navigation;
|
|
29
|
+
export declare function Pagination({ page, total, onPageChange }: {
|
|
30
|
+
page: number;
|
|
31
|
+
total: number;
|
|
32
|
+
onPageChange: (p: number) => void;
|
|
33
|
+
}): React.JSX.Element;
|
|
34
|
+
export declare function Search({ query, onQueryChange, results, loading, error }: {
|
|
35
|
+
query: string;
|
|
36
|
+
onQueryChange: (s: string) => void;
|
|
37
|
+
results: readonly {
|
|
38
|
+
id: string;
|
|
39
|
+
label: string;
|
|
40
|
+
onSelect: () => void;
|
|
41
|
+
}[];
|
|
42
|
+
loading?: boolean;
|
|
43
|
+
error?: string;
|
|
44
|
+
}): React.JSX.Element;
|
|
45
|
+
export declare function BackButton({ onBack }: {
|
|
46
|
+
onBack: () => void;
|
|
47
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useColors, useControllable, useHIG } from './provider.js';
|
|
6
|
+
import { Button } from './button.js';
|
|
7
|
+
import { Text, Inline, Stack } from './surface.js';
|
|
8
|
+
import { Field, SearchInput } from './field.js';
|
|
9
|
+
export function Tabs({ label, items, value, defaultValue, onValueChange }) { const colors = useColors(); const { direction } = useHIG(); const [current, set] = useControllable(value, defaultValue ?? items.find(item => !item.disabled)?.value ?? '', onValueChange); return _jsxs(View, { style: { direction, gap: 12 }, children: [_jsx(Inline, { accessibilityRole: 'tablist', accessibilityLabel: label, children: items.map(i => _jsx(Pressable, { accessibilityRole: 'tab', "aria-selected": current === i.value, "aria-disabled": !!i.disabled, accessibilityState: { selected: current === i.value, disabled: !!i.disabled }, disabled: i.disabled, onPress: () => { if (!i.disabled)
|
|
10
|
+
set(i.value); }, style: ({ pressed }) => ({ minHeight: 48, paddingHorizontal: 20, paddingVertical: 12, borderRadius: 9999, alignItems: 'center', justifyContent: 'center', backgroundColor: current === i.value ? colors.action : colors.nested, opacity: i.disabled ? .5 : pressed ? .85 : 1 }), children: _jsx(Text, { style: { fontWeight: '600', color: current === i.value ? colors.onAction : colors.text }, children: i.label }) }, i.value)) }), items.find(i => i.value === current)?.content] }); }
|
|
11
|
+
export function Accordion({ title, children, open, onOpenChange }) { const [current, set] = useControllable(open, false, onOpenChange, 'disclosure'); return _jsxs(View, { children: [_jsx(Button, { intent: 'secondary', suppressFeedback: true, accessibilityState: { expanded: current }, onPress: () => set(!current), children: title }), current && children] }); }
|
|
12
|
+
export function Navigation({ label, items }) { const colors = useColors(); return _jsx(Stack, { accessibilityLabel: label, style: { gap: 4 }, children: items.map(i => _jsx(Button, { fullWidth: true, intent: 'ghost', accessibilityState: { selected: !!i.active }, onPress: i.onNavigate, style: { alignItems: 'flex-start', backgroundColor: i.active ? colors.nested : 'transparent' }, children: i.label }, i.id)) }); }
|
|
13
|
+
export const BottomNavigation = Navigation;
|
|
14
|
+
export function Pagination({ page, total, onPageChange }) { const { locale, messages } = useHIG(); return _jsxs(Inline, { children: [_jsx(Button, { intent: 'secondary', disabled: page <= 1, onPress: () => onPageChange(page - 1), children: messages.previous ?? en.previous }), _jsx(Text, { children: (messages.pageOf ?? en.pageOf)(formatNumber(page, locale), formatNumber(total, locale)) }), _jsx(Button, { intent: 'secondary', disabled: page >= total, onPress: () => onPageChange(page + 1), children: messages.next ?? en.next })] }); }
|
|
15
|
+
export function Search({ query, onQueryChange, results, loading, error }) { const { locale, messages } = useHIG(); return _jsxs(Stack, { children: [_jsx(Field, { label: messages.search ?? en.search, children: _jsx(SearchInput, { value: query, onChangeText: onQueryChange }) }), _jsx(Text, { accessibilityLiveRegion: 'polite', children: loading ? messages.searching ?? en.searching : error ?? (results.length ? (messages.resultCount ?? en.resultCount)(results.length, locale) : messages.noResults ?? en.noResults) }), !loading && !error && results.map(r => _jsx(Button, { intent: 'ghost', onPress: r.onSelect, children: r.label }, r.id))] }); }
|
|
16
|
+
export function BackButton({ onBack }) { const { messages } = useHIG(); return _jsx(Button, { intent: 'secondary', onPress: onBack, children: messages.back ?? en.back }); }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { GestureResponderEvent, ModalProps, StyleProp, ViewProps, ViewStyle } from 'react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Text as RNText, TextInput, View } from 'react-native';
|
|
4
|
+
export interface DialogProps {
|
|
5
|
+
open: boolean;
|
|
6
|
+
onOpenChange: (open: boolean) => void;
|
|
7
|
+
title: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
initialFocusRef?: React.RefObject<React.ComponentRef<typeof View> | React.ComponentRef<typeof RNText> | React.ComponentRef<typeof TextInput> | null>;
|
|
11
|
+
returnFocusRef?: React.RefObject<React.ComponentRef<typeof View> | React.ComponentRef<typeof RNText> | React.ComponentRef<typeof TextInput> | null>;
|
|
12
|
+
/** Close button text and accessible name; defaults to HIGProvider `messages.close`. */ closeLabel?: string;
|
|
13
|
+
/** Custom content owns its visible heading, actions, padding and scrolling. The native Modal remains HIG-owned. */ contentMode?: 'default' | 'custom';
|
|
14
|
+
/** Accessible caller heading used when custom content renders the title. Otherwise HIG keeps a visually hidden title. */ titleRef?: React.RefObject<React.ComponentRef<typeof View> | React.ComponentRef<typeof RNText> | React.ComponentRef<typeof TextInput> | null>;
|
|
15
|
+
/** Custom-mode stage inside the Modal, for example GestureHandlerRootView on Android. */ stageComponent?: React.ComponentType<ViewProps>;
|
|
16
|
+
stageStyle?: StyleProp<ViewStyle>;
|
|
17
|
+
stageTestID?: string;
|
|
18
|
+
/** Custom-mode backdrop, including the host's dismissal policy and decoration. */ backdrop?: React.ReactNode;
|
|
19
|
+
/** Custom-mode surface layout; no implicit padding or scroll view is added. */ contentStyle?: StyleProp<ViewStyle>;
|
|
20
|
+
/** Identifies the actual modal content surface in either mode. */ testID?: string;
|
|
21
|
+
/** Native Modal animation. Reduced motion always selects `none`; the default stays `none`. */ animationType?: ModalProps['animationType'];
|
|
22
|
+
}
|
|
23
|
+
export declare function Dialog({ open, onOpenChange, title, description, children, initialFocusRef, returnFocusRef, closeLabel, contentMode, titleRef, stageComponent: Stage, stageStyle, stageTestID, backdrop, contentStyle, testID, animationType }: DialogProps): React.JSX.Element;
|
|
24
|
+
export declare const Sheet: typeof Dialog;
|
|
25
|
+
export declare const AlertDialog: typeof Dialog;
|
|
26
|
+
export declare function Menu({ label, items, closeLabel }: {
|
|
27
|
+
label: string;
|
|
28
|
+
items: readonly {
|
|
29
|
+
label: string;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
onSelect: (event: GestureResponderEvent) => void;
|
|
32
|
+
}[]; /** Close button text and accessible name; defaults to HIGProvider `messages.close`. */
|
|
33
|
+
closeLabel?: string;
|
|
34
|
+
}): React.JSX.Element;
|
|
35
|
+
/** Touch alternative to popover/hover tooltip: persistent help text. */
|
|
36
|
+
export declare function HelpText({ children }: React.PropsWithChildren): React.JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
3
|
+
import { useColors, useHIG } from './provider.js';
|
|
4
|
+
import React, { useEffect, useRef, useId, useCallback } from 'react';
|
|
5
|
+
import { Modal, KeyboardAvoidingView, Platform, ScrollView, AccessibilityInfo, findNodeHandle, View } from 'react-native';
|
|
6
|
+
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
7
|
+
import { Heading, Text, Stack } from './surface.js';
|
|
8
|
+
import { Button } from './button.js';
|
|
9
|
+
/** Native focus requests remain best effort; host supplies a live trigger ref for restoration. */
|
|
10
|
+
/** Android TalkBack ignores the TYPE_VIEW_FOCUSED event behind setAccessibilityFocus in RN 0.81 Fabric (emulator: focus fell back to the first screen element); a hover-enter event moves its focus. */
|
|
11
|
+
function focusNative(target) { if (Platform.OS === 'web' || !target)
|
|
12
|
+
return; const handle = findNodeHandle(target); if (handle == null)
|
|
13
|
+
return; AccessibilityInfo.setAccessibilityFocus(handle); if (Platform.OS === 'android')
|
|
14
|
+
AccessibilityInfo.sendAccessibilityEvent(target, 'viewHoverEnter'); }
|
|
15
|
+
/** React Native's iOS Modal defaults to portrait only; opening an overlay must not rotate a landscape host. */
|
|
16
|
+
const overlayOrientations = ['portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right'];
|
|
17
|
+
export function Dialog({ open, onOpenChange, title, description, children, initialFocusRef, returnFocusRef, closeLabel, contentMode = 'default', titleRef, stageComponent: Stage = View, stageStyle, stageTestID, backdrop, contentStyle, testID, animationType = 'none' }) {
|
|
18
|
+
const { messages, reducedMotion, direction } = useHIG();
|
|
19
|
+
const colors = useColors();
|
|
20
|
+
const heading = useRef(null);
|
|
21
|
+
const previous = useRef(open);
|
|
22
|
+
const latest = useRef({ open, returnFocusRef });
|
|
23
|
+
latest.current = { open, returnFocusRef };
|
|
24
|
+
const returnPending = useRef(false), frame = useRef(undefined);
|
|
25
|
+
const resolvedAnimation = reducedMotion ? 'none' : animationType;
|
|
26
|
+
const restoreFocus = useCallback(() => {
|
|
27
|
+
if (latest.current.open || !returnPending.current || frame.current !== undefined)
|
|
28
|
+
return;
|
|
29
|
+
frame.current = requestAnimationFrame(() => { frame.current = undefined; if (!latest.current.open && returnPending.current) {
|
|
30
|
+
returnPending.current = false;
|
|
31
|
+
focusNative(latest.current.returnFocusRef?.current ?? null);
|
|
32
|
+
} });
|
|
33
|
+
}, []);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const wasOpen = previous.current;
|
|
36
|
+
previous.current = open;
|
|
37
|
+
if (frame.current !== undefined) {
|
|
38
|
+
cancelAnimationFrame(frame.current);
|
|
39
|
+
frame.current = undefined;
|
|
40
|
+
}
|
|
41
|
+
if (open)
|
|
42
|
+
returnPending.current = false;
|
|
43
|
+
else {
|
|
44
|
+
if (wasOpen)
|
|
45
|
+
returnPending.current = true;
|
|
46
|
+
if (Platform.OS !== 'ios' || resolvedAnimation === 'none')
|
|
47
|
+
restoreFocus();
|
|
48
|
+
}
|
|
49
|
+
}, [open, resolvedAnimation, restoreFocus]);
|
|
50
|
+
useEffect(() => () => { if (frame.current !== undefined)
|
|
51
|
+
cancelAnimationFrame(frame.current); returnPending.current = false; }, []);
|
|
52
|
+
const modal = _jsx(Modal, { visible: open, transparent: true, animationType: resolvedAnimation, supportedOrientations: overlayOrientations, onShow: () => { if (latest.current.open)
|
|
53
|
+
focusNative(initialFocusRef?.current ?? (contentMode === 'custom' ? titleRef?.current : null) ?? heading.current); }, onDismiss: restoreFocus, onRequestClose: () => onOpenChange(false), accessibilityViewIsModal: true, children: contentMode === 'custom' ? _jsxs(Stage, { style: [{ flex: 1, backgroundColor: '#000b', justifyContent: 'center', direction }, stageStyle], testID: stageTestID, children: [backdrop, _jsxs(View, { accessible: false, accessibilityLabel: title, accessibilityViewIsModal: true, onAccessibilityEscape: () => onOpenChange(false), collapsable: false, style: [{ direction }, contentStyle], testID: testID, children: [!titleRef && _jsx(Heading, { ref: heading, accessible: true, accessibilityLabel: title, style: { position: 'absolute', width: 1, height: 1, overflow: 'hidden' }, children: title }), children] })] }) : _jsx(SafeAreaView, { style: { flex: 1, backgroundColor: '#000b', justifyContent: 'center' }, children: _jsx(KeyboardAvoidingView, { behavior: Platform.OS === 'ios' ? 'padding' : 'height', style: { maxHeight: '90%' }, children: _jsx(ScrollView, { testID: testID, keyboardShouldPersistTaps: 'handled', contentContainerStyle: { padding: 24, backgroundColor: colors.surface, borderRadius: 14 }, children: _jsxs(Stack, { children: [_jsx(Heading, { ref: heading, children: title }), description !== undefined && _jsx(Text, { children: description }), children, _jsx(Button, { intent: 'secondary', suppressFeedback: true, onPress: () => onOpenChange(false), children: closeLabel ?? messages.close ?? en.close })] }) }) }) }) });
|
|
54
|
+
return modal;
|
|
55
|
+
}
|
|
56
|
+
export const Sheet = Dialog;
|
|
57
|
+
export const AlertDialog = Dialog;
|
|
58
|
+
export function Menu({ label, items, closeLabel }) { const [open, setOpen] = React.useState(false); const { feedback, messages } = useHIG(); const id = useId(); const sequence = useRef(0); const trigger = useRef(null); return _jsxs(_Fragment, { children: [_jsx(Button, { ref: trigger, intent: 'secondary', suppressFeedback: true, onPress: () => setOpen(true), children: label }), _jsx(Dialog, { open: open, onOpenChange: setOpen, title: label, description: messages.menuDescription ?? en.menuDescription, closeLabel: closeLabel, returnFocusRef: trigger, children: items.map((item, i) => _jsx(Button, { disabled: item.disabled, suppressFeedback: true, intent: 'secondary', onPress: event => { if (item.disabled)
|
|
59
|
+
return; item.onSelect(event); if (event.isDefaultPrevented())
|
|
60
|
+
return; setOpen(false); try {
|
|
61
|
+
feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent: 'selection', origin: 'native' });
|
|
62
|
+
}
|
|
63
|
+
catch { /* Optional feedback cannot alter the action. */ } }, children: item.label }, i)) })] }); }
|
|
64
|
+
/** Touch alternative to popover/hover tooltip: persistent help text. */
|
|
65
|
+
export function HelpText({ children }) { return _jsx(Text, { children: children }); }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { FeedbackSink, FeedbackIntent } from '@bloxwap/hig/contracts/feedback';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { nativeSrgb } from '@bloxwap/hig/tokens';
|
|
4
|
+
import { type Environment } from '@bloxwap/hig/contracts';
|
|
5
|
+
import { type HIGMessages } from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
export type { HIGMessages } from '@bloxwap/hig/contracts/messages';
|
|
7
|
+
/** Direction of a host-supplied locale (for example expo-localization's `getLocales()[0]`) for `HIGProvider direction`; see #86. */
|
|
8
|
+
export { localeDirection, type HostLocale } from '@bloxwap/hig/contracts';
|
|
9
|
+
/** Colour space the host paints React Native colours in. `display-p3` is for iOS hosts whose React Native default colour space is Display P3 (an app delegate `defaultColorSpace()` override); there HIG paints its generated `nativeDisplayP3` table (`nativeColors.iosDisplayP3`). Android and web stay sRGB, because HIG publishes no other table for them. */
|
|
10
|
+
export type HIGColorSpace = 'srgb' | 'display-p3';
|
|
11
|
+
/** Semantic token roles every native component paints from. */
|
|
12
|
+
export type HIGColorRole = keyof typeof nativeSrgb;
|
|
13
|
+
/** Native colour roles, including any provider primary colour override. */
|
|
14
|
+
export type HIGColors = Readonly<Record<HIGColorRole, string>>;
|
|
15
|
+
/** HIG's table for a colour space and platform: `nativeDisplayP3` for `display-p3` on iOS, sRGB everywhere else (including unknown values from untyped JS). */
|
|
16
|
+
export declare function colorTable(colorSpace?: HIGColorSpace, os?: string): HIGColors;
|
|
17
|
+
export interface HIGContext extends Environment {
|
|
18
|
+
primaryColor?: string;
|
|
19
|
+
onAccepted?: (id: string) => void;
|
|
20
|
+
feedback?: FeedbackSink;
|
|
21
|
+
fontFamily?: string;
|
|
22
|
+
fontFamilies?: Readonly<Record<string, string>>; /** Registered static companion faces by script and weight. Text selects the detected script and nearest registered weight. */
|
|
23
|
+
fontFamiliesByScript?: Readonly<Partial<Record<'latin' | 'ko' | 'zh', Readonly<Record<string, string>>>>>; /** Registered monospace face for code/commands, e.g. BloxwapMonoRegular. */
|
|
24
|
+
monoFontFamily?: string; /** Default Dynamic Type / font-scale cap for HIG Text; a Text prop overrides it. Leave unset for prose. */
|
|
25
|
+
maxFontSizeMultiplier?: number; /** Per-script letter spacing in em for Korean and Chinese companion faces; overrides `scriptLetterSpacing`. */
|
|
26
|
+
letterSpacingByScript?: Readonly<Partial<Record<'ko' | 'zh', number>>>; /** Colour space HIG paints in; defaults to `srgb` and is inherited by nested providers. Read the resolved table with `useColors()`. */
|
|
27
|
+
colorSpace: HIGColorSpace; /** Host translations of built-in copy, merged through nested providers. Components fall back to the English export per key; read the full resolved catalog with `useMessages()`. */
|
|
28
|
+
messages: Readonly<Partial<HIGMessages>>;
|
|
29
|
+
}
|
|
30
|
+
export interface HIGProviderProps extends Partial<Omit<HIGContext, 'messages'>> {
|
|
31
|
+
colorSpace?: HIGColorSpace; /** Translations for HIG's built-in strings; omitted keys fall back to the enclosing provider, then English. */
|
|
32
|
+
messages?: Partial<HIGMessages>;
|
|
33
|
+
}
|
|
34
|
+
/** Direction defaults to the OS layout direction (I18nManager) so HIG roots never force LTR inside an RTL app. React Native 0.83 Android does not report a per-app RTL locale through I18nManager (#86): RTL hosts pass `direction={localeDirection(getLocales()[0])}`. Hosts that disallow RTL leave `direction` unset. */
|
|
35
|
+
export declare function HIGProvider({ children, density, locale, direction, reducedMotion, onAccepted, feedback, fontFamily, fontFamilies, fontFamiliesByScript, monoFontFamily, maxFontSizeMultiplier, letterSpacingByScript, colorSpace, primaryColor, messages }: React.PropsWithChildren<HIGProviderProps>): React.JSX.Element;
|
|
36
|
+
export declare const useHIG: () => HIGContext;
|
|
37
|
+
/** The nearest HIGProvider's colour table (sRGB by default). Every HIG native component paints through this; hosts may read it for their own views. */
|
|
38
|
+
export declare function useColors(): HIGColors;
|
|
39
|
+
/** Approved Bloxwap brand colours in the host's colour space, independent of a product accent. */
|
|
40
|
+
export declare function useBrandColors(): HIGColors;
|
|
41
|
+
/** Complete built-in copy for the nearest HIGProvider: host translations over the English defaults. */
|
|
42
|
+
export declare function useMessages(): HIGMessages;
|
|
43
|
+
export declare function useControllable<T>(value: T | undefined, initial: T, onChange?: (value: T) => void, intent?: FeedbackIntent): [T, (next: T) => void];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useState, useRef, useId } from 'react';
|
|
3
|
+
import { AccessibilityInfo, I18nManager, Platform } from 'react-native';
|
|
4
|
+
import { nativeSrgb, nativeDisplayP3, resolvePrimaryColor } from '@bloxwap/hig/tokens';
|
|
5
|
+
import { defaultEnvironment } from '@bloxwap/hig/contracts';
|
|
6
|
+
import { defaultMessages, resolveMessages } from '@bloxwap/hig/contracts/messages';
|
|
7
|
+
/** Direction of a host-supplied locale (for example expo-localization's `getLocales()[0]`) for `HIGProvider direction`; see #86. */
|
|
8
|
+
export { localeDirection } from '@bloxwap/hig/contracts';
|
|
9
|
+
/** HIG's table for a colour space and platform: `nativeDisplayP3` for `display-p3` on iOS, sRGB everywhere else (including unknown values from untyped JS). */
|
|
10
|
+
export function colorTable(colorSpace, os = Platform.OS) { return colorSpace === 'display-p3' && os === 'ios' ? nativeDisplayP3 : nativeSrgb; }
|
|
11
|
+
const Context = createContext({ ...defaultEnvironment, direction: I18nManager.isRTL ? 'rtl' : 'ltr', colorSpace: 'srgb', messages: {} });
|
|
12
|
+
const ColorsContext = createContext(nativeSrgb);
|
|
13
|
+
/** Direction defaults to the OS layout direction (I18nManager) so HIG roots never force LTR inside an RTL app. React Native 0.83 Android does not report a per-app RTL locale through I18nManager (#86): RTL hosts pass `direction={localeDirection(getLocales()[0])}`. Hosts that disallow RTL leave `direction` unset. */
|
|
14
|
+
export function HIGProvider({ children, density = 'comfortable', locale = 'en-US', direction = I18nManager.isRTL ? 'rtl' : 'ltr', reducedMotion, onAccepted, feedback, fontFamily, fontFamilies, fontFamiliesByScript, monoFontFamily, maxFontSizeMultiplier, letterSpacingByScript, colorSpace, primaryColor, messages }) {
|
|
15
|
+
const parent = useContext(Context);
|
|
16
|
+
const inherited = parent.messages;
|
|
17
|
+
const resolved = useMemo(() => resolveMessages(inherited, messages), [inherited, messages]);
|
|
18
|
+
const accent = primaryColor ?? parent.primaryColor;
|
|
19
|
+
const normalized = useMemo(() => accent === undefined ? undefined : resolvePrimaryColor(accent).action, [accent]);
|
|
20
|
+
const space = colorSpace ?? parent.colorSpace;
|
|
21
|
+
const baseColors = colorTable(space);
|
|
22
|
+
const colors = useMemo(() => normalized === undefined ? baseColors : { ...baseColors, ...resolvePrimaryColor(normalized, space === 'display-p3' && Platform.OS === 'ios' ? 'display-p3' : 'srgb') }, [baseColors, space, normalized]);
|
|
23
|
+
const [osReduced, setOSReduced] = useState(false);
|
|
24
|
+
useEffect(() => { let alive = true; void AccessibilityInfo.isReduceMotionEnabled().then(v => { if (alive)
|
|
25
|
+
setOSReduced(v); }).catch(() => { }); const sub = AccessibilityInfo.addEventListener('reduceMotionChanged', setOSReduced); return () => { alive = false; sub.remove(); }; }, []);
|
|
26
|
+
return _jsx(Context.Provider, { value: { density, locale, direction, reducedMotion: reducedMotion ?? osReduced, onAccepted, feedback, fontFamily, fontFamilies, fontFamiliesByScript: fontFamiliesByScript ?? parent.fontFamiliesByScript, monoFontFamily, maxFontSizeMultiplier, letterSpacingByScript, colorSpace: space, primaryColor: normalized, messages: resolved }, children: _jsx(ColorsContext.Provider, { value: colors, children: children }) });
|
|
27
|
+
}
|
|
28
|
+
export const useHIG = () => useContext(Context);
|
|
29
|
+
/** The nearest HIGProvider's colour table (sRGB by default). Every HIG native component paints through this; hosts may read it for their own views. */
|
|
30
|
+
export function useColors() { return useContext(ColorsContext); }
|
|
31
|
+
/** Approved Bloxwap brand colours in the host's colour space, independent of a product accent. */
|
|
32
|
+
export function useBrandColors() { return colorTable(useContext(Context).colorSpace); }
|
|
33
|
+
/** Complete built-in copy for the nearest HIGProvider: host translations over the English defaults. */
|
|
34
|
+
export function useMessages() { const overrides = useContext(Context).messages; return useMemo(() => resolveMessages({ ...defaultMessages }, overrides), [overrides]); }
|
|
35
|
+
export function useControllable(value, initial, onChange, intent = 'selection') {
|
|
36
|
+
const [internal, setInternal] = useState(initial);
|
|
37
|
+
const current = value === undefined ? internal : value;
|
|
38
|
+
const { feedback } = useHIG();
|
|
39
|
+
const id = useId();
|
|
40
|
+
const sequence = useRef(0);
|
|
41
|
+
const pending = useRef(null);
|
|
42
|
+
useEffect(() => { const request = pending.current; if (!request)
|
|
43
|
+
return; pending.current = null; if (Object.is(current, request.value)) {
|
|
44
|
+
try {
|
|
45
|
+
feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent, origin: 'native' });
|
|
46
|
+
}
|
|
47
|
+
catch { /* Effects remain optional. */ }
|
|
48
|
+
} });
|
|
49
|
+
return [current, (next) => { if (Object.is(current, next))
|
|
50
|
+
return; pending.current = { value: next }; if (value === undefined)
|
|
51
|
+
setInternal(next); onChange?.(next); }];
|
|
52
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChoicesProps } from './selection-types.js';
|
|
3
|
+
export declare function RadioGroup({ label, options, value, defaultValue, disabled, onValueChange }: ChoicesProps): React.JSX.Element;
|
|
4
|
+
/** Equal-width choices with one interruptible selection indicator. */
|
|
5
|
+
export declare function SegmentedControl({ label, options, value, defaultValue, disabled, onValueChange }: ChoicesProps): React.JSX.Element;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Animated, Easing, Platform, Pressable, View } from 'react-native';
|
|
4
|
+
import { tokens } from '@bloxwap/hig/tokens';
|
|
5
|
+
import { useControllable, useColors, useHIG } from './provider.js';
|
|
6
|
+
import { Text } from './surface.js';
|
|
7
|
+
export function RadioGroup({ label, options, value, defaultValue = '', disabled, onValueChange }) {
|
|
8
|
+
const [current, set] = useControllable(value, defaultValue, onValueChange);
|
|
9
|
+
const { direction, locale } = useHIG();
|
|
10
|
+
const colors = useColors();
|
|
11
|
+
return _jsxs(View, { accessibilityRole: 'radiogroup', accessibilityLabel: label, style: { direction }, children: [_jsx(Text, { children: label }), options.map(o => {
|
|
12
|
+
const blocked = !!disabled || !!o.disabled;
|
|
13
|
+
const activate = () => { if (!blocked)
|
|
14
|
+
set(o.value); };
|
|
15
|
+
return _jsxs(Pressable, { accessible: true, accessibilityRole: 'radio', "aria-checked": current === o.value, "aria-disabled": blocked, accessibilityLabel: o.label, accessibilityHint: o.description, accessibilityLanguage: o.lang, accessibilityState: { checked: current === o.value, disabled: blocked }, accessibilityActions: [{ name: 'activate' }], disabled: blocked, onPress: activate, onAccessibilityAction: event => { if (event.nativeEvent.actionName === 'activate')
|
|
16
|
+
activate(); }, style: { minHeight: 48, paddingVertical: 12, flexDirection: 'row', alignItems: 'center', gap: 12, opacity: blocked ? 0.5 : 1 }, children: [_jsx(Text, { accessible: false, children: current === o.value ? '●' : '○' }), _jsxs(View, { style: { flex: 1 }, children: [_jsx(Text, { accessible: false, accessibilityLanguage: o.lang, children: o.label }), o.description !== undefined && _jsx(Text, { accessible: false, accessibilityLanguage: locale, style: { color: colors.muted, fontSize: 14, lineHeight: 20 }, children: o.description })] })] }, o.value);
|
|
17
|
+
})] });
|
|
18
|
+
}
|
|
19
|
+
/** Equal-width choices with one interruptible selection indicator. */
|
|
20
|
+
export function SegmentedControl({ label, options, value, defaultValue = '', disabled, onValueChange }) {
|
|
21
|
+
const [current, set] = useControllable(value, defaultValue, onValueChange);
|
|
22
|
+
const { direction, locale, reducedMotion } = useHIG();
|
|
23
|
+
const colors = useColors();
|
|
24
|
+
const [width, setWidth] = useState(0);
|
|
25
|
+
const translateX = useRef(new Animated.Value(0)).current;
|
|
26
|
+
const selected = options.findIndex(option => option.value === current), count = options.length;
|
|
27
|
+
const segmentWidth = count > 0 ? Math.max(0, (width - (count - 1) * 4) / count) : 0;
|
|
28
|
+
const target = selected >= 0 ? (direction === 'rtl' ? -1 : 1) * selected * (segmentWidth + 4) : 0;
|
|
29
|
+
// RN Web resolves `start` through its own locale context rather than this View's direction.
|
|
30
|
+
const anchor = Platform.OS === 'web' ? (direction === 'rtl' ? { right: 0 } : { left: 0 }) : { start: 0 };
|
|
31
|
+
const previous = useRef(null);
|
|
32
|
+
useLayoutEffect(() => {
|
|
33
|
+
const old = previous.current;
|
|
34
|
+
previous.current = { selected, width, count, direction };
|
|
35
|
+
// Initial layout, rotation, option-count changes and reduced motion snap into place.
|
|
36
|
+
// A new selection interrupts the running animation at its current position.
|
|
37
|
+
if (reducedMotion || !old || old.selected === selected || old.selected < 0 || selected < 0 || old.width !== width || old.count !== count || old.direction !== direction) {
|
|
38
|
+
translateX.stopAnimation();
|
|
39
|
+
translateX.setValue(target);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const animation = Animated.timing(translateX, { toValue: target, duration: tokens.motion.base, easing: Easing.bezier(...tokens.easing.standard), useNativeDriver: Platform.OS !== 'web', isInteraction: false });
|
|
43
|
+
animation.start();
|
|
44
|
+
return () => animation.stop();
|
|
45
|
+
}, [selected, width, count, direction, reducedMotion, target, translateX]);
|
|
46
|
+
return _jsxs(View, { accessibilityRole: 'radiogroup', accessibilityLabel: label, style: { direction, gap: 8 }, children: [_jsx(Text, { style: { fontWeight: '600' }, children: label }), _jsx(View, { style: { padding: 4, borderRadius: 9999, backgroundColor: colors.nested }, children: _jsxs(View, { onLayout: event => setWidth(event.nativeEvent.layout.width), style: { flexDirection: 'row', gap: 4 }, children: [selected >= 0 && width > 0 && _jsx(Animated.View, { pointerEvents: 'none', accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants', style: { position: 'absolute', ...anchor, top: 0, bottom: 0, width: segmentWidth, borderRadius: 9999, backgroundColor: colors.surface, opacity: disabled || options[selected].disabled ? 0.5 : 1, transform: [{ translateX }] } }), options.map(option => {
|
|
47
|
+
const checked = current === option.value, blocked = !!disabled || !!option.disabled;
|
|
48
|
+
const activate = () => { if (!blocked)
|
|
49
|
+
set(option.value); };
|
|
50
|
+
return _jsxs(Pressable, { accessible: true, accessibilityRole: 'radio', accessibilityLabel: option.label, accessibilityHint: option.description, accessibilityLanguage: option.lang, "aria-checked": checked, "aria-disabled": blocked, accessibilityState: { checked, disabled: blocked }, accessibilityActions: [{ name: 'activate' }], disabled: blocked, onPress: activate, onAccessibilityAction: event => { if (event.nativeEvent.actionName === 'activate')
|
|
51
|
+
activate(); }, style: { flex: 1, minWidth: 0, minHeight: 48, paddingHorizontal: 12, paddingVertical: 8, alignItems: 'stretch', justifyContent: 'center', borderRadius: 9999, opacity: blocked ? 0.5 : 1 }, children: [_jsx(Text, { accessible: false, accessibilityLanguage: option.lang, style: { color: checked ? colors.text : colors.muted, fontWeight: '500', textAlign: 'center' }, children: option.label }), option.description !== undefined && _jsx(Text, { accessible: false, accessibilityLanguage: locale, style: { color: colors.muted, fontSize: 14, lineHeight: 20, textAlign: 'center' }, children: option.description })] }, option.value);
|
|
52
|
+
})] }) })] });
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function MarketRow({ symbol, name, price, change, onSelect }: {
|
|
3
|
+
symbol: string;
|
|
4
|
+
name: string;
|
|
5
|
+
price: number | null;
|
|
6
|
+
change: number | null;
|
|
7
|
+
onSelect: () => void;
|
|
8
|
+
}): React.JSX.Element;
|
|
9
|
+
export declare function BalanceCard({ label, balance, stale }: {
|
|
10
|
+
label: string;
|
|
11
|
+
balance: number | null;
|
|
12
|
+
stale?: boolean;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export declare function TradeEntry({ asset, amount, onAmountChange, onConfirm, busy, error, available }: {
|
|
15
|
+
asset: string;
|
|
16
|
+
amount: string;
|
|
17
|
+
onAmountChange: (v: string) => void;
|
|
18
|
+
onConfirm: () => void;
|
|
19
|
+
busy?: boolean;
|
|
20
|
+
error?: string;
|
|
21
|
+
available: string;
|
|
22
|
+
}): React.JSX.Element;
|
|
23
|
+
export declare function InstallCommand({ command, onCopy }: {
|
|
24
|
+
command: string;
|
|
25
|
+
onCopy: () => Promise<void> | void;
|
|
26
|
+
}): React.JSX.Element;
|
|
27
|
+
export declare function CodeWindow({ language, children }: React.PropsWithChildren<{
|
|
28
|
+
language: string;
|
|
29
|
+
}>): React.JSX.Element;
|
|
30
|
+
export declare function MarketingHero({ title, description, href, cta }: {
|
|
31
|
+
title: string;
|
|
32
|
+
description: string;
|
|
33
|
+
href: string;
|
|
34
|
+
cta: string;
|
|
35
|
+
}): React.JSX.Element;
|
|
36
|
+
export declare function ActivityList({ items }: {
|
|
37
|
+
items: readonly {
|
|
38
|
+
id: string;
|
|
39
|
+
label: string;
|
|
40
|
+
status: string;
|
|
41
|
+
}[];
|
|
42
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useColors, useHIG } from './provider.js';
|
|
6
|
+
import { Button, Link } from './button.js';
|
|
7
|
+
import { Surface, Stack, Heading, Text } from './surface.js';
|
|
8
|
+
import { Field, AmountInput } from './field.js';
|
|
9
|
+
import { Dialog } from './overlay.js';
|
|
10
|
+
import { Row, Usd, Percent, List } from './data.js';
|
|
11
|
+
export function MarketRow({ symbol, name, price, change, onSelect }) { return _jsxs(Row, { children: [_jsxs(Button, { intent: 'ghost', onPress: onSelect, children: [name, " (", symbol, ")"] }), _jsx(Usd, { value: price }), _jsx(Percent, { value: change })] }); }
|
|
12
|
+
export function BalanceCard({ label, balance, stale }) { const colors = useColors(); return _jsxs(Surface, { style: { gap: 8 }, children: [_jsx(Text, { style: { color: colors.muted, fontSize: 14, lineHeight: 21 }, children: label }), _jsx(Usd, { value: balance, stale: stale, style: { fontSize: 24, lineHeight: 30, fontWeight: '600' } })] }); }
|
|
13
|
+
export function TradeEntry({ asset, amount, onAmountChange, onConfirm, busy, error, available }) { const { messages } = useHIG(); const [review, setReview] = useState(false); return _jsx(Surface, { children: _jsxs(Stack, { children: [_jsx(Heading, { children: (messages.reviewAssetOrder ?? en.reviewAssetOrder)(asset) }), _jsx(Field, { label: (messages.amountInAsset ?? en.amountInAsset)(asset), description: (messages.availableAmount ?? en.availableAmount)(available), error: error, children: _jsx(AmountInput, { value: amount, onChangeText: onAmountChange, editable: !busy }) }), _jsx(Button, { fullWidth: true, disabled: !amount || !!error, busy: busy, onPress: () => setReview(true), children: messages.reviewOrder ?? en.reviewOrder }), _jsxs(Dialog, { open: review, onOpenChange: setReview, title: messages.confirmOrder ?? en.confirmOrder, description: (messages.confirmOrderDescription ?? en.confirmOrderDescription)(amount, asset), children: [_jsx(Button, { busy: busy, disabled: !!error, onPress: onConfirm, children: messages.confirmOrder ?? en.confirmOrder }), error && _jsx(Text, { accessibilityLiveRegion: 'polite', children: error })] })] }) }); }
|
|
14
|
+
/** Code and commands stay monospace and left-to-right inside RTL roots. */
|
|
15
|
+
function useCodeStyle() { const env = useHIG(); return { fontFamily: env.monoFontFamily ?? Platform.select({ ios: 'Menlo', default: 'monospace' }), writingDirection: 'ltr', textAlign: 'left' }; }
|
|
16
|
+
export function InstallCommand({ command, onCopy }) { const { messages } = useHIG(); const [status, setStatus] = useState(''); const code = useCodeStyle(); return _jsxs(Surface, { children: [_jsx(Text, { selectable: true, style: code, children: command }), _jsx(Button, { intent: 'secondary', onPress: () => { Promise.resolve().then(onCopy).then(() => setStatus(messages.copied ?? en.copied)).catch(() => setStatus(messages.copyFailed ?? en.copyFailed)); }, children: messages.copyInstallCommand ?? en.copyInstallCommand }), _jsx(Text, { accessibilityLiveRegion: 'polite', accessibilityElementsHidden: !status, children: status })] }); }
|
|
17
|
+
export function CodeWindow({ language, children }) { const code = useCodeStyle(); return _jsxs(Surface, { children: [_jsx(Text, { children: language }), _jsx(Text, { selectable: true, style: code, children: children })] }); }
|
|
18
|
+
export function MarketingHero({ title, description, href, cta }) { return _jsxs(Stack, { children: [_jsx(Heading, { children: title }), _jsx(Text, { children: description }), _jsx(Link, { href: href, children: cta })] }); }
|
|
19
|
+
export function ActivityList({ items }) { const { messages } = useHIG(); return _jsx(List, { items: items, keyFor: i => i.id, render: i => _jsxs(Row, { children: [_jsx(Text, { children: i.label }), _jsx(Text, { children: i.status })] }), empty: messages.noActivity ?? en.noActivity }); }
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HIGColors } from './provider.js';
|
|
2
|
+
/** Semantic token roles a host may choose for a control or status accent. Raw colours are not accepted, so product palettes are never copied into HIG consumers. */
|
|
3
|
+
export declare const accentRoles: readonly ['action', 'positive', 'negative', 'warning', 'info', 'buy', 'sell'];
|
|
4
|
+
export type AccentRole = typeof accentRoles[number];
|
|
5
|
+
/** Resolves a role to its colour in the provider's table (`useColors()`); anything outside the role list (for example a hex string from untyped JS) falls back to the component default. */
|
|
6
|
+
export declare function roleColor(role: unknown, fallback: AccentRole, colors: HIGColors): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Semantic token roles a host may choose for a control or status accent. Raw colours are not accepted, so product palettes are never copied into HIG consumers. */
|
|
2
|
+
export const accentRoles = ['action', 'positive', 'negative', 'warning', 'info', 'buy', 'sell'];
|
|
3
|
+
/** Resolves a role to its colour in the provider's table (`useColors()`); anything outside the role list (for example a hex string from untyped JS) falls back to the component default. */
|
|
4
|
+
export function roleColor(role, fallback, colors) { return colors[accentRoles.includes(role) ? role : fallback]; }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useControllable, useHIG } from './provider.js';
|
|
6
|
+
import { Button } from './button.js';
|
|
7
|
+
import { Dialog } from './overlay.js';
|
|
8
|
+
import { RadioGroup } from './radio-group.js';
|
|
9
|
+
export function Select(props) { const { messages } = useHIG(); const [open, setOpen] = useState(false); const trigger = useRef(null); const [current, set] = useControllable(props.value, props.defaultValue ?? '', props.onValueChange); return _jsxs(View, { children: [_jsxs(Button, { ref: trigger, disabled: props.disabled, intent: 'secondary', onPress: () => setOpen(true), children: [props.label, ": ", props.options.find(o => o.value === current)?.label ?? messages.choose ?? en.choose] }), _jsx(Dialog, { title: props.label, description: messages.chooseOne ?? en.chooseOne, open: open, onOpenChange: setOpen, returnFocusRef: trigger, children: _jsx(RadioGroup, { ...props, value: current, onValueChange: v => { set(v); setOpen(false); } }) })] }); }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface Choice {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string; /** Optional translated name or supporting text, shown below the option label. */
|
|
4
|
+
description?: string; /** BCP-47 language of the label, for native pronunciation and shared-script punctuation. */
|
|
5
|
+
lang?: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface CheckedProps {
|
|
9
|
+
label: string;
|
|
10
|
+
checked?: boolean;
|
|
11
|
+
defaultChecked?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
onCheckedChange?: (v: boolean) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface ChoicesProps {
|
|
16
|
+
label: string;
|
|
17
|
+
options: readonly Choice[];
|
|
18
|
+
value?: string;
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
onValueChange?: (v: string) => void;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|