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/Bars.tsx ADDED
@@ -0,0 +1,570 @@
1
+ import { forwardRef, useState, type ReactNode } from "react";
2
+ import type { StyleProp, TextStyle, ViewStyle } from "react-native";
3
+
4
+ import { Glass } from "./Glass";
5
+ import { Button } from "./Button";
6
+ import { Text } from "./Text";
7
+ import { colors, radii } from "./internal/tokens";
8
+ import { primitives } from "./internal/primitives";
9
+ import { useIsDark, useSpring } from "./internal/motion";
10
+
11
+ // ---------------------------------------------------------------------------
12
+ // SearchBar
13
+
14
+ export interface SearchBarProps {
15
+ /** Controlled text. Omit and the bar keeps its own. */
16
+ value?: string;
17
+ defaultValue?: string;
18
+ onChangeText?: (text: string) => void;
19
+ onSubmit?: (text: string) => void;
20
+ placeholder?: string;
21
+ /** Shows a cancel button beside the field while it holds text or focus. */
22
+ showCancel?: boolean;
23
+ onCancel?: () => void;
24
+ accessibilityLabel?: string;
25
+ style?: StyleProp<ViewStyle>;
26
+ isDark?: boolean;
27
+ testID?: string;
28
+ }
29
+
30
+ /**
31
+ * A search field for a bar or a screen header.
32
+ *
33
+ * Distinct from NativeAIInput: that is an AI composer with send semantics, this
34
+ * is ordinary app search — magnifier, themed placeholder, and a clear button
35
+ * once there is something to clear.
36
+ */
37
+ export const SearchBar = forwardRef<any, SearchBarProps>(function SearchBar(
38
+ {
39
+ value: valueProp,
40
+ defaultValue = "",
41
+ onChangeText,
42
+ onSubmit,
43
+ placeholder = "Search",
44
+ showCancel = false,
45
+ onCancel,
46
+ accessibilityLabel = "Search",
47
+ style,
48
+ isDark: isDarkProp,
49
+ testID,
50
+ ...props
51
+ },
52
+ ref,
53
+ ) {
54
+ const isDark = useIsDark(isDarkProp);
55
+ const theme = isDark ? colors.dark : colors.light;
56
+ const { View, Text: RNText, TextInput, Pressable } = primitives();
57
+
58
+ const [internal, setInternal] = useState(defaultValue);
59
+ const value = valueProp !== undefined ? valueProp : internal;
60
+
61
+ const handleChange = (next: string) => {
62
+ if (valueProp === undefined) setInternal(next);
63
+ onChangeText?.(next);
64
+ };
65
+
66
+ const clear = () => handleChange("");
67
+
68
+ return (
69
+ <View
70
+ ref={ref}
71
+ testID={testID}
72
+ style={[{ flexDirection: "row", alignItems: "center", gap: 8 }, style as ViewStyle]}
73
+ {...props}
74
+ >
75
+ <Glass
76
+ effect="regular"
77
+ isDark={isDark}
78
+ style={{
79
+ flex: 1,
80
+ flexDirection: "row",
81
+ alignItems: "center",
82
+ gap: 8,
83
+ height: 36,
84
+ borderRadius: radii.pill,
85
+ paddingHorizontal: 12,
86
+ }}
87
+ >
88
+ <RNText accessibilityElementsHidden importantForAccessibility="no" style={{ fontSize: 14, color: theme.muted }}>
89
+ {"\u2315"}
90
+ </RNText>
91
+ <View style={{ flex: 1, justifyContent: "center" }}>
92
+ {!value && placeholder ? (
93
+ // Themed placeholder: the OS default colour ignores the theme.
94
+ <RNText
95
+ pointerEvents="none"
96
+ numberOfLines={1}
97
+ style={{ position: "absolute", left: 0, fontSize: 15, color: theme.muted }}
98
+ >
99
+ {placeholder}
100
+ </RNText>
101
+ ) : null}
102
+ <TextInput
103
+ accessibilityRole="search"
104
+ accessibilityLabel={accessibilityLabel}
105
+ value={value}
106
+ onChangeText={handleChange}
107
+ onSubmitEditing={() => onSubmit?.(value)}
108
+ returnKeyType="search"
109
+ autoCorrect={false}
110
+ placeholder=""
111
+ style={{
112
+ fontSize: 15,
113
+ paddingVertical: 4,
114
+ color: theme.foreground,
115
+ // Transparent: the themed placeholder above provides the hint.
116
+ backgroundColor: "transparent",
117
+ }}
118
+ />
119
+ </View>
120
+ {value.length > 0 && (
121
+ <Pressable
122
+ accessibilityRole="button"
123
+ accessibilityLabel="Clear search"
124
+ onPress={clear}
125
+ hitSlop={8}
126
+ >
127
+ <View
128
+ style={{
129
+ width: 16,
130
+ height: 16,
131
+ // A circle from its own size: half the 16pt box.
132
+ borderRadius: 16 / 2,
133
+ backgroundColor: theme.separator,
134
+ alignItems: "center",
135
+ justifyContent: "center",
136
+ }}
137
+ >
138
+ <RNText style={{ fontSize: 10, color: theme.muted }}>{"\u00D7"}</RNText>
139
+ </View>
140
+ </Pressable>
141
+ )}
142
+ </Glass>
143
+ {showCancel && (
144
+ <Pressable
145
+ accessibilityRole="button"
146
+ accessibilityLabel="Cancel"
147
+ onPress={() => {
148
+ clear();
149
+ onCancel?.();
150
+ }}
151
+ >
152
+ <RNText style={{ fontSize: 15, color: theme.fill }}>Cancel</RNText>
153
+ </Pressable>
154
+ )}
155
+ </View>
156
+ );
157
+ });
158
+
159
+ // ---------------------------------------------------------------------------
160
+ // Chip
161
+
162
+ export interface ChipProps {
163
+ label: string;
164
+ icon?: ReactNode;
165
+ /** Shows a close affordance; called when it is pressed. */
166
+ onClose?: () => void;
167
+ /** Tapping the chip. Omit to make it a static tag. */
168
+ onPress?: () => void;
169
+ /** Controlled selection. Omit for a plain tag with no selected state. */
170
+ selected?: boolean;
171
+ defaultSelected?: boolean;
172
+ onSelectedChange?: (selected: boolean) => void;
173
+ disabled?: boolean;
174
+ style?: StyleProp<ViewStyle>;
175
+ isDark?: boolean;
176
+ testID?: string;
177
+ }
178
+
179
+ /**
180
+ * A filter or tag pill.
181
+ *
182
+ * Selected state is a glass pill tinted with `glassActive` — the same selected
183
+ * treatment SegmentedControl and TabBar use, rather than a new colour.
184
+ */
185
+ export const Chip = forwardRef<any, ChipProps>(function Chip(
186
+ {
187
+ label,
188
+ icon,
189
+ onClose,
190
+ onPress,
191
+ selected: selectedProp,
192
+ defaultSelected = false,
193
+ onSelectedChange,
194
+ disabled = false,
195
+ style,
196
+ isDark: isDarkProp,
197
+ testID,
198
+ ...props
199
+ },
200
+ ref,
201
+ ) {
202
+ const isDark = useIsDark(isDarkProp);
203
+ const theme = isDark ? colors.dark : colors.light;
204
+ const { View, Text: RNText, Pressable } = primitives();
205
+
206
+ const [internalSelected, setInternalSelected] = useState(defaultSelected);
207
+ const selected = selectedProp !== undefined ? selectedProp : internalSelected;
208
+ const selectable = selectedProp !== undefined || onSelectedChange !== undefined || defaultSelected;
209
+
210
+ const handlePress = () => {
211
+ if (disabled) return;
212
+ if (selectable) {
213
+ const next = !selected;
214
+ if (selectedProp === undefined) setInternalSelected(next);
215
+ onSelectedChange?.(next);
216
+ }
217
+ onPress?.();
218
+ };
219
+
220
+ const pill = (
221
+ <Glass
222
+ effect="regular"
223
+ isDark={isDark}
224
+ tintColor={selected ? theme.glassActive : undefined}
225
+ interactive={!disabled}
226
+ style={{
227
+ flexDirection: "row",
228
+ alignItems: "center",
229
+ gap: 6,
230
+ height: 30,
231
+ paddingHorizontal: 12,
232
+ borderRadius: radii.pill,
233
+ opacity: disabled ? 0.38 : 1,
234
+ ...(style as ViewStyle),
235
+ }}
236
+ >
237
+ {icon ? <View>{icon}</View> : null}
238
+ <RNText
239
+ numberOfLines={1}
240
+ style={{ fontSize: 13, fontWeight: selected ? "600" : "500", color: selected ? theme.foreground : theme.muted }}
241
+ >
242
+ {label}
243
+ </RNText>
244
+ {onClose && (
245
+ <Pressable
246
+ accessibilityRole="button"
247
+ accessibilityLabel={`Remove ${label}`}
248
+ onPress={onClose}
249
+ hitSlop={8}
250
+ >
251
+ <RNText style={{ fontSize: 11, color: theme.muted }}>{"\u00D7"}</RNText>
252
+ </Pressable>
253
+ )}
254
+ </Glass>
255
+ );
256
+
257
+ if (!onPress && !selectable) {
258
+ return (
259
+ <View ref={ref} testID={testID} accessibilityRole="text" accessibilityLabel={label} {...props}>
260
+ {pill}
261
+ </View>
262
+ );
263
+ }
264
+
265
+ return (
266
+ <Pressable
267
+ ref={ref}
268
+ testID={testID}
269
+ accessibilityRole="button"
270
+ accessibilityLabel={label}
271
+ accessibilityState={{ selected: selectable ? selected : undefined, disabled }}
272
+ disabled={disabled}
273
+ onPress={handlePress}
274
+ {...props}
275
+ >
276
+ {pill}
277
+ </Pressable>
278
+ );
279
+ });
280
+
281
+ // ---------------------------------------------------------------------------
282
+ // FAB
283
+
284
+ export interface FABProps {
285
+ onPress: () => void;
286
+ /** Required: an icon-only circle has no text to announce. */
287
+ accessibilityLabel: string;
288
+ /** The icon. When a label string is also supplied, the FAB is extended. */
289
+ icon?: ReactNode;
290
+ /** Turns the circle into an extended pill with visible text. */
291
+ label?: string;
292
+ size?: "md" | "lg";
293
+ disabled?: boolean;
294
+ style?: StyleProp<ViewStyle>;
295
+ isDark?: boolean;
296
+ testID?: string;
297
+ }
298
+
299
+ const fabSizes = { md: 56, lg: 64 };
300
+
301
+ /**
302
+ * The floating action button.
303
+ *
304
+ * The flagship glass circle of the library: a round `Glass` with `interactive`
305
+ * so the material itself responds to touch. The caller positions it; the
306
+ * component does not assume an edge.
307
+ */
308
+ export const FAB = forwardRef<any, FABProps>(function FAB(
309
+ {
310
+ onPress,
311
+ accessibilityLabel,
312
+ icon,
313
+ label,
314
+ size = "md",
315
+ disabled = false,
316
+ style,
317
+ isDark: isDarkProp,
318
+ testID,
319
+ ...props
320
+ },
321
+ ref,
322
+ ) {
323
+ const isDark = useIsDark(isDarkProp);
324
+ const theme = isDark ? colors.dark : colors.light;
325
+ const { View, Text: RNText, Pressable } = primitives();
326
+
327
+ const dimension = fabSizes[size];
328
+ const extended = Boolean(label);
329
+
330
+ return (
331
+ <Pressable
332
+ ref={ref}
333
+ testID={testID}
334
+ accessibilityRole="button"
335
+ accessibilityLabel={accessibilityLabel}
336
+ accessibilityState={{ disabled }}
337
+ disabled={disabled}
338
+ onPress={disabled ? undefined : onPress}
339
+ style={({ pressed }: { pressed: boolean }) => ({
340
+ alignSelf: "flex-start",
341
+ opacity: disabled ? 0.38 : pressed ? 0.85 : 1,
342
+ })}
343
+ {...props}
344
+ >
345
+ <Glass
346
+ effect="clear"
347
+ interactive={!disabled}
348
+ isDark={isDark}
349
+ style={{
350
+ height: dimension,
351
+ width: extended ? undefined : dimension,
352
+ minWidth: dimension,
353
+ borderRadius: extended ? dimension / 2 : dimension / 2,
354
+ paddingHorizontal: extended ? 20 : 0,
355
+ flexDirection: "row",
356
+ alignItems: "center",
357
+ justifyContent: "center",
358
+ gap: 8,
359
+ ...(style as ViewStyle),
360
+ }}
361
+ >
362
+ {icon ? <View>{icon}</View> : null}
363
+ {label ? (
364
+ <RNText style={{ fontSize: 15, fontWeight: "600", color: theme.foreground }} numberOfLines={1}>
365
+ {label}
366
+ </RNText>
367
+ ) : null}
368
+ </Glass>
369
+ </Pressable>
370
+ );
371
+ });
372
+
373
+ // ---------------------------------------------------------------------------
374
+ // IconButton
375
+
376
+ export interface IconButtonProps {
377
+ /** Required: the icon carries no text of its own. */
378
+ accessibilityLabel: string;
379
+ onPress: () => void;
380
+ icon: ReactNode;
381
+ size?: "sm" | "md" | "lg";
382
+ variant?: "glass" | "ghost";
383
+ disabled?: boolean;
384
+ style?: StyleProp<ViewStyle>;
385
+ isDark?: boolean;
386
+ testID?: string;
387
+ }
388
+
389
+ const iconButtonSizes = { sm: 28, md: 36, lg: 44 };
390
+
391
+ /**
392
+ * An icon-only button on glass.
393
+ *
394
+ * Button takes an icon alongside a label; this is the icon-only form, which
395
+ * every kit ships for toolbars and bar actions.
396
+ */
397
+ export const IconButton = forwardRef<any, IconButtonProps>(function IconButton(
398
+ {
399
+ accessibilityLabel,
400
+ onPress,
401
+ icon,
402
+ size = "md",
403
+ variant = "glass",
404
+ disabled = false,
405
+ style,
406
+ isDark: isDarkProp,
407
+ testID,
408
+ ...props
409
+ },
410
+ ref,
411
+ ) {
412
+ const isDark = useIsDark(isDarkProp);
413
+ const theme = isDark ? colors.dark : colors.light;
414
+ const { View, Pressable } = primitives();
415
+ const dimension = iconButtonSizes[size];
416
+
417
+ return (
418
+ <Pressable
419
+ ref={ref}
420
+ testID={testID}
421
+ accessibilityRole="button"
422
+ accessibilityLabel={accessibilityLabel}
423
+ accessibilityState={{ disabled }}
424
+ disabled={disabled}
425
+ onPress={disabled ? undefined : onPress}
426
+ style={({ pressed }: { pressed: boolean }) => ({ opacity: disabled ? 0.38 : pressed ? 0.8 : 1 })}
427
+ {...props}
428
+ >
429
+ <Glass
430
+ effect={variant === "ghost" ? "none" : "regular"}
431
+ interactive={!disabled && variant !== "ghost"}
432
+ isDark={isDark}
433
+ style={{
434
+ width: dimension,
435
+ height: dimension,
436
+ borderRadius: dimension / 2,
437
+ alignItems: "center",
438
+ justifyContent: "center",
439
+ backgroundColor: variant === "ghost" ? "transparent" : undefined,
440
+ ...(style as ViewStyle),
441
+ }}
442
+ >
443
+ <View style={{ width: dimension * 0.5, height: dimension * 0.5, alignItems: "center", justifyContent: "center" }}>
444
+ {icon}
445
+ </View>
446
+ </Glass>
447
+ </Pressable>
448
+ );
449
+ });
450
+
451
+ // ---------------------------------------------------------------------------
452
+ // AppBar
453
+
454
+ export interface AppBarAction {
455
+ /** Announced to screen readers; the icon is decorative. */
456
+ accessibilityLabel: string;
457
+ icon: ReactNode;
458
+ onPress: () => void;
459
+ disabled?: boolean;
460
+ }
461
+
462
+ export interface AppBarProps {
463
+ title: string;
464
+ /** Optional second line under the title. */
465
+ subtitle?: string;
466
+ /** A back or menu action at the leading edge. */
467
+ leading?: AppBarAction;
468
+ /** Actions at the trailing edge. */
469
+ actions?: AppBarAction[];
470
+ /**
471
+ * The caller's safe-area inset above the bar. Glacia takes it as a prop
472
+ * rather than adding a native insets dependency: on a device the app already
473
+ * knows its insets, and passing a number keeps this component dependency-free.
474
+ */
475
+ topInset?: number;
476
+ style?: StyleProp<ViewStyle>;
477
+ isDark?: boolean;
478
+ testID?: string;
479
+ }
480
+
481
+ /**
482
+ * The top bar.
483
+ *
484
+ * A glass bar across the top of the screen with a leading action, a title and
485
+ * trailing actions — the counterpart to the existing bottom TabBar.
486
+ */
487
+ export const AppBar = forwardRef<any, AppBarProps>(function AppBar(
488
+ {
489
+ title,
490
+ subtitle,
491
+ leading,
492
+ actions,
493
+ topInset = 0,
494
+ style,
495
+ isDark: isDarkProp,
496
+ testID,
497
+ ...props
498
+ },
499
+ ref,
500
+ ) {
501
+ const isDark = useIsDark(isDarkProp);
502
+ const theme = isDark ? colors.dark : colors.light;
503
+ const { View, Text: RNText, Pressable } = primitives();
504
+ const actionCount = actions?.length ?? 0;
505
+
506
+ const renderAction = (action: AppBarAction, key: string) => (
507
+ <Pressable
508
+ key={key}
509
+ accessibilityRole="button"
510
+ accessibilityLabel={action.accessibilityLabel}
511
+ accessibilityState={{ disabled: action.disabled }}
512
+ disabled={action.disabled}
513
+ onPress={action.disabled ? undefined : action.onPress}
514
+ hitSlop={6}
515
+ style={{ padding: 6, opacity: action.disabled ? 0.38 : 1 }}
516
+ >
517
+ {action.icon}
518
+ </Pressable>
519
+ );
520
+
521
+ return (
522
+ <Glass
523
+ ref={ref}
524
+ effect="regular"
525
+ isDark={isDark}
526
+ testID={testID}
527
+ style={{
528
+ borderRadius: 0,
529
+ borderTopWidth: 0,
530
+ borderLeftWidth: 0,
531
+ borderRightWidth: 0,
532
+ ...(style as ViewStyle),
533
+ }}
534
+ {...props}
535
+ >
536
+ <View
537
+ style={{
538
+ paddingTop: topInset,
539
+ paddingHorizontal: 8,
540
+ paddingBottom: 8,
541
+ flexDirection: "row",
542
+ alignItems: "center",
543
+ gap: 4,
544
+ minHeight: 44 + topInset,
545
+ }}
546
+ >
547
+ {leading ? renderAction(leading, "leading") : <View style={{ width: 8 }} />}
548
+ <View style={{ flex: 1, paddingHorizontal: 4 }}>
549
+ <RNText
550
+ accessibilityRole="header"
551
+ numberOfLines={1}
552
+ style={{ fontSize: 17, fontWeight: "600", color: theme.foreground }}
553
+ >
554
+ {title}
555
+ </RNText>
556
+ {subtitle ? (
557
+ <RNText numberOfLines={1} style={{ fontSize: 12, color: theme.muted }}>
558
+ {subtitle}
559
+ </RNText>
560
+ ) : null}
561
+ </View>
562
+ {actions && actionCount > 0 ? (
563
+ <View style={{ flexDirection: "row", alignItems: "center" }}>
564
+ {actions.map((action, index) => renderAction(action, `action-${index}`))}
565
+ </View>
566
+ ) : null}
567
+ </View>
568
+ </Glass>
569
+ );
570
+ });
package/src/Button.tsx CHANGED
@@ -1,6 +1,10 @@
1
1
  import { forwardRef, type ReactNode } from "react";
2
+ import type { StyleProp, TextStyle, ViewStyle } from "react-native";
3
+
2
4
  import { Glass } from "./Glass";
3
- import { colors, radii } from "./internal/tokens";
5
+ import { colors } from "./internal/tokens";
6
+ import { primitives } from "./internal/primitives";
7
+ import { useIsDark } from "./internal/motion";
4
8
 
5
9
  export interface ButtonProps {
6
10
  variant?: "glass" | "filled" | "ghost";
@@ -10,9 +14,11 @@ export interface ButtonProps {
10
14
  accessibilityLabel: string;
11
15
  icon?: ReactNode;
12
16
  children?: ReactNode;
13
- style?: any;
17
+ style?: StyleProp<ViewStyle>;
14
18
  tint?: string;
15
19
  isDark?: boolean;
20
+ /** Passed through to the pressable root so the button is testable. */
21
+ testID?: string;
16
22
  }
17
23
 
18
24
  const sizeHeights = {
@@ -21,6 +27,13 @@ const sizeHeights = {
21
27
  lg: 48,
22
28
  };
23
29
 
30
+ /**
31
+ * A pressable button on Glacia's glass.
32
+ *
33
+ * The root is a Pressable so it gets the platform's own press semantics
34
+ * (focus, screen-reader activation, pressed feedback) while the material —
35
+ * Apple's glass on iOS 26+, Glacia's tint elsewhere — comes from `Glass`.
36
+ */
24
37
  export const Button = forwardRef<any, ButtonProps>(function Button(
25
38
  {
26
39
  variant = "glass",
@@ -32,56 +45,68 @@ export const Button = forwardRef<any, ButtonProps>(function Button(
32
45
  children,
33
46
  style,
34
47
  tint,
35
- isDark = false,
48
+ isDark: isDarkProp,
49
+ testID,
36
50
  ...props
37
51
  },
38
52
  ref,
39
53
  ) {
54
+ const isDark = useIsDark(isDarkProp);
40
55
  const themeColors = isDark ? colors.dark : colors.light;
56
+ const { Pressable, View, Text } = primitives();
41
57
  const height = sizeHeights[size];
42
58
 
43
- const buttonStyle = {
59
+ const buttonStyle: ViewStyle = {
44
60
  height,
45
61
  borderRadius: height / 2,
46
- flexDirection: "row" as const,
47
- alignItems: "center" as const,
48
- justifyContent: "center" as const,
62
+ flexDirection: "row",
63
+ alignItems: "center",
64
+ justifyContent: "center",
49
65
  paddingHorizontal: size === "sm" ? 12 : size === "lg" ? 22 : 16,
50
66
  opacity: disabled ? 0.38 : 1,
51
67
  backgroundColor:
52
68
  variant === "filled"
53
69
  ? tint || themeColors.fill
54
70
  : variant === "ghost"
55
- ? "transparent"
56
- : undefined,
57
- ...style,
71
+ ? "transparent"
72
+ : undefined,
73
+ ...(style as ViewStyle),
58
74
  };
59
75
 
60
- const textStyle = {
76
+ const textStyle: TextStyle = {
61
77
  color: variant === "filled" ? "#FFFFFF" : tint || themeColors.foreground,
62
78
  fontSize: size === "sm" ? 13 : size === "lg" ? 16 : 14,
63
- fontWeight: "500" as const,
79
+ fontWeight: "500",
64
80
  };
65
81
 
66
82
  return (
67
- <div
83
+ <Pressable
68
84
  ref={ref}
69
- role="button"
70
- tabIndex={disabled ? -1 : 0}
71
- aria-label={accessibilityLabel}
72
- aria-disabled={disabled}
73
- onClick={disabled ? undefined : onPress}
74
- style={{ display: "inline-block", cursor: disabled ? "default" : "pointer" }}
85
+ testID={testID}
86
+ accessibilityRole="button"
87
+ accessibilityLabel={accessibilityLabel}
88
+ accessibilityState={{ disabled }}
89
+ disabled={disabled}
90
+ onPress={disabled ? undefined : onPress}
91
+ style={({ pressed }: { pressed: boolean }) => ({ opacity: pressed && !disabled ? 0.85 : 1 })}
75
92
  {...props}
76
93
  >
77
94
  <Glass
78
95
  effect={variant === "ghost" ? "none" : "regular"}
79
96
  interactive={!disabled}
97
+ isDark={isDark}
80
98
  style={buttonStyle}
81
99
  >
82
- {icon && <span style={{ marginRight: children ? 8 : 0 }}>{icon}</span>}
83
- {typeof children === "string" ? <span style={textStyle}>{children}</span> : children}
100
+ {icon ? <View style={{ marginRight: children ? 8 : 0 }}>{icon}</View> : null}
101
+ {typeof children === "string" ? (
102
+ // A string label is text: it needs Text to inherit font and colour.
103
+ <Text style={textStyle} numberOfLines={1}>
104
+ {children}
105
+ </Text>
106
+ ) : (
107
+ children
108
+ )}
84
109
  </Glass>
85
- </div>
110
+ </Pressable>
86
111
  );
87
112
  });