glacia-native 0.4.0 → 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/Carousel.js +103 -0
- package/lib/module/Display.js +240 -0
- package/lib/module/Feedback.js +172 -0
- package/lib/module/Forms2.js +227 -0
- package/lib/module/Overlays.js +166 -0
- package/lib/module/Pickers.js +243 -0
- package/lib/module/Text.js +37 -0
- package/lib/module/index.js +58 -1
- package/lib/module/internal/GlassView.js +23 -7
- package/lib/module/internal/primitives.js +7 -2
- package/lib/module/internal/tokens.js +55 -1
- package/lib/typescript/Bars.d.ts +121 -0
- package/lib/typescript/Carousel.d.ts +47 -0
- package/lib/typescript/Display.d.ts +119 -0
- package/lib/typescript/Feedback.d.ts +138 -0
- package/lib/typescript/Forms2.d.ts +128 -0
- package/lib/typescript/Glass.d.ts +1 -1
- package/lib/typescript/Overlays.d.ts +105 -0
- package/lib/typescript/Pickers.d.ts +105 -0
- package/lib/typescript/Text.d.ts +28 -0
- package/lib/typescript/index.d.ts +9 -1
- package/lib/typescript/internal/GlassView.d.ts +10 -1
- package/lib/typescript/internal/tokens.d.ts +61 -0
- package/package.json +2 -2
- package/src/Bars.tsx +570 -0
- package/src/Carousel.tsx +233 -0
- package/src/Display.tsx +550 -0
- package/src/Feedback.tsx +579 -0
- package/src/Forms2.tsx +608 -0
- package/src/Overlays.tsx +474 -0
- package/src/Pickers.tsx +590 -0
- package/src/Text.tsx +83 -0
- package/src/index.ts +101 -1
- package/src/internal/GlassView.tsx +29 -7
- package/src/internal/primitives.ts +7 -2
- package/src/internal/tokens.ts +62 -0
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ButtonGroup = exports.InputOTP = exports.ToggleGroup = exports.Toggle = exports.Stepper = 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 tokens_1 = require("./internal/tokens");
|
|
8
|
+
const primitives_1 = require("./internal/primitives");
|
|
9
|
+
const motion_1 = require("./internal/motion");
|
|
10
|
+
/**
|
|
11
|
+
* Minus / value / plus.
|
|
12
|
+
*
|
|
13
|
+
* The same interaction contract Slider established: `adjustable` with
|
|
14
|
+
* increment and decrement accessibility actions, and clamping at min and max
|
|
15
|
+
* rather than wrapping or drifting past the range.
|
|
16
|
+
*/
|
|
17
|
+
exports.Stepper = (0, react_1.forwardRef)(function Stepper({ value: valueProp, defaultValue = 0, onValueChange, min = 0, max = 100, step = 1, disabled = false, accessibilityLabel, formatValue, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
18
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
19
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
20
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
21
|
+
const [internal, setInternal] = (0, react_1.useState)(defaultValue);
|
|
22
|
+
const value = valueProp !== undefined ? valueProp : internal;
|
|
23
|
+
const apply = (next) => {
|
|
24
|
+
const clamped = Math.min(Math.max(next, min), max);
|
|
25
|
+
if (clamped === value)
|
|
26
|
+
return;
|
|
27
|
+
if (valueProp === undefined)
|
|
28
|
+
setInternal(clamped);
|
|
29
|
+
onValueChange?.(clamped);
|
|
30
|
+
};
|
|
31
|
+
const atMin = value <= min;
|
|
32
|
+
const atMax = value >= max;
|
|
33
|
+
const stepButton = (label, sign, action, blocked) => ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { disabled: disabled || blocked }, disabled: disabled || blocked, onPress: action, style: { width: 36, height: 36, alignItems: "center", justifyContent: "center", opacity: disabled || blocked ? 0.38 : 1 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 20, fontWeight: "500", color: theme.foreground, lineHeight: 22 }, children: sign }) }));
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, testID: testID, accessibilityRole: "adjustable", accessibilityLabel: accessibilityLabel, accessibilityValue: { min, max, now: value }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => {
|
|
35
|
+
const delta = event?.nativeEvent?.actionName === "increment" ? step : -step;
|
|
36
|
+
apply(value + delta);
|
|
37
|
+
}, style: {
|
|
38
|
+
flexDirection: "row",
|
|
39
|
+
alignItems: "center",
|
|
40
|
+
alignSelf: "flex-start",
|
|
41
|
+
borderRadius: tokens_1.radii.pill,
|
|
42
|
+
paddingHorizontal: 2,
|
|
43
|
+
opacity: disabled ? 0.38 : 1,
|
|
44
|
+
...style,
|
|
45
|
+
}, ...props, children: [stepButton(`Decrease ${accessibilityLabel}`, "\u2212", () => apply(value - step), atMin), (0, jsx_runtime_1.jsx)(View, { style: { minWidth: 44, alignItems: "center", justifyContent: "center" }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 16, fontWeight: "600", color: theme.foreground }, numberOfLines: 1, children: formatValue ? formatValue(value) : String(value) }) }), stepButton(`Increase ${accessibilityLabel}`, "+", () => apply(value + step), atMax)] }));
|
|
46
|
+
});
|
|
47
|
+
const toggleSizes = { sm: 30, md: 36, lg: 44 };
|
|
48
|
+
/**
|
|
49
|
+
* A button that stays pressed.
|
|
50
|
+
*
|
|
51
|
+
* Distinct from Switch: this is a button with an on-state (bold, favourite,
|
|
52
|
+
* pinned), not a setting. It reports `selected`, which is what web's Toggle
|
|
53
|
+
* announces.
|
|
54
|
+
*/
|
|
55
|
+
exports.Toggle = (0, react_1.forwardRef)(function Toggle({ pressed: pressedProp, defaultPressed = false, onPressedChange, selected, icon, children, variant = "glass", size = "md", disabled = false, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
56
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
57
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
58
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
59
|
+
// `selected` is accepted as an alias so the controlled prop matches web.
|
|
60
|
+
const controlled = pressedProp !== undefined ? pressedProp : selected;
|
|
61
|
+
const [internal, setInternal] = (0, react_1.useState)(defaultPressed);
|
|
62
|
+
const isPressed = controlled !== undefined ? controlled : internal;
|
|
63
|
+
const dimension = toggleSizes[size];
|
|
64
|
+
const handlePress = () => {
|
|
65
|
+
const next = !isPressed;
|
|
66
|
+
if (controlled === undefined)
|
|
67
|
+
setInternal(next);
|
|
68
|
+
onPressedChange?.(next);
|
|
69
|
+
};
|
|
70
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel ?? (typeof children === "string" ? children : undefined), accessibilityState: { selected: isPressed, disabled }, disabled: disabled, onPress: handlePress, style: ({ pressed }) => ({ alignSelf: "flex-start", opacity: disabled ? 0.38 : pressed ? 0.8 : 1 }), ...props, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: variant === "ghost" ? "none" : "regular", interactive: !disabled && variant !== "ghost", isDark: isDark, tintColor: isPressed && variant !== "ghost" ? theme.glassActive : undefined, style: {
|
|
71
|
+
height: dimension,
|
|
72
|
+
borderRadius: tokens_1.radii.pill,
|
|
73
|
+
paddingHorizontal: icon && !children ? 0 : 12,
|
|
74
|
+
width: icon && !children ? dimension : undefined,
|
|
75
|
+
flexDirection: "row",
|
|
76
|
+
alignItems: "center",
|
|
77
|
+
justifyContent: "center",
|
|
78
|
+
gap: 6,
|
|
79
|
+
backgroundColor: variant === "ghost" ? "transparent" : undefined,
|
|
80
|
+
...style,
|
|
81
|
+
}, children: [icon ? (0, jsx_runtime_1.jsx)(View, { children: icon }) : null, typeof children === "string" ? ((0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: {
|
|
82
|
+
fontSize: size === "sm" ? 12 : size === "lg" ? 15 : 13,
|
|
83
|
+
fontWeight: isPressed ? "600" : "500",
|
|
84
|
+
color: isPressed ? theme.foreground : theme.muted,
|
|
85
|
+
}, children: children })) : (children)] }) }));
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* A row of toggles acting as one choice.
|
|
89
|
+
*
|
|
90
|
+
* Built from the same pieces as SegmentedControl — one glass container, toggles
|
|
91
|
+
* inside it, `glassActive` marking the active ones — but each item carries the
|
|
92
|
+
* button styling of Toggle.
|
|
93
|
+
*/
|
|
94
|
+
exports.ToggleGroup = (0, react_1.forwardRef)(function ToggleGroup({ items, multiple = false, value: valueProp, defaultValue, onValueChange, size = "md", disabled = false, accessibilityLabel = "Toggle group", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
95
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
96
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
97
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
98
|
+
const initial = defaultValue ?? (multiple ? [] : "");
|
|
99
|
+
const [internal, setInternal] = (0, react_1.useState)(initial);
|
|
100
|
+
const selection = valueProp !== undefined ? valueProp : internal;
|
|
101
|
+
const isOn = (value) => Array.isArray(selection) ? selection.includes(value) : selection === value;
|
|
102
|
+
const toggle = (value) => {
|
|
103
|
+
let next;
|
|
104
|
+
if (multiple) {
|
|
105
|
+
const current = Array.isArray(selection) ? selection : [];
|
|
106
|
+
next = current.includes(value) ? current.filter((v) => v !== value) : [...current, value];
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Single mode: the same item pressed again clears it, as Toggle does.
|
|
110
|
+
next = selection === value ? "" : value;
|
|
111
|
+
}
|
|
112
|
+
if (valueProp === undefined)
|
|
113
|
+
setInternal(next);
|
|
114
|
+
onValueChange?.(next);
|
|
115
|
+
};
|
|
116
|
+
const height = size === "sm" ? 30 : size === "lg" ? 42 : 36;
|
|
117
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, testID: testID, accessibilityRole: "radiogroup", accessibilityLabel: accessibilityLabel, style: {
|
|
118
|
+
flexDirection: "row",
|
|
119
|
+
alignItems: "center",
|
|
120
|
+
alignSelf: "flex-start",
|
|
121
|
+
padding: 3,
|
|
122
|
+
gap: 3,
|
|
123
|
+
borderRadius: tokens_1.radii.pill,
|
|
124
|
+
...style,
|
|
125
|
+
}, ...props, children: items.map((item) => {
|
|
126
|
+
const on = isOn(item.value);
|
|
127
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: item.label, accessibilityState: { selected: on, disabled }, disabled: disabled, onPress: () => toggle(item.value), style: { opacity: disabled ? 0.38 : 1 }, children: (0, jsx_runtime_1.jsxs)(View, { style: {
|
|
128
|
+
height: height - 6,
|
|
129
|
+
paddingHorizontal: 14,
|
|
130
|
+
borderRadius: tokens_1.radii.pill,
|
|
131
|
+
flexDirection: "row",
|
|
132
|
+
alignItems: "center",
|
|
133
|
+
justifyContent: "center",
|
|
134
|
+
gap: 6,
|
|
135
|
+
backgroundColor: on ? theme.glassActive : "transparent",
|
|
136
|
+
borderWidth: on ? 0.5 : 0,
|
|
137
|
+
borderColor: theme.edge,
|
|
138
|
+
}, children: [item.icon ? (0, jsx_runtime_1.jsx)(View, { children: item.icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 13, fontWeight: on ? "600" : "500", color: on ? theme.foreground : theme.muted }, children: item.label })] }) }, item.value));
|
|
139
|
+
}) }));
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* A verification-code row.
|
|
143
|
+
*
|
|
144
|
+
* One real text field drives the boxes. Keeping a single field — rather than N
|
|
145
|
+
* inputs — is what makes paste and autofill fill every box in one go, and it is
|
|
146
|
+
* what keeps the caret and keyboard behaviour sane across platforms.
|
|
147
|
+
*/
|
|
148
|
+
exports.InputOTP = (0, react_1.forwardRef)(function InputOTP({ value: valueProp, defaultValue = "", onChange, onComplete, length = 6, disabled = false, accessibilityLabel = "Verification code", 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, Text: RNText, TextInput } = (0, primitives_1.primitives)();
|
|
152
|
+
const [internal, setInternal] = (0, react_1.useState)(defaultValue);
|
|
153
|
+
const value = valueProp !== undefined ? valueProp : internal;
|
|
154
|
+
// The code is digits only, and never longer than the boxes available.
|
|
155
|
+
const normalise = (raw) => raw.replace(/[^0-9]/g, "").slice(0, length);
|
|
156
|
+
const handleChange = (raw) => {
|
|
157
|
+
const next = normalise(raw);
|
|
158
|
+
if (valueProp === undefined)
|
|
159
|
+
setInternal(next);
|
|
160
|
+
onChange?.(next);
|
|
161
|
+
if (next.length === length)
|
|
162
|
+
onComplete?.(next);
|
|
163
|
+
};
|
|
164
|
+
const focusedIndex = Math.min(value.length, length - 1);
|
|
165
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: [{ flexDirection: "row", alignItems: "center", gap: 8, alignSelf: "flex-start" }, style], ...props, children: [Array.from({ length }, (_, index) => {
|
|
166
|
+
const char = value[index] ?? "";
|
|
167
|
+
const isActive = index === focusedIndex && !disabled;
|
|
168
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, tintColor: isActive ? theme.glassActive : undefined, style: {
|
|
169
|
+
width: 44,
|
|
170
|
+
height: 52,
|
|
171
|
+
borderRadius: tokens_1.radii.md,
|
|
172
|
+
alignItems: "center",
|
|
173
|
+
justifyContent: "center",
|
|
174
|
+
borderColor: isActive ? theme.fill : theme.edge,
|
|
175
|
+
opacity: disabled ? 0.38 : 1,
|
|
176
|
+
}, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 22, fontWeight: "600", color: theme.foreground }, children: char }) }, index));
|
|
177
|
+
}), (0, jsx_runtime_1.jsx)(TextInput, { accessibilityRole: "text", accessibilityLabel: accessibilityLabel, accessibilityValue: { text: value }, value: value, onChangeText: handleChange, editable: !disabled, keyboardType: "number-pad", maxLength: length, textContentType: "oneTimeCode", autoComplete: "one-time-code", style: {
|
|
178
|
+
position: "absolute",
|
|
179
|
+
left: 0,
|
|
180
|
+
right: 0,
|
|
181
|
+
top: 0,
|
|
182
|
+
bottom: 0,
|
|
183
|
+
// Invisible but present: the boxes are the visible representation.
|
|
184
|
+
opacity: 0.02,
|
|
185
|
+
color: "transparent",
|
|
186
|
+
} })] }));
|
|
187
|
+
});
|
|
188
|
+
/**
|
|
189
|
+
* A connected row of buttons.
|
|
190
|
+
*
|
|
191
|
+
* Stateless by design: it reports presses and holds no selection, which is what
|
|
192
|
+
* separates it from SegmentedControl (a stateful choice) and ToggleGroup.
|
|
193
|
+
*/
|
|
194
|
+
exports.ButtonGroup = (0, react_1.forwardRef)(function ButtonGroup({ items, size = "md", variant = "attached", onItemPress, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
195
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
196
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
197
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
198
|
+
const height = size === "sm" ? 32 : size === "lg" ? 46 : 40;
|
|
199
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "group", accessibilityLabel: accessibilityLabel, style: {
|
|
200
|
+
flexDirection: "row",
|
|
201
|
+
alignSelf: "flex-start",
|
|
202
|
+
gap: variant === "segmented" ? 6 : 0,
|
|
203
|
+
...style,
|
|
204
|
+
}, ...props, children: items.map((item, index) => {
|
|
205
|
+
const first = index === 0;
|
|
206
|
+
const last = index === items.length - 1;
|
|
207
|
+
// Attached buttons share edges: only the outer corners are rounded,
|
|
208
|
+
// and the inner edges stay square so the group reads as one control.
|
|
209
|
+
const pill = variant === "segmented" ? tokens_1.radii.pill : 0;
|
|
210
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: item.label, accessibilityState: { disabled: item.disabled }, disabled: item.disabled, onPress: () => {
|
|
211
|
+
item.onPress();
|
|
212
|
+
onItemPress?.(item, index);
|
|
213
|
+
}, style: ({ pressed }) => ({
|
|
214
|
+
opacity: item.disabled ? 0.38 : pressed ? 0.85 : 1,
|
|
215
|
+
}), children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", interactive: !item.disabled, isDark: isDark, style: {
|
|
216
|
+
height,
|
|
217
|
+
paddingHorizontal: 18,
|
|
218
|
+
justifyContent: "center",
|
|
219
|
+
alignItems: "center",
|
|
220
|
+
borderRadius: variant === "segmented" ? pill : undefined,
|
|
221
|
+
borderTopLeftRadius: variant === "segmented" ? pill : first ? tokens_1.radii.md : 0,
|
|
222
|
+
borderBottomLeftRadius: variant === "segmented" ? pill : first ? tokens_1.radii.md : 0,
|
|
223
|
+
borderTopRightRadius: variant === "segmented" ? pill : last ? tokens_1.radii.md : 0,
|
|
224
|
+
borderBottomRightRadius: variant === "segmented" ? pill : last ? tokens_1.radii.md : 0,
|
|
225
|
+
}, children: (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: size === "sm" ? 13 : 14, fontWeight: "500", color: theme.foreground }, children: item.label }) }) }, `${item.label}-${index}`));
|
|
226
|
+
}) }));
|
|
227
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Drawer = exports.Sheet = exports.Menu = void 0;
|
|
4
|
+
exports.anchorPopover = anchorPopover;
|
|
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
|
+
/**
|
|
12
|
+
* Registers Android's hardware back while an overlay is open.
|
|
13
|
+
*
|
|
14
|
+
* Shared by Menu, Sheet and Drawer so every overlay dismisses the same way a
|
|
15
|
+
* Dialog does: the back button closes the layer, not the screen behind it.
|
|
16
|
+
*/
|
|
17
|
+
function useBackDismiss(open, onDismiss) {
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
19
|
+
if (!open)
|
|
20
|
+
return;
|
|
21
|
+
const BackHandler = (0, primitives_1.primitives)().getBackHandler();
|
|
22
|
+
if (!BackHandler)
|
|
23
|
+
return;
|
|
24
|
+
const sub = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
25
|
+
onDismiss();
|
|
26
|
+
return true;
|
|
27
|
+
});
|
|
28
|
+
return () => sub.remove();
|
|
29
|
+
}, [open, onDismiss]);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Keeps a popover inside the window.
|
|
33
|
+
*
|
|
34
|
+
* Called with the trigger's measured frame and the popover's own size; returns
|
|
35
|
+
* the offsets that bring it back on screen. A menu near the bottom edge flips
|
|
36
|
+
* above its trigger rather than hanging off the display.
|
|
37
|
+
*/
|
|
38
|
+
function anchorPopover(trigger, popover, viewport, gap = 6) {
|
|
39
|
+
const below = trigger.y + trigger.height + gap;
|
|
40
|
+
const above = trigger.y - popover.height - gap;
|
|
41
|
+
const fitsBelow = below + popover.height <= viewport.height;
|
|
42
|
+
const flipped = !fitsBelow && above >= 0;
|
|
43
|
+
const top = Math.max(0, Math.min(flipped ? above : below, viewport.height - popover.height));
|
|
44
|
+
const left = Math.max(0, Math.min(trigger.x, viewport.width - popover.width));
|
|
45
|
+
return { left, top, flipped };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* An anchored dropdown menu.
|
|
49
|
+
*
|
|
50
|
+
* A press outside or on an item closes it; Android's back button does too. The
|
|
51
|
+
* popover is a glass surface with `glassActive` rows, matching the way the
|
|
52
|
+
* library marks a tappable row rather than nesting another glass panel.
|
|
53
|
+
*/
|
|
54
|
+
exports.Menu = (0, react_1.forwardRef)(function Menu({ trigger, items, open: openProp, onOpenChange, width = 220, accessibilityLabel = "Menu", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
55
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
56
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
57
|
+
const { View, Text: RNText, Pressable, Modal } = (0, primitives_1.primitives)();
|
|
58
|
+
const [internalOpen, setInternalOpen] = (0, react_1.useState)(false);
|
|
59
|
+
const open = openProp !== undefined ? openProp : internalOpen;
|
|
60
|
+
const setOpen = (0, react_1.useCallback)((next) => {
|
|
61
|
+
if (openProp === undefined)
|
|
62
|
+
setInternalOpen(next);
|
|
63
|
+
onOpenChange?.(next);
|
|
64
|
+
}, [openProp, onOpenChange]);
|
|
65
|
+
const dismiss = (0, react_1.useCallback)(() => setOpen(false), [setOpen]);
|
|
66
|
+
useBackDismiss(open, dismiss);
|
|
67
|
+
const { value: enter, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "snappy");
|
|
68
|
+
const scale = animated ? enter.interpolate({ inputRange: [0, 1], outputRange: [0.96, 1] }) : 1;
|
|
69
|
+
const popover = ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID ? `${testID}-popover` : undefined, style: { width, borderRadius: tokens_1.radii.md, paddingVertical: 4, overflow: "hidden", ...style }, children: items.map((item, index) => ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: item.accessibilityLabel ?? item.label, accessibilityState: { disabled: item.disabled }, disabled: item.disabled, onPress: () => {
|
|
70
|
+
setOpen(false);
|
|
71
|
+
item.onPress();
|
|
72
|
+
}, style: { flexDirection: "row", alignItems: "center", gap: 10, paddingVertical: 10, paddingHorizontal: 12, opacity: item.disabled ? 0.38 : 1 }, children: [item.icon ? (0, jsx_runtime_1.jsx)(View, { children: item.icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 15, color: item.destructive ? theme.destructive : theme.foreground }, children: item.label })] }, `${item.label}-${index}`))) }));
|
|
73
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, style: { alignSelf: "flex-start" }, ...props, children: [(0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { expanded: open }, onPress: () => setOpen(!open), children: trigger }), (0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close menu", onPress: dismiss, style: { flex: 1, backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(View, { style: { flex: 1, alignItems: "center", justifyContent: "center", padding: 24 }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, children: animated ? ((0, jsx_runtime_1.jsx)(AnimatedScale, { scale: scale, children: popover })) : (popover) }) }) }) })] }));
|
|
74
|
+
});
|
|
75
|
+
/** Wraps a popover in the entrance scale, which must land on an Animated.View. */
|
|
76
|
+
function AnimatedScale({ scale, children }) {
|
|
77
|
+
const { Animated } = (0, primitives_1.primitives)();
|
|
78
|
+
return (0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ scale }] }, children: children });
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A bottom sheet.
|
|
82
|
+
*
|
|
83
|
+
* The general-purpose container: it slides up on the springs token, dismisses
|
|
84
|
+
* on a scrim press and on Android back. ActionSheet remains the action-menu
|
|
85
|
+
* specialisation of this shape; Sheet is for arbitrary content — a form, a
|
|
86
|
+
* calendar, a detail panel.
|
|
87
|
+
*/
|
|
88
|
+
exports.Sheet = (0, react_1.forwardRef)(function Sheet({ open: openProp, defaultOpen = false, onOpenChange, title, children, footer, dismissOnBackdropPress = true, showHandle = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
89
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
90
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
91
|
+
const { View, Text: RNText, Pressable, Modal } = (0, primitives_1.primitives)();
|
|
92
|
+
const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
|
|
93
|
+
const open = openProp !== undefined ? openProp : internalOpen;
|
|
94
|
+
const setOpen = (0, react_1.useCallback)((next) => {
|
|
95
|
+
if (openProp === undefined)
|
|
96
|
+
setInternalOpen(next);
|
|
97
|
+
onOpenChange?.(next);
|
|
98
|
+
}, [openProp, onOpenChange]);
|
|
99
|
+
const dismiss = (0, react_1.useCallback)(() => setOpen(false), [setOpen]);
|
|
100
|
+
useBackDismiss(open, dismiss);
|
|
101
|
+
// 0 is fully dismissed, 1 fully presented; the panel rides up this value.
|
|
102
|
+
const { value: rise, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "gentle");
|
|
103
|
+
const translateY = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: [420, 0] }) : 0;
|
|
104
|
+
return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close sheet", onPress: dismissOnBackdropPress ? dismiss : undefined, style: { flex: 1, justifyContent: "flex-end", backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { width: "100%" }, children: animated ? ((0, jsx_runtime_1.jsx)(SheetRise, { translateY: translateY, children: (0, jsx_runtime_1.jsx)(SheetPanel, { title: title, footer: footer, showHandle: showHandle, isDark: isDark, testID: testID, style: style, children: children }) })) : ((0, jsx_runtime_1.jsx)(SheetPanel, { title: title, footer: footer, showHandle: showHandle, isDark: isDark, testID: testID, style: style, children: children })) }) }) }));
|
|
105
|
+
});
|
|
106
|
+
function SheetRise({ translateY, children }) {
|
|
107
|
+
const { Animated } = (0, primitives_1.primitives)();
|
|
108
|
+
return (0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ translateY }] }, children: children });
|
|
109
|
+
}
|
|
110
|
+
/** The panel itself: a glass surface with a handle, a title and a footer. */
|
|
111
|
+
function SheetPanel({ title, footer, showHandle, isDark, testID, style, children, }) {
|
|
112
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
113
|
+
const { View, Text: RNText } = (0, primitives_1.primitives)();
|
|
114
|
+
return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID, style: {
|
|
115
|
+
borderTopLeftRadius: tokens_1.radii.xl,
|
|
116
|
+
borderTopRightRadius: tokens_1.radii.xl,
|
|
117
|
+
borderBottomLeftRadius: 0,
|
|
118
|
+
borderBottomRightRadius: 0,
|
|
119
|
+
paddingBottom: 20,
|
|
120
|
+
maxHeight: 560,
|
|
121
|
+
...style,
|
|
122
|
+
}, children: [showHandle ? ((0, jsx_runtime_1.jsx)(View, { style: { alignItems: "center", paddingTop: 8, paddingBottom: 4 }, children: (0, jsx_runtime_1.jsx)(View, { accessibilityElementsHidden: true,
|
|
123
|
+
// A capsule: the radius is half the handle's own height.
|
|
124
|
+
style: { width: 36, height: 5, borderRadius: 5 / 2, backgroundColor: theme.separator } }) })) : null, title ? ((0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 20, paddingVertical: 10 }, children: (0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "heading", style: { fontSize: 17, fontWeight: "600", color: theme.foreground }, children: title }) })) : null, (0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 20 }, children: children }), footer ? (0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 20, paddingTop: 12, gap: 8 }, children: footer }) : null] }));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A side navigation drawer.
|
|
128
|
+
*
|
|
129
|
+
* The same overlay discipline as Sheet — scrim, spring slide, Android back —
|
|
130
|
+
* but anchored to a side edge, with a square panel that runs the full height.
|
|
131
|
+
* The caller supplies the content, typically a List.
|
|
132
|
+
*/
|
|
133
|
+
exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defaultOpen = false, onOpenChange, side = "left", width = 280, children, dismissOnBackdropPress = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
134
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
135
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
136
|
+
const { View, Pressable, Modal } = (0, primitives_1.primitives)();
|
|
137
|
+
const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
|
|
138
|
+
const open = openProp !== undefined ? openProp : internalOpen;
|
|
139
|
+
const setOpen = (0, react_1.useCallback)((next) => {
|
|
140
|
+
if (openProp === undefined)
|
|
141
|
+
setInternalOpen(next);
|
|
142
|
+
onOpenChange?.(next);
|
|
143
|
+
}, [openProp, onOpenChange]);
|
|
144
|
+
const dismiss = (0, react_1.useCallback)(() => setOpen(false), [setOpen]);
|
|
145
|
+
useBackDismiss(open, dismiss);
|
|
146
|
+
const { value: slide, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "gentle");
|
|
147
|
+
// Slide in from off-screen: negative from the left, positive from the right.
|
|
148
|
+
const translateX = animated
|
|
149
|
+
? slide.interpolate({ inputRange: [0, 1], outputRange: [side === "left" ? -width : width, 0] })
|
|
150
|
+
: 0;
|
|
151
|
+
const panel = ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID, style: {
|
|
152
|
+
width,
|
|
153
|
+
height: "100%",
|
|
154
|
+
borderRadius: 0,
|
|
155
|
+
paddingTop: 56,
|
|
156
|
+
...style,
|
|
157
|
+
}, children: children }));
|
|
158
|
+
return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close drawer", onPress: dismissOnBackdropPress ? dismiss : undefined, style: { flex: 1, backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(View, { style: {
|
|
159
|
+
flex: 1,
|
|
160
|
+
alignItems: side === "left" ? "flex-start" : "flex-end",
|
|
161
|
+
}, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { height: "100%" }, children: animated ? (0, jsx_runtime_1.jsx)(DrawerSlide, { translateX: translateX, children: panel }) : panel }) }) }) }));
|
|
162
|
+
});
|
|
163
|
+
function DrawerSlide({ translateX, children }) {
|
|
164
|
+
const { Animated } = (0, primitives_1.primitives)();
|
|
165
|
+
return (0, jsx_runtime_1.jsx)(Animated.View, { style: { height: "100%", transform: [{ translateX }] }, children: children });
|
|
166
|
+
}
|