@jztack/ui-native 0.0.0-stage → 0.1.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 +128 -2
- package/dist/Alert.d.ts +20 -0
- package/dist/Alert.js +14 -0
- package/dist/AppBar.d.ts +21 -0
- package/dist/AppBar.js +16 -0
- package/dist/Avatar.d.ts +21 -0
- package/dist/Avatar.js +23 -0
- package/dist/Badge.d.ts +15 -0
- package/dist/Badge.js +27 -0
- package/dist/BottomTabBar.d.ts +26 -0
- package/dist/BottomTabBar.js +39 -0
- package/dist/Button.d.ts +21 -0
- package/dist/Button.js +63 -0
- package/dist/Card.d.ts +37 -0
- package/dist/Card.js +41 -0
- package/dist/Checkbox.d.ts +11 -0
- package/dist/Checkbox.js +11 -0
- package/dist/ConfirmActionModal.d.ts +27 -0
- package/dist/ConfirmActionModal.js +43 -0
- package/dist/DeleteButton.d.ts +20 -0
- package/dist/DeleteButton.js +41 -0
- package/dist/Dialog.d.ts +10 -0
- package/dist/Dialog.js +10 -0
- package/dist/DropdownMenu.d.ts +25 -0
- package/dist/DropdownMenu.js +57 -0
- package/dist/EmptyState.d.ts +13 -0
- package/dist/EmptyState.js +10 -0
- package/dist/ErrorBoundary.d.ts +33 -0
- package/dist/ErrorBoundary.js +37 -0
- package/dist/Field.d.ts +24 -0
- package/dist/Field.js +20 -0
- package/dist/FormFields.d.ts +37 -0
- package/dist/FormFields.js +24 -0
- package/dist/FormPanel.d.ts +20 -0
- package/dist/FormPanel.js +14 -0
- package/dist/Input.d.ts +30 -0
- package/dist/Input.js +52 -0
- package/dist/OptionList.d.ts +25 -0
- package/dist/OptionList.js +15 -0
- package/dist/PageHeader.d.ts +13 -0
- package/dist/PageHeader.js +10 -0
- package/dist/Primitives.d.ts +636 -0
- package/dist/Primitives.js +5 -0
- package/dist/Progress.d.ts +8 -0
- package/dist/Progress.js +42 -0
- package/dist/RadioGroup.d.ts +15 -0
- package/dist/RadioGroup.js +11 -0
- package/dist/ScrollOverflowContainer.d.ts +14 -0
- package/dist/ScrollOverflowContainer.js +83 -0
- package/dist/SegmentedControl.d.ts +19 -0
- package/dist/SegmentedControl.js +15 -0
- package/dist/Select.d.ts +9 -0
- package/dist/Select.js +27 -0
- package/dist/Select.web.d.ts +10 -0
- package/dist/Select.web.js +41 -0
- package/dist/SelectTypes.d.ts +17 -0
- package/dist/SelectTypes.js +1 -0
- package/dist/Separator.d.ts +6 -0
- package/dist/Separator.js +9 -0
- package/dist/Sheet.d.ts +31 -0
- package/dist/Sheet.js +43 -0
- package/dist/Skeleton.d.ts +11 -0
- package/dist/Skeleton.js +30 -0
- package/dist/StartupScreen.d.ts +9 -0
- package/dist/StartupScreen.js +9 -0
- package/dist/StateViews.d.ts +13 -0
- package/dist/StateViews.js +14 -0
- package/dist/Switch.d.ts +13 -0
- package/dist/Switch.js +42 -0
- package/dist/Table.d.ts +22 -0
- package/dist/Table.js +17 -0
- package/dist/TextField.d.ts +22 -0
- package/dist/TextField.js +116 -0
- package/dist/Toast.d.ts +34 -0
- package/dist/Toast.js +92 -0
- package/dist/ToastHost.d.ts +6 -0
- package/dist/ToastHost.js +4 -0
- package/dist/ToastHost.web.d.ts +7 -0
- package/dist/ToastHost.web.js +11 -0
- package/dist/Toggle.d.ts +16 -0
- package/dist/Toggle.js +7 -0
- package/dist/ToggleGroup.d.ts +27 -0
- package/dist/ToggleGroup.js +27 -0
- package/dist/haptics.d.ts +45 -0
- package/dist/haptics.js +96 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +46 -0
- package/dist/shadows.d.ts +28 -0
- package/dist/shadows.js +19 -0
- package/dist/theme.d.ts +23 -0
- package/dist/theme.js +19 -0
- package/dist/useDismissOnEscape.d.ts +7 -0
- package/dist/useDismissOnEscape.js +10 -0
- package/dist/useDismissOnEscape.web.d.ts +2 -0
- package/dist/useDismissOnEscape.web.js +14 -0
- package/dist/useResponsive.d.ts +28 -0
- package/dist/useResponsive.js +23 -0
- package/dist/useTextFieldCurrency.d.ts +9 -0
- package/dist/useTextFieldCurrency.js +45 -0
- package/package.json +52 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ProgressProps {
|
|
2
|
+
/** 0..max. Omit for the indeterminate state. */
|
|
3
|
+
value?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
testID?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Same API as web (DESIGN §2.1 #11): `value` (+ `max`) only. */
|
|
8
|
+
export declare function Progress({ value, max, testID }: ProgressProps): import("react").JSX.Element;
|
package/dist/Progress.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { Animated, Platform } from 'react-native';
|
|
4
|
+
import { Box } from './Primitives';
|
|
5
|
+
/** Same API as web (DESIGN §2.1 #11): `value` (+ `max`) only. */
|
|
6
|
+
export function Progress({ value, max = 100, testID }) {
|
|
7
|
+
const widthAnim = useRef(new Animated.Value(0)).current;
|
|
8
|
+
const pulse = useRef(new Animated.Value(0.35)).current;
|
|
9
|
+
const indeterminate = value === undefined;
|
|
10
|
+
const pct = indeterminate ? 100 : Math.max(0, Math.min(100, (value / max) * 100));
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (indeterminate) {
|
|
13
|
+
const loop = Animated.loop(Animated.sequence([
|
|
14
|
+
Animated.timing(pulse, {
|
|
15
|
+
toValue: 0.8,
|
|
16
|
+
duration: 800,
|
|
17
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
18
|
+
}),
|
|
19
|
+
Animated.timing(pulse, {
|
|
20
|
+
toValue: 0.35,
|
|
21
|
+
duration: 800,
|
|
22
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
23
|
+
}),
|
|
24
|
+
]));
|
|
25
|
+
loop.start();
|
|
26
|
+
return () => loop.stop();
|
|
27
|
+
}
|
|
28
|
+
Animated.timing(widthAnim, {
|
|
29
|
+
toValue: pct,
|
|
30
|
+
duration: 300,
|
|
31
|
+
useNativeDriver: false,
|
|
32
|
+
}).start();
|
|
33
|
+
return undefined;
|
|
34
|
+
}, [indeterminate, pct, pulse, widthAnim]);
|
|
35
|
+
return (_jsx(Box, { height: 8, borderRadius: "full", bg: "muted", overflow: "hidden", testID: testID, accessibilityRole: "progressbar", accessibilityValue: indeterminate ? undefined : { min: 0, max, now: value }, children: indeterminate ? (_jsx(Animated.View, { style: { width: '100%', height: '100%', opacity: pulse }, children: _jsx(Box, { height: "100%", bg: "primary" }) })) : (_jsx(Animated.View, { style: {
|
|
36
|
+
height: '100%',
|
|
37
|
+
width: widthAnim.interpolate({
|
|
38
|
+
inputRange: [0, 100],
|
|
39
|
+
outputRange: ['0%', '100%'],
|
|
40
|
+
}),
|
|
41
|
+
}, children: _jsx(Box, { height: "100%", bg: "primary" }) })) }));
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface RadioOption {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
hint?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface RadioGroupProps {
|
|
7
|
+
options: RadioOption[];
|
|
8
|
+
value?: string;
|
|
9
|
+
onValueChange?: (value: string) => void;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
testID?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Options-array collapse of the web compound (DESIGN §2.1 #12, rule R5).
|
|
14
|
+
* The indicator is a themed ring + dot, never colour-only. */
|
|
15
|
+
export declare function RadioGroup({ options, value, onValueChange, disabled, testID }: RadioGroupProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable } from 'react-native';
|
|
3
|
+
import { Box, Text } from './Primitives';
|
|
4
|
+
/** Options-array collapse of the web compound (DESIGN §2.1 #12, rule R5).
|
|
5
|
+
* The indicator is a themed ring + dot, never colour-only. */
|
|
6
|
+
export function RadioGroup({ options, value, onValueChange, disabled, testID }) {
|
|
7
|
+
return (_jsx(Box, { testID: testID, accessibilityRole: "radiogroup", children: options.map((option) => {
|
|
8
|
+
const selected = option.value === value;
|
|
9
|
+
return (_jsx(Pressable, { onPress: () => onValueChange?.(option.value), disabled: disabled, accessibilityRole: "radio", accessibilityState: { selected, disabled: !!disabled }, testID: testID ? `${testID}-${option.value}` : undefined, children: _jsxs(Box, { flexDirection: "row", alignItems: "center", minHeight: 48, opacity: disabled ? 0.5 : 1, children: [_jsx(Box, { width: 22, height: 22, borderRadius: "full", borderWidth: 2, borderColor: selected ? 'primary' : 'border', alignItems: "center", justifyContent: "center", mr: "s", children: selected ? _jsx(Box, { width: 10, height: 10, borderRadius: "full", bg: "primary" }) : null }), _jsxs(Box, { flex: 1, children: [_jsx(Text, { variant: "body", children: option.label }), option.hint ? _jsx(Text, { variant: "bodySecondary", children: option.hint }) : null] })] }) }, option.value));
|
|
10
|
+
}) }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ScrollViewProps, type ViewStyle } from 'react-native';
|
|
2
|
+
export interface ScrollOverflowContainerProps extends ScrollViewProps {
|
|
3
|
+
/** Theme color key the fade edges resolve to. Canonical keys only. */
|
|
4
|
+
fadeColor?: string;
|
|
5
|
+
fadeHeight?: number;
|
|
6
|
+
showIndicatorBadge?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function getGradientFadeStyle(direction: 'top' | 'bottom', color: string): ViewStyle;
|
|
9
|
+
/**
|
|
10
|
+
* Native-only extra (DESIGN §3): ScrollView with gradient fade edges and an
|
|
11
|
+
* overflow indicator badge. The web counterpart concept is ScrollArea with a
|
|
12
|
+
* deliberately different API; no convergence is proposed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ScrollOverflowContainer({ children, style, contentContainerStyle, fadeColor, fadeHeight, showIndicatorBadge, onScroll, onContentSizeChange, onLayout, testID, ...rest }: ScrollOverflowContainerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from '@shopify/restyle';
|
|
3
|
+
import { useCallback, useRef, useState } from 'react';
|
|
4
|
+
import { Platform, ScrollView, TouchableOpacity, } from 'react-native';
|
|
5
|
+
import { Box } from './Primitives';
|
|
6
|
+
import { getShadowStyle } from './shadows';
|
|
7
|
+
export function getGradientFadeStyle(direction, color) {
|
|
8
|
+
if (Platform.OS === 'web') {
|
|
9
|
+
return {
|
|
10
|
+
backgroundImage: `linear-gradient(to ${direction}, transparent, ${color})`,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
backgroundColor: color,
|
|
15
|
+
opacity: direction === 'bottom' ? 0.6 : 0.4,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Native-only extra (DESIGN §3): ScrollView with gradient fade edges and an
|
|
20
|
+
* overflow indicator badge. The web counterpart concept is ScrollArea with a
|
|
21
|
+
* deliberately different API; no convergence is proposed.
|
|
22
|
+
*/
|
|
23
|
+
export function ScrollOverflowContainer({ children, style, contentContainerStyle, fadeColor = 'card', fadeHeight = 32, showIndicatorBadge = true, onScroll, onContentSizeChange, onLayout, testID = 'scroll-overflow-container', ...rest }) {
|
|
24
|
+
const theme = useTheme();
|
|
25
|
+
const scrollViewRef = useRef(null);
|
|
26
|
+
const [canScrollDown, setCanScrollDown] = useState(false);
|
|
27
|
+
const [canScrollUp, setCanScrollUp] = useState(false);
|
|
28
|
+
const contentHeightRef = useRef(0);
|
|
29
|
+
const layoutHeightRef = useRef(0);
|
|
30
|
+
const scrollYRef = useRef(0);
|
|
31
|
+
const checkOverflow = useCallback(() => {
|
|
32
|
+
const contentH = contentHeightRef.current;
|
|
33
|
+
const layoutH = layoutHeightRef.current;
|
|
34
|
+
const scrollY = scrollYRef.current;
|
|
35
|
+
const threshold = 10;
|
|
36
|
+
const hasOverflow = contentH > layoutH + threshold;
|
|
37
|
+
const isAtBottom = scrollY + layoutH >= contentH - threshold;
|
|
38
|
+
const isAtTop = scrollY <= threshold;
|
|
39
|
+
setCanScrollDown(hasOverflow && !isAtBottom);
|
|
40
|
+
setCanScrollUp(hasOverflow && !isAtTop);
|
|
41
|
+
}, []);
|
|
42
|
+
const handleScroll = (e) => {
|
|
43
|
+
scrollYRef.current = e.nativeEvent.contentOffset.y;
|
|
44
|
+
checkOverflow();
|
|
45
|
+
onScroll?.(e);
|
|
46
|
+
};
|
|
47
|
+
const handleContentSizeChange = (w, h) => {
|
|
48
|
+
contentHeightRef.current = h;
|
|
49
|
+
checkOverflow();
|
|
50
|
+
onContentSizeChange?.(w, h);
|
|
51
|
+
};
|
|
52
|
+
const handleLayout = (e) => {
|
|
53
|
+
layoutHeightRef.current = e.nativeEvent.layout.height;
|
|
54
|
+
checkOverflow();
|
|
55
|
+
onLayout?.(e);
|
|
56
|
+
};
|
|
57
|
+
const handleScrollDownPress = () => {
|
|
58
|
+
scrollViewRef.current?.scrollTo({
|
|
59
|
+
y: scrollYRef.current + Math.max(layoutHeightRef.current * 0.7, 100),
|
|
60
|
+
animated: true,
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const resolvedFadeColor = theme.colors[fadeColor] ?? '';
|
|
64
|
+
return (_jsxs(Box, { position: "relative", style: style, children: [_jsx(ScrollView, { ref: (node) => {
|
|
65
|
+
scrollViewRef.current = node;
|
|
66
|
+
}, onScroll: handleScroll, onContentSizeChange: handleContentSizeChange, onLayout: handleLayout, scrollEventThrottle: 16, contentContainerStyle: contentContainerStyle, testID: testID, ...rest, children: children }), canScrollUp && (_jsx(Box, { position: "absolute", top: 0, left: 0, right: 0, height: Math.round(fadeHeight * 0.65), pointerEvents: "none", testID: `${testID}-top-fade`, style: getGradientFadeStyle('top', resolvedFadeColor) })), canScrollDown && (_jsxs(Box, { position: "absolute", bottom: 0, left: 0, right: 0, height: fadeHeight, pointerEvents: "box-none", alignItems: "center", justifyContent: "flex-end", testID: `${testID}-bottom-fade`, children: [_jsx(Box, { position: "absolute", bottom: 0, left: 0, right: 0, height: fadeHeight, pointerEvents: "none", style: getGradientFadeStyle('bottom', resolvedFadeColor) }), showIndicatorBadge && (_jsx(TouchableOpacity, { onPress: handleScrollDownPress, activeOpacity: 0.7, testID: `${testID}-indicator`, accessibilityLabel: "More content available below", accessibilityRole: "button", style: {
|
|
67
|
+
marginBottom: 4,
|
|
68
|
+
width: 22,
|
|
69
|
+
height: 22,
|
|
70
|
+
borderRadius: 11,
|
|
71
|
+
alignItems: 'center',
|
|
72
|
+
justifyContent: 'center',
|
|
73
|
+
backgroundColor: theme.colors['background-secondary'],
|
|
74
|
+
borderWidth: 1,
|
|
75
|
+
borderColor: theme.colors.border,
|
|
76
|
+
...getShadowStyle('table'),
|
|
77
|
+
}, children: _jsx(Box, { width: 6, height: 6, style: {
|
|
78
|
+
borderBottomWidth: 1.5,
|
|
79
|
+
borderRightWidth: 1.5,
|
|
80
|
+
borderColor: theme.colors['foreground-secondary'],
|
|
81
|
+
transform: [{ rotate: '45deg' }, { translateY: -1 }],
|
|
82
|
+
} }) }))] }))] }));
|
|
83
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface SegmentOption<T extends string> {
|
|
2
|
+
value: T;
|
|
3
|
+
label: string;
|
|
4
|
+
/** Optional count badge (e.g. open follow-ups). */
|
|
5
|
+
count?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SegmentedControlProps<T extends string> {
|
|
8
|
+
options: readonly SegmentOption<T>[];
|
|
9
|
+
selected: T;
|
|
10
|
+
onSelect: (value: T) => void;
|
|
11
|
+
testID?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Native-only extra (DESIGN §3): equal-width tab strip with count badges
|
|
15
|
+
* and tablist semantics, rebuilt on the ToggleGroup substrate's visual
|
|
16
|
+
* language. Spec proposal P2 (adopt into the shared spec) is parked past
|
|
17
|
+
* v1 (decisions log, Dec 4, 2026).
|
|
18
|
+
*/
|
|
19
|
+
export declare function SegmentedControl<T extends string>({ options, selected, onSelect, testID, }: SegmentedControlProps<T>): import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable } from 'react-native';
|
|
3
|
+
import { Box, Text } from './Primitives';
|
|
4
|
+
/**
|
|
5
|
+
* Native-only extra (DESIGN §3): equal-width tab strip with count badges
|
|
6
|
+
* and tablist semantics, rebuilt on the ToggleGroup substrate's visual
|
|
7
|
+
* language. Spec proposal P2 (adopt into the shared spec) is parked past
|
|
8
|
+
* v1 (decisions log, Dec 4, 2026).
|
|
9
|
+
*/
|
|
10
|
+
export function SegmentedControl({ options, selected, onSelect, testID, }) {
|
|
11
|
+
return (_jsx(Box, { flexDirection: "row", bg: "background-secondary", borderRadius: "md", p: "xs", accessibilityRole: "tablist", testID: testID, children: options.map((option) => {
|
|
12
|
+
const isSelected = option.value === selected;
|
|
13
|
+
return (_jsx(Pressable, { onPress: () => onSelect(option.value), accessibilityRole: "tab", accessibilityState: { selected: isSelected }, testID: testID ? `${testID}-${option.value}` : undefined, style: { flex: 1 }, children: _jsxs(Box, { flexDirection: "row", alignItems: "center", justifyContent: "center", py: "s", px: "xs", borderRadius: "sm", bg: isSelected ? 'card' : 'transparent', style: { minHeight: 40 }, children: [_jsx(Text, { variant: "bodySecondary", fontWeight: "700", numberOfLines: 1, color: isSelected ? 'foreground' : 'foreground-secondary', children: option.label }), option.count !== undefined && (_jsx(Box, { ml: "xs", px: "xs", borderRadius: "sm", bg: isSelected ? 'accent-bg' : 'transparent', children: _jsx(Text, { variant: "caption", fontWeight: "700", color: "accent", children: option.count }) }))] }) }, option.value));
|
|
14
|
+
}) }));
|
|
15
|
+
}
|
package/dist/Select.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SelectProps } from './SelectTypes';
|
|
2
|
+
export type { SelectOption, SelectProps } from './SelectTypes';
|
|
3
|
+
/**
|
|
4
|
+
* Native resolution of Select (DESIGN §2.1 #14): TWJS's DropdownSelector
|
|
5
|
+
* API — an options array, a 48px/16px trigger, and the Sheet list. The web
|
|
6
|
+
* resolution (Select.web.tsx) renders a real DOM <select>; the split lives
|
|
7
|
+
* inside the package so consumers see one component.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Select({ label, options, value, onValueChange, placeholder, disabled, inlineControlHeight, testID, }: SelectProps): import("react").JSX.Element;
|
package/dist/Select.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from '@shopify/restyle';
|
|
3
|
+
import { ChevronDown } from 'lucide-react-native';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { Pressable } from 'react-native';
|
|
6
|
+
import { OptionList } from './OptionList';
|
|
7
|
+
import { Box, Text } from './Primitives';
|
|
8
|
+
/**
|
|
9
|
+
* Native resolution of Select (DESIGN §2.1 #14): TWJS's DropdownSelector
|
|
10
|
+
* API — an options array, a 48px/16px trigger, and the Sheet list. The web
|
|
11
|
+
* resolution (Select.web.tsx) renders a real DOM <select>; the split lives
|
|
12
|
+
* inside the package so consumers see one component.
|
|
13
|
+
*/
|
|
14
|
+
export function Select({ label, options, value, onValueChange, placeholder, disabled = false, inlineControlHeight, testID = 'select', }) {
|
|
15
|
+
const theme = useTheme();
|
|
16
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
17
|
+
const inline = inlineControlHeight !== undefined;
|
|
18
|
+
const selectedOption = options.find((opt) => opt.value === value);
|
|
19
|
+
const handleSelect = (val) => {
|
|
20
|
+
onValueChange(val);
|
|
21
|
+
setIsOpen(false);
|
|
22
|
+
};
|
|
23
|
+
return (_jsxs(Box, { mb: inline ? 'none' : 's', width: "100%", testID: testID, children: [label ? (_jsx(Text, { variant: "bodySecondary", fontWeight: "700", mb: "xs", style: disabled ? { opacity: 0.6 } : undefined, children: label })) : null, _jsx(Pressable, { onPress: () => {
|
|
24
|
+
if (!disabled)
|
|
25
|
+
setIsOpen(true);
|
|
26
|
+
}, disabled: disabled, accessibilityRole: "button", accessibilityState: { disabled, expanded: isOpen }, testID: `${testID}-trigger`, children: _jsxs(Box, { flexDirection: "row", alignItems: "center", justifyContent: "space-between", borderWidth: 1, borderColor: "border", borderRadius: "lg", bg: disabled ? 'background-secondary' : 'card', px: "m", minHeight: inlineControlHeight ?? 48, style: disabled ? { opacity: 0.6 } : undefined, children: [_jsx(Text, { variant: "body", style: { fontSize: 16 }, color: selectedOption ? 'foreground' : 'foreground-secondary', numberOfLines: inline ? 1 : undefined, flexShrink: inline ? 1 : undefined, children: selectedOption ? selectedOption.label : (placeholder ?? '') }), _jsx(ChevronDown, { size: 18, color: theme.colors['foreground-secondary'] })] }) }), _jsx(OptionList, { open: isOpen, onClose: () => setIsOpen(false), title: label, items: options, selectedValue: value, onSelect: handleSelect, testID: `${testID}-list` })] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { SelectProps } from './SelectTypes';
|
|
3
|
+
export type { SelectOption, SelectProps } from './SelectTypes';
|
|
4
|
+
/**
|
|
5
|
+
* Web resolution of Select (DESIGN §2.1 #14, §7.2): a real DOM <select> —
|
|
6
|
+
* keyboard/a11y-correct and it does not occlude map screens (the behaviour
|
|
7
|
+
* TWJS's DropdownSelector proved on web). Open question Q4 records the
|
|
8
|
+
* deliberate split; this file is it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function Select({ label, options, value, onValueChange, placeholder, disabled, inlineControlHeight, testID, }: SelectProps): React.JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from '@shopify/restyle';
|
|
3
|
+
import { Box, Text } from './Primitives';
|
|
4
|
+
/**
|
|
5
|
+
* Web resolution of Select (DESIGN §2.1 #14, §7.2): a real DOM <select> —
|
|
6
|
+
* keyboard/a11y-correct and it does not occlude map screens (the behaviour
|
|
7
|
+
* TWJS's DropdownSelector proved on web). Open question Q4 records the
|
|
8
|
+
* deliberate split; this file is it.
|
|
9
|
+
*/
|
|
10
|
+
export function Select({ label, options, value, onValueChange, placeholder, disabled = false, inlineControlHeight, testID = 'select', }) {
|
|
11
|
+
const theme = useTheme();
|
|
12
|
+
const inline = inlineControlHeight !== undefined;
|
|
13
|
+
const selectedOption = options.find((opt) => opt.value === value);
|
|
14
|
+
const hasEmptyOption = options.some((opt) => opt.value === '');
|
|
15
|
+
const showPlaceholderOption = !selectedOption && !hasEmptyOption;
|
|
16
|
+
const arrowColor = encodeURIComponent(theme.colors['foreground-secondary'] ?? '');
|
|
17
|
+
return (_jsxs(Box, { mb: inline ? 'none' : 's', width: "100%", testID: testID, children: [label ? (_jsx(Text, { variant: "bodySecondary", fontWeight: "700", mb: "xs", style: disabled ? { opacity: 0.6 } : undefined, children: label })) : null, _jsx(Box, { borderWidth: 1, borderColor: "border", borderRadius: "lg", bg: disabled ? 'background-secondary' : 'card', px: "m", height: inlineControlHeight, style: { overflow: 'hidden', opacity: disabled ? 0.6 : 1 }, testID: `${testID}-control`, children: _jsxs("select", { "data-testid": `${testID}-native-select`, value: value, disabled: disabled, onChange: (e) => onValueChange(e.target.value), style: {
|
|
18
|
+
width: '100%',
|
|
19
|
+
minHeight: inline ? undefined : 48,
|
|
20
|
+
height: inline ? '100%' : undefined,
|
|
21
|
+
boxSizing: inline ? 'border-box' : undefined,
|
|
22
|
+
border: 'none',
|
|
23
|
+
backgroundColor: disabled ? theme.colors['background-secondary'] : theme.colors.card,
|
|
24
|
+
fontSize: 16,
|
|
25
|
+
color: selectedOption ? theme.colors.foreground : theme.colors['foreground-secondary'],
|
|
26
|
+
outline: 'none',
|
|
27
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
28
|
+
appearance: 'none',
|
|
29
|
+
WebkitAppearance: 'none',
|
|
30
|
+
paddingRight: 24,
|
|
31
|
+
backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='${arrowColor}' d='M6 8L1 3h10z'/%3E%3C/svg%3E")`,
|
|
32
|
+
backgroundRepeat: 'no-repeat',
|
|
33
|
+
backgroundPosition: 'right 8px center',
|
|
34
|
+
}, children: [showPlaceholderOption && (_jsx("option", { value: "", disabled: true, style: {
|
|
35
|
+
backgroundColor: theme.colors.card,
|
|
36
|
+
color: theme.colors['foreground-secondary'],
|
|
37
|
+
}, children: placeholder ?? '' })), options.map((opt) => (_jsx("option", { value: opt.value, style: {
|
|
38
|
+
backgroundColor: theme.colors.card,
|
|
39
|
+
color: theme.colors.foreground,
|
|
40
|
+
}, children: opt.label }, opt.value)))] }) })] }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface SelectOption {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SelectProps {
|
|
6
|
+
label?: string;
|
|
7
|
+
options: SelectOption[];
|
|
8
|
+
value: string;
|
|
9
|
+
onValueChange: (value: string) => void;
|
|
10
|
+
/** Supplied by the app's i18n (R9) — the package bakes in no copy. */
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Fits an unlabeled selector beside buttons without form-field spacing
|
|
14
|
+
* (retained from TWJS's DropdownSelector — dense-context escape hatch). */
|
|
15
|
+
inlineControlHeight?: number;
|
|
16
|
+
testID?: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface SeparatorProps {
|
|
2
|
+
orientation?: 'horizontal' | 'vertical';
|
|
3
|
+
testID?: string;
|
|
4
|
+
}
|
|
5
|
+
/** Same API as web (DESIGN §2.1 #15): `orientation` only. */
|
|
6
|
+
export declare function Separator({ orientation, testID }: SeparatorProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from './Primitives';
|
|
3
|
+
/** Same API as web (DESIGN §2.1 #15): `orientation` only. */
|
|
4
|
+
export function Separator({ orientation = 'horizontal', testID }) {
|
|
5
|
+
if (orientation === 'vertical') {
|
|
6
|
+
return _jsx(Box, { width: 1, alignSelf: "stretch", bg: "border", testID: testID });
|
|
7
|
+
}
|
|
8
|
+
return _jsx(Box, { height: 1, width: "100%", bg: "border", testID: testID });
|
|
9
|
+
}
|
package/dist/Sheet.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export interface SheetBaseProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onOpenChange: (open: boolean) => void;
|
|
5
|
+
title?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
footer?: React.ReactNode;
|
|
9
|
+
showCloseButton?: boolean;
|
|
10
|
+
/** Accessibility label for the close control (copy via props, R9). */
|
|
11
|
+
closeLabel?: string;
|
|
12
|
+
maxWidth?: number;
|
|
13
|
+
maxHeightRatio?: number;
|
|
14
|
+
/** 'responsive' = bottom sheet on phone, centered ≥768px (the standard
|
|
15
|
+
* Sheet pattern); 'center' = centered at all widths (Dialog). */
|
|
16
|
+
presentation?: 'responsive' | 'center';
|
|
17
|
+
testID?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The one overlay substrate (DESIGN §2.1 #16/#7, rule R6/R7): ModalSheet
|
|
21
|
+
* evolved. Sheet and Dialog are both presentations of this component —
|
|
22
|
+
* presentation is the only difference, behaviour is identical: backdrop /
|
|
23
|
+
* Android back / Escape (web) / close button all call
|
|
24
|
+
* `onOpenChange(false)`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function SheetBase({ open, onOpenChange, title, description, children, footer, showCloseButton, closeLabel, maxWidth, maxHeightRatio, presentation, testID, }: SheetBaseProps): React.JSX.Element;
|
|
27
|
+
export interface SheetProps extends Omit<SheetBaseProps, 'presentation' | 'testID'> {
|
|
28
|
+
testID?: string;
|
|
29
|
+
}
|
|
30
|
+
/** The standardized Sheet: bottom sheet on phone, centered dialog ≥768px. */
|
|
31
|
+
export declare function Sheet(props: SheetProps): React.JSX.Element;
|
package/dist/Sheet.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from '@shopify/restyle';
|
|
3
|
+
import { X } from 'lucide-react-native';
|
|
4
|
+
import { Modal, Pressable } from 'react-native';
|
|
5
|
+
import { Box, Text } from './Primitives';
|
|
6
|
+
import { useDismissOnEscape } from './useDismissOnEscape';
|
|
7
|
+
import { useResponsive } from './useResponsive';
|
|
8
|
+
const OVERLAY_BACKGROUND = 'rgba(15, 23, 42, 0.55)';
|
|
9
|
+
/**
|
|
10
|
+
* The one overlay substrate (DESIGN §2.1 #16/#7, rule R6/R7): ModalSheet
|
|
11
|
+
* evolved. Sheet and Dialog are both presentations of this component —
|
|
12
|
+
* presentation is the only difference, behaviour is identical: backdrop /
|
|
13
|
+
* Android back / Escape (web) / close button all call
|
|
14
|
+
* `onOpenChange(false)`.
|
|
15
|
+
*/
|
|
16
|
+
export function SheetBase({ open, onOpenChange, title, description, children, footer, showCloseButton = true, closeLabel = 'Close', maxWidth = 480, maxHeightRatio = 0.9, presentation = 'responsive', testID = 'sheet', }) {
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
const { height, isPhone } = useResponsive();
|
|
19
|
+
const close = () => onOpenChange(false);
|
|
20
|
+
useDismissOnEscape(open, close);
|
|
21
|
+
const bottomSheet = presentation === 'responsive' && isPhone;
|
|
22
|
+
return (_jsx(Modal, { testID: testID, visible: open, transparent: true, animationType: bottomSheet ? 'slide' : 'fade', onRequestClose: close, children: _jsxs(Box, { flex: 1, style: { backgroundColor: OVERLAY_BACKGROUND }, accessibilityViewIsModal: true, justifyContent: bottomSheet ? 'flex-end' : 'center', alignItems: "center", px: bottomSheet ? 'none' : 'm', py: bottomSheet ? 'none' : 'm', children: [_jsx(Pressable, { testID: `${testID}-backdrop`, onPress: close, accessibilityRole: "button", accessibilityLabel: closeLabel, style: { position: 'absolute', top: 0, right: 0, bottom: 0, left: 0 } }), _jsxs(Box, { testID: `${testID}-card`, width: "100%", alignSelf: "center", bg: "card", style: {
|
|
23
|
+
maxWidth: bottomSheet ? undefined : maxWidth,
|
|
24
|
+
maxHeight: Math.round(height * maxHeightRatio),
|
|
25
|
+
borderTopLeftRadius: theme.borderRadii.xl,
|
|
26
|
+
borderTopRightRadius: theme.borderRadii.xl,
|
|
27
|
+
borderBottomLeftRadius: bottomSheet ? 0 : theme.borderRadii.xl,
|
|
28
|
+
borderBottomRightRadius: bottomSheet ? 0 : theme.borderRadii.xl,
|
|
29
|
+
elevation: 10,
|
|
30
|
+
overflow: 'hidden',
|
|
31
|
+
}, children: [bottomSheet ? (_jsx(Box, { alignItems: "center", pt: "s", children: _jsx(Box, { width: 40, height: 4, borderRadius: "full", bg: "border" }) })) : null, title || showCloseButton ? (_jsxs(Box, { flexDirection: "row", alignItems: "flex-start", justifyContent: "space-between", px: "m", pt: "m", children: [_jsxs(Box, { flex: 1, children: [title ? _jsx(Text, { variant: "title", children: title }) : null, description ? (_jsx(Text, { variant: "bodySecondary", mt: "xxs", children: description })) : null] }), showCloseButton ? (_jsx(Pressable, { onPress: close, accessibilityRole: "button", accessibilityLabel: closeLabel, testID: `${testID}-close`, style: {
|
|
32
|
+
width: 48,
|
|
33
|
+
height: 48,
|
|
34
|
+
marginTop: -12,
|
|
35
|
+
marginRight: -12,
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
justifyContent: 'center',
|
|
38
|
+
}, children: _jsx(X, { size: 20, color: theme.colors['foreground-secondary'] }) })) : null] })) : null, _jsx(Box, { px: "m", py: "m", children: children }), footer ? (_jsx(Box, { px: "m", pb: "m", children: footer })) : null] })] }) }));
|
|
39
|
+
}
|
|
40
|
+
/** The standardized Sheet: bottom sheet on phone, centered dialog ≥768px. */
|
|
41
|
+
export function Sheet(props) {
|
|
42
|
+
return _jsx(SheetBase, { ...props, presentation: "responsive", testID: props.testID ?? 'sheet' });
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type SkeletonRadius = 'none' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full';
|
|
2
|
+
export interface SkeletonProps {
|
|
3
|
+
height?: number;
|
|
4
|
+
width?: number | 'auto' | `${number}%`;
|
|
5
|
+
borderRadius?: SkeletonRadius;
|
|
6
|
+
}
|
|
7
|
+
/** Pulsing loading placeholder row (the twin's `Skeleton`, DESIGN §2.1 #17). */
|
|
8
|
+
export declare function Skeleton({ height, width, borderRadius }: SkeletonProps): import("react").JSX.Element;
|
|
9
|
+
/** Alias matching TWJS's long-standing export name. */
|
|
10
|
+
export declare const SkeletonRow: typeof Skeleton;
|
|
11
|
+
export declare function SkeletonCard(): import("react").JSX.Element;
|
package/dist/Skeleton.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { Animated, Platform } from 'react-native';
|
|
4
|
+
import { Box } from './Primitives';
|
|
5
|
+
/** Pulsing loading placeholder row (the twin's `Skeleton`, DESIGN §2.1 #17). */
|
|
6
|
+
export function Skeleton({ height = 20, width = '100%', borderRadius = 'sm' }) {
|
|
7
|
+
const opacity = useRef(new Animated.Value(0.3)).current;
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const loop = Animated.loop(Animated.sequence([
|
|
10
|
+
Animated.timing(opacity, {
|
|
11
|
+
toValue: 0.7,
|
|
12
|
+
duration: 800,
|
|
13
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
14
|
+
}),
|
|
15
|
+
Animated.timing(opacity, {
|
|
16
|
+
toValue: 0.3,
|
|
17
|
+
duration: 800,
|
|
18
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
19
|
+
}),
|
|
20
|
+
]));
|
|
21
|
+
loop.start();
|
|
22
|
+
return () => loop.stop();
|
|
23
|
+
}, [opacity]);
|
|
24
|
+
return (_jsx(Animated.View, { style: { opacity, width, height }, children: _jsx(Box, { bg: "border", borderRadius: borderRadius === 'none' ? undefined : borderRadius, width: "100%", height: "100%" }) }));
|
|
25
|
+
}
|
|
26
|
+
/** Alias matching TWJS's long-standing export name. */
|
|
27
|
+
export const SkeletonRow = Skeleton;
|
|
28
|
+
export function SkeletonCard() {
|
|
29
|
+
return (_jsxs(Box, { p: "m", borderRadius: "lg", borderWidth: 1, borderColor: "border", bg: "background-secondary", children: [_jsx(Skeleton, { height: 24, width: "60%", borderRadius: "sm" }), _jsx(Box, { height: 8 }), _jsx(Skeleton, { height: 16, width: "40%", borderRadius: "sm" }), _jsx(Box, { height: 16 }), _jsx(Skeleton, { height: 14, width: "90%", borderRadius: "sm" }), _jsx(Box, { height: 6 }), _jsx(Skeleton, { height: 14, width: "80%", borderRadius: "sm" })] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface StartupScreenProps {
|
|
2
|
+
/** Resolved strings (R9) — mobile-web's version took a TranslationKey;
|
|
3
|
+
* the app resolves it before passing it in. */
|
|
4
|
+
title: string;
|
|
5
|
+
message: string;
|
|
6
|
+
helpText?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Startup frame (absorbed from mobile-web, DESIGN §6.1). */
|
|
9
|
+
export declare function StartupScreen({ title, message, helpText }: StartupScreenProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from '@shopify/restyle';
|
|
3
|
+
import { ActivityIndicator } from 'react-native';
|
|
4
|
+
import { Box, Text } from './Primitives';
|
|
5
|
+
/** Startup frame (absorbed from mobile-web, DESIGN §6.1). */
|
|
6
|
+
export function StartupScreen({ title, message, helpText }) {
|
|
7
|
+
const theme = useTheme();
|
|
8
|
+
return (_jsxs(Box, { flex: 1, bg: "background", justifyContent: "center", alignItems: "center", p: "l", testID: "startup-screen", accessibilityLiveRegion: "polite", children: [_jsx(Text, { variant: "header", mb: "l", children: title }), _jsx(ActivityIndicator, { size: "large", color: theme.colors.primary }), _jsx(Text, { variant: "body", mt: "m", children: message }), helpText ? (_jsx(Text, { variant: "bodySecondary", mt: "s", children: helpText })) : null] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Fetching state for list-style views (absorbed from mobile-web's
|
|
2
|
+
* StateViews, DESIGN §6.1). */
|
|
3
|
+
export declare function LoadingRows({ rows }: {
|
|
4
|
+
rows?: number;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
export interface ErrorStateProps {
|
|
7
|
+
message: string;
|
|
8
|
+
/** Resolved by the app's i18n (R9) — mobile-web's version called
|
|
9
|
+
* useTranslation internally; the twin takes the string. */
|
|
10
|
+
retryLabel: string;
|
|
11
|
+
onRetry: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function ErrorState({ message, retryLabel, onRetry }: ErrorStateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from './Button';
|
|
3
|
+
import { Box, Text } from './Primitives';
|
|
4
|
+
import { Skeleton } from './Skeleton';
|
|
5
|
+
const DEFAULT_SKELETON_ROWS = 3;
|
|
6
|
+
const SKELETON_ROW_HEIGHT = 44;
|
|
7
|
+
/** Fetching state for list-style views (absorbed from mobile-web's
|
|
8
|
+
* StateViews, DESIGN §6.1). */
|
|
9
|
+
export function LoadingRows({ rows = DEFAULT_SKELETON_ROWS }) {
|
|
10
|
+
return (_jsx(Box, { p: "m", style: { gap: 12 }, children: Array.from({ length: rows }, (_, index) => (_jsx(Skeleton, { height: SKELETON_ROW_HEIGHT }, index))) }));
|
|
11
|
+
}
|
|
12
|
+
export function ErrorState({ message, retryLabel, onRetry }) {
|
|
13
|
+
return (_jsxs(Box, { p: "l", alignItems: "center", style: { gap: 12 }, children: [_jsx(Text, { variant: "bodySecondary", color: "danger-foreground", textAlign: "center", children: message }), _jsx(Button, { variant: "outline", size: "sm", onPress: onRetry, children: retryLabel })] }));
|
|
14
|
+
}
|
package/dist/Switch.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
2
|
+
export interface SwitchProps {
|
|
3
|
+
checked: boolean;
|
|
4
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
/** Fires the `selection` pattern on change when haptics are configured. */
|
|
7
|
+
haptic?: boolean;
|
|
8
|
+
style?: StyleProp<ViewStyle>;
|
|
9
|
+
testID?: string;
|
|
10
|
+
}
|
|
11
|
+
/** `checked` / `onCheckedChange` kept (DESIGN §2.1 #19). The visual track is
|
|
12
|
+
* 44×24; the touch box is expanded to ≥48px via hitSlop + min dimensions. */
|
|
13
|
+
export declare function Switch({ checked, onCheckedChange, disabled, haptic, style, testID, }: SwitchProps): import("react").JSX.Element;
|
package/dist/Switch.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { Animated, Pressable } from 'react-native';
|
|
4
|
+
import { triggerHaptic } from './haptics';
|
|
5
|
+
import { Box } from './Primitives';
|
|
6
|
+
const TRACK_WIDTH = 44;
|
|
7
|
+
const TRACK_HEIGHT = 24;
|
|
8
|
+
const THUMB_SIZE = 20;
|
|
9
|
+
/** `checked` / `onCheckedChange` kept (DESIGN §2.1 #19). The visual track is
|
|
10
|
+
* 44×24; the touch box is expanded to ≥48px via hitSlop + min dimensions. */
|
|
11
|
+
export function Switch({ checked, onCheckedChange, disabled, haptic = false, style, testID, }) {
|
|
12
|
+
const thumbX = useRef(new Animated.Value(checked ? 1 : 0)).current;
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
Animated.timing(thumbX, {
|
|
15
|
+
toValue: checked ? 1 : 0,
|
|
16
|
+
duration: 150,
|
|
17
|
+
useNativeDriver: false,
|
|
18
|
+
}).start();
|
|
19
|
+
}, [checked, thumbX]);
|
|
20
|
+
const handlePress = () => {
|
|
21
|
+
if (haptic)
|
|
22
|
+
triggerHaptic('selection');
|
|
23
|
+
onCheckedChange?.(!checked);
|
|
24
|
+
};
|
|
25
|
+
return (_jsx(Pressable, { onPress: handlePress, disabled: disabled, accessibilityRole: "switch", accessibilityState: { checked, disabled: !!disabled }, hitSlop: { top: 12, bottom: 12, left: 2, right: 2 }, testID: testID, style: [
|
|
26
|
+
{ minWidth: 48, minHeight: 48, alignItems: 'center', justifyContent: 'center' },
|
|
27
|
+
style,
|
|
28
|
+
], children: _jsx(Box, { width: TRACK_WIDTH, height: TRACK_HEIGHT, borderRadius: "full", bg: checked ? 'primary' : 'muted', justifyContent: "center", opacity: disabled ? 0.5 : 1, children: _jsx(Animated.View, { style: {
|
|
29
|
+
width: THUMB_SIZE,
|
|
30
|
+
height: THUMB_SIZE,
|
|
31
|
+
borderRadius: THUMB_SIZE / 2,
|
|
32
|
+
marginLeft: 2,
|
|
33
|
+
transform: [
|
|
34
|
+
{
|
|
35
|
+
translateX: thumbX.interpolate({
|
|
36
|
+
inputRange: [0, 1],
|
|
37
|
+
outputRange: [0, TRACK_WIDTH - THUMB_SIZE - 4],
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
}, children: _jsx(Box, { width: THUMB_SIZE, height: THUMB_SIZE, borderRadius: "full", bg: "card" }) }) }) }));
|
|
42
|
+
}
|
package/dist/Table.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export interface ColumnDef<T> {
|
|
3
|
+
key: string;
|
|
4
|
+
header: string;
|
|
5
|
+
width?: number;
|
|
6
|
+
flex?: number;
|
|
7
|
+
render?: (item: T) => React.ReactNode;
|
|
8
|
+
renderCell?: (item: T) => React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export interface TableProps<T> {
|
|
11
|
+
data: T[];
|
|
12
|
+
columns: ColumnDef<T>[];
|
|
13
|
+
keyExtractor: (item: T) => string;
|
|
14
|
+
/** Default: the layout token (600). Horizontal scroll below min-width. */
|
|
15
|
+
minWidth?: number | `${number}%`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Table (DESIGN §2.1 #20, adapted-major): the twin keeps TWJS's data-driven
|
|
19
|
+
* API — the web Table is a DOM compound and neither side adopts the other's
|
|
20
|
+
* shape. Platform counterparts under one name, recorded divergence.
|
|
21
|
+
*/
|
|
22
|
+
export declare function Table<T>({ data, columns, keyExtractor, minWidth }: TableProps<T>): React.JSX.Element;
|