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
@@ -0,0 +1,579 @@
1
+ import { forwardRef, useEffect, useRef, useState, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
4
+ import { Glass } from "./Glass";
5
+ import { Separator } from "./Display";
6
+ import { colors, radii, toneColor, type Tone } from "./internal/tokens";
7
+ import { primitives } from "./internal/primitives";
8
+ import { useIsDark, useSpring } from "./internal/motion";
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // Toast
12
+
13
+ export interface ToastAction {
14
+ label: string;
15
+ onPress: () => void;
16
+ }
17
+
18
+ export interface ToastProps {
19
+ /** Controlled visibility. Omit it and the toast keeps its own state. */
20
+ visible?: boolean;
21
+ defaultVisible?: boolean;
22
+ onDismiss?: () => void;
23
+ message: string;
24
+ /** One optional action, e.g. Undo. */
25
+ action?: ToastAction;
26
+ /** A leading icon (an SVG node the caller supplies). */
27
+ icon?: ReactNode;
28
+ /**
29
+ * Milliseconds before it dismisses itself. 0 keeps it until dismissed.
30
+ * The timer is cleared on unmount as well as on dismiss.
31
+ */
32
+ duration?: number;
33
+ tone?: Tone | "neutral";
34
+ style?: StyleProp<ViewStyle>;
35
+ isDark?: boolean;
36
+ testID?: string;
37
+ }
38
+
39
+ /**
40
+ * A transient message on a glass pill.
41
+ *
42
+ * A toast is not a dialog: it never blocks the screen, so it renders in place
43
+ * and lets touches through to what is underneath. It dismisses itself after
44
+ * `duration` unless it is controlled or `duration` is 0.
45
+ */
46
+ export const Toast = forwardRef<any, ToastProps>(function Toast(
47
+ {
48
+ visible: visibleProp,
49
+ defaultVisible = false,
50
+ onDismiss,
51
+ message,
52
+ action,
53
+ icon,
54
+ duration = 4000,
55
+ tone = "neutral",
56
+ style,
57
+ isDark: isDarkProp,
58
+ testID,
59
+ ...props
60
+ },
61
+ ref,
62
+ ) {
63
+ const isDark = useIsDark(isDarkProp);
64
+ const theme = isDark ? colors.dark : colors.light;
65
+ const { View, Text: RNText, Pressable } = primitives();
66
+
67
+ const [internalVisible, setInternalVisible] = useState(defaultVisible);
68
+ const visible = visibleProp !== undefined ? visibleProp : internalVisible;
69
+
70
+ const dismiss = () => {
71
+ if (visibleProp === undefined) setInternalVisible(false);
72
+ onDismiss?.();
73
+ };
74
+
75
+ // The timer lives and dies with the toast. A ref keeps the latest dismiss
76
+ // closure out of the effect's dependencies, so a parent re-render does not
77
+ // restart the countdown.
78
+ const dismissRef = useRef(dismiss);
79
+ dismissRef.current = dismiss;
80
+
81
+ useEffect(() => {
82
+ if (!visible || duration <= 0) return;
83
+ const timer = setTimeout(() => dismissRef.current(), duration);
84
+ return () => clearTimeout(timer);
85
+ }, [visible, duration]);
86
+
87
+ const { value: enter, animated } = useSpring(visible ? 1 : 0, "snappy");
88
+ const rise = animated ? enter.interpolate({ inputRange: [0, 1], outputRange: [12, 0] }) : 0;
89
+ const fade = animated ? enter.interpolate({ inputRange: [0, 1], outputRange: [0, 1] }) : 1;
90
+
91
+ if (!visible) return null;
92
+
93
+ const accent = tone === "neutral" ? theme.foreground : toneColor(theme, tone);
94
+
95
+ return (
96
+ <View
97
+ ref={ref}
98
+ testID={testID}
99
+ pointerEvents="box-none"
100
+ style={{ alignItems: "center", ...(style as ViewStyle) }}
101
+ {...props}
102
+ >
103
+ {/* The pill's entrance: it rises and fades in on the springs token. */}
104
+ <Entrance animated={animated} rise={rise} fade={fade}>
105
+ <Glass
106
+ effect="regular"
107
+ isDark={isDark}
108
+ style={{
109
+ flexDirection: "row",
110
+ alignItems: "center",
111
+ gap: 10,
112
+ paddingVertical: 10,
113
+ paddingHorizontal: 14,
114
+ borderRadius: radii.pill,
115
+ maxWidth: 420,
116
+ borderColor: tone === "neutral" ? theme.edge : accent,
117
+ }}
118
+ >
119
+ {icon ? <View>{icon}</View> : null}
120
+ <RNText
121
+ accessibilityRole="alert"
122
+ accessibilityLiveRegion="polite"
123
+ style={{ fontSize: 14, color: theme.foreground, flexShrink: 1 }}
124
+ >
125
+ {message}
126
+ </RNText>
127
+ {action && (
128
+ <Pressable
129
+ accessibilityRole="button"
130
+ accessibilityLabel={action.label}
131
+ onPress={action.onPress}
132
+ style={{ paddingHorizontal: 4 }}
133
+ >
134
+ <RNText style={{ fontSize: 14, fontWeight: "600", color: theme.fill }}>
135
+ {action.label}
136
+ </RNText>
137
+ </Pressable>
138
+ )}
139
+ </Glass>
140
+ </Entrance>
141
+ </View>
142
+ );
143
+ });
144
+
145
+ /**
146
+ * Applies the toast's entrance motion around the pill.
147
+ *
148
+ * A thin wrapper because animated styles must land on an Animated.View, while
149
+ * the pill itself is a Glass — wrapping keeps both honest.
150
+ */
151
+ function Entrance({
152
+ animated,
153
+ rise,
154
+ fade,
155
+ children,
156
+ }: {
157
+ animated: boolean;
158
+ rise: any;
159
+ fade: any;
160
+ children: ReactNode;
161
+ }) {
162
+ const { Animated } = primitives();
163
+ if (!animated) return <>{children}</>;
164
+ return (
165
+ <Animated.View style={{ transform: [{ translateY: rise }], opacity: fade }}>
166
+ {children}
167
+ </Animated.View>
168
+ );
169
+ }
170
+
171
+ // ---------------------------------------------------------------------------
172
+ // Banner
173
+
174
+ export interface BannerProps {
175
+ title?: string;
176
+ message: string;
177
+ tone?: Tone;
178
+ /** A leading icon node. */
179
+ icon?: ReactNode;
180
+ /** Shows a dismiss button when provided. */
181
+ onDismiss?: () => void;
182
+ /** A single inline action, e.g. Retry. */
183
+ action?: ToastAction;
184
+ style?: StyleProp<ViewStyle>;
185
+ isDark?: boolean;
186
+ testID?: string;
187
+ }
188
+
189
+ /**
190
+ * An inline alert.
191
+ *
192
+ * Unlike AlertDialog it is not modal and not an overlay: it sits in the layout
193
+ * and pushes the content below it down. The surface is glass with the tone's
194
+ * colour as its edge, so the tone reads at a glance without turning the whole
195
+ * panel into a solid block of colour.
196
+ */
197
+ export const Banner = forwardRef<any, BannerProps>(function Banner(
198
+ { title, message, tone = "info", icon, onDismiss, action, style, isDark: isDarkProp, testID, ...props },
199
+ ref,
200
+ ) {
201
+ const isDark = useIsDark(isDarkProp);
202
+ const theme = isDark ? colors.dark : colors.light;
203
+ const { View, Text: RNText, Pressable } = primitives();
204
+ const accent = toneColor(theme, tone);
205
+
206
+ return (
207
+ <Glass
208
+ ref={ref}
209
+ effect="regular"
210
+ isDark={isDark}
211
+ testID={testID}
212
+ style={{ borderRadius: radii.md, borderColor: accent, ...(style as ViewStyle) }}
213
+ {...props}
214
+ >
215
+ <View style={{ flexDirection: "row", alignItems: "flex-start", gap: 10, padding: 12 }}>
216
+ {icon ? <View style={{ paddingTop: 1 }}>{icon}</View> : null}
217
+ <View style={{ flex: 1, gap: 2 }}>
218
+ {title && (
219
+ <RNText
220
+ accessibilityRole="heading"
221
+ style={{ fontSize: 14, fontWeight: "600", color: theme.foreground }}
222
+ >
223
+ {title}
224
+ </RNText>
225
+ )}
226
+ <RNText accessibilityRole="alert" style={{ fontSize: 13, color: theme.muted, lineHeight: 18 }}>
227
+ {message}
228
+ </RNText>
229
+ {action && (
230
+ <Pressable
231
+ accessibilityRole="button"
232
+ accessibilityLabel={action.label}
233
+ onPress={action.onPress}
234
+ style={{ alignSelf: "flex-start", paddingTop: 6 }}
235
+ >
236
+ <RNText style={{ fontSize: 13, fontWeight: "600", color: accent }}>
237
+ {action.label}
238
+ </RNText>
239
+ </Pressable>
240
+ )}
241
+ </View>
242
+ {onDismiss && (
243
+ <Pressable
244
+ accessibilityRole="button"
245
+ accessibilityLabel="Dismiss"
246
+ onPress={onDismiss}
247
+ hitSlop={8}
248
+ style={{ padding: 2 }}
249
+ >
250
+ <RNText style={{ fontSize: 15, color: theme.muted }}>{"\u00D7"}</RNText>
251
+ </Pressable>
252
+ )}
253
+ </View>
254
+ </Glass>
255
+ );
256
+ });
257
+
258
+ // ---------------------------------------------------------------------------
259
+ // List
260
+
261
+ export interface ListItemProps {
262
+ /** An avatar, icon or other leading node. */
263
+ leading?: ReactNode;
264
+ /** The row's main text. */
265
+ title: string;
266
+ /** Secondary line under the title. */
267
+ description?: string;
268
+ /** A value text, a control, or any trailing node. */
269
+ trailing?: ReactNode;
270
+ /** Draws a chevron when the row is tappable and nothing else trails it. */
271
+ chevron?: boolean;
272
+ onPress?: () => void;
273
+ disabled?: boolean;
274
+ selected?: boolean;
275
+ style?: StyleProp<ViewStyle>;
276
+ isDark?: boolean;
277
+ testID?: string;
278
+ }
279
+
280
+ /**
281
+ * One row of a List.
282
+ *
283
+ * The row is a Pressable when it has an `onPress`, and inert otherwise, which
284
+ * is what the platform expects: a row that does nothing should not announce
285
+ * itself as a button. The chevron is decoration and is hidden from screen
286
+ * readers, since the row's own role already says it is tappable.
287
+ */
288
+ export const ListItem = forwardRef<any, ListItemProps>(function ListItem(
289
+ {
290
+ leading,
291
+ title,
292
+ description,
293
+ trailing,
294
+ chevron,
295
+ onPress,
296
+ disabled = false,
297
+ selected = false,
298
+ style,
299
+ isDark: isDarkProp,
300
+ testID,
301
+ ...props
302
+ },
303
+ ref,
304
+ ) {
305
+ const isDark = useIsDark(isDarkProp);
306
+ const theme = isDark ? colors.dark : colors.light;
307
+ const { View, Text: RNText, Pressable } = primitives();
308
+
309
+ const interactive = Boolean(onPress) && !disabled;
310
+ const showChevron = interactive && chevron !== false && trailing === undefined;
311
+
312
+ const content = (
313
+ <>
314
+ {leading ? <View style={{ marginRight: 12 }}>{leading}</View> : null}
315
+ <View style={{ flex: 1, gap: 2 }}>
316
+ <RNText
317
+ numberOfLines={1}
318
+ style={{ fontSize: 16, color: theme.foreground, fontWeight: "400" }}
319
+ >
320
+ {title}
321
+ </RNText>
322
+ {description ? (
323
+ <RNText numberOfLines={2} style={{ fontSize: 13, color: theme.muted, lineHeight: 17 }}>
324
+ {description}
325
+ </RNText>
326
+ ) : null}
327
+ </View>
328
+ {trailing ? <View style={{ marginLeft: 8 }}>{trailing}</View> : null}
329
+ {showChevron ? (
330
+ <RNText accessibilityElementsHidden importantForAccessibility="no" style={{ marginLeft: 6, fontSize: 17, color: theme.muted }}>
331
+ {"\u203A"}
332
+ </RNText>
333
+ ) : null}
334
+ </>
335
+ );
336
+
337
+ const rowStyle: ViewStyle = {
338
+ flexDirection: "row",
339
+ alignItems: "center",
340
+ minHeight: 48,
341
+ paddingVertical: 10,
342
+ paddingHorizontal: 14,
343
+ backgroundColor: selected ? theme.glassActive : "transparent",
344
+ opacity: disabled ? 0.38 : 1,
345
+ ...(style as ViewStyle),
346
+ };
347
+
348
+ if (!interactive) {
349
+ return (
350
+ <View ref={ref} testID={testID} accessibilityRole="text" accessibilityState={{ disabled }} style={rowStyle} {...props}>
351
+ {content}
352
+ </View>
353
+ );
354
+ }
355
+
356
+ return (
357
+ <Pressable
358
+ ref={ref}
359
+ testID={testID}
360
+ accessibilityRole="button"
361
+ accessibilityLabel={description ? `${title}, ${description}` : title}
362
+ accessibilityState={{ selected, disabled }}
363
+ disabled={disabled}
364
+ onPress={onPress}
365
+ style={({ pressed }: { pressed: boolean }) => ({ ...rowStyle, opacity: pressed ? 0.7 : rowStyle.opacity })}
366
+ {...props}
367
+ >
368
+ {content}
369
+ </Pressable>
370
+ );
371
+ });
372
+
373
+ export interface ListProps {
374
+ children?: ReactNode;
375
+ /** Renders the rows on one glass panel with separators between them. */
376
+ inset?: boolean;
377
+ style?: StyleProp<ViewStyle>;
378
+ isDark?: boolean;
379
+ testID?: string;
380
+ }
381
+
382
+ /**
383
+ * A grouped list of rows — the backbone of settings and profile screens.
384
+ *
385
+ * With `inset`, the rows sit on one glass panel with hairline separators, which
386
+ * is the shape iOS settings screens use. The separators are drawn by the
387
+ * caller's ListItem spacing rather than by nesting glass inside glass.
388
+ */
389
+ export const List = forwardRef<any, ListProps>(function List(
390
+ { children, inset = false, style, isDark: isDarkProp, testID, ...props },
391
+ ref,
392
+ ) {
393
+ const isDark = useIsDark(isDarkProp);
394
+ const { View } = primitives();
395
+
396
+ const rows = Array.isArray(children) ? children.filter(Boolean) : children == null ? [] : [children];
397
+
398
+ const body = (
399
+ <View style={{ gap: 2 }}>
400
+ {rows.map((row, index) => (
401
+ <View key={index}>
402
+ {index > 0 ? <Separator isDark={isDark} inset={inset ? 14 : 0} /> : null}
403
+ {row}
404
+ </View>
405
+ ))}
406
+ </View>
407
+ );
408
+
409
+ if (!inset) {
410
+ return (
411
+ <View ref={ref} testID={testID} style={style} {...props}>
412
+ {body}
413
+ </View>
414
+ );
415
+ }
416
+
417
+ return (
418
+ <Glass
419
+ ref={ref}
420
+ effect="regular"
421
+ isDark={isDark}
422
+ testID={testID}
423
+ style={{ borderRadius: radii.md, overflow: "hidden", ...(style as ViewStyle) }}
424
+ {...props}
425
+ >
426
+ {body}
427
+ </Glass>
428
+ );
429
+ });
430
+
431
+ /** A titled group of rows, e.g. "Account" above its settings. */
432
+ export interface ListSectionProps {
433
+ header?: string;
434
+ children?: ReactNode;
435
+ style?: StyleProp<ViewStyle>;
436
+ isDark?: boolean;
437
+ testID?: string;
438
+ }
439
+
440
+ export const ListSection = forwardRef<any, ListSectionProps>(function ListSection(
441
+ { header, children, style, isDark: isDarkProp, testID, ...props },
442
+ ref,
443
+ ) {
444
+ const isDark = useIsDark(isDarkProp);
445
+ const theme = isDark ? colors.dark : colors.light;
446
+ const { View, Text: RNText } = primitives();
447
+
448
+ return (
449
+ <View ref={ref} testID={testID} style={[{ gap: 6 }, style as ViewStyle]} {...props}>
450
+ {header ? (
451
+ <RNText
452
+ accessibilityRole="heading"
453
+ style={{
454
+ fontSize: 12,
455
+ fontWeight: "600",
456
+ letterSpacing: 0.4,
457
+ textTransform: "uppercase",
458
+ color: theme.muted,
459
+ paddingHorizontal: 14,
460
+ }}
461
+ >
462
+ {header}
463
+ </RNText>
464
+ ) : null}
465
+ <List inset isDark={isDark}>
466
+ {children}
467
+ </List>
468
+ </View>
469
+ );
470
+ });
471
+
472
+ // ---------------------------------------------------------------------------
473
+ // Accordion
474
+
475
+ export interface AccordionSection {
476
+ /** Stable identity for the section. */
477
+ value: string;
478
+ title: string;
479
+ /** Optional second line in the header. */
480
+ description?: string;
481
+ content: ReactNode;
482
+ }
483
+
484
+ export interface AccordionProps {
485
+ sections: AccordionSection[];
486
+ /** Allow several sections open at once. */
487
+ multiple?: boolean;
488
+ /** Controlled open sections. Omit for uncontrolled. */
489
+ openSections?: string[];
490
+ defaultOpenSections?: string[];
491
+ onOpenSectionsChange?: (open: string[]) => void;
492
+ style?: StyleProp<ViewStyle>;
493
+ isDark?: boolean;
494
+ testID?: string;
495
+ }
496
+
497
+ /**
498
+ * Expandable sections.
499
+ *
500
+ * The header is a Pressable reporting `expanded`; the panel is measured with
501
+ * the height the content reports and animated on the springs token, so the
502
+ * reveal is a real transition rather than an instant jump.
503
+ */
504
+ export const Accordion = forwardRef<any, AccordionProps>(function Accordion(
505
+ {
506
+ sections,
507
+ multiple = false,
508
+ openSections: openProp,
509
+ defaultOpenSections = [],
510
+ onOpenSectionsChange,
511
+ style,
512
+ isDark: isDarkProp,
513
+ testID,
514
+ ...props
515
+ },
516
+ ref,
517
+ ) {
518
+ const isDark = useIsDark(isDarkProp);
519
+ const theme = isDark ? colors.dark : colors.light;
520
+ const { View, Text: RNText, Pressable } = primitives();
521
+
522
+ const [internalOpen, setInternalOpen] = useState<string[]>(defaultOpenSections);
523
+ const open = openProp !== undefined ? openProp : internalOpen;
524
+
525
+ const toggle = (value: string) => {
526
+ const isOpen = open.includes(value);
527
+ let next: string[];
528
+ if (isOpen) next = open.filter((item) => item !== value);
529
+ else next = multiple ? [...open, value] : [value];
530
+ if (openProp === undefined) setInternalOpen(next);
531
+ onOpenSectionsChange?.(next);
532
+ };
533
+
534
+ return (
535
+ <Glass
536
+ ref={ref}
537
+ effect="regular"
538
+ isDark={isDark}
539
+ testID={testID}
540
+ style={{ borderRadius: radii.md, overflow: "hidden", ...(style as ViewStyle) }}
541
+ {...props}
542
+ >
543
+ {sections.map((section, index) => {
544
+ const expanded = open.includes(section.value);
545
+ return (
546
+ <View key={section.value}>
547
+ {index > 0 ? <Separator isDark={isDark} /> : null}
548
+ <Pressable
549
+ accessibilityRole="button"
550
+ accessibilityLabel={section.title}
551
+ accessibilityState={{ expanded }}
552
+ onPress={() => toggle(section.value)}
553
+ style={{ paddingVertical: 12, paddingHorizontal: 14, flexDirection: "row", alignItems: "center" }}
554
+ >
555
+ <View style={{ flex: 1, gap: 2 }}>
556
+ <RNText style={{ fontSize: 15, fontWeight: "500", color: theme.foreground }}>
557
+ {section.title}
558
+ </RNText>
559
+ {section.description ? (
560
+ <RNText style={{ fontSize: 13, color: theme.muted }}>{section.description}</RNText>
561
+ ) : null}
562
+ </View>
563
+ <RNText
564
+ accessibilityElementsHidden
565
+ importantForAccessibility="no"
566
+ style={{ fontSize: 13, color: theme.muted, marginLeft: 8 }}
567
+ >
568
+ {expanded ? "\u2303" : "\u2304"}
569
+ </RNText>
570
+ </Pressable>
571
+ {expanded ? (
572
+ <View style={{ paddingHorizontal: 14, paddingBottom: 12 }}>{section.content}</View>
573
+ ) : null}
574
+ </View>
575
+ );
576
+ })}
577
+ </Glass>
578
+ );
579
+ });