glacia-native 0.3.5 → 0.5.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/lib/module/Bars.js +176 -0
- package/lib/module/Button.js +15 -2
- package/lib/module/Card.js +29 -14
- package/lib/module/Carousel.js +103 -0
- package/lib/module/Dialog.js +43 -32
- package/lib/module/Display.js +240 -0
- package/lib/module/Feedback.js +172 -0
- package/lib/module/Form.js +51 -12
- package/lib/module/Forms2.js +227 -0
- package/lib/module/Glass.js +11 -2
- package/lib/module/Input.js +19 -7
- package/lib/module/Overlays.js +166 -0
- package/lib/module/Pickers.js +243 -0
- package/lib/module/SegmentedControl.js +65 -21
- package/lib/module/Slider.js +121 -25
- package/lib/module/Switch.js +33 -15
- package/lib/module/TabBar.js +63 -25
- package/lib/module/Table.js +24 -6
- package/lib/module/Tabs.js +55 -33
- package/lib/module/Text.js +37 -0
- package/lib/module/ai.js +49 -20
- package/lib/module/charts/BarChart.js +4 -2
- package/lib/module/charts/FunnelChart.js +4 -2
- package/lib/module/charts/HeatmapChart.js +4 -2
- package/lib/module/charts/LineChart.js +4 -2
- package/lib/module/charts/PlotChart.js +11 -3
- package/lib/module/charts/RadarChart.js +4 -2
- package/lib/module/charts/RingChart.js +4 -2
- package/lib/module/charts/ScatterChart.js +20 -3
- package/lib/module/charts/WaterfallChart.js +12 -3
- package/lib/module/charts/advanced.js +12 -6
- package/lib/module/charts/extra.js +6 -3
- package/lib/module/index.js +58 -1
- package/lib/module/internal/GlassView.js +31 -17
- package/lib/module/internal/fallback.js +14 -3
- package/lib/module/internal/glass-routing.js +56 -0
- package/lib/module/internal/motion.js +55 -0
- package/lib/module/internal/primitives.js +413 -0
- package/lib/module/internal/tokens.js +55 -1
- package/lib/typescript/Bars.d.ts +121 -0
- package/lib/typescript/Button.d.ts +11 -1
- package/lib/typescript/Card.d.ts +20 -8
- package/lib/typescript/Carousel.d.ts +47 -0
- package/lib/typescript/Dialog.d.ts +19 -6
- package/lib/typescript/Display.d.ts +119 -0
- package/lib/typescript/Feedback.d.ts +138 -0
- package/lib/typescript/Form.d.ts +27 -11
- package/lib/typescript/Forms2.d.ts +128 -0
- package/lib/typescript/Glass.d.ts +10 -1
- package/lib/typescript/Input.d.ts +11 -1
- package/lib/typescript/Overlays.d.ts +105 -0
- package/lib/typescript/Pickers.d.ts +105 -0
- package/lib/typescript/SegmentedControl.d.ts +11 -1
- package/lib/typescript/Slider.d.ts +13 -1
- package/lib/typescript/Switch.d.ts +12 -1
- package/lib/typescript/TabBar.d.ts +13 -1
- package/lib/typescript/Table.d.ts +14 -5
- package/lib/typescript/Tabs.d.ts +8 -5
- package/lib/typescript/Text.d.ts +28 -0
- package/lib/typescript/ai.d.ts +12 -9
- package/lib/typescript/charts/BarChart.d.ts +1 -1
- package/lib/typescript/charts/FunnelChart.d.ts +1 -1
- package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
- package/lib/typescript/charts/LineChart.d.ts +1 -1
- package/lib/typescript/charts/PlotChart.d.ts +1 -1
- package/lib/typescript/charts/RadarChart.d.ts +1 -1
- package/lib/typescript/charts/RingChart.d.ts +1 -1
- package/lib/typescript/charts/ScatterChart.d.ts +1 -1
- package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
- package/lib/typescript/charts/advanced.d.ts +5 -5
- package/lib/typescript/charts/extra.d.ts +2 -2
- package/lib/typescript/index.d.ts +9 -1
- package/lib/typescript/internal/GlassView.d.ts +21 -4
- package/lib/typescript/internal/fallback.d.ts +10 -1
- package/lib/typescript/internal/glass-routing.d.ts +30 -0
- package/lib/typescript/internal/motion.d.ts +19 -0
- package/lib/typescript/internal/primitives.d.ts +41 -0
- package/lib/typescript/internal/tokens.d.ts +61 -0
- package/package.json +2 -2
- package/src/Bars.tsx +570 -0
- package/src/Button.tsx +47 -22
- package/src/Card.tsx +52 -31
- package/src/Carousel.tsx +233 -0
- package/src/Dialog.tsx +99 -64
- package/src/Display.tsx +550 -0
- package/src/Feedback.tsx +579 -0
- package/src/Form.tsx +90 -25
- package/src/Forms2.tsx +608 -0
- package/src/Glass.tsx +24 -1
- package/src/Input.tsx +33 -12
- package/src/Overlays.tsx +474 -0
- package/src/Pickers.tsx +590 -0
- package/src/SegmentedControl.tsx +104 -32
- package/src/Slider.tsx +151 -47
- package/src/Switch.tsx +56 -32
- package/src/TabBar.tsx +100 -30
- package/src/Table.tsx +38 -14
- package/src/Tabs.tsx +85 -32
- package/src/Text.tsx +83 -0
- package/src/ai.tsx +77 -31
- package/src/charts/BarChart.tsx +4 -2
- package/src/charts/FunnelChart.tsx +4 -2
- package/src/charts/HeatmapChart.tsx +4 -2
- package/src/charts/LineChart.tsx +4 -2
- package/src/charts/PlotChart.tsx +23 -3
- package/src/charts/RadarChart.tsx +4 -2
- package/src/charts/RingChart.tsx +4 -2
- package/src/charts/ScatterChart.tsx +24 -3
- package/src/charts/WaterfallChart.tsx +21 -3
- package/src/charts/advanced.tsx +12 -6
- package/src/charts/extra.tsx +6 -3
- package/src/index.ts +101 -1
- package/src/internal/GlassView.tsx +51 -19
- package/src/internal/fallback.tsx +23 -8
- package/src/internal/glass-routing.ts +68 -0
- package/src/internal/motion.ts +60 -0
- package/src/internal/primitives.ts +482 -0
- package/src/internal/tokens.ts +62 -0
- package/lib/module/charts/primitives.js +0 -212
- package/lib/typescript/charts/primitives.d.ts +0 -23
- package/src/charts/primitives.ts +0 -262
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Progress = exports.Spinner = exports.Skeleton = exports.Separator = exports.Badge = exports.Avatar = void 0;
|
|
4
|
+
exports.initialsOf = initialsOf;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const Glass_1 = require("./Glass");
|
|
8
|
+
const tokens_1 = require("./internal/tokens");
|
|
9
|
+
const primitives_1 = require("./internal/primitives");
|
|
10
|
+
const motion_1 = require("./internal/motion");
|
|
11
|
+
const avatarSizes = { sm: 28, md: 40, lg: 64 };
|
|
12
|
+
/** First letters of the first and last word, as an avatar fallback. */
|
|
13
|
+
function initialsOf(name) {
|
|
14
|
+
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
15
|
+
if (words.length === 0)
|
|
16
|
+
return "";
|
|
17
|
+
if (words.length === 1)
|
|
18
|
+
return words[0].slice(0, 2).toUpperCase();
|
|
19
|
+
return (words[0][0] + words[words.length - 1][0]).toUpperCase();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A person or entity: their picture, or their initials when there is none.
|
|
23
|
+
*
|
|
24
|
+
* The frame is Glacia's glass so it belongs to the same family as the rest of
|
|
25
|
+
* the library; the initials sit on it in the theme's foreground colour.
|
|
26
|
+
*/
|
|
27
|
+
exports.Avatar = (0, react_1.forwardRef)(function Avatar({ source, name, size = "md", status, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
28
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
29
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
30
|
+
const { View, Text, Image } = (0, primitives_1.primitives)();
|
|
31
|
+
// A broken remote image falls back to initials rather than an empty circle.
|
|
32
|
+
const [failed, setFailed] = (0, react_1.useState)(false);
|
|
33
|
+
const dimension = avatarSizes[size];
|
|
34
|
+
const initials = name ? initialsOf(name) : "";
|
|
35
|
+
const statusColor = status === "online" ? theme.on : status === "busy" ? theme.destructive : theme.muted;
|
|
36
|
+
const dot = Math.max(8, Math.round(dimension * 0.26));
|
|
37
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, accessible: true, accessibilityRole: "image", accessibilityLabel: name ? `Avatar of ${name}` : "Avatar", style: { width: dimension, height: dimension, ...style }, ...props, children: [(0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: {
|
|
38
|
+
width: dimension,
|
|
39
|
+
height: dimension,
|
|
40
|
+
borderRadius: dimension / 2,
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
justifyContent: "center",
|
|
43
|
+
overflow: "hidden",
|
|
44
|
+
}, children: source && !failed ? ((0, jsx_runtime_1.jsx)(Image, { source: source, accessibilityLabel: name ?? "Avatar", onError: () => setFailed(true), style: { width: dimension, height: dimension } })) : ((0, jsx_runtime_1.jsx)(Text, { style: {
|
|
45
|
+
fontSize: Math.round(dimension * 0.38),
|
|
46
|
+
fontWeight: "600",
|
|
47
|
+
color: theme.foreground,
|
|
48
|
+
}, children: initials })) }), status && ((0, jsx_runtime_1.jsx)(View, { style: {
|
|
49
|
+
position: "absolute",
|
|
50
|
+
right: 0,
|
|
51
|
+
bottom: 0,
|
|
52
|
+
width: dot,
|
|
53
|
+
height: dot,
|
|
54
|
+
borderRadius: dot / 2,
|
|
55
|
+
backgroundColor: statusColor,
|
|
56
|
+
borderWidth: 1.5,
|
|
57
|
+
borderColor: theme.glassActive,
|
|
58
|
+
} }))] }));
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* A small count or dot.
|
|
62
|
+
*
|
|
63
|
+
* Deliberately not glass: a badge is a micro-element, and a translucent 16pt
|
|
64
|
+
* chip loses its contrast against whatever it sits on. It uses the solid theme
|
|
65
|
+
* tint instead, which is what makes it legible in both themes.
|
|
66
|
+
*/
|
|
67
|
+
exports.Badge = (0, react_1.forwardRef)(function Badge({ children, tone = "fill", overlay, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
68
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
69
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
70
|
+
const { View, Text } = (0, primitives_1.primitives)();
|
|
71
|
+
const background = tone === "destructive"
|
|
72
|
+
? theme.destructive
|
|
73
|
+
: tone === "success"
|
|
74
|
+
? theme.on
|
|
75
|
+
: tone === "muted"
|
|
76
|
+
? theme.muted
|
|
77
|
+
: theme.fill;
|
|
78
|
+
const isDot = children == null;
|
|
79
|
+
const height = isDot ? 10 : 18;
|
|
80
|
+
const badge = ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: isDot ? undefined : String(children), style: {
|
|
81
|
+
minWidth: height,
|
|
82
|
+
height,
|
|
83
|
+
borderRadius: height / 2,
|
|
84
|
+
paddingHorizontal: isDot ? 0 : 6,
|
|
85
|
+
alignItems: "center",
|
|
86
|
+
justifyContent: "center",
|
|
87
|
+
backgroundColor: background,
|
|
88
|
+
...style,
|
|
89
|
+
}, ...props, children: !isDot && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, fontWeight: "700", color: theme.onTint }, numberOfLines: 1, children: children })) }));
|
|
90
|
+
if (overlay === undefined)
|
|
91
|
+
return badge;
|
|
92
|
+
// Overlaid: the badge floats at the top-right of whatever it decorates, which
|
|
93
|
+
// needs a positioned box around the child rather than a bare fragment.
|
|
94
|
+
return ((0, jsx_runtime_1.jsxs)(View, { style: { alignSelf: "flex-start" }, children: [overlay, (0, jsx_runtime_1.jsx)(View, { style: { position: "absolute", top: -4, right: -4 }, children: badge })] }));
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* A hairline divider in the theme's separator colour.
|
|
98
|
+
*
|
|
99
|
+
* A plain View rather than a Glass: a 1pt rule is not a surface, and glass on
|
|
100
|
+
* a line has nothing to refract.
|
|
101
|
+
*/
|
|
102
|
+
exports.Separator = (0, react_1.forwardRef)(function Separator({ orientation = "horizontal", inset = 0, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
103
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
104
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
105
|
+
const { View } = (0, primitives_1.primitives)();
|
|
106
|
+
const separatorStyle = orientation === "horizontal"
|
|
107
|
+
? { height: 0.5, alignSelf: "stretch", marginLeft: inset, backgroundColor: theme.separator }
|
|
108
|
+
: { width: 0.5, alignSelf: "stretch", backgroundColor: theme.separator };
|
|
109
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "none", style: { ...separatorStyle, ...style }, ...props }));
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* A loading placeholder.
|
|
113
|
+
*
|
|
114
|
+
* The pulse is opacity only and slow, on the gentle spring, so it reads as
|
|
115
|
+
* "loading" without motion that could bother someone sensitive to movement.
|
|
116
|
+
* Nothing about it is essential to understanding the screen, so it is hidden
|
|
117
|
+
* from screen readers rather than announced.
|
|
118
|
+
*/
|
|
119
|
+
exports.Skeleton = (0, react_1.forwardRef)(function Skeleton({ shape = "rect", width, height, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
120
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
121
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
122
|
+
const { View, Animated } = (0, primitives_1.primitives)();
|
|
123
|
+
const { value: pulse, animated } = (0, motion_1.useSpring)(1, "gentle");
|
|
124
|
+
const opacity = animated
|
|
125
|
+
? pulse.interpolate({ inputRange: [0, 1], outputRange: [0.35, 1] })
|
|
126
|
+
: 1;
|
|
127
|
+
const resolvedWidth = width ?? (shape === "line" ? "100%" : shape === "circle" ? 40 : 120);
|
|
128
|
+
const resolvedHeight = height ?? (shape === "line" ? 12 : shape === "circle" ? 40 : 80);
|
|
129
|
+
const radius = shape === "circle" ? Math.min(resolvedHeight, 9999) / 2 : shape === "line" ? tokens_1.radii.sm : tokens_1.radii.md;
|
|
130
|
+
const skeletonStyle = {
|
|
131
|
+
width: resolvedWidth,
|
|
132
|
+
height: resolvedHeight,
|
|
133
|
+
borderRadius: radius,
|
|
134
|
+
backgroundColor: theme.skeleton,
|
|
135
|
+
...style,
|
|
136
|
+
};
|
|
137
|
+
const a11y = { accessibilityRole: "none", accessible: false, testID };
|
|
138
|
+
return animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { ref: ref, style: { ...skeletonStyle, opacity }, ...a11y, ...props })) : ((0, jsx_runtime_1.jsx)(View, { ref: ref, style: skeletonStyle, ...a11y, ...props }));
|
|
139
|
+
});
|
|
140
|
+
const spinnerSizes = { sm: 16, md: 22, lg: 32 };
|
|
141
|
+
/**
|
|
142
|
+
* A loading spinner, drawn by Glacia.
|
|
143
|
+
*
|
|
144
|
+
* An SVG arc that rotates on the gentle spring through Animated — not the
|
|
145
|
+
* platform's ActivityIndicator, so it looks the same on every platform and
|
|
146
|
+
* wears the theme's colour instead of inheriting the system tint.
|
|
147
|
+
*/
|
|
148
|
+
exports.Spinner = (0, react_1.forwardRef)(function Spinner({ size = "md", tint, accessibilityLabel = "Loading", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
149
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
150
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
151
|
+
const { View, Svg, Circle, Animated } = (0, primitives_1.primitives)();
|
|
152
|
+
const dimension = spinnerSizes[size];
|
|
153
|
+
const stroke = Math.max(2, Math.round(dimension / 9));
|
|
154
|
+
const color = tint ?? theme.muted;
|
|
155
|
+
// An arc, not a full ring: a complete circle rotating looks static.
|
|
156
|
+
const circumference = 2 * Math.PI * ((dimension - stroke) / 2);
|
|
157
|
+
const dash = circumference * 0.28;
|
|
158
|
+
// A continuous spin never settles, so it is driven by Animated.timing on a
|
|
159
|
+
// loop rather than the spring hook, which is built for one-off targets.
|
|
160
|
+
const { Animated: AnimatedAPI, isNative } = (0, primitives_1.primitives)();
|
|
161
|
+
const spinning = isNative && Boolean(AnimatedAPI?.timing);
|
|
162
|
+
const rotation = (0, react_1.useRef)(null);
|
|
163
|
+
if (rotation.current === null) {
|
|
164
|
+
rotation.current = spinning ? new AnimatedAPI.Value(0) : null;
|
|
165
|
+
}
|
|
166
|
+
(0, react_1.useEffect)(() => {
|
|
167
|
+
if (!spinning || !rotation.current)
|
|
168
|
+
return;
|
|
169
|
+
rotation.current.setValue(0);
|
|
170
|
+
const loop = AnimatedAPI.loop(AnimatedAPI.timing(rotation.current, {
|
|
171
|
+
toValue: 1,
|
|
172
|
+
duration: 900,
|
|
173
|
+
useNativeDriver: true,
|
|
174
|
+
}));
|
|
175
|
+
loop.start?.();
|
|
176
|
+
return () => loop.stop?.();
|
|
177
|
+
}, [AnimatedAPI, spinning]);
|
|
178
|
+
const spinStyle = spinning
|
|
179
|
+
? {
|
|
180
|
+
transform: [
|
|
181
|
+
{
|
|
182
|
+
rotate: rotation.current.interpolate({
|
|
183
|
+
inputRange: [0, 1],
|
|
184
|
+
outputRange: ["0deg", "360deg"],
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
}
|
|
189
|
+
: undefined;
|
|
190
|
+
const svg = ((0, jsx_runtime_1.jsxs)(Svg, { width: dimension, height: dimension, viewBox: `0 0 ${dimension} ${dimension}`, children: [(0, jsx_runtime_1.jsx)(Circle, { cx: dimension / 2, cy: dimension / 2, r: (dimension - stroke) / 2, stroke: theme.skeleton, strokeWidth: stroke, fill: "none" }), (0, jsx_runtime_1.jsx)(Circle, { cx: dimension / 2, cy: dimension / 2, r: (dimension - stroke) / 2, stroke: color, strokeWidth: stroke, fill: "none", strokeLinecap: "round", strokeDasharray: `${dash} ${circumference - dash}` })] }));
|
|
191
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "progressbar", accessibilityLabel: accessibilityLabel, style: [{ width: dimension, height: dimension }, style], ...props, children: spinning ? (0, jsx_runtime_1.jsx)(Animated.View, { style: spinStyle, children: svg }) : svg }));
|
|
192
|
+
});
|
|
193
|
+
const RING = 64;
|
|
194
|
+
/**
|
|
195
|
+
* Progress, linear or circular.
|
|
196
|
+
*
|
|
197
|
+
* The track is a glass surface, so it refracts what it sits on exactly like the
|
|
198
|
+
* rest of the library; the fill is the theme accent. Both forms report
|
|
199
|
+
* `progressbar` with a value, which is the contract NativeTask relies on
|
|
200
|
+
* internally — this component generalises it.
|
|
201
|
+
*/
|
|
202
|
+
exports.Progress = (0, react_1.forwardRef)(function Progress({ value, variant = "bar", tint, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
203
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
204
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
205
|
+
const { View, Text, Svg, Circle } = (0, primitives_1.primitives)();
|
|
206
|
+
const clamped = Math.min(Math.max(value, 0), 100);
|
|
207
|
+
const fill = tint ?? theme.fill;
|
|
208
|
+
const a11y = {
|
|
209
|
+
accessibilityRole: "progressbar",
|
|
210
|
+
accessibilityValue: { min: 0, max: 100, now: Math.round(clamped) },
|
|
211
|
+
accessibilityLabel,
|
|
212
|
+
testID,
|
|
213
|
+
};
|
|
214
|
+
if (variant === "ring") {
|
|
215
|
+
const stroke = 6;
|
|
216
|
+
const radius = (RING - stroke) / 2;
|
|
217
|
+
const circumference = 2 * Math.PI * radius;
|
|
218
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, style: [{ width: RING, height: RING }, style], ...a11y, ...props, children: [(0, jsx_runtime_1.jsxs)(Svg, { width: RING, height: RING, viewBox: `0 0 ${RING} ${RING}`, children: [(0, jsx_runtime_1.jsx)(Circle, { cx: RING / 2, cy: RING / 2, r: radius, stroke: theme.skeleton, strokeWidth: stroke, fill: "none" }), (0, jsx_runtime_1.jsx)(Circle, { cx: RING / 2, cy: RING / 2, r: radius, stroke: fill, strokeWidth: stroke, fill: "none", strokeLinecap: "round", strokeDasharray: `${(clamped / 100) * circumference} ${circumference}`,
|
|
219
|
+
// Start the arc at twelve o'clock, the way progress dials read.
|
|
220
|
+
transform: `rotate(-90 ${RING / 2} ${RING / 2})` })] }), (0, jsx_runtime_1.jsx)(View, { style: {
|
|
221
|
+
position: "absolute",
|
|
222
|
+
width: RING,
|
|
223
|
+
height: RING,
|
|
224
|
+
alignItems: "center",
|
|
225
|
+
justifyContent: "center",
|
|
226
|
+
}, children: (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 13, fontWeight: "600", color: theme.foreground }, children: `${Math.round(clamped)}%` }) })] }));
|
|
227
|
+
}
|
|
228
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, style: {
|
|
229
|
+
height: 8,
|
|
230
|
+
borderRadius: tokens_1.radii.pill,
|
|
231
|
+
overflow: "hidden",
|
|
232
|
+
justifyContent: "center",
|
|
233
|
+
...style,
|
|
234
|
+
}, ...a11y, ...props, children: (0, jsx_runtime_1.jsx)(View, { style: {
|
|
235
|
+
width: `${clamped}%`,
|
|
236
|
+
height: 8,
|
|
237
|
+
borderRadius: tokens_1.radii.pill,
|
|
238
|
+
backgroundColor: fill,
|
|
239
|
+
} }) }));
|
|
240
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Accordion = exports.ListSection = exports.List = exports.ListItem = exports.Banner = exports.Toast = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const Glass_1 = require("./Glass");
|
|
7
|
+
const Display_1 = require("./Display");
|
|
8
|
+
const tokens_1 = require("./internal/tokens");
|
|
9
|
+
const primitives_1 = require("./internal/primitives");
|
|
10
|
+
const motion_1 = require("./internal/motion");
|
|
11
|
+
/**
|
|
12
|
+
* A transient message on a glass pill.
|
|
13
|
+
*
|
|
14
|
+
* A toast is not a dialog: it never blocks the screen, so it renders in place
|
|
15
|
+
* and lets touches through to what is underneath. It dismisses itself after
|
|
16
|
+
* `duration` unless it is controlled or `duration` is 0.
|
|
17
|
+
*/
|
|
18
|
+
exports.Toast = (0, react_1.forwardRef)(function Toast({ visible: visibleProp, defaultVisible = false, onDismiss, message, action, icon, duration = 4000, tone = "neutral", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
19
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
20
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
21
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
22
|
+
const [internalVisible, setInternalVisible] = (0, react_1.useState)(defaultVisible);
|
|
23
|
+
const visible = visibleProp !== undefined ? visibleProp : internalVisible;
|
|
24
|
+
const dismiss = () => {
|
|
25
|
+
if (visibleProp === undefined)
|
|
26
|
+
setInternalVisible(false);
|
|
27
|
+
onDismiss?.();
|
|
28
|
+
};
|
|
29
|
+
// The timer lives and dies with the toast. A ref keeps the latest dismiss
|
|
30
|
+
// closure out of the effect's dependencies, so a parent re-render does not
|
|
31
|
+
// restart the countdown.
|
|
32
|
+
const dismissRef = (0, react_1.useRef)(dismiss);
|
|
33
|
+
dismissRef.current = dismiss;
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
if (!visible || duration <= 0)
|
|
36
|
+
return;
|
|
37
|
+
const timer = setTimeout(() => dismissRef.current(), duration);
|
|
38
|
+
return () => clearTimeout(timer);
|
|
39
|
+
}, [visible, duration]);
|
|
40
|
+
const { value: enter, animated } = (0, motion_1.useSpring)(visible ? 1 : 0, "snappy");
|
|
41
|
+
const rise = animated ? enter.interpolate({ inputRange: [0, 1], outputRange: [12, 0] }) : 0;
|
|
42
|
+
const fade = animated ? enter.interpolate({ inputRange: [0, 1], outputRange: [0, 1] }) : 1;
|
|
43
|
+
if (!visible)
|
|
44
|
+
return null;
|
|
45
|
+
const accent = tone === "neutral" ? theme.foreground : (0, tokens_1.toneColor)(theme, tone);
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, pointerEvents: "box-none", style: { alignItems: "center", ...style }, ...props, children: (0, jsx_runtime_1.jsx)(Entrance, { animated: animated, rise: rise, fade: fade, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: {
|
|
47
|
+
flexDirection: "row",
|
|
48
|
+
alignItems: "center",
|
|
49
|
+
gap: 10,
|
|
50
|
+
paddingVertical: 10,
|
|
51
|
+
paddingHorizontal: 14,
|
|
52
|
+
borderRadius: tokens_1.radii.pill,
|
|
53
|
+
maxWidth: 420,
|
|
54
|
+
borderColor: tone === "neutral" ? theme.edge : accent,
|
|
55
|
+
}, children: [icon ? (0, jsx_runtime_1.jsx)(View, { children: icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "alert", accessibilityLiveRegion: "polite", style: { fontSize: 14, color: theme.foreground, flexShrink: 1 }, children: message }), action && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: action.label, onPress: action.onPress, style: { paddingHorizontal: 4 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 14, fontWeight: "600", color: theme.fill }, children: action.label }) }))] }) }) }));
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Applies the toast's entrance motion around the pill.
|
|
59
|
+
*
|
|
60
|
+
* A thin wrapper because animated styles must land on an Animated.View, while
|
|
61
|
+
* the pill itself is a Glass — wrapping keeps both honest.
|
|
62
|
+
*/
|
|
63
|
+
function Entrance({ animated, rise, fade, children, }) {
|
|
64
|
+
const { Animated } = (0, primitives_1.primitives)();
|
|
65
|
+
if (!animated)
|
|
66
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
|
|
67
|
+
return ((0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ translateY: rise }], opacity: fade }, children: children }));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* An inline alert.
|
|
71
|
+
*
|
|
72
|
+
* Unlike AlertDialog it is not modal and not an overlay: it sits in the layout
|
|
73
|
+
* and pushes the content below it down. The surface is glass with the tone's
|
|
74
|
+
* colour as its edge, so the tone reads at a glance without turning the whole
|
|
75
|
+
* panel into a solid block of colour.
|
|
76
|
+
*/
|
|
77
|
+
exports.Banner = (0, react_1.forwardRef)(function Banner({ title, message, tone = "info", icon, onDismiss, action, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
78
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
79
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
80
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
81
|
+
const accent = (0, tokens_1.toneColor)(theme, tone);
|
|
82
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, testID: testID, style: { borderRadius: tokens_1.radii.md, borderColor: accent, ...style }, ...props, children: (0, jsx_runtime_1.jsxs)(View, { style: { flexDirection: "row", alignItems: "flex-start", gap: 10, padding: 12 }, children: [icon ? (0, jsx_runtime_1.jsx)(View, { style: { paddingTop: 1 }, children: icon }) : null, (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, gap: 2 }, children: [title && ((0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "heading", style: { fontSize: 14, fontWeight: "600", color: theme.foreground }, children: title })), (0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "alert", style: { fontSize: 13, color: theme.muted, lineHeight: 18 }, children: message }), action && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: action.label, onPress: action.onPress, style: { alignSelf: "flex-start", paddingTop: 6 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 13, fontWeight: "600", color: accent }, children: action.label }) }))] }), onDismiss && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Dismiss", onPress: onDismiss, hitSlop: 8, style: { padding: 2 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 15, color: theme.muted }, children: "\u00D7" }) }))] }) }));
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* One row of a List.
|
|
86
|
+
*
|
|
87
|
+
* The row is a Pressable when it has an `onPress`, and inert otherwise, which
|
|
88
|
+
* is what the platform expects: a row that does nothing should not announce
|
|
89
|
+
* itself as a button. The chevron is decoration and is hidden from screen
|
|
90
|
+
* readers, since the row's own role already says it is tappable.
|
|
91
|
+
*/
|
|
92
|
+
exports.ListItem = (0, react_1.forwardRef)(function ListItem({ leading, title, description, trailing, chevron, onPress, disabled = false, selected = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
93
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
94
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
95
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
96
|
+
const interactive = Boolean(onPress) && !disabled;
|
|
97
|
+
const showChevron = interactive && chevron !== false && trailing === undefined;
|
|
98
|
+
const content = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [leading ? (0, jsx_runtime_1.jsx)(View, { style: { marginRight: 12 }, children: leading }) : null, (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, gap: 2 }, children: [(0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 16, color: theme.foreground, fontWeight: "400" }, children: title }), description ? ((0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 2, style: { fontSize: 13, color: theme.muted, lineHeight: 17 }, children: description })) : null] }), trailing ? (0, jsx_runtime_1.jsx)(View, { style: { marginLeft: 8 }, children: trailing }) : null, showChevron ? ((0, jsx_runtime_1.jsx)(RNText, { accessibilityElementsHidden: true, importantForAccessibility: "no", style: { marginLeft: 6, fontSize: 17, color: theme.muted }, children: "\u203A" })) : null] }));
|
|
99
|
+
const rowStyle = {
|
|
100
|
+
flexDirection: "row",
|
|
101
|
+
alignItems: "center",
|
|
102
|
+
minHeight: 48,
|
|
103
|
+
paddingVertical: 10,
|
|
104
|
+
paddingHorizontal: 14,
|
|
105
|
+
backgroundColor: selected ? theme.glassActive : "transparent",
|
|
106
|
+
opacity: disabled ? 0.38 : 1,
|
|
107
|
+
...style,
|
|
108
|
+
};
|
|
109
|
+
if (!interactive) {
|
|
110
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityState: { disabled }, style: rowStyle, ...props, children: content }));
|
|
111
|
+
}
|
|
112
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: description ? `${title}, ${description}` : title, accessibilityState: { selected, disabled }, disabled: disabled, onPress: onPress, style: ({ pressed }) => ({ ...rowStyle, opacity: pressed ? 0.7 : rowStyle.opacity }), ...props, children: content }));
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* A grouped list of rows — the backbone of settings and profile screens.
|
|
116
|
+
*
|
|
117
|
+
* With `inset`, the rows sit on one glass panel with hairline separators, which
|
|
118
|
+
* is the shape iOS settings screens use. The separators are drawn by the
|
|
119
|
+
* caller's ListItem spacing rather than by nesting glass inside glass.
|
|
120
|
+
*/
|
|
121
|
+
exports.List = (0, react_1.forwardRef)(function List({ children, inset = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
122
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
123
|
+
const { View } = (0, primitives_1.primitives)();
|
|
124
|
+
const rows = Array.isArray(children) ? children.filter(Boolean) : children == null ? [] : [children];
|
|
125
|
+
const body = ((0, jsx_runtime_1.jsx)(View, { style: { gap: 2 }, children: rows.map((row, index) => ((0, jsx_runtime_1.jsxs)(View, { children: [index > 0 ? (0, jsx_runtime_1.jsx)(Display_1.Separator, { isDark: isDark, inset: inset ? 14 : 0 }) : null, row] }, index))) }));
|
|
126
|
+
if (!inset) {
|
|
127
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: style, ...props, children: body }));
|
|
128
|
+
}
|
|
129
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, testID: testID, style: { borderRadius: tokens_1.radii.md, overflow: "hidden", ...style }, ...props, children: body }));
|
|
130
|
+
});
|
|
131
|
+
exports.ListSection = (0, react_1.forwardRef)(function ListSection({ header, children, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
132
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
133
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
134
|
+
const { View, Text: RNText } = (0, primitives_1.primitives)();
|
|
135
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: [{ gap: 6 }, style], ...props, children: [header ? ((0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "heading", style: {
|
|
136
|
+
fontSize: 12,
|
|
137
|
+
fontWeight: "600",
|
|
138
|
+
letterSpacing: 0.4,
|
|
139
|
+
textTransform: "uppercase",
|
|
140
|
+
color: theme.muted,
|
|
141
|
+
paddingHorizontal: 14,
|
|
142
|
+
}, children: header })) : null, (0, jsx_runtime_1.jsx)(exports.List, { inset: true, isDark: isDark, children: children })] }));
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Expandable sections.
|
|
146
|
+
*
|
|
147
|
+
* The header is a Pressable reporting `expanded`; the panel is measured with
|
|
148
|
+
* the height the content reports and animated on the springs token, so the
|
|
149
|
+
* reveal is a real transition rather than an instant jump.
|
|
150
|
+
*/
|
|
151
|
+
exports.Accordion = (0, react_1.forwardRef)(function Accordion({ sections, multiple = false, openSections: openProp, defaultOpenSections = [], onOpenSectionsChange, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
152
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
153
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
154
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
155
|
+
const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpenSections);
|
|
156
|
+
const open = openProp !== undefined ? openProp : internalOpen;
|
|
157
|
+
const toggle = (value) => {
|
|
158
|
+
const isOpen = open.includes(value);
|
|
159
|
+
let next;
|
|
160
|
+
if (isOpen)
|
|
161
|
+
next = open.filter((item) => item !== value);
|
|
162
|
+
else
|
|
163
|
+
next = multiple ? [...open, value] : [value];
|
|
164
|
+
if (openProp === undefined)
|
|
165
|
+
setInternalOpen(next);
|
|
166
|
+
onOpenSectionsChange?.(next);
|
|
167
|
+
};
|
|
168
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, testID: testID, style: { borderRadius: tokens_1.radii.md, overflow: "hidden", ...style }, ...props, children: sections.map((section, index) => {
|
|
169
|
+
const expanded = open.includes(section.value);
|
|
170
|
+
return ((0, jsx_runtime_1.jsxs)(View, { children: [index > 0 ? (0, jsx_runtime_1.jsx)(Display_1.Separator, { isDark: isDark }) : null, (0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: section.title, accessibilityState: { expanded }, onPress: () => toggle(section.value), style: { paddingVertical: 12, paddingHorizontal: 14, flexDirection: "row", alignItems: "center" }, children: [(0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, gap: 2 }, children: [(0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 15, fontWeight: "500", color: theme.foreground }, children: section.title }), section.description ? ((0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 13, color: theme.muted }, children: section.description })) : null] }), (0, jsx_runtime_1.jsx)(RNText, { accessibilityElementsHidden: true, importantForAccessibility: "no", style: { fontSize: 13, color: theme.muted, marginLeft: 8 }, children: expanded ? "\u2303" : "\u2304" })] }), expanded ? ((0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 14, paddingBottom: 12 }, children: section.content })) : null] }, section.value));
|
|
171
|
+
}) }));
|
|
172
|
+
});
|
package/lib/module/Form.js
CHANGED
|
@@ -8,12 +8,14 @@ exports.Select = Select;
|
|
|
8
8
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
9
|
const react_1 = require("react");
|
|
10
10
|
const tokens_1 = require("./internal/tokens");
|
|
11
|
-
const primitives_1 = require("./
|
|
11
|
+
const primitives_1 = require("./internal/primitives");
|
|
12
|
+
const motion_1 = require("./internal/motion");
|
|
12
13
|
/** The text above a control. */
|
|
13
|
-
exports.Label = (0, react_1.forwardRef)(function Label({ children, required = false, disabled = false,
|
|
14
|
+
exports.Label = (0, react_1.forwardRef)(function Label({ children, required = false, disabled = false, nativeID, isDark: isDarkProp, style }, ref) {
|
|
15
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
14
16
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
15
17
|
const { Text } = (0, primitives_1.primitives)();
|
|
16
|
-
return ((0, jsx_runtime_1.jsxs)(Text, { ref: ref, nativeID:
|
|
18
|
+
return ((0, jsx_runtime_1.jsxs)(Text, { ref: ref, nativeID: nativeID, accessibilityRole: "text", style: {
|
|
17
19
|
fontSize: 13,
|
|
18
20
|
fontWeight: "600",
|
|
19
21
|
color: disabled ? theme.muted : theme.foreground,
|
|
@@ -25,7 +27,8 @@ exports.Label = (0, react_1.forwardRef)(function Label({ children, required = fa
|
|
|
25
27
|
* Label, control and message stacked in the order assistive tech announces
|
|
26
28
|
* them, so a caller never has to place these three by hand.
|
|
27
29
|
*/
|
|
28
|
-
function Field({ label, description, error, required = false, disabled = false, isDark
|
|
30
|
+
function Field({ label, description, error, required = false, disabled = false, isDark: isDarkProp, children, style, }) {
|
|
31
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
29
32
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
30
33
|
const { View, Text } = (0, primitives_1.primitives)();
|
|
31
34
|
const message = error ?? description;
|
|
@@ -35,11 +38,23 @@ function Field({ label, description, error, required = false, disabled = false,
|
|
|
35
38
|
}, children: message }))] }));
|
|
36
39
|
}
|
|
37
40
|
/** A tick box for a single boolean, with an optional label and description. */
|
|
38
|
-
function Checkbox({ checked = false, onCheckedChange, label, description, indeterminate = false, disabled = false, isDark
|
|
41
|
+
function Checkbox({ checked: checkedProp, defaultChecked = false, onCheckedChange, label, description, indeterminate = false, disabled = false, isDark: isDarkProp, style, testID, }) {
|
|
42
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
39
43
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
40
44
|
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
45
|
+
// Controlled when `checked` is given, otherwise the box owns its state.
|
|
46
|
+
const [internalChecked, setInternalChecked] = (0, react_1.useState)(defaultChecked);
|
|
47
|
+
const checked = checkedProp !== undefined ? checkedProp : internalChecked;
|
|
48
|
+
const toggle = () => {
|
|
49
|
+
if (disabled)
|
|
50
|
+
return;
|
|
51
|
+
const next = !checked;
|
|
52
|
+
if (checkedProp === undefined)
|
|
53
|
+
setInternalChecked(next);
|
|
54
|
+
onCheckedChange?.(next);
|
|
55
|
+
};
|
|
41
56
|
const filled = checked || indeterminate;
|
|
42
|
-
return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "checkbox", accessibilityState: { checked, disabled }, accessibilityLabel: label, disabled: disabled, onPress:
|
|
57
|
+
return ((0, jsx_runtime_1.jsxs)(Pressable, { testID: testID, accessibilityRole: "checkbox", accessibilityState: { checked, disabled }, accessibilityLabel: label, disabled: disabled, onPress: toggle, style: {
|
|
43
58
|
flexDirection: "row",
|
|
44
59
|
alignItems: "flex-start",
|
|
45
60
|
gap: 10,
|
|
@@ -60,13 +75,28 @@ function Checkbox({ checked = false, onCheckedChange, label, description, indete
|
|
|
60
75
|
(0, jsx_runtime_1.jsx)(Text, { style: { color: "#fff", fontSize: 12, fontWeight: "700", lineHeight: 14 }, children: "\u2713" })) : null }), (label || description) && ((0, jsx_runtime_1.jsxs)(View, { style: { flex: 1 }, children: [label && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 14, color: theme.foreground, fontWeight: "500" }, children: label })), description && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: theme.muted, marginTop: 2 }, children: description }))] }))] }));
|
|
61
76
|
}
|
|
62
77
|
/** One choice from a small, always-visible set. */
|
|
63
|
-
function RadioGroup({ value, onValueChange, options, horizontal = false, disabled = false, isDark
|
|
78
|
+
function RadioGroup({ value: valueProp, defaultValue, onValueChange, options, horizontal = false, disabled = false, isDark: isDarkProp, style, testID, }) {
|
|
79
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
64
80
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
65
81
|
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
66
|
-
|
|
82
|
+
// Controlled when `value` is given, otherwise the group owns its selection.
|
|
83
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)(defaultValue);
|
|
84
|
+
const value = valueProp !== undefined ? valueProp : internalValue;
|
|
85
|
+
const select = (next, isDisabled) => {
|
|
86
|
+
if (isDisabled)
|
|
87
|
+
return;
|
|
88
|
+
if (valueProp === undefined)
|
|
89
|
+
setInternalValue(next);
|
|
90
|
+
onValueChange?.(next);
|
|
91
|
+
};
|
|
92
|
+
return ((0, jsx_runtime_1.jsx)(View, { testID: testID, accessibilityRole: "radiogroup", style: {
|
|
93
|
+
gap: horizontal ? 14 : 10,
|
|
94
|
+
flexDirection: horizontal ? "row" : "column",
|
|
95
|
+
...style,
|
|
96
|
+
}, children: options.map((option) => {
|
|
67
97
|
const isSelected = option.value === value;
|
|
68
98
|
const isDisabled = disabled || option.disabled;
|
|
69
|
-
return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "radio", accessibilityState: { checked: isSelected, disabled: isDisabled }, accessibilityLabel: option.label, disabled: isDisabled, onPress: () =>
|
|
99
|
+
return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "radio", accessibilityState: { checked: isSelected, disabled: isDisabled }, accessibilityLabel: option.label, disabled: isDisabled, onPress: () => select(option.value, isDisabled), style: {
|
|
70
100
|
flexDirection: "row",
|
|
71
101
|
alignItems: "flex-start",
|
|
72
102
|
gap: 9,
|
|
@@ -88,12 +118,21 @@ function RadioGroup({ value, onValueChange, options, horizontal = false, disable
|
|
|
88
118
|
* list opens inline: predictable across platforms and reachable without a
|
|
89
119
|
* modal. A long list scrolls naturally with the page.
|
|
90
120
|
*/
|
|
91
|
-
function Select({ value, onValueChange, options, placeholder = "Select an option", disabled = false, isDark
|
|
121
|
+
function Select({ value: valueProp, defaultValue, onValueChange, options, placeholder = "Select an option", disabled = false, isDark: isDarkProp, style, testID, }) {
|
|
122
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
92
123
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
93
124
|
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
94
125
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
126
|
+
// Controlled when `value` is given, otherwise the select owns its choice.
|
|
127
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)(defaultValue);
|
|
128
|
+
const value = valueProp !== undefined ? valueProp : internalValue;
|
|
129
|
+
const choose = (next) => {
|
|
130
|
+
if (valueProp === undefined)
|
|
131
|
+
setInternalValue(next);
|
|
132
|
+
onValueChange?.(next);
|
|
133
|
+
};
|
|
95
134
|
const selected = options.find((option) => option.value === value);
|
|
96
|
-
return ((0, jsx_runtime_1.jsxs)(View, { style: style, children: [(0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityState: { expanded: open, disabled }, accessibilityLabel: selected?.label ?? placeholder, disabled: disabled, onPress: () => setOpen(!open), style: {
|
|
135
|
+
return ((0, jsx_runtime_1.jsxs)(View, { style: style, children: [(0, jsx_runtime_1.jsxs)(Pressable, { testID: testID, accessibilityRole: "button", accessibilityState: { expanded: open, disabled }, accessibilityLabel: selected?.label ?? placeholder, disabled: disabled, onPress: () => setOpen(!open), style: {
|
|
97
136
|
minHeight: 42,
|
|
98
137
|
flexDirection: "row",
|
|
99
138
|
alignItems: "center",
|
|
@@ -114,7 +153,7 @@ function Select({ value, onValueChange, options, placeholder = "Select an option
|
|
|
114
153
|
}, children: options.map((option) => {
|
|
115
154
|
const isSelected = option.value === value;
|
|
116
155
|
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityState: { selected: isSelected }, accessibilityLabel: option.label, onPress: () => {
|
|
117
|
-
|
|
156
|
+
choose(option.value);
|
|
118
157
|
setOpen(false);
|
|
119
158
|
}, style: {
|
|
120
159
|
paddingVertical: 10,
|