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/TabBar.tsx CHANGED
@@ -1,6 +1,10 @@
1
- import { useState, forwardRef, type ReactNode } from "react";
1
+ import { forwardRef, useState, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
2
4
  import { Glass } from "./Glass";
3
5
  import { colors, radii } from "./internal/tokens";
6
+ import { primitives } from "./internal/primitives";
7
+ import { useIsDark, useSpring } from "./internal/motion";
4
8
 
5
9
  export interface TabBarItem {
6
10
  id: string;
@@ -13,10 +17,23 @@ export interface TabBarProps {
13
17
  activeId?: string;
14
18
  defaultActiveId?: string;
15
19
  onTabChange?: (id: string) => void;
16
- style?: any;
20
+ style?: StyleProp<ViewStyle>;
17
21
  isDark?: boolean;
22
+ /** Passed through to the bar so it is testable. */
23
+ testID?: string;
18
24
  }
19
25
 
26
+ const BAR_HEIGHT = 52;
27
+
28
+ /**
29
+ * The bottom bar of an app: a row of tabs on one glass surface.
30
+ *
31
+ * The platform rule is the point of this component. On iOS 26+ the surface is
32
+ * Apple's real Liquid Glass (`UIGlassEffect` via `@callstack/liquid-glass`)
33
+ * with Glacia's own items inside it; on older iOS and on Android it is
34
+ * Glacia's bar. The items are always our Pressables and Texts — no native tab
35
+ * bar is used on any platform.
36
+ */
20
37
  export const TabBar = forwardRef<any, TabBarProps>(function TabBar(
21
38
  {
22
39
  items,
@@ -24,62 +41,115 @@ export const TabBar = forwardRef<any, TabBarProps>(function TabBar(
24
41
  defaultActiveId,
25
42
  onTabChange,
26
43
  style,
27
- isDark = false,
44
+ isDark: isDarkProp,
45
+ testID,
28
46
  ...props
29
47
  },
30
48
  ref,
31
49
  ) {
50
+ const isDark = useIsDark(isDarkProp);
51
+ const themeColors = isDark ? colors.dark : colors.light;
52
+ const { View, Text, Pressable, Animated } = primitives();
53
+
32
54
  const [internalId, setInternalId] = useState(defaultActiveId || items[0]?.id || "");
33
55
  const activeId = activeProp !== undefined ? activeProp : internalId;
34
- const themeColors = isDark ? colors.dark : colors.light;
56
+
57
+ const activeIndex = Math.max(
58
+ 0,
59
+ items.findIndex((item) => item.id === activeId),
60
+ );
61
+ // The active wash slides between equally wide items on the springs token.
62
+ const { value: slide, animated } = useSpring(activeIndex, "snappy");
35
63
 
36
64
  const handleSelect = (id: string) => {
37
- if (activeProp === undefined) {
38
- setInternalId(id);
39
- }
65
+ if (activeProp === undefined) setInternalId(id);
40
66
  onTabChange?.(id);
41
67
  };
42
68
 
43
- const barStyle = {
44
- position: "relative" as const,
45
- display: "flex" as const,
46
- flexDirection: "row" as const,
47
- alignItems: "center" as const,
48
- justifyContent: "space-around" as const,
49
- height: 52,
69
+ const barStyle: ViewStyle = {
70
+ flexDirection: "row",
71
+ alignItems: "center",
72
+ justifyContent: "space-around",
73
+ height: BAR_HEIGHT,
50
74
  paddingHorizontal: 8,
51
75
  borderRadius: radii.xl,
52
- ...style,
76
+ ...(style as ViewStyle),
77
+ };
78
+
79
+ const count = Math.max(items.length, 1);
80
+ const itemWidth = `${100 / count}%`;
81
+
82
+ const indicatorStyle = {
83
+ position: "absolute" as const,
84
+ top: 6,
85
+ bottom: 6,
86
+ left: 8,
87
+ width: itemWidth,
88
+ borderRadius: radii.lg,
89
+ backgroundColor: themeColors.glassActive,
90
+ opacity: 0.75,
53
91
  };
54
92
 
55
93
  return (
56
- <Glass ref={ref} effect="regular" style={barStyle} {...props}>
94
+ <Glass ref={ref} effect="regular" isDark={isDark} style={barStyle} testID={testID} {...props}>
95
+ {/* The selected item's wash, one View behind the labels. */}
96
+ {animated ? (
97
+ <Animated.View
98
+ pointerEvents="none"
99
+ style={{
100
+ ...indicatorStyle,
101
+ transform: [
102
+ {
103
+ translateX: slide.interpolate({
104
+ inputRange: [0, Math.max(count - 1, 1)],
105
+ outputRange: [
106
+ "0%",
107
+ `${((count - 1) * 100) / count}%`,
108
+ ],
109
+ }),
110
+ },
111
+ ],
112
+ }}
113
+ />
114
+ ) : (
115
+ <View
116
+ pointerEvents="none"
117
+ style={{ ...indicatorStyle, left: `${(activeIndex * 100) / count}%` }}
118
+ />
119
+ )}
120
+
57
121
  {items.map((tab) => {
58
122
  const isActive = tab.id === activeId;
59
123
  return (
60
- <button
124
+ <Pressable
61
125
  key={tab.id}
62
- type="button"
63
- onClick={() => handleSelect(tab.id)}
126
+ accessibilityRole="tab"
127
+ accessibilityLabel={tab.label}
128
+ accessibilityState={{ selected: isActive }}
129
+ onPress={() => handleSelect(tab.id)}
64
130
  style={{
65
131
  flex: 1,
66
- display: "flex",
132
+ height: "100%",
67
133
  flexDirection: "column",
68
134
  alignItems: "center",
69
135
  justifyContent: "center",
70
136
  gap: 2,
71
- padding: "4px 8px",
72
- border: 0,
73
- background: "transparent",
74
- color: isActive ? themeColors.fill : themeColors.muted,
75
- fontSize: 11,
76
- fontWeight: isActive ? 600 : 500,
77
- cursor: "pointer",
137
+ paddingHorizontal: 8,
138
+ paddingVertical: 4,
78
139
  }}
79
140
  >
80
- {tab.icon && <span style={{ fontSize: 18 }}>{tab.icon}</span>}
81
- <span>{tab.label}</span>
82
- </button>
141
+ {tab.icon ?? null}
142
+ <Text
143
+ numberOfLines={1}
144
+ style={{
145
+ fontSize: 11,
146
+ fontWeight: isActive ? "600" : "500",
147
+ color: isActive ? themeColors.fill : themeColors.muted,
148
+ }}
149
+ >
150
+ {tab.label}
151
+ </Text>
152
+ </Pressable>
83
153
  );
84
154
  })}
85
155
  </Glass>
package/src/Table.tsx CHANGED
@@ -1,7 +1,9 @@
1
1
  import type { ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
2
3
 
3
4
  import { colors } 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 NativeTableColumn {
7
9
  key: string;
@@ -17,6 +19,12 @@ export interface NativeTableColumn {
17
19
  export interface NativeTableRow {
18
20
  id: string;
19
21
  cells: Record<string, ReactNode>;
22
+ /**
23
+ * What screen readers announce when the row is pressable. Use it when the
24
+ * cells hold elements rather than text; without it the primary cell is used
25
+ * only if it is a string or number.
26
+ */
27
+ accessibilityLabel?: string;
20
28
  }
21
29
 
22
30
  export interface NativeTableProps {
@@ -24,11 +32,13 @@ export interface NativeTableProps {
24
32
  rows: NativeTableRow[];
25
33
  /** Tap handler for a whole row. */
26
34
  onRowPress?: (row: NativeTableRow) => void;
27
- /** Text direction for right-aligned columns; defaults to left. */
35
+ /** A caption describing the table's contents, shown above it. */
28
36
  caption?: string;
29
37
  isDark?: boolean;
30
- style?: any;
38
+ style?: StyleProp<ViewStyle>;
31
39
  emptyMessage?: string;
40
+ /** Passed through to the table root so it is testable. */
41
+ testID?: string;
32
42
  }
33
43
 
34
44
  /**
@@ -44,16 +54,18 @@ export function NativeTable({
44
54
  rows,
45
55
  onRowPress,
46
56
  caption,
47
- isDark = false,
57
+ isDark: isDarkProp,
48
58
  style,
49
59
  emptyMessage = "No rows to display",
60
+ testID,
50
61
  }: NativeTableProps) {
62
+ const isDark = useIsDark(isDarkProp);
51
63
  const theme = isDark ? colors.dark : colors.light;
52
64
  const { View, Text, Pressable } = primitives();
53
65
 
54
66
  if (rows.length === 0) {
55
67
  return (
56
- <View style={[{ paddingVertical: 20, alignItems: "center" }, style]}>
68
+ <View style={[{ paddingVertical: 20, alignItems: "center" }, style as ViewStyle]}>
57
69
  <Text style={{ fontSize: 12, color: theme.muted }}>{emptyMessage}</Text>
58
70
  </View>
59
71
  );
@@ -65,7 +77,7 @@ export function NativeTable({
65
77
  const detailColumns = columns.filter((column) => column.key !== primaryKey);
66
78
 
67
79
  return (
68
- <View style={style}>
80
+ <View style={style as ViewStyle} testID={testID}>
69
81
  {caption && (
70
82
  <Text style={{ fontSize: 11, color: theme.muted, marginBottom: 8 }}>{caption}</Text>
71
83
  )}
@@ -75,7 +87,7 @@ export function NativeTable({
75
87
  const wrapperProps = onRowPress
76
88
  ? {
77
89
  accessibilityRole: "button",
78
- accessibilityLabel: String(row.cells[primaryKey ?? ""] ?? ""),
90
+ accessibilityLabel: rowAccessibilityLabel(row, primaryKey),
79
91
  onPress: () => onRowPress(row),
80
92
  }
81
93
  : { accessibilityRole: "text" };
@@ -136,6 +148,20 @@ export function NativeTable({
136
148
  );
137
149
  }
138
150
 
151
+ /**
152
+ * What screen readers announce for a pressable row.
153
+ *
154
+ * A cell can be any element, and `String(cell)` of an element announces
155
+ * "[object Object]". So: an explicit row label wins, then a textual primary
156
+ * cell, then a neutral fallback.
157
+ */
158
+ function rowAccessibilityLabel(row: NativeTableRow, primaryKey: string | undefined): string {
159
+ if (row.accessibilityLabel) return row.accessibilityLabel;
160
+ const primary = primaryKey ? row.cells[primaryKey] : undefined;
161
+ if (typeof primary === "string" || typeof primary === "number") return String(primary);
162
+ return "Row";
163
+ }
164
+
139
165
  export interface NativeScrollAreaProps {
140
166
  children?: ReactNode;
141
167
  /** Fixed height. Without one the area grows with its content. */
@@ -144,7 +170,7 @@ export interface NativeScrollAreaProps {
144
170
  bordered?: boolean;
145
171
  horizontal?: boolean;
146
172
  isDark?: boolean;
147
- style?: any;
173
+ style?: StyleProp<ViewStyle>;
148
174
  /** Announced to screen readers. */
149
175
  accessibilityLabel?: string;
150
176
  }
@@ -161,10 +187,11 @@ export function NativeScrollArea({
161
187
  maxHeight,
162
188
  bordered = false,
163
189
  horizontal = false,
164
- isDark = false,
190
+ isDark: isDarkProp,
165
191
  style,
166
192
  accessibilityLabel,
167
193
  }: NativeScrollAreaProps) {
194
+ const isDark = useIsDark(isDarkProp);
168
195
  const theme = isDark ? colors.dark : colors.light;
169
196
  const { View, getScrollView } = primitives();
170
197
 
@@ -176,17 +203,14 @@ export function NativeScrollArea({
176
203
  borderWidth: bordered ? 1 : 0,
177
204
  borderColor: theme.edge,
178
205
  overflow: "hidden",
179
- ...style,
206
+ ...(style as ViewStyle),
180
207
  };
181
208
 
182
209
  if (!ScrollView) {
183
210
  // Off-device there is no ScrollView; render the content in a clipped box so
184
211
  // layout still matches instead of dropping children.
185
212
  return (
186
- <View
187
- accessibilityLabel={accessibilityLabel}
188
- style={{ ...containerStyle, overflow: "auto" }}
189
- >
213
+ <View accessibilityLabel={accessibilityLabel} style={containerStyle}>
190
214
  {children}
191
215
  </View>
192
216
  );
package/src/Tabs.tsx CHANGED
@@ -1,6 +1,10 @@
1
- import { useState, forwardRef, type ReactNode } from "react";
1
+ import { forwardRef, useState, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
2
4
  import { Glass } from "./Glass";
3
5
  import { colors, radii } from "./internal/tokens";
6
+ import { primitives } from "./internal/primitives";
7
+ import { useIsDark, useSpring } from "./internal/motion";
4
8
 
5
9
  export interface TabItem {
6
10
  /** Stable identifier for the tab. */
@@ -17,18 +21,20 @@ export interface TabsProps {
17
21
  activeId?: string;
18
22
  defaultActiveId?: string;
19
23
  onTabChange?: (id: string) => void;
20
- style?: any;
24
+ style?: StyleProp<ViewStyle>;
21
25
  isDark?: boolean;
26
+ /** Passed through to the rail so it is testable. */
27
+ testID?: string;
22
28
  }
23
29
 
24
30
  /**
25
31
  * A row of tabs on a glass rail, in the reference implementation's style: the
26
32
  * selected tab is a lifted inner pane rather than a flat highlight.
27
33
  *
28
- * Follows the same conventions as the other native components — no browser
29
- * APIs and no CSS — so it renders on iOS and Android. On iOS 26 the rail is
30
- * real glass through `@callstack/liquid-glass`; elsewhere it is a translucent
31
- * tint of the same shape with no layout shift.
34
+ * Same conventions as every other component here — React Native primitives
35
+ * only, no browser APIs. The rail is Apple's real glass on iOS 26+ and
36
+ * Glacia's translucent fallback of the same shape on older iOS and Android, so
37
+ * the layout never shifts between platforms.
32
38
  */
33
39
  export const Tabs = forwardRef<any, TabsProps>(function Tabs(
34
40
  {
@@ -37,70 +43,117 @@ export const Tabs = forwardRef<any, TabsProps>(function Tabs(
37
43
  defaultActiveId,
38
44
  onTabChange,
39
45
  style,
40
- isDark = false,
46
+ isDark: isDarkProp,
47
+ testID,
41
48
  ...props
42
49
  },
43
50
  ref,
44
51
  ) {
52
+ const isDark = useIsDark(isDarkProp);
53
+ const themeColors = isDark ? colors.dark : colors.light;
54
+ const { View, Text, Pressable, Animated } = primitives();
55
+
45
56
  const [internalId, setInternalId] = useState(defaultActiveId || items[0]?.id || "");
46
57
  const activeId = activeProp !== undefined ? activeProp : internalId;
47
- const themeColors = isDark ? colors.dark : colors.light;
58
+
59
+ const activeIndex = Math.max(
60
+ 0,
61
+ items.findIndex((tab) => tab.id === activeId),
62
+ );
63
+ const { value: slide, animated } = useSpring(activeIndex, "snappy");
48
64
 
49
65
  const handleSelect = (id: string) => {
50
66
  if (activeProp === undefined) setInternalId(id);
51
67
  onTabChange?.(id);
52
68
  };
53
69
 
70
+ const count = Math.max(items.length, 1);
71
+ const itemWidth = `${100 / count}%`;
72
+
73
+ // The selection is a lens, not a fill: a lifted pane on the rail.
74
+ const paneStyle = {
75
+ position: "absolute" as const,
76
+ top: 4,
77
+ bottom: 4,
78
+ left: 4,
79
+ width: itemWidth,
80
+ borderRadius: radii.pill,
81
+ backgroundColor: isDark ? "rgba(255,255,255,0.16)" : "rgba(255,255,255,0.72)",
82
+ borderWidth: 0.5,
83
+ borderColor: themeColors.edge,
84
+ };
85
+
54
86
  return (
55
87
  <Glass
56
88
  ref={ref}
57
89
  effect="regular"
90
+ isDark={isDark}
58
91
  style={{
59
- display: "flex",
60
92
  flexDirection: "row",
61
93
  alignItems: "center",
94
+ alignSelf: "flex-start",
62
95
  gap: 2,
63
96
  padding: 4,
64
97
  borderRadius: radii.pill,
65
- ...style,
98
+ ...(style as ViewStyle),
66
99
  }}
100
+ testID={testID}
67
101
  {...props}
68
102
  >
103
+ {animated ? (
104
+ <Animated.View
105
+ pointerEvents="none"
106
+ style={{
107
+ ...paneStyle,
108
+ transform: [
109
+ {
110
+ translateX: slide.interpolate({
111
+ inputRange: [0, Math.max(count - 1, 1)],
112
+ outputRange: ["0%", `${((count - 1) * 100) / count}%`],
113
+ }),
114
+ },
115
+ ],
116
+ }}
117
+ />
118
+ ) : (
119
+ <View
120
+ pointerEvents="none"
121
+ style={{ ...paneStyle, left: `${(activeIndex * 100) / count}%` }}
122
+ />
123
+ )}
124
+
69
125
  {items.map((tab) => {
70
126
  const isActive = tab.id === activeId;
71
127
  return (
72
- <button
128
+ <Pressable
73
129
  key={tab.id}
74
- type="button"
75
- onClick={() => handleSelect(tab.id)}
76
- aria-selected={isActive}
77
- role="tab"
130
+ accessibilityRole="tab"
131
+ accessibilityLabel={tab.label}
132
+ accessibilityState={{ selected: isActive }}
133
+ onPress={() => handleSelect(tab.id)}
78
134
  style={{
79
135
  flex: 1,
80
- display: "flex",
136
+ height: 36,
81
137
  flexDirection: "row",
82
138
  alignItems: "center",
83
139
  justifyContent: "center",
84
140
  gap: 6,
85
- padding: "8px 12px",
86
- border: 0,
141
+ paddingHorizontal: 12,
87
142
  borderRadius: radii.pill,
88
- // The selection is a lens, not a fill: a lifted pane on the rail.
89
- background: isActive
90
- ? isDark
91
- ? "rgba(255,255,255,0.16)"
92
- : "rgba(255,255,255,0.72)"
93
- : "transparent",
94
- color: isActive ? themeColors.foreground : themeColors.muted,
95
- fontSize: 13,
96
- fontWeight: isActive ? 600 : 500,
97
- cursor: "pointer",
98
- whiteSpace: "nowrap",
99
143
  }}
100
144
  >
101
- {tab.icon && <span style={{ fontSize: 14 }}>{tab.icon}</span>}
102
- <span>{tab.label}</span>
103
- </button>
145
+ {tab.icon ?? null}
146
+ <Text
147
+ numberOfLines={1}
148
+ style={{
149
+ fontSize: 13,
150
+ fontWeight: isActive ? "600" : "500",
151
+ color: isActive ? themeColors.foreground : themeColors.muted,
152
+ }}
153
+ >
154
+ {tab.label}
155
+ </Text>
156
+ </Pressable>
104
157
  );
105
158
  })}
106
159
  </Glass>
package/src/Text.tsx ADDED
@@ -0,0 +1,83 @@
1
+ import { forwardRef, type ReactNode } from "react";
2
+ import type { StyleProp, TextStyle } from "react-native";
3
+
4
+ import { colors, typeScale } from "./internal/tokens";
5
+ import { primitives } from "./internal/primitives";
6
+ import { useIsDark } from "./internal/motion";
7
+
8
+ export type TextVariant = "title" | "heading" | "body" | "caption" | "label";
9
+
10
+ export interface TextProps {
11
+ /**
12
+ * The type step. The names come from the package's type scale, so a title in
13
+ * one app reads the same as a title in another.
14
+ */
15
+ variant?: TextVariant;
16
+ /** Secondary text: descriptions, hints, timestamps. */
17
+ muted?: boolean;
18
+ /** Renders the text in the destructive tone (errors, danger). */
19
+ destructive?: boolean;
20
+ /** Number of lines before truncating. */
21
+ numberOfLines?: number;
22
+ children?: ReactNode;
23
+ style?: StyleProp<TextStyle>;
24
+ isDark?: boolean;
25
+ testID?: string;
26
+ }
27
+
28
+ /** The accessibility role each variant announces. */
29
+ const roles: Record<TextVariant, "heading" | "text"> = {
30
+ title: "heading",
31
+ heading: "heading",
32
+ body: "text",
33
+ caption: "text",
34
+ label: "text",
35
+ };
36
+
37
+ /**
38
+ * Themed text.
39
+ *
40
+ * Every Glacia component that renders words uses this, so type, colour and
41
+ * contrast come from one place. It wraps the resolver's `Text`, which is React
42
+ * Native's own on a device.
43
+ */
44
+ export const Text = forwardRef<any, TextProps>(function Text(
45
+ {
46
+ variant = "body",
47
+ muted = false,
48
+ destructive = false,
49
+ numberOfLines,
50
+ children,
51
+ style,
52
+ isDark: isDarkProp,
53
+ testID,
54
+ ...props
55
+ },
56
+ ref,
57
+ ) {
58
+ const isDark = useIsDark(isDarkProp);
59
+ const theme = isDark ? colors.dark : colors.light;
60
+ const { Text: RNText } = primitives();
61
+ const scale = typeScale[variant];
62
+
63
+ const textStyle: TextStyle = {
64
+ fontSize: scale.fontSize,
65
+ lineHeight: scale.lineHeight,
66
+ fontWeight: scale.fontWeight,
67
+ color: destructive ? theme.destructive : muted ? theme.muted : theme.foreground,
68
+ ...(style as TextStyle),
69
+ };
70
+
71
+ return (
72
+ <RNText
73
+ ref={ref}
74
+ testID={testID}
75
+ accessibilityRole={roles[variant]}
76
+ numberOfLines={numberOfLines}
77
+ style={textStyle}
78
+ {...props}
79
+ >
80
+ {children}
81
+ </RNText>
82
+ );
83
+ });