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.
Files changed (121) hide show
  1. package/lib/module/Bars.js +176 -0
  2. package/lib/module/Button.js +15 -2
  3. package/lib/module/Card.js +29 -14
  4. package/lib/module/Carousel.js +103 -0
  5. package/lib/module/Dialog.js +43 -32
  6. package/lib/module/Display.js +240 -0
  7. package/lib/module/Feedback.js +172 -0
  8. package/lib/module/Form.js +51 -12
  9. package/lib/module/Forms2.js +227 -0
  10. package/lib/module/Glass.js +11 -2
  11. package/lib/module/Input.js +19 -7
  12. package/lib/module/Overlays.js +166 -0
  13. package/lib/module/Pickers.js +243 -0
  14. package/lib/module/SegmentedControl.js +65 -21
  15. package/lib/module/Slider.js +121 -25
  16. package/lib/module/Switch.js +33 -15
  17. package/lib/module/TabBar.js +63 -25
  18. package/lib/module/Table.js +24 -6
  19. package/lib/module/Tabs.js +55 -33
  20. package/lib/module/Text.js +37 -0
  21. package/lib/module/ai.js +49 -20
  22. package/lib/module/charts/BarChart.js +4 -2
  23. package/lib/module/charts/FunnelChart.js +4 -2
  24. package/lib/module/charts/HeatmapChart.js +4 -2
  25. package/lib/module/charts/LineChart.js +4 -2
  26. package/lib/module/charts/PlotChart.js +11 -3
  27. package/lib/module/charts/RadarChart.js +4 -2
  28. package/lib/module/charts/RingChart.js +4 -2
  29. package/lib/module/charts/ScatterChart.js +20 -3
  30. package/lib/module/charts/WaterfallChart.js +12 -3
  31. package/lib/module/charts/advanced.js +12 -6
  32. package/lib/module/charts/extra.js +6 -3
  33. package/lib/module/index.js +58 -1
  34. package/lib/module/internal/GlassView.js +31 -17
  35. package/lib/module/internal/fallback.js +14 -3
  36. package/lib/module/internal/glass-routing.js +56 -0
  37. package/lib/module/internal/motion.js +55 -0
  38. package/lib/module/internal/primitives.js +413 -0
  39. package/lib/module/internal/tokens.js +55 -1
  40. package/lib/typescript/Bars.d.ts +121 -0
  41. package/lib/typescript/Button.d.ts +11 -1
  42. package/lib/typescript/Card.d.ts +20 -8
  43. package/lib/typescript/Carousel.d.ts +47 -0
  44. package/lib/typescript/Dialog.d.ts +19 -6
  45. package/lib/typescript/Display.d.ts +119 -0
  46. package/lib/typescript/Feedback.d.ts +138 -0
  47. package/lib/typescript/Form.d.ts +27 -11
  48. package/lib/typescript/Forms2.d.ts +128 -0
  49. package/lib/typescript/Glass.d.ts +10 -1
  50. package/lib/typescript/Input.d.ts +11 -1
  51. package/lib/typescript/Overlays.d.ts +105 -0
  52. package/lib/typescript/Pickers.d.ts +105 -0
  53. package/lib/typescript/SegmentedControl.d.ts +11 -1
  54. package/lib/typescript/Slider.d.ts +13 -1
  55. package/lib/typescript/Switch.d.ts +12 -1
  56. package/lib/typescript/TabBar.d.ts +13 -1
  57. package/lib/typescript/Table.d.ts +14 -5
  58. package/lib/typescript/Tabs.d.ts +8 -5
  59. package/lib/typescript/Text.d.ts +28 -0
  60. package/lib/typescript/ai.d.ts +12 -9
  61. package/lib/typescript/charts/BarChart.d.ts +1 -1
  62. package/lib/typescript/charts/FunnelChart.d.ts +1 -1
  63. package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
  64. package/lib/typescript/charts/LineChart.d.ts +1 -1
  65. package/lib/typescript/charts/PlotChart.d.ts +1 -1
  66. package/lib/typescript/charts/RadarChart.d.ts +1 -1
  67. package/lib/typescript/charts/RingChart.d.ts +1 -1
  68. package/lib/typescript/charts/ScatterChart.d.ts +1 -1
  69. package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
  70. package/lib/typescript/charts/advanced.d.ts +5 -5
  71. package/lib/typescript/charts/extra.d.ts +2 -2
  72. package/lib/typescript/index.d.ts +9 -1
  73. package/lib/typescript/internal/GlassView.d.ts +21 -4
  74. package/lib/typescript/internal/fallback.d.ts +10 -1
  75. package/lib/typescript/internal/glass-routing.d.ts +30 -0
  76. package/lib/typescript/internal/motion.d.ts +19 -0
  77. package/lib/typescript/internal/primitives.d.ts +41 -0
  78. package/lib/typescript/internal/tokens.d.ts +61 -0
  79. package/package.json +2 -2
  80. package/src/Bars.tsx +570 -0
  81. package/src/Button.tsx +47 -22
  82. package/src/Card.tsx +52 -31
  83. package/src/Carousel.tsx +233 -0
  84. package/src/Dialog.tsx +99 -64
  85. package/src/Display.tsx +550 -0
  86. package/src/Feedback.tsx +579 -0
  87. package/src/Form.tsx +90 -25
  88. package/src/Forms2.tsx +608 -0
  89. package/src/Glass.tsx +24 -1
  90. package/src/Input.tsx +33 -12
  91. package/src/Overlays.tsx +474 -0
  92. package/src/Pickers.tsx +590 -0
  93. package/src/SegmentedControl.tsx +104 -32
  94. package/src/Slider.tsx +151 -47
  95. package/src/Switch.tsx +56 -32
  96. package/src/TabBar.tsx +100 -30
  97. package/src/Table.tsx +38 -14
  98. package/src/Tabs.tsx +85 -32
  99. package/src/Text.tsx +83 -0
  100. package/src/ai.tsx +77 -31
  101. package/src/charts/BarChart.tsx +4 -2
  102. package/src/charts/FunnelChart.tsx +4 -2
  103. package/src/charts/HeatmapChart.tsx +4 -2
  104. package/src/charts/LineChart.tsx +4 -2
  105. package/src/charts/PlotChart.tsx +23 -3
  106. package/src/charts/RadarChart.tsx +4 -2
  107. package/src/charts/RingChart.tsx +4 -2
  108. package/src/charts/ScatterChart.tsx +24 -3
  109. package/src/charts/WaterfallChart.tsx +21 -3
  110. package/src/charts/advanced.tsx +12 -6
  111. package/src/charts/extra.tsx +6 -3
  112. package/src/index.ts +101 -1
  113. package/src/internal/GlassView.tsx +51 -19
  114. package/src/internal/fallback.tsx +23 -8
  115. package/src/internal/glass-routing.ts +68 -0
  116. package/src/internal/motion.ts +60 -0
  117. package/src/internal/primitives.ts +482 -0
  118. package/src/internal/tokens.ts +62 -0
  119. package/lib/module/charts/primitives.js +0 -212
  120. package/lib/typescript/charts/primitives.d.ts +0 -23
  121. package/src/charts/primitives.ts +0 -262
package/src/Input.tsx CHANGED
@@ -1,7 +1,9 @@
1
- import { forwardRef, type ReactNode } from "react";
1
+ import { forwardRef, useState, type ReactNode } from "react";
2
+ import type { StyleProp, TextStyle, ViewStyle } from "react-native";
2
3
 
3
4
  import { colors, radii } from "./internal/tokens";
4
- import { primitives } from "./charts/primitives";
5
+ import { primitives } from "./internal/primitives";
6
+ import { useIsDark } from "./internal/motion";
5
7
 
6
8
  export interface InputProps {
7
9
  value?: string;
@@ -21,10 +23,14 @@ export interface InputProps {
21
23
  accessibilityLabel?: string;
22
24
  returnKeyType?: "done" | "next" | "go" | "search" | "send";
23
25
  onSubmitEditing?: () => void;
26
+ /** Starting text for uncontrolled use, like React Native's `defaultValue`. */
27
+ defaultValue?: string;
24
28
  prefix?: ReactNode;
25
29
  suffix?: ReactNode;
26
30
  isDark?: boolean;
27
- style?: any;
31
+ style?: StyleProp<ViewStyle>;
32
+ /** Passed through to the text field so it is testable. */
33
+ testID?: string;
28
34
  // Standard TextInput props a caller may still want to pass through.
29
35
  maxLength?: number;
30
36
  editable?: boolean;
@@ -41,6 +47,11 @@ const fontSizes = { sm: 14, md: 15, lg: 16 };
41
47
  * The native TextInput has no placeholder styling prop, so the placeholder is
42
48
  * drawn as a sibling Text: that keeps its colour tied to the theme instead of
43
49
  * the OS default, which changes between iOS versions.
50
+ *
51
+ * The field works controlled (`value` + `onChangeText`) or uncontrolled (no
52
+ * `value` prop). In uncontrolled use it tracks its own text so the themed
53
+ * placeholder disappears as soon as the user types; without that state the
54
+ * overlay would sit on top of the typed text until the parent re-rendered.
44
55
  */
45
56
  export const Input = forwardRef<any, InputProps>(function Input(
46
57
  {
@@ -59,10 +70,12 @@ export const Input = forwardRef<any, InputProps>(function Input(
59
70
  accessibilityLabel,
60
71
  returnKeyType,
61
72
  onSubmitEditing,
73
+ defaultValue,
62
74
  prefix,
63
75
  suffix,
64
- isDark = false,
76
+ isDark: isDarkProp,
65
77
  style,
78
+ testID,
66
79
  maxLength,
67
80
  editable,
68
81
  onFocus,
@@ -70,20 +83,27 @@ export const Input = forwardRef<any, InputProps>(function Input(
70
83
  },
71
84
  ref,
72
85
  ) {
86
+ const isDark = useIsDark(isDarkProp);
73
87
  const theme = isDark ? colors.dark : colors.light;
74
88
  const { View, Text, TextInput } = primitives();
75
89
 
90
+ // Uncontrolled support: with no `value` prop the field owns its text.
91
+ const [internalText, setInternalText] = useState(defaultValue ?? "");
92
+ const text = value !== undefined ? value : internalText;
93
+ const handleChangeText = (next: string) => {
94
+ if (value === undefined) setInternalText(next);
95
+ onChangeText?.(next);
96
+ };
97
+
76
98
  const isEditable = editable !== undefined ? editable : !disabled;
77
- const showPlaceholder = !value && placeholder;
99
+ const showPlaceholder = !text && Boolean(placeholder);
78
100
 
79
- const fieldStyle: any = {
101
+ const fieldStyle: TextStyle = {
80
102
  flex: 1,
81
103
  paddingVertical: height_padding(size),
82
104
  paddingHorizontal: 0,
83
105
  fontSize: fontSizes[size],
84
106
  color: theme.foreground,
85
- // RN draws its own underline on Android; the border is ours.
86
- outlineStyle: "none",
87
107
  };
88
108
 
89
109
  return (
@@ -99,7 +119,7 @@ export const Input = forwardRef<any, InputProps>(function Input(
99
119
  backgroundColor: theme.glass,
100
120
  paddingHorizontal: 12,
101
121
  opacity: disabled ? 0.5 : 1,
102
- ...style,
122
+ ...(style as ViewStyle),
103
123
  }}
104
124
  >
105
125
  {prefix}
@@ -113,8 +133,8 @@ export const Input = forwardRef<any, InputProps>(function Input(
113
133
  top: multiline ? 0 : undefined,
114
134
  fontSize: fontSizes[size],
115
135
  color: theme.muted,
116
- pointerEvents: "none",
117
136
  }}
137
+ pointerEvents="none"
118
138
  numberOfLines={1}
119
139
  >
120
140
  {placeholder}
@@ -123,8 +143,9 @@ export const Input = forwardRef<any, InputProps>(function Input(
123
143
 
124
144
  <TextInput
125
145
  ref={ref}
126
- value={value}
127
- onChangeText={onChangeText}
146
+ testID={testID}
147
+ value={text}
148
+ onChangeText={handleChangeText}
128
149
  editable={isEditable}
129
150
  secureTextEntry={secureTextEntry}
130
151
  keyboardType={keyboardType}
@@ -0,0 +1,474 @@
1
+ import { forwardRef, useCallback, useEffect, useState, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
4
+ import { Glass } from "./Glass";
5
+ import { Text } from "./Text";
6
+ import { colors, radii } from "./internal/tokens";
7
+ import { primitives } from "./internal/primitives";
8
+ import { useIsDark, useSpring } from "./internal/motion";
9
+
10
+ /**
11
+ * Registers Android's hardware back while an overlay is open.
12
+ *
13
+ * Shared by Menu, Sheet and Drawer so every overlay dismisses the same way a
14
+ * Dialog does: the back button closes the layer, not the screen behind it.
15
+ */
16
+ function useBackDismiss(open: boolean, onDismiss: () => void) {
17
+ useEffect(() => {
18
+ if (!open) return;
19
+ const BackHandler = primitives().getBackHandler();
20
+ if (!BackHandler) return;
21
+ const sub = BackHandler.addEventListener("hardwareBackPress", () => {
22
+ onDismiss();
23
+ return true;
24
+ });
25
+ return () => sub.remove();
26
+ }, [open, onDismiss]);
27
+ }
28
+
29
+ /**
30
+ * Keeps a popover inside the window.
31
+ *
32
+ * Called with the trigger's measured frame and the popover's own size; returns
33
+ * the offsets that bring it back on screen. A menu near the bottom edge flips
34
+ * above its trigger rather than hanging off the display.
35
+ */
36
+ export function anchorPopover(
37
+ trigger: { x: number; y: number; width: number; height: number },
38
+ popover: { width: number; height: number },
39
+ viewport: { width: number; height: number },
40
+ gap = 6,
41
+ ): { left: number; top: number; flipped: boolean } {
42
+ const below = trigger.y + trigger.height + gap;
43
+ const above = trigger.y - popover.height - gap;
44
+ const fitsBelow = below + popover.height <= viewport.height;
45
+ const flipped = !fitsBelow && above >= 0;
46
+ const top = Math.max(0, Math.min(flipped ? above : below, viewport.height - popover.height));
47
+ const left = Math.max(0, Math.min(trigger.x, viewport.width - popover.width));
48
+ return { left, top, flipped };
49
+ }
50
+
51
+ // ---------------------------------------------------------------------------
52
+ // Menu
53
+
54
+ export interface MenuItem {
55
+ label: string;
56
+ onPress: () => void;
57
+ icon?: ReactNode;
58
+ disabled?: boolean;
59
+ /** Renders in the destructive tone, for delete-and-similar. */
60
+ destructive?: boolean;
61
+ accessibilityLabel?: string;
62
+ }
63
+
64
+ export interface MenuProps {
65
+ /** The control that opens the menu. */
66
+ trigger: ReactNode;
67
+ items: MenuItem[];
68
+ /** Controlled open state. Omit and the menu keeps its own. */
69
+ open?: boolean;
70
+ onOpenChange?: (open: boolean) => void;
71
+ /** The menu's width. The list scrolls if the items exceed the screen. */
72
+ width?: number;
73
+ accessibilityLabel?: string;
74
+ style?: StyleProp<ViewStyle>;
75
+ isDark?: boolean;
76
+ testID?: string;
77
+ }
78
+
79
+ /**
80
+ * An anchored dropdown menu.
81
+ *
82
+ * A press outside or on an item closes it; Android's back button does too. The
83
+ * popover is a glass surface with `glassActive` rows, matching the way the
84
+ * library marks a tappable row rather than nesting another glass panel.
85
+ */
86
+ export const Menu = forwardRef<any, MenuProps>(function Menu(
87
+ {
88
+ trigger,
89
+ items,
90
+ open: openProp,
91
+ onOpenChange,
92
+ width = 220,
93
+ accessibilityLabel = "Menu",
94
+ style,
95
+ isDark: isDarkProp,
96
+ testID,
97
+ ...props
98
+ },
99
+ ref,
100
+ ) {
101
+ const isDark = useIsDark(isDarkProp);
102
+ const theme = isDark ? colors.dark : colors.light;
103
+ const { View, Text: RNText, Pressable, Modal } = primitives();
104
+
105
+ const [internalOpen, setInternalOpen] = useState(false);
106
+ const open = openProp !== undefined ? openProp : internalOpen;
107
+
108
+ const setOpen = useCallback(
109
+ (next: boolean) => {
110
+ if (openProp === undefined) setInternalOpen(next);
111
+ onOpenChange?.(next);
112
+ },
113
+ [openProp, onOpenChange],
114
+ );
115
+
116
+ const dismiss = useCallback(() => setOpen(false), [setOpen]);
117
+ useBackDismiss(open, dismiss);
118
+
119
+ const { value: enter, animated } = useSpring(open ? 1 : 0, "snappy");
120
+ const scale = animated ? enter.interpolate({ inputRange: [0, 1], outputRange: [0.96, 1] }) : 1;
121
+
122
+ const popover = (
123
+ <Glass
124
+ effect="regular"
125
+ isDark={isDark}
126
+ testID={testID ? `${testID}-popover` : undefined}
127
+ style={{ width, borderRadius: radii.md, paddingVertical: 4, overflow: "hidden", ...(style as ViewStyle) }}
128
+ >
129
+ {items.map((item, index) => (
130
+ <Pressable
131
+ key={`${item.label}-${index}`}
132
+ accessibilityRole="button"
133
+ accessibilityLabel={item.accessibilityLabel ?? item.label}
134
+ accessibilityState={{ disabled: item.disabled }}
135
+ disabled={item.disabled}
136
+ onPress={() => {
137
+ setOpen(false);
138
+ item.onPress();
139
+ }}
140
+ style={{ flexDirection: "row", alignItems: "center", gap: 10, paddingVertical: 10, paddingHorizontal: 12, opacity: item.disabled ? 0.38 : 1 }}
141
+ >
142
+ {item.icon ? <View>{item.icon}</View> : null}
143
+ <RNText
144
+ numberOfLines={1}
145
+ style={{ fontSize: 15, color: item.destructive ? theme.destructive : theme.foreground }}
146
+ >
147
+ {item.label}
148
+ </RNText>
149
+ </Pressable>
150
+ ))}
151
+ </Glass>
152
+ );
153
+
154
+ return (
155
+ <View ref={ref} style={{ alignSelf: "flex-start" }} {...props}>
156
+ <Pressable
157
+ accessibilityRole="button"
158
+ accessibilityLabel={accessibilityLabel}
159
+ accessibilityState={{ expanded: open }}
160
+ onPress={() => setOpen(!open)}
161
+ >
162
+ {trigger}
163
+ </Pressable>
164
+
165
+ <Modal visible={open} transparent animationType="fade" onRequestClose={dismiss}>
166
+ {/* The backdrop: any press outside the popover dismisses the menu. */}
167
+ <Pressable
168
+ accessibilityRole="button"
169
+ accessibilityLabel="Close menu"
170
+ onPress={dismiss}
171
+ style={{ flex: 1, backgroundColor: theme.scrim }}
172
+ >
173
+ <View style={{ flex: 1, alignItems: "center", justifyContent: "center", padding: 24 }}>
174
+ <Pressable accessibilityRole="none" onPress={() => {}}>
175
+ {animated ? (
176
+ <AnimatedScale scale={scale}>{popover}</AnimatedScale>
177
+ ) : (
178
+ popover
179
+ )}
180
+ </Pressable>
181
+ </View>
182
+ </Pressable>
183
+ </Modal>
184
+ </View>
185
+ );
186
+ });
187
+
188
+ /** Wraps a popover in the entrance scale, which must land on an Animated.View. */
189
+ function AnimatedScale({ scale, children }: { scale: any; children: ReactNode }) {
190
+ const { Animated } = primitives();
191
+ return <Animated.View style={{ transform: [{ scale }] }}>{children}</Animated.View>;
192
+ }
193
+
194
+ // ---------------------------------------------------------------------------
195
+ // Sheet
196
+
197
+ export interface SheetProps {
198
+ /** Controlled visibility. Omit and the sheet keeps its own. */
199
+ open?: boolean;
200
+ defaultOpen?: boolean;
201
+ onOpenChange?: (open: boolean) => void;
202
+ title?: string;
203
+ children?: ReactNode;
204
+ footer?: ReactNode;
205
+ /** Tapping the scrim dismisses. */
206
+ dismissOnBackdropPress?: boolean;
207
+ /** The drag handle at the top of the panel. */
208
+ showHandle?: boolean;
209
+ style?: StyleProp<ViewStyle>;
210
+ isDark?: boolean;
211
+ testID?: string;
212
+ }
213
+
214
+ /**
215
+ * A bottom sheet.
216
+ *
217
+ * The general-purpose container: it slides up on the springs token, dismisses
218
+ * on a scrim press and on Android back. ActionSheet remains the action-menu
219
+ * specialisation of this shape; Sheet is for arbitrary content — a form, a
220
+ * calendar, a detail panel.
221
+ */
222
+ export const Sheet = forwardRef<any, SheetProps>(function Sheet(
223
+ {
224
+ open: openProp,
225
+ defaultOpen = false,
226
+ onOpenChange,
227
+ title,
228
+ children,
229
+ footer,
230
+ dismissOnBackdropPress = true,
231
+ showHandle = true,
232
+ style,
233
+ isDark: isDarkProp,
234
+ testID,
235
+ ...props
236
+ },
237
+ ref,
238
+ ) {
239
+ const isDark = useIsDark(isDarkProp);
240
+ const theme = isDark ? colors.dark : colors.light;
241
+ const { View, Text: RNText, Pressable, Modal } = primitives();
242
+
243
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
244
+ const open = openProp !== undefined ? openProp : internalOpen;
245
+
246
+ const setOpen = useCallback(
247
+ (next: boolean) => {
248
+ if (openProp === undefined) setInternalOpen(next);
249
+ onOpenChange?.(next);
250
+ },
251
+ [openProp, onOpenChange],
252
+ );
253
+
254
+ const dismiss = useCallback(() => setOpen(false), [setOpen]);
255
+ useBackDismiss(open, dismiss);
256
+
257
+ // 0 is fully dismissed, 1 fully presented; the panel rides up this value.
258
+ const { value: rise, animated } = useSpring(open ? 1 : 0, "gentle");
259
+ const translateY = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: [420, 0] }) : 0;
260
+
261
+ return (
262
+ <Modal visible={open} transparent animationType="fade" onRequestClose={dismiss}>
263
+ <Pressable
264
+ accessibilityRole="button"
265
+ accessibilityLabel="Close sheet"
266
+ onPress={dismissOnBackdropPress ? dismiss : undefined}
267
+ style={{ flex: 1, justifyContent: "flex-end", backgroundColor: theme.scrim }}
268
+ >
269
+ <Pressable accessibilityRole="none" onPress={() => {}} style={{ width: "100%" }}>
270
+ {animated ? (
271
+ <SheetRise translateY={translateY}>
272
+ <SheetPanel
273
+ title={title}
274
+ footer={footer}
275
+ showHandle={showHandle}
276
+ isDark={isDark}
277
+ testID={testID}
278
+ style={style}
279
+ >
280
+ {children}
281
+ </SheetPanel>
282
+ </SheetRise>
283
+ ) : (
284
+ <SheetPanel
285
+ title={title}
286
+ footer={footer}
287
+ showHandle={showHandle}
288
+ isDark={isDark}
289
+ testID={testID}
290
+ style={style}
291
+ >
292
+ {children}
293
+ </SheetPanel>
294
+ )}
295
+ </Pressable>
296
+ </Pressable>
297
+ </Modal>
298
+ );
299
+ });
300
+
301
+ function SheetRise({ translateY, children }: { translateY: any; children: ReactNode }) {
302
+ const { Animated } = primitives();
303
+ return <Animated.View style={{ transform: [{ translateY }] }}>{children}</Animated.View>;
304
+ }
305
+
306
+ /** The panel itself: a glass surface with a handle, a title and a footer. */
307
+ function SheetPanel({
308
+ title,
309
+ footer,
310
+ showHandle,
311
+ isDark,
312
+ testID,
313
+ style,
314
+ children,
315
+ }: {
316
+ title?: string;
317
+ footer?: ReactNode;
318
+ showHandle: boolean;
319
+ isDark: boolean;
320
+ testID?: string;
321
+ style?: StyleProp<ViewStyle>;
322
+ children?: ReactNode;
323
+ }) {
324
+ const theme = isDark ? colors.dark : colors.light;
325
+ const { View, Text: RNText } = primitives();
326
+
327
+ return (
328
+ <Glass
329
+ effect="regular"
330
+ isDark={isDark}
331
+ testID={testID}
332
+ style={{
333
+ borderTopLeftRadius: radii.xl,
334
+ borderTopRightRadius: radii.xl,
335
+ borderBottomLeftRadius: 0,
336
+ borderBottomRightRadius: 0,
337
+ paddingBottom: 20,
338
+ maxHeight: 560,
339
+ ...(style as ViewStyle),
340
+ }}
341
+ >
342
+ {showHandle ? (
343
+ <View style={{ alignItems: "center", paddingTop: 8, paddingBottom: 4 }}>
344
+ <View
345
+ accessibilityElementsHidden
346
+ // A capsule: the radius is half the handle's own height.
347
+ style={{ width: 36, height: 5, borderRadius: 5 / 2, backgroundColor: theme.separator }}
348
+ />
349
+ </View>
350
+ ) : null}
351
+ {title ? (
352
+ <View style={{ paddingHorizontal: 20, paddingVertical: 10 }}>
353
+ <RNText accessibilityRole="heading" style={{ fontSize: 17, fontWeight: "600", color: theme.foreground }}>
354
+ {title}
355
+ </RNText>
356
+ </View>
357
+ ) : null}
358
+ <View style={{ paddingHorizontal: 20 }}>{children}</View>
359
+ {footer ? <View style={{ paddingHorizontal: 20, paddingTop: 12, gap: 8 }}>{footer}</View> : null}
360
+ </Glass>
361
+ );
362
+ }
363
+
364
+ // ---------------------------------------------------------------------------
365
+ // Drawer
366
+
367
+ export interface DrawerProps {
368
+ /** Controlled visibility. Omit and the drawer keeps its own. */
369
+ open?: boolean;
370
+ defaultOpen?: boolean;
371
+ onOpenChange?: (open: boolean) => void;
372
+ /** The edge the panel slides in from. */
373
+ side?: "left" | "right";
374
+ /** Panel width. */
375
+ width?: number;
376
+ children?: ReactNode;
377
+ /** Tapping the scrim dismisses. */
378
+ dismissOnBackdropPress?: boolean;
379
+ style?: StyleProp<ViewStyle>;
380
+ isDark?: boolean;
381
+ testID?: string;
382
+ }
383
+
384
+ /**
385
+ * A side navigation drawer.
386
+ *
387
+ * The same overlay discipline as Sheet — scrim, spring slide, Android back —
388
+ * but anchored to a side edge, with a square panel that runs the full height.
389
+ * The caller supplies the content, typically a List.
390
+ */
391
+ export const Drawer = forwardRef<any, DrawerProps>(function Drawer(
392
+ {
393
+ open: openProp,
394
+ defaultOpen = false,
395
+ onOpenChange,
396
+ side = "left",
397
+ width = 280,
398
+ children,
399
+ dismissOnBackdropPress = true,
400
+ style,
401
+ isDark: isDarkProp,
402
+ testID,
403
+ ...props
404
+ },
405
+ ref,
406
+ ) {
407
+ const isDark = useIsDark(isDarkProp);
408
+ const theme = isDark ? colors.dark : colors.light;
409
+ const { View, Pressable, Modal } = primitives();
410
+
411
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
412
+ const open = openProp !== undefined ? openProp : internalOpen;
413
+
414
+ const setOpen = useCallback(
415
+ (next: boolean) => {
416
+ if (openProp === undefined) setInternalOpen(next);
417
+ onOpenChange?.(next);
418
+ },
419
+ [openProp, onOpenChange],
420
+ );
421
+
422
+ const dismiss = useCallback(() => setOpen(false), [setOpen]);
423
+ useBackDismiss(open, dismiss);
424
+
425
+ const { value: slide, animated } = useSpring(open ? 1 : 0, "gentle");
426
+ // Slide in from off-screen: negative from the left, positive from the right.
427
+ const translateX = animated
428
+ ? slide.interpolate({ inputRange: [0, 1], outputRange: [side === "left" ? -width : width, 0] })
429
+ : 0;
430
+
431
+ const panel = (
432
+ <Glass
433
+ effect="regular"
434
+ isDark={isDark}
435
+ testID={testID}
436
+ style={{
437
+ width,
438
+ height: "100%",
439
+ borderRadius: 0,
440
+ paddingTop: 56,
441
+ ...(style as ViewStyle),
442
+ }}
443
+ >
444
+ {children}
445
+ </Glass>
446
+ );
447
+
448
+ return (
449
+ <Modal visible={open} transparent animationType="fade" onRequestClose={dismiss}>
450
+ <Pressable
451
+ accessibilityRole="button"
452
+ accessibilityLabel="Close drawer"
453
+ onPress={dismissOnBackdropPress ? dismiss : undefined}
454
+ style={{ flex: 1, backgroundColor: theme.scrim }}
455
+ >
456
+ <View
457
+ style={{
458
+ flex: 1,
459
+ alignItems: side === "left" ? "flex-start" : "flex-end",
460
+ }}
461
+ >
462
+ <Pressable accessibilityRole="none" onPress={() => {}} style={{ height: "100%" }}>
463
+ {animated ? <DrawerSlide translateX={translateX}>{panel}</DrawerSlide> : panel}
464
+ </Pressable>
465
+ </View>
466
+ </Pressable>
467
+ </Modal>
468
+ );
469
+ });
470
+
471
+ function DrawerSlide({ translateX, children }: { translateX: any; children: ReactNode }) {
472
+ const { Animated } = primitives();
473
+ return <Animated.View style={{ height: "100%", transform: [{ translateX }] }}>{children}</Animated.View>;
474
+ }