glacia-native 0.4.0 → 0.5.1

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 (73) hide show
  1. package/lib/module/Bars.js +269 -0
  2. package/lib/module/Carousel.js +103 -0
  3. package/lib/module/Display.js +317 -0
  4. package/lib/module/Feedback.js +386 -0
  5. package/lib/module/Forms2.js +454 -0
  6. package/lib/module/Message.js +88 -0
  7. package/lib/module/Overlays.js +328 -0
  8. package/lib/module/Pickers.js +243 -0
  9. package/lib/module/SegmentedControl.js +5 -1
  10. package/lib/module/Slider.js +6 -1
  11. package/lib/module/Switch.js +4 -1
  12. package/lib/module/TabBar.js +5 -1
  13. package/lib/module/Text.js +37 -0
  14. package/lib/module/ai.js +8 -3
  15. package/lib/module/index.js +79 -1
  16. package/lib/module/internal/GlassContainer.js +54 -0
  17. package/lib/module/internal/GlassView.js +31 -7
  18. package/lib/module/internal/a11y.js +94 -0
  19. package/lib/module/internal/fallback.js +19 -8
  20. package/lib/module/internal/glass-routing.js +7 -0
  21. package/lib/module/internal/haptics.js +54 -0
  22. package/lib/module/internal/motion.js +10 -1
  23. package/lib/module/internal/primitives.js +73 -3
  24. package/lib/module/internal/tokens.js +101 -1
  25. package/lib/typescript/Bars.d.ts +188 -0
  26. package/lib/typescript/Carousel.d.ts +47 -0
  27. package/lib/typescript/Display.d.ts +178 -0
  28. package/lib/typescript/Feedback.d.ts +196 -0
  29. package/lib/typescript/Forms2.d.ts +209 -0
  30. package/lib/typescript/Glass.d.ts +1 -1
  31. package/lib/typescript/Message.d.ts +71 -0
  32. package/lib/typescript/Overlays.d.ts +146 -0
  33. package/lib/typescript/Pickers.d.ts +105 -0
  34. package/lib/typescript/SegmentedControl.d.ts +2 -0
  35. package/lib/typescript/Slider.d.ts +2 -0
  36. package/lib/typescript/Switch.d.ts +2 -0
  37. package/lib/typescript/TabBar.d.ts +2 -0
  38. package/lib/typescript/Text.d.ts +28 -0
  39. package/lib/typescript/index.d.ts +11 -1
  40. package/lib/typescript/internal/GlassContainer.d.ts +37 -0
  41. package/lib/typescript/internal/GlassView.d.ts +18 -1
  42. package/lib/typescript/internal/a11y.d.ts +19 -0
  43. package/lib/typescript/internal/fallback.d.ts +5 -0
  44. package/lib/typescript/internal/glass-routing.d.ts +10 -0
  45. package/lib/typescript/internal/haptics.d.ts +7 -0
  46. package/lib/typescript/internal/motion.d.ts +4 -0
  47. package/lib/typescript/internal/primitives.d.ts +21 -0
  48. package/lib/typescript/internal/tokens.d.ts +114 -0
  49. package/package.json +2 -2
  50. package/src/Bars.tsx +797 -0
  51. package/src/Carousel.tsx +233 -0
  52. package/src/Display.tsx +778 -0
  53. package/src/Feedback.tsx +969 -0
  54. package/src/Forms2.tsx +1014 -0
  55. package/src/Message.tsx +219 -0
  56. package/src/Overlays.tsx +685 -0
  57. package/src/Pickers.tsx +590 -0
  58. package/src/SegmentedControl.tsx +6 -0
  59. package/src/Slider.tsx +7 -0
  60. package/src/Switch.tsx +5 -0
  61. package/src/TabBar.tsx +6 -0
  62. package/src/Text.tsx +83 -0
  63. package/src/ai.tsx +9 -3
  64. package/src/index.ts +142 -1
  65. package/src/internal/GlassContainer.tsx +82 -0
  66. package/src/internal/GlassView.tsx +37 -7
  67. package/src/internal/a11y.ts +105 -0
  68. package/src/internal/fallback.tsx +19 -2
  69. package/src/internal/glass-routing.ts +17 -0
  70. package/src/internal/haptics.ts +59 -0
  71. package/src/internal/motion.ts +10 -1
  72. package/src/internal/primitives.ts +84 -3
  73. package/src/internal/tokens.ts +110 -0
@@ -0,0 +1,219 @@
1
+ import { forwardRef, type ReactNode } from "react";
2
+ import type { StyleProp, ViewStyle } from "react-native";
3
+
4
+ import { Avatar } from "./Display";
5
+ import { colors, radii } from "./internal/tokens";
6
+ import { primitives } from "./internal/primitives";
7
+ import { useIsDark } from "./internal/motion";
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // MessageBubble
11
+
12
+ export interface MessageBubbleProps {
13
+ /** Whether the message is the device owner's (right, tinted) or not (left). */
14
+ outgoing?: boolean;
15
+ children?: ReactNode;
16
+ style?: StyleProp<ViewStyle>;
17
+ isDark?: boolean;
18
+ testID?: string;
19
+ }
20
+
21
+ /**
22
+ * One message's bubble.
23
+ *
24
+ * Both directions are flat tints, not glass: a chat transcript is a long
25
+ * scrolling list, and glass under every line would stack translucent surfaces
26
+ * over each other and over the conversation behind them. The glass in a chat
27
+ * belongs to the composer, which floats over the transcript — so
28
+ * `NativeAIInput` is glass and the bubbles are not.
29
+ *
30
+ * Incoming messages take the theme's wash; outgoing take `glassActive`, the
31
+ * same tint the library uses for any selected surface, so a transcript reads
32
+ * consistently with the rest of Glacia.
33
+ */
34
+ export const MessageBubble = forwardRef<any, MessageBubbleProps>(function MessageBubble(
35
+ { outgoing = false, children, style, isDark: isDarkProp, testID, ...props },
36
+ ref,
37
+ ) {
38
+ const isDark = useIsDark(isDarkProp);
39
+ const theme = isDark ? colors.dark : colors.light;
40
+ const { View } = primitives();
41
+
42
+ return (
43
+ <View
44
+ ref={ref}
45
+ testID={testID}
46
+ style={{
47
+ alignSelf: outgoing ? "flex-end" : "flex-start",
48
+ maxWidth: "82%",
49
+ paddingHorizontal: 12,
50
+ paddingVertical: 8,
51
+ borderRadius: radii.lg,
52
+ backgroundColor: outgoing ? theme.glassActive : theme.wash,
53
+ ...(style as ViewStyle),
54
+ }}
55
+ {...props}
56
+ >
57
+ {children}
58
+ </View>
59
+ );
60
+ });
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // MessageAttachment
64
+
65
+ export interface MessageAttachmentProps {
66
+ /** The file's name, shown and used as the accessible label. */
67
+ name: string;
68
+ /** A human-readable size, e.g. "1.2 MB". */
69
+ size?: string;
70
+ /** A leading node, typically an SVG icon. */
71
+ icon?: ReactNode;
72
+ /** Makes the chip tappable, e.g. to open the file. */
73
+ onPress?: () => void;
74
+ disabled?: boolean;
75
+ style?: StyleProp<ViewStyle>;
76
+ isDark?: boolean;
77
+ testID?: string;
78
+ }
79
+
80
+ /**
81
+ * A file chip for a message.
82
+ *
83
+ * A flat, bordered chip rather than a glass one, for the same reason the
84
+ * bubbles are flat: it sits inside a bubble or beside one, and glass inside
85
+ * glass is never allowed. The size is a caller-formatted string — byte
86
+ * formatting belongs to the app's locale, not to a component library.
87
+ */
88
+ export const MessageAttachment = forwardRef<any, MessageAttachmentProps>(
89
+ function MessageAttachment(
90
+ { name, size, icon, onPress, disabled = false, style, isDark: isDarkProp, testID, ...props },
91
+ ref,
92
+ ) {
93
+ const isDark = useIsDark(isDarkProp);
94
+ const theme = isDark ? colors.dark : colors.light;
95
+ const { View, Text, Pressable } = primitives();
96
+
97
+ const body = (
98
+ <>
99
+ {icon ? <View style={{ marginRight: 8 }}>{icon}</View> : null}
100
+ <View style={{ flexShrink: 1 }}>
101
+ <Text numberOfLines={1} style={{ fontSize: 14, color: theme.foreground }}>
102
+ {name}
103
+ </Text>
104
+ {size ? (
105
+ <Text style={{ fontSize: 11, color: theme.muted }}>{size}</Text>
106
+ ) : null}
107
+ </View>
108
+ </>
109
+ );
110
+
111
+ const chipStyle: ViewStyle = {
112
+ flexDirection: "row",
113
+ alignItems: "center",
114
+ paddingHorizontal: 10,
115
+ paddingVertical: 7,
116
+ borderRadius: radii.md,
117
+ backgroundColor: theme.wash,
118
+ borderWidth: 0.5,
119
+ borderColor: theme.separator,
120
+ opacity: disabled ? 0.38 : 1,
121
+ ...(style as ViewStyle),
122
+ };
123
+
124
+ if (!onPress) {
125
+ return (
126
+ <View ref={ref} testID={testID} accessibilityRole="text" accessibilityLabel={size ? `${name}, ${size}` : name} style={chipStyle} {...props}>
127
+ {body}
128
+ </View>
129
+ );
130
+ }
131
+
132
+ return (
133
+ <Pressable
134
+ ref={ref}
135
+ testID={testID}
136
+ accessibilityRole="button"
137
+ accessibilityLabel={size ? `${name}, ${size}` : name}
138
+ accessibilityState={{ disabled }}
139
+ disabled={disabled}
140
+ onPress={onPress}
141
+ style={chipStyle}
142
+ {...props}
143
+ >
144
+ {body}
145
+ </Pressable>
146
+ );
147
+ },
148
+ );
149
+
150
+ // ---------------------------------------------------------------------------
151
+ // Message
152
+
153
+ export interface MessageProps {
154
+ /** The sender's name, shown above the content. */
155
+ name?: string;
156
+ /** A time or timestamp, shown beside the name. */
157
+ time?: string;
158
+ /** Draws an Avatar showing `name`'s initials beside the content. */
159
+ avatar?: boolean;
160
+ /** The bubble direction. */
161
+ outgoing?: boolean;
162
+ /** The message's content: text, or a bubble, or a bubble with attachments. */
163
+ children?: ReactNode;
164
+ style?: StyleProp<ViewStyle>;
165
+ isDark?: boolean;
166
+ testID?: string;
167
+ }
168
+
169
+ /**
170
+ * A whole message: who sent it, when, and what they said.
171
+ *
172
+ * The row every chat screen builds by hand — an avatar, a name and time line,
173
+ * and the content under it. Grouping it means the alignment, spacing and
174
+ * accessibility grouping are decided once: the row is announced as a single
175
+ * message (name, time, content) rather than as three unrelated pieces of text.
176
+ */
177
+ export const Message = forwardRef<any, MessageProps>(function Message(
178
+ { name, time, avatar = false, outgoing = false, children, style, isDark: isDarkProp, testID, ...props },
179
+ ref,
180
+ ) {
181
+ const isDark = useIsDark(isDarkProp);
182
+ const theme = isDark ? colors.dark : colors.light;
183
+ const { View, Text } = primitives();
184
+
185
+ const meta = [name, time].filter(Boolean).join(", ");
186
+
187
+ return (
188
+ <View
189
+ ref={ref}
190
+ testID={testID}
191
+ accessibilityRole="text"
192
+ accessibilityLabel={meta || undefined}
193
+ style={{
194
+ flexDirection: outgoing ? "row-reverse" : "row",
195
+ alignItems: "flex-end",
196
+ gap: 8,
197
+ paddingHorizontal: 4,
198
+ paddingVertical: 4,
199
+ ...(style as ViewStyle),
200
+ }}
201
+ {...props}
202
+ >
203
+ {avatar ? (
204
+ <Avatar name={name ?? ""} size="sm" isDark={isDark} />
205
+ ) : null}
206
+ <View style={{ flexShrink: 1, alignItems: outgoing ? "flex-end" : "flex-start", gap: 2 }}>
207
+ {name || time ? (
208
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
209
+ {name ? (
210
+ <Text style={{ fontSize: 12, fontWeight: "600", color: theme.foreground }}>{name}</Text>
211
+ ) : null}
212
+ {time ? <Text style={{ fontSize: 11, color: theme.muted }}>{time}</Text> : null}
213
+ </View>
214
+ ) : null}
215
+ {children}
216
+ </View>
217
+ </View>
218
+ );
219
+ });