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/Form.tsx CHANGED
@@ -1,38 +1,44 @@
1
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 LabelProps {
7
9
  children?: ReactNode;
8
10
  /** Marks the field required with a visible asterisk. */
9
11
  required?: boolean;
10
12
  disabled?: boolean;
11
- /** Ties the label to the control for screen readers. */
12
- htmlFor?: string;
13
+ /**
14
+ * The id of the control this label describes. Same meaning and prop name as
15
+ * React Native's `nativeID`.
16
+ */
17
+ nativeID?: string;
13
18
  isDark?: boolean;
14
- style?: any;
19
+ style?: StyleProp<TextStyle>;
15
20
  }
16
21
 
17
22
  /** The text above a control. */
18
23
  export const Label = forwardRef<any, LabelProps>(function Label(
19
- { children, required = false, disabled = false, htmlFor, isDark = false, style },
24
+ { children, required = false, disabled = false, nativeID, isDark: isDarkProp, style },
20
25
  ref,
21
26
  ) {
27
+ const isDark = useIsDark(isDarkProp);
22
28
  const theme = isDark ? colors.dark : colors.light;
23
29
  const { Text } = primitives();
24
30
 
25
31
  return (
26
32
  <Text
27
33
  ref={ref}
28
- nativeID={htmlFor}
34
+ nativeID={nativeID}
29
35
  accessibilityRole="text"
30
36
  style={{
31
37
  fontSize: 13,
32
38
  fontWeight: "600",
33
39
  color: disabled ? theme.muted : theme.foreground,
34
40
  opacity: disabled ? 0.6 : 1,
35
- ...style,
41
+ ...(style as TextStyle),
36
42
  }}
37
43
  >
38
44
  {children}
@@ -51,7 +57,7 @@ export interface FieldProps {
51
57
  disabled?: boolean;
52
58
  isDark?: boolean;
53
59
  children?: ReactNode;
54
- style?: any;
60
+ style?: StyleProp<ViewStyle>;
55
61
  }
56
62
 
57
63
  /**
@@ -64,16 +70,17 @@ export function Field({
64
70
  error,
65
71
  required = false,
66
72
  disabled = false,
67
- isDark = false,
73
+ isDark: isDarkProp,
68
74
  children,
69
75
  style,
70
76
  }: FieldProps) {
77
+ const isDark = useIsDark(isDarkProp);
71
78
  const theme = isDark ? colors.dark : colors.light;
72
79
  const { View, Text } = primitives();
73
80
  const message = error ?? description;
74
81
 
75
82
  return (
76
- <View style={{ gap: 6, ...style }}>
83
+ <View style={{ gap: 6, ...(style as ViewStyle) }}>
77
84
  {label && (
78
85
  <Label required={required} disabled={disabled} isDark={isDark}>
79
86
  {label}
@@ -99,44 +106,63 @@ export function Field({
99
106
 
100
107
  export interface CheckboxProps {
101
108
  checked?: boolean;
109
+ /** Starting state for uncontrolled use. */
110
+ defaultChecked?: boolean;
102
111
  onCheckedChange?: (checked: boolean) => void;
103
112
  label?: string;
104
113
  description?: string;
105
114
  indeterminate?: boolean;
106
115
  disabled?: boolean;
107
116
  isDark?: boolean;
108
- style?: any;
117
+ style?: StyleProp<ViewStyle>;
118
+ /** Passed through to the pressable row so it is testable. */
119
+ testID?: string;
109
120
  }
110
121
 
111
122
  /** A tick box for a single boolean, with an optional label and description. */
112
123
  export function Checkbox({
113
- checked = false,
124
+ checked: checkedProp,
125
+ defaultChecked = false,
114
126
  onCheckedChange,
115
127
  label,
116
128
  description,
117
129
  indeterminate = false,
118
130
  disabled = false,
119
- isDark = false,
131
+ isDark: isDarkProp,
120
132
  style,
133
+ testID,
121
134
  }: CheckboxProps) {
135
+ const isDark = useIsDark(isDarkProp);
122
136
  const theme = isDark ? colors.dark : colors.light;
123
137
  const { View, Text, Pressable } = primitives();
124
138
 
139
+ // Controlled when `checked` is given, otherwise the box owns its state.
140
+ const [internalChecked, setInternalChecked] = useState(defaultChecked);
141
+ const checked = checkedProp !== undefined ? checkedProp : internalChecked;
142
+
143
+ const toggle = () => {
144
+ if (disabled) return;
145
+ const next = !checked;
146
+ if (checkedProp === undefined) setInternalChecked(next);
147
+ onCheckedChange?.(next);
148
+ };
149
+
125
150
  const filled = checked || indeterminate;
126
151
 
127
152
  return (
128
153
  <Pressable
154
+ testID={testID}
129
155
  accessibilityRole="checkbox"
130
156
  accessibilityState={{ checked, disabled }}
131
157
  accessibilityLabel={label}
132
158
  disabled={disabled}
133
- onPress={() => !disabled && onCheckedChange?.(!checked)}
159
+ onPress={toggle}
134
160
  style={{
135
161
  flexDirection: "row",
136
162
  alignItems: "flex-start",
137
163
  gap: 10,
138
164
  opacity: disabled ? 0.45 : 1,
139
- ...style,
165
+ ...(style as ViewStyle),
140
166
  }}
141
167
  >
142
168
  <View
@@ -185,32 +211,54 @@ export interface RadioOption {
185
211
 
186
212
  export interface RadioGroupProps {
187
213
  value?: string;
214
+ /** Starting selection for uncontrolled use. */
215
+ defaultValue?: string;
188
216
  onValueChange?: (value: string) => void;
189
217
  options: RadioOption[];
190
218
  /** Lay the options out in a row instead of a column. */
191
219
  horizontal?: boolean;
192
220
  disabled?: boolean;
193
221
  isDark?: boolean;
194
- style?: any;
222
+ style?: StyleProp<ViewStyle>;
223
+ /** Passed through to the group so it is testable. */
224
+ testID?: string;
195
225
  }
196
226
 
197
227
  /** One choice from a small, always-visible set. */
198
228
  export function RadioGroup({
199
- value,
229
+ value: valueProp,
230
+ defaultValue,
200
231
  onValueChange,
201
232
  options,
202
233
  horizontal = false,
203
234
  disabled = false,
204
- isDark = false,
235
+ isDark: isDarkProp,
205
236
  style,
237
+ testID,
206
238
  }: RadioGroupProps) {
239
+ const isDark = useIsDark(isDarkProp);
207
240
  const theme = isDark ? colors.dark : colors.light;
208
241
  const { View, Text, Pressable } = primitives();
209
242
 
243
+ // Controlled when `value` is given, otherwise the group owns its selection.
244
+ const [internalValue, setInternalValue] = useState(defaultValue);
245
+ const value = valueProp !== undefined ? valueProp : internalValue;
246
+
247
+ const select = (next: string, isDisabled: boolean | undefined) => {
248
+ if (isDisabled) return;
249
+ if (valueProp === undefined) setInternalValue(next);
250
+ onValueChange?.(next);
251
+ };
252
+
210
253
  return (
211
254
  <View
255
+ testID={testID}
212
256
  accessibilityRole="radiogroup"
213
- style={{ gap: horizontal ? 14 : 10, flexDirection: horizontal ? "row" : "column", ...style }}
257
+ style={{
258
+ gap: horizontal ? 14 : 10,
259
+ flexDirection: horizontal ? "row" : "column",
260
+ ...(style as ViewStyle),
261
+ }}
214
262
  >
215
263
  {options.map((option) => {
216
264
  const isSelected = option.value === value;
@@ -223,7 +271,7 @@ export function RadioGroup({
223
271
  accessibilityState={{ checked: isSelected, disabled: isDisabled }}
224
272
  accessibilityLabel={option.label}
225
273
  disabled={isDisabled}
226
- onPress={() => !isDisabled && onValueChange?.(option.value)}
274
+ onPress={() => select(option.value, isDisabled)}
227
275
  style={{
228
276
  flexDirection: "row",
229
277
  alignItems: "flex-start",
@@ -263,12 +311,16 @@ export interface SelectOption {
263
311
 
264
312
  export interface SelectProps {
265
313
  value?: string;
314
+ /** Starting selection for uncontrolled use. */
315
+ defaultValue?: string;
266
316
  onValueChange?: (value: string) => void;
267
317
  options: SelectOption[];
268
318
  placeholder?: string;
269
319
  disabled?: boolean;
270
320
  isDark?: boolean;
271
- style?: any;
321
+ style?: StyleProp<ViewStyle>;
322
+ /** Passed through to the trigger so it is testable. */
323
+ testID?: string;
272
324
  }
273
325
 
274
326
  /**
@@ -279,23 +331,36 @@ export interface SelectProps {
279
331
  * modal. A long list scrolls naturally with the page.
280
332
  */
281
333
  export function Select({
282
- value,
334
+ value: valueProp,
335
+ defaultValue,
283
336
  onValueChange,
284
337
  options,
285
338
  placeholder = "Select an option",
286
339
  disabled = false,
287
- isDark = false,
340
+ isDark: isDarkProp,
288
341
  style,
342
+ testID,
289
343
  }: SelectProps) {
344
+ const isDark = useIsDark(isDarkProp);
290
345
  const theme = isDark ? colors.dark : colors.light;
291
346
  const { View, Text, Pressable } = primitives();
292
347
  const [open, setOpen] = useState(false);
293
348
 
349
+ // Controlled when `value` is given, otherwise the select owns its choice.
350
+ const [internalValue, setInternalValue] = useState(defaultValue);
351
+ const value = valueProp !== undefined ? valueProp : internalValue;
352
+
353
+ const choose = (next: string) => {
354
+ if (valueProp === undefined) setInternalValue(next);
355
+ onValueChange?.(next);
356
+ };
357
+
294
358
  const selected = options.find((option) => option.value === value);
295
359
 
296
360
  return (
297
- <View style={style}>
361
+ <View style={style as StyleProp<ViewStyle>}>
298
362
  <Pressable
363
+ testID={testID}
299
364
  accessibilityRole="button"
300
365
  accessibilityState={{ expanded: open, disabled }}
301
366
  accessibilityLabel={selected?.label ?? placeholder}
@@ -340,7 +405,7 @@ export function Select({
340
405
  accessibilityState={{ selected: isSelected }}
341
406
  accessibilityLabel={option.label}
342
407
  onPress={() => {
343
- onValueChange?.(option.value);
408
+ choose(option.value);
344
409
  setOpen(false);
345
410
  }}
346
411
  style={{