glacia-native 0.5.0 → 0.5.2
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.
- package/LICENSE +29 -4
- package/README.md +27 -0
- package/lib/module/Bars.js +103 -9
- package/lib/module/Button.js +11 -8
- package/lib/module/Card.js +2 -2
- package/lib/module/Dialog.js +16 -17
- package/lib/module/Display.js +86 -8
- package/lib/module/Feedback.js +244 -21
- package/lib/module/Form.js +29 -33
- package/lib/module/Forms2.js +257 -13
- package/lib/module/Glass.js +2 -2
- package/lib/module/Input.js +12 -10
- package/lib/module/Message.js +84 -0
- package/lib/module/Overlays.js +195 -17
- package/lib/module/Pickers.js +16 -16
- package/lib/module/SegmentedControl.js +24 -11
- package/lib/module/Slider.js +24 -10
- package/lib/module/Switch.js +25 -10
- package/lib/module/TabBar.js +23 -13
- package/lib/module/Table.js +4 -3
- package/lib/module/Tabs.js +3 -2
- package/lib/module/ai.js +26 -18
- package/lib/module/charts/BarChart.js +11 -3
- package/lib/module/index.js +23 -2
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +10 -2
- package/lib/module/internal/a11y.js +94 -0
- package/lib/module/internal/blur.js +78 -0
- package/lib/module/internal/fallback.js +120 -19
- package/lib/module/internal/glass-routing.js +7 -0
- package/lib/module/internal/glow.js +36 -0
- package/lib/module/internal/haptics.js +54 -0
- package/lib/module/internal/lens.js +70 -0
- package/lib/module/internal/material.js +64 -0
- package/lib/module/internal/motion.js +10 -1
- package/lib/module/internal/primitives.js +70 -4
- package/lib/module/internal/rim.js +35 -0
- package/lib/module/internal/tokens.js +80 -2
- package/lib/typescript/Bars.d.ts +67 -0
- package/lib/typescript/Display.d.ts +59 -0
- package/lib/typescript/Feedback.d.ts +58 -0
- package/lib/typescript/Forms2.d.ts +81 -0
- package/lib/typescript/Message.d.ts +67 -0
- package/lib/typescript/Overlays.d.ts +41 -0
- package/lib/typescript/SegmentedControl.d.ts +2 -0
- package/lib/typescript/Slider.d.ts +2 -0
- package/lib/typescript/Switch.d.ts +2 -0
- package/lib/typescript/TabBar.d.ts +2 -0
- package/lib/typescript/index.d.ts +9 -6
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +21 -0
- package/lib/typescript/internal/a11y.d.ts +19 -0
- package/lib/typescript/internal/blur.d.ts +24 -0
- package/lib/typescript/internal/fallback.d.ts +32 -2
- package/lib/typescript/internal/glass-routing.d.ts +10 -0
- package/lib/typescript/internal/glow.d.ts +11 -0
- package/lib/typescript/internal/haptics.d.ts +7 -0
- package/lib/typescript/internal/lens.d.ts +47 -0
- package/lib/typescript/internal/material.d.ts +27 -0
- package/lib/typescript/internal/motion.d.ts +4 -0
- package/lib/typescript/internal/primitives.d.ts +23 -0
- package/lib/typescript/internal/rim.d.ts +16 -0
- package/lib/typescript/internal/tokens.d.ts +89 -0
- package/package.json +12 -3
- package/src/Bars.tsx +239 -2
- package/src/Button.tsx +16 -9
- package/src/Card.tsx +2 -2
- package/src/Dialog.tsx +37 -26
- package/src/Display.tsx +237 -6
- package/src/Feedback.tsx +448 -35
- package/src/Form.tsx +60 -40
- package/src/Forms2.tsx +455 -8
- package/src/Glass.tsx +4 -0
- package/src/Input.tsx +15 -11
- package/src/Message.tsx +218 -0
- package/src/Overlays.tsx +269 -39
- package/src/Pickers.tsx +11 -6
- package/src/SegmentedControl.tsx +39 -9
- package/src/Slider.tsx +26 -10
- package/src/Switch.tsx +29 -10
- package/src/TabBar.tsx +39 -12
- package/src/Table.tsx +4 -3
- package/src/Tabs.tsx +5 -0
- package/src/ai.tsx +37 -23
- package/src/charts/BarChart.tsx +41 -3
- package/src/index.ts +43 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +25 -0
- package/src/internal/a11y.ts +105 -0
- package/src/internal/blur.ts +90 -0
- package/src/internal/fallback.tsx +170 -15
- package/src/internal/glass-routing.ts +17 -0
- package/src/internal/glow.tsx +62 -0
- package/src/internal/haptics.ts +59 -0
- package/src/internal/lens.tsx +105 -0
- package/src/internal/material.ts +92 -0
- package/src/internal/motion.ts +10 -1
- package/src/internal/primitives.ts +83 -4
- package/src/internal/rim.tsx +79 -0
- package/src/internal/tokens.ts +82 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
MIT License with Anti-Plagiarism & Brand Protection Terms
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026
|
|
3
|
+
Copyright (c) 2026 Binyam Feyissa. All rights reserved.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -9,8 +9,28 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
|
10
10
|
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
1. COPYRIGHT & ATTRIBUTION:
|
|
13
|
+
The above copyright notice, this permission notice, and the third-party
|
|
14
|
+
attribution notices below shall be included in all copies or substantial
|
|
15
|
+
portions of the Software.
|
|
16
|
+
|
|
17
|
+
2. ACCEPTABLE USE & ANTI-PLAGIARISM RESTRICTIONS:
|
|
18
|
+
You are granted full permission to use, customize, and integrate the Software
|
|
19
|
+
in your own commercial, private, open-source, or enterprise end-user software,
|
|
20
|
+
websites, web applications, and mobile applications ("Applications").
|
|
21
|
+
|
|
22
|
+
However, the following are strictly prohibited:
|
|
23
|
+
a) You may NOT republish, re-upload, rebrand, or redistribute this repository,
|
|
24
|
+
source code, component registry, or design token suite as a competing standalone
|
|
25
|
+
UI component library, design system kit, template product, or under an alternate
|
|
26
|
+
package name on public registries (including npm, PyPI, GitHub, or any other registry).
|
|
27
|
+
b) You may NOT misrepresent yourself as the creator or original author of Glacia,
|
|
28
|
+
or remove or alter the original author attributions.
|
|
29
|
+
|
|
30
|
+
3. TRADEMARKS & BRAND ASSETS:
|
|
31
|
+
This license does not grant permission to use the trade names, trademarks,
|
|
32
|
+
service marks, product names, logos, or brand marks of "Glacia" or "Binyam Feyissa"
|
|
33
|
+
in connection with derivative works, forks, or any competing distributions.
|
|
14
34
|
|
|
15
35
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
36
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
@@ -19,3 +39,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
39
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
40
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
41
|
SOFTWARE.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
Attribution and Third-Party Acknowledgements:
|
|
46
|
+
- React Native glass effect architecture powered by @callstack/liquid-glass (MIT License): https://github.com/callstack/liquid-glass
|
package/README.md
CHANGED
|
@@ -147,6 +147,33 @@ const styles = StyleSheet.create({
|
|
|
147
147
|
|
|
148
148
|
---
|
|
149
149
|
|
|
150
|
+
## The fallback material
|
|
151
|
+
|
|
152
|
+
On iOS 26+ every glass surface is Apple's `UIGlassEffect`. On iOS below 26, on
|
|
153
|
+
Android and in Expo Go, the fallback renders the same design in layers, so it
|
|
154
|
+
reads as glass rather than as a translucent rectangle:
|
|
155
|
+
|
|
156
|
+
1. **Backdrop blur** — a real native blur view, when one is installed:
|
|
157
|
+
`expo-blur` (Expo apps) or `@react-native-community/blur` (bare React Native).
|
|
158
|
+
Both are optional peer dependencies; without either, the surface degrades to
|
|
159
|
+
tint + rim + edge + shadow instead of failing.
|
|
160
|
+
2. **Tint** — the `glass` token (or your `tintColor`, or 0.35 alpha for `clear`).
|
|
161
|
+
3. **Rim light** — a gradient stroke painted on the edge, brightest along the
|
|
162
|
+
top, so rounded corners read as lit curves.
|
|
163
|
+
4. **Top highlight** — a soft white falloff just inside the top edge.
|
|
164
|
+
5. **Edge** — the 0.5px hairline in the `edge` token.
|
|
165
|
+
6. **Drop shadow** — the surface lifts off the page behind it.
|
|
166
|
+
|
|
167
|
+
`Glass` accepts two optional props for this branch: `surface` picks one of the
|
|
168
|
+
web's six lenses (`"panel"`, `"control"`, `"field"`, `"overlay"`, `"hint"`,
|
|
169
|
+
`"rail"`), and `pressed` fades the specular press glow in. Neither is forwarded
|
|
170
|
+
to Apple's view — on iOS 26 the real material replaces the whole stack.
|
|
171
|
+
|
|
172
|
+
Reduce Transparency is honoured exactly as before: the layered material is
|
|
173
|
+
replaced by one solid colour.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
150
177
|
## Optical Diagnostics
|
|
151
178
|
|
|
152
179
|
You can check whether the running device supports Apple's native `UIGlassEffect` at runtime:
|
package/lib/module/Bars.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppBar = exports.IconButton = exports.FAB = exports.Chip = exports.SearchBar = void 0;
|
|
3
|
+
exports.FABGroup = exports.AppBar = exports.IconButton = exports.FAB = exports.Chip = exports.SearchBar = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const Glass_1 = require("./Glass");
|
|
@@ -26,7 +26,7 @@ exports.SearchBar = (0, react_1.forwardRef)(function SearchBar({ value: valuePro
|
|
|
26
26
|
onChangeText?.(next);
|
|
27
27
|
};
|
|
28
28
|
const clear = () => handleChange("");
|
|
29
|
-
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: [{ flexDirection: "row", alignItems: "center", gap: 8 }, style], ...props, children: [(0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: {
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: [{ flexDirection: "row", alignItems: "center", gap: 8 }, style], ...props, children: [(0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", surface: "field", isDark: isDark, style: {
|
|
30
30
|
flex: 1,
|
|
31
31
|
flexDirection: "row",
|
|
32
32
|
alignItems: "center",
|
|
@@ -66,6 +66,7 @@ exports.Chip = (0, react_1.forwardRef)(function Chip({ label, icon, onClose, onP
|
|
|
66
66
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
67
67
|
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
68
68
|
const [internalSelected, setInternalSelected] = (0, react_1.useState)(defaultSelected);
|
|
69
|
+
const [held, setHeld] = (0, react_1.useState)(false);
|
|
69
70
|
const selected = selectedProp !== undefined ? selectedProp : internalSelected;
|
|
70
71
|
const selectable = selectedProp !== undefined || onSelectedChange !== undefined || defaultSelected;
|
|
71
72
|
const handlePress = () => {
|
|
@@ -79,16 +80,16 @@ exports.Chip = (0, react_1.forwardRef)(function Chip({ label, icon, onClose, onP
|
|
|
79
80
|
}
|
|
80
81
|
onPress?.();
|
|
81
82
|
};
|
|
82
|
-
const pill = ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, tintColor: selected ? theme.glassActive : undefined, interactive: !disabled, style: {
|
|
83
|
+
const pill = ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", surface: "control", pressed: held, isDark: isDark, tintColor: selected ? theme.glassActive : undefined, interactive: !disabled, style: {
|
|
83
84
|
flexDirection: "row",
|
|
84
85
|
alignItems: "center",
|
|
85
86
|
gap: 6,
|
|
86
|
-
height:
|
|
87
|
+
height: 34,
|
|
87
88
|
paddingHorizontal: 12,
|
|
88
89
|
borderRadius: tokens_1.radii.pill,
|
|
89
90
|
opacity: disabled ? 0.38 : 1,
|
|
90
91
|
...style,
|
|
91
|
-
}, children: [icon ? (0, jsx_runtime_1.jsx)(View, { children: icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize:
|
|
92
|
+
}, children: [icon ? (0, jsx_runtime_1.jsx)(View, { children: icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 14, fontWeight: selected ? "600" : "500", color: selected ? theme.foreground : theme.muted }, children: label }), onClose && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: `Remove ${label}`, onPress: onClose, hitSlop: 8, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 11, color: theme.muted }, children: "\u00D7" }) }))] }));
|
|
92
93
|
if (!onPress && !selectable) {
|
|
93
94
|
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: label, ...props, children: pill }));
|
|
94
95
|
}
|
|
@@ -111,7 +112,7 @@ exports.FAB = (0, react_1.forwardRef)(function FAB({ onPress, accessibilityLabel
|
|
|
111
112
|
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, disabled: disabled, onPress: disabled ? undefined : onPress, style: ({ pressed }) => ({
|
|
112
113
|
alignSelf: "flex-start",
|
|
113
114
|
opacity: disabled ? 0.38 : pressed ? 0.85 : 1,
|
|
114
|
-
}), ...props, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "clear", interactive: !disabled, isDark: isDark, style: {
|
|
115
|
+
}), ...props, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "clear", surface: "control", interactive: !disabled, isDark: isDark, style: {
|
|
115
116
|
height: dimension,
|
|
116
117
|
width: extended ? undefined : dimension,
|
|
117
118
|
minWidth: dimension,
|
|
@@ -136,7 +137,7 @@ exports.IconButton = (0, react_1.forwardRef)(function IconButton({ accessibility
|
|
|
136
137
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
137
138
|
const { View, Pressable } = (0, primitives_1.primitives)();
|
|
138
139
|
const dimension = iconButtonSizes[size];
|
|
139
|
-
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, disabled: disabled, onPress: disabled ? undefined : onPress, style: ({ pressed }) => ({ opacity: disabled ? 0.38 : pressed ? 0.8 : 1 }), ...props, children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: variant === "ghost" ? "none" : "regular", interactive: !disabled && variant !== "ghost", isDark: isDark, style: {
|
|
140
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, disabled: disabled, onPress: disabled ? undefined : onPress, style: ({ pressed }) => ({ opacity: disabled ? 0.38 : pressed ? 0.8 : 1 }), ...props, children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: variant === "ghost" ? "none" : "regular", surface: "control", interactive: !disabled && variant !== "ghost", isDark: isDark, style: {
|
|
140
141
|
width: dimension,
|
|
141
142
|
height: dimension,
|
|
142
143
|
borderRadius: dimension / 2,
|
|
@@ -151,18 +152,34 @@ exports.IconButton = (0, react_1.forwardRef)(function IconButton({ accessibility
|
|
|
151
152
|
*
|
|
152
153
|
* A glass bar across the top of the screen with a leading action, a title and
|
|
153
154
|
* trailing actions — the counterpart to the existing bottom TabBar.
|
|
155
|
+
*
|
|
156
|
+
* `scrolled` mirrors iOS 26's scroll-edge effect. At the top of the screen the
|
|
157
|
+
* bar is quiet: its bottom edge is invisible and the glass blends into the
|
|
158
|
+
* content above it. Once content has scrolled under it, the edge token becomes
|
|
159
|
+
* visible and the surface reads as a distinct layer — the change iOS makes when
|
|
160
|
+
* a navigation bar starts floating over scrolled content.
|
|
161
|
+
*
|
|
162
|
+
* ```
|
|
163
|
+
* const [scrolled, setScrolled] = useState(false);
|
|
164
|
+
* <ScrollView onScroll={(e) => setScrolled(e.nativeEvent.contentOffset.y > 8)}
|
|
165
|
+
* scrollEventThrottle={16}>{...}</ScrollView>
|
|
166
|
+
* <AppBar title="Inbox" scrolled={scrolled} />
|
|
167
|
+
* ```
|
|
154
168
|
*/
|
|
155
|
-
exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, leading, actions, topInset = 0, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
169
|
+
exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, leading, actions, topInset = 0, scrolled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
156
170
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
157
171
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
158
172
|
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
159
173
|
const actionCount = actions?.length ?? 0;
|
|
160
174
|
const renderAction = (action, key) => ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: action.accessibilityLabel, accessibilityState: { disabled: action.disabled }, disabled: action.disabled, onPress: action.disabled ? undefined : action.onPress, hitSlop: 6, style: { padding: 6, opacity: action.disabled ? 0.38 : 1 }, children: action.icon }, key));
|
|
161
|
-
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, testID: testID, style: {
|
|
175
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", surface: "rail", isDark: isDark, testID: testID, style: {
|
|
162
176
|
borderRadius: 0,
|
|
163
177
|
borderTopWidth: 0,
|
|
164
178
|
borderLeftWidth: 0,
|
|
165
179
|
borderRightWidth: 0,
|
|
180
|
+
// Quiet at the top of a screen, defined once content is under it: the
|
|
181
|
+
// bottom edge is the difference iOS draws on a scrolled navigation bar.
|
|
182
|
+
...(scrolled ? { borderBottomWidth: 0.5, borderBottomColor: theme.edge } : { borderBottomWidth: 0 }),
|
|
166
183
|
...style,
|
|
167
184
|
}, ...props, children: (0, jsx_runtime_1.jsxs)(View, { style: {
|
|
168
185
|
paddingTop: topInset,
|
|
@@ -174,3 +191,80 @@ exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, lead
|
|
|
174
191
|
minHeight: 44 + topInset,
|
|
175
192
|
}, children: [leading ? renderAction(leading, "leading") : (0, jsx_runtime_1.jsx)(View, { style: { width: 8 } }), (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, paddingHorizontal: 4 }, children: [(0, jsx_runtime_1.jsx)(RNText, { accessibilityRole: "header", numberOfLines: 1, style: { fontSize: 17, fontWeight: "600", color: theme.foreground }, children: title }), subtitle ? ((0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 12, color: theme.muted }, children: subtitle })) : null] }), actions && actionCount > 0 ? ((0, jsx_runtime_1.jsx)(View, { style: { flexDirection: "row", alignItems: "center" }, children: actions.map((action, index) => renderAction(action, `action-${index}`)) })) : null] }) }));
|
|
176
193
|
});
|
|
194
|
+
// The main button's size, and the mini buttons' — both from the size scale so
|
|
195
|
+
// a mini button is never a hand-tuned multiple of the main one.
|
|
196
|
+
const fabGroupSizes = {
|
|
197
|
+
md: { main: 56, mini: 44 },
|
|
198
|
+
lg: { main: 64, mini: 52 },
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* A main button that expands into a stack of labelled mini buttons.
|
|
202
|
+
*
|
|
203
|
+
* The pattern Paper calls `FAB.Group`: one floating button stands in for a set
|
|
204
|
+
* of actions until it is opened, then the actions appear above it, each on its
|
|
205
|
+
* own glass pill with a label. A scrim behind them takes the next press and
|
|
206
|
+
* closes the group, which is how a floating action set gets out of the way
|
|
207
|
+
* without a dismissal button.
|
|
208
|
+
*
|
|
209
|
+
* The mini buttons rise on the bouncy spring with a small stagger, and the main
|
|
210
|
+
* button's icon rotates 45° — both settle instantly under Reduce Motion.
|
|
211
|
+
*
|
|
212
|
+
* **Merging is an iOS 26+ visual effect.** This component is one glass surface
|
|
213
|
+
* plus one per action; to have them blend into a single connected surface, put
|
|
214
|
+
* the group inside a `GlassContainer` on iOS 26. It works standalone — nothing
|
|
215
|
+
* depends on the container — and that composition is left to the caller rather
|
|
216
|
+
* than forced, because a group outside a container is the correct rendering on
|
|
217
|
+
* every other platform anyway.
|
|
218
|
+
*/
|
|
219
|
+
exports.FABGroup = (0, react_1.forwardRef)(function FABGroup({ actions, icon, closeIcon, open: openProp, defaultOpen = false, onOpenChange, accessibilityLabel = "More actions", size = "md", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
220
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
221
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
222
|
+
const { View, Text: RNText, Pressable, Animated } = (0, primitives_1.primitives)();
|
|
223
|
+
const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
|
|
224
|
+
const open = openProp !== undefined ? openProp : internalOpen;
|
|
225
|
+
const setOpen = (next) => {
|
|
226
|
+
if (openProp === undefined)
|
|
227
|
+
setInternalOpen(next);
|
|
228
|
+
onOpenChange?.(next);
|
|
229
|
+
};
|
|
230
|
+
// The stack's rise is one value: 0 closed, 1 open. The mini buttons ride it
|
|
231
|
+
// with their own stagger, so they follow the lead rather than all snapping
|
|
232
|
+
// at once.
|
|
233
|
+
const { value: rise, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "bouncy");
|
|
234
|
+
const { main: dimension, mini } = fabGroupSizes[size];
|
|
235
|
+
const closeFirst = closeIcon ?? icon;
|
|
236
|
+
const rotate = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: ["0deg", "45deg"] }) : open ? "45deg" : "0deg";
|
|
237
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: style, ...props, children: [open ? ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close actions", onPress: () => setOpen(false), style: { position: "absolute", top: -2000, left: -2000, right: -2000, bottom: -2000, backgroundColor: theme.scrim } })) : null, (0, jsx_runtime_1.jsxs)(View, { style: { alignItems: "flex-end", gap: 10 }, children: [open
|
|
238
|
+
? actions.map((action, index) => {
|
|
239
|
+
// Later actions sit higher, so the first is nearest the button.
|
|
240
|
+
const order = actions.length - 1 - index;
|
|
241
|
+
const translateY = animated
|
|
242
|
+
? rise.interpolate({
|
|
243
|
+
inputRange: [0, 1],
|
|
244
|
+
outputRange: [24 + order * 18, 0],
|
|
245
|
+
})
|
|
246
|
+
: 0;
|
|
247
|
+
const opacity = animated ? rise.interpolate({ inputRange: [0, 0.4, 1], outputRange: [0, 0, 1] }) : 1;
|
|
248
|
+
const pill = ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "button", accessibilityLabel: action.label, onPress: () => {
|
|
249
|
+
setOpen(false);
|
|
250
|
+
action.onPress();
|
|
251
|
+
}, style: { flexDirection: "row", alignItems: "center", gap: 8 }, children: [(0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "control", isDark: isDark, style: { borderRadius: tokens_1.radii.pill, paddingHorizontal: 12, paddingVertical: 7 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 13, fontWeight: "600", color: theme.foreground }, numberOfLines: 1, children: action.label }) }), (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "control", isDark: isDark, style: {
|
|
252
|
+
width: mini,
|
|
253
|
+
height: mini,
|
|
254
|
+
borderRadius: mini / 2,
|
|
255
|
+
alignItems: "center",
|
|
256
|
+
justifyContent: "center",
|
|
257
|
+
}, children: action.icon })] }));
|
|
258
|
+
if (!animated) {
|
|
259
|
+
return ((0, jsx_runtime_1.jsx)(View, { children: pill }, `${action.label}-${index}`));
|
|
260
|
+
}
|
|
261
|
+
return ((0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ translateY }], opacity }, children: pill }, `${action.label}-${index}`));
|
|
262
|
+
})
|
|
263
|
+
: null, (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { expanded: open }, onPress: () => setOpen(!open), children: (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "clear", surface: "control", interactive: true, isDark: isDark, style: {
|
|
264
|
+
width: dimension,
|
|
265
|
+
height: dimension,
|
|
266
|
+
borderRadius: dimension / 2,
|
|
267
|
+
alignItems: "center",
|
|
268
|
+
justifyContent: "center",
|
|
269
|
+
}, children: animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ rotate }] }, children: open ? closeFirst : icon })) : ((0, jsx_runtime_1.jsx)(View, { children: open ? closeFirst : icon })) }) })] })] }));
|
|
270
|
+
});
|
package/lib/module/Button.js
CHANGED
|
@@ -7,10 +7,12 @@ const Glass_1 = require("./Glass");
|
|
|
7
7
|
const tokens_1 = require("./internal/tokens");
|
|
8
8
|
const primitives_1 = require("./internal/primitives");
|
|
9
9
|
const motion_1 = require("./internal/motion");
|
|
10
|
+
// The web control scale: 28 / 34 / 44, one horizontal padding and one type
|
|
11
|
+
// size for every button, and the inherited 400 weight rather than a 500.
|
|
10
12
|
const sizeHeights = {
|
|
11
|
-
sm:
|
|
12
|
-
md:
|
|
13
|
-
lg:
|
|
13
|
+
sm: 28,
|
|
14
|
+
md: 34,
|
|
15
|
+
lg: 44,
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
18
|
* A pressable button on Glacia's glass.
|
|
@@ -23,6 +25,7 @@ exports.Button = (0, react_1.forwardRef)(function Button({ variant = "glass", si
|
|
|
23
25
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
24
26
|
const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
25
27
|
const { Pressable, View, Text } = (0, primitives_1.primitives)();
|
|
28
|
+
const [held, setHeld] = (0, react_1.useState)(false);
|
|
26
29
|
const height = sizeHeights[size];
|
|
27
30
|
const buttonStyle = {
|
|
28
31
|
height,
|
|
@@ -30,7 +33,7 @@ exports.Button = (0, react_1.forwardRef)(function Button({ variant = "glass", si
|
|
|
30
33
|
flexDirection: "row",
|
|
31
34
|
alignItems: "center",
|
|
32
35
|
justifyContent: "center",
|
|
33
|
-
paddingHorizontal:
|
|
36
|
+
paddingHorizontal: 14,
|
|
34
37
|
opacity: disabled ? 0.38 : 1,
|
|
35
38
|
backgroundColor: variant === "filled"
|
|
36
39
|
? tint || themeColors.fill
|
|
@@ -40,11 +43,11 @@ exports.Button = (0, react_1.forwardRef)(function Button({ variant = "glass", si
|
|
|
40
43
|
...style,
|
|
41
44
|
};
|
|
42
45
|
const textStyle = {
|
|
43
|
-
color: variant === "filled" ?
|
|
44
|
-
fontSize:
|
|
45
|
-
fontWeight: "
|
|
46
|
+
color: variant === "filled" ? themeColors.onTint : tint || themeColors.foreground,
|
|
47
|
+
fontSize: 14,
|
|
48
|
+
fontWeight: "400",
|
|
46
49
|
};
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, disabled: disabled, onPress: disabled ? undefined : onPress, style: ({ pressed }) => ({ opacity: pressed && !disabled ? 0.85 : 1 }), ...props, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: variant === "ghost" ? "none" : "regular", interactive: !disabled, isDark: isDark, style: buttonStyle, children: [icon ? (0, jsx_runtime_1.jsx)(View, { style: { marginRight: children ?
|
|
50
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, disabled: disabled, onPress: disabled ? undefined : onPress, onPressIn: () => setHeld(true), onPressOut: () => setHeld(false), style: ({ pressed }) => ({ opacity: pressed && !disabled ? 0.85 : 1 }), ...props, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: variant === "ghost" ? "none" : "regular", surface: "control", pressed: held && !disabled, interactive: !disabled, isDark: isDark, style: buttonStyle, children: [icon ? (0, jsx_runtime_1.jsx)(View, { style: { marginRight: children ? 7 : 0 }, children: icon }) : null, typeof children === "string" ? (
|
|
48
51
|
// A string label is text: it needs Text to inherit font and colour.
|
|
49
52
|
(0, jsx_runtime_1.jsx)(Text, { style: textStyle, numberOfLines: 1, children: children })) : (children)] }) }));
|
|
50
53
|
});
|
package/lib/module/Card.js
CHANGED
|
@@ -19,10 +19,10 @@ const motion_1 = require("./internal/motion");
|
|
|
19
19
|
exports.Card = (0, react_1.forwardRef)(function Card({ effect = "regular", style, children, isDark: isDarkProp, testID, ...props }, ref) {
|
|
20
20
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
21
21
|
const cardStyle = {
|
|
22
|
-
padding:
|
|
22
|
+
padding: 24,
|
|
23
23
|
borderRadius: tokens_1.radii.lg,
|
|
24
24
|
flexDirection: "column",
|
|
25
|
-
gap:
|
|
25
|
+
gap: 16,
|
|
26
26
|
...style,
|
|
27
27
|
};
|
|
28
28
|
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: effect, isDark: isDark, style: cardStyle, testID: testID, ...props, children: children }));
|
package/lib/module/Dialog.js
CHANGED
|
@@ -55,14 +55,16 @@ function Dialog({ open: controlledOpen, onOpenChange, title, description, childr
|
|
|
55
55
|
justifyContent: "center",
|
|
56
56
|
padding: 24,
|
|
57
57
|
backgroundColor: "rgba(0, 0, 0, 0.45)",
|
|
58
|
-
}, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { width: "100%", maxWidth: 380 }, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID, style: {
|
|
59
|
-
borderRadius: tokens_1.radii.
|
|
60
|
-
borderWidth: 1,
|
|
61
|
-
borderColor: theme.edge,
|
|
58
|
+
}, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { width: "100%", maxWidth: 380 }, children: (0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", surface: "overlay", isDark: isDark, testID: testID, style: {
|
|
59
|
+
borderRadius: tokens_1.radii.xl,
|
|
62
60
|
padding: 20,
|
|
63
61
|
gap: 8,
|
|
62
|
+
// The web overlay shadow: the panel has to float above the scrim.
|
|
63
|
+
shadowOpacity: 0.12,
|
|
64
|
+
shadowRadius: 50,
|
|
65
|
+
shadowOffset: { width: 0, height: 20 },
|
|
64
66
|
...style,
|
|
65
|
-
}, children: [title && ((0, jsx_runtime_1.jsx)(Text, { accessibilityRole: "heading", style: { fontSize: 17, fontWeight: "600", color: theme.foreground }, children: title })), description && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize:
|
|
67
|
+
}, children: [title && ((0, jsx_runtime_1.jsx)(Text, { accessibilityRole: "heading", style: { fontSize: 17, fontWeight: "600", color: theme.foreground }, children: title })), description && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 14, color: theme.muted, lineHeight: 20 }, children: description })), children, footer && (0, jsx_runtime_1.jsx)(View, { style: { marginTop: 12, gap: 8 }, children: footer })] }) }) }) }));
|
|
66
68
|
}
|
|
67
69
|
/** Opens the dialog without the caller tracking state. */
|
|
68
70
|
function DialogTrigger({ label, children, ...dialogProps }) {
|
|
@@ -124,16 +126,13 @@ function ActionSheet({ open: controlledOpen, onOpenChange, title, message, optio
|
|
|
124
126
|
setUncontrolled(false);
|
|
125
127
|
onOpenChange?.(false);
|
|
126
128
|
};
|
|
127
|
-
return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "slide", onRequestClose: close, testID: testID, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Dismiss actions", onPress: close, style: { flex: 1, justifyContent: "flex-end", backgroundColor: "rgba(0,0,0,0.4)" }, children: (0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { padding: 10, gap: 8 }, children: [(0, jsx_runtime_1.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}, children: (0, jsx_runtime_1.jsx)(Text, { style: {
|
|
136
|
-
fontSize: 16,
|
|
137
|
-
color: option.destructive ? theme.destructive : theme.foreground,
|
|
138
|
-
}, children: option.label }) }, option.label)))] }), (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: { borderRadius: tokens_1.radii.lg }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: cancelLabel, onPress: close, style: { paddingVertical: 14, alignItems: "center" }, children: (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 16, fontWeight: "600", color: theme.foreground }, children: cancelLabel }) }) })] }) }) }));
|
|
129
|
+
return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "slide", onRequestClose: close, testID: testID, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Dismiss actions", onPress: close, style: { flex: 1, justifyContent: "flex-end", backgroundColor: "rgba(0,0,0,0.4)" }, children: (0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { padding: 10, gap: 8 }, children: [(title || message) && ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "overlay", isDark: isDark, style: { borderRadius: tokens_1.radii.lg }, children: (0, jsx_runtime_1.jsxs)(View, { style: { paddingVertical: 12, paddingHorizontal: 16, alignItems: "center" }, children: [title && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 13, fontWeight: "600", color: theme.foreground }, children: title })), message && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 12, color: theme.muted, marginTop: 4, textAlign: "center" }, children: message }))] }) })), options.map((option) => ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "overlay", isDark: isDark, style: { borderRadius: tokens_1.radii.pill }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: option.label, onPress: () => {
|
|
130
|
+
option.onPress?.();
|
|
131
|
+
close();
|
|
132
|
+
}, style: { minHeight: 44, paddingVertical: 12, paddingHorizontal: 20, alignItems: "center", justifyContent: "center" }, children: (0, jsx_runtime_1.jsx)(Text, { style: {
|
|
133
|
+
fontSize: 17,
|
|
134
|
+
// The web's iOS-style action sheet: every row is the tint
|
|
135
|
+
// colour, and only a destructive one is red.
|
|
136
|
+
color: option.destructive ? theme.destructive : theme.fill,
|
|
137
|
+
}, children: option.label }) }) }, option.label))), (0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "overlay", isDark: isDark, style: { borderRadius: tokens_1.radii.pill }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: cancelLabel, onPress: close, style: { minHeight: 44, paddingVertical: 12, alignItems: "center", justifyContent: "center" }, children: (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 17, fontWeight: "600", color: theme.foreground }, children: cancelLabel }) }) })] }) }) }));
|
|
139
138
|
}
|
package/lib/module/Display.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Progress = exports.Spinner = exports.Skeleton = exports.Separator = exports.Badge = exports.Avatar = void 0;
|
|
3
|
+
exports.NativeImage = exports.Rating = exports.Progress = exports.Spinner = exports.Skeleton = exports.Separator = exports.Badge = exports.Avatar = void 0;
|
|
4
4
|
exports.initialsOf = initialsOf;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_1 = require("react");
|
|
@@ -34,7 +34,7 @@ exports.Avatar = (0, react_1.forwardRef)(function Avatar({ source, name, size =
|
|
|
34
34
|
const initials = name ? initialsOf(name) : "";
|
|
35
35
|
const statusColor = status === "online" ? theme.on : status === "busy" ? theme.destructive : theme.muted;
|
|
36
36
|
const dot = Math.max(8, Math.round(dimension * 0.26));
|
|
37
|
-
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, accessible: true, accessibilityRole: "image", accessibilityLabel: name ? `Avatar of ${name}` : "Avatar", style: { width: dimension, height: dimension, ...style }, ...props, children: [(0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, style: {
|
|
37
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, accessible: true, accessibilityRole: "image", accessibilityLabel: name ? `Avatar of ${name}` : "Avatar", style: { width: dimension, height: dimension, ...style }, ...props, children: [(0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", surface: "panel", isDark: isDark, style: {
|
|
38
38
|
width: dimension,
|
|
39
39
|
height: dimension,
|
|
40
40
|
borderRadius: dimension / 2,
|
|
@@ -76,17 +76,18 @@ exports.Badge = (0, react_1.forwardRef)(function Badge({ children, tone = "fill"
|
|
|
76
76
|
? theme.muted
|
|
77
77
|
: theme.fill;
|
|
78
78
|
const isDot = children == null;
|
|
79
|
-
|
|
79
|
+
// The web badge is 24 tall with 10 of horizontal padding and 12/500 type.
|
|
80
|
+
const height = isDot ? 10 : 24;
|
|
80
81
|
const badge = ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: isDot ? undefined : String(children), style: {
|
|
81
82
|
minWidth: height,
|
|
82
83
|
height,
|
|
83
84
|
borderRadius: height / 2,
|
|
84
|
-
paddingHorizontal: isDot ? 0 :
|
|
85
|
+
paddingHorizontal: isDot ? 0 : 10,
|
|
85
86
|
alignItems: "center",
|
|
86
87
|
justifyContent: "center",
|
|
87
88
|
backgroundColor: background,
|
|
88
89
|
...style,
|
|
89
|
-
}, ...props, children: !isDot && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize:
|
|
90
|
+
}, ...props, children: !isDot && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 12, fontWeight: "500", color: theme.onTint }, numberOfLines: 1, children: children })) }));
|
|
90
91
|
if (overlay === undefined)
|
|
91
92
|
return badge;
|
|
92
93
|
// Overlaid: the badge floats at the top-right of whatever it decorates, which
|
|
@@ -104,8 +105,8 @@ exports.Separator = (0, react_1.forwardRef)(function Separator({ orientation = "
|
|
|
104
105
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
105
106
|
const { View } = (0, primitives_1.primitives)();
|
|
106
107
|
const separatorStyle = orientation === "horizontal"
|
|
107
|
-
? { height:
|
|
108
|
-
: { width:
|
|
108
|
+
? { height: 1, alignSelf: "stretch", marginLeft: inset, backgroundColor: theme.separator }
|
|
109
|
+
: { width: 1, alignSelf: "stretch", backgroundColor: theme.separator };
|
|
109
110
|
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "none", style: { ...separatorStyle, ...style }, ...props }));
|
|
110
111
|
});
|
|
111
112
|
/**
|
|
@@ -225,7 +226,7 @@ exports.Progress = (0, react_1.forwardRef)(function Progress({ value, variant =
|
|
|
225
226
|
justifyContent: "center",
|
|
226
227
|
}, children: (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 13, fontWeight: "600", color: theme.foreground }, children: `${Math.round(clamped)}%` }) })] }));
|
|
227
228
|
}
|
|
228
|
-
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, style: {
|
|
229
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", surface: "rail", isDark: isDark, style: {
|
|
229
230
|
height: 8,
|
|
230
231
|
borderRadius: tokens_1.radii.pill,
|
|
231
232
|
overflow: "hidden",
|
|
@@ -238,3 +239,80 @@ exports.Progress = (0, react_1.forwardRef)(function Progress({ value, variant =
|
|
|
238
239
|
backgroundColor: fill,
|
|
239
240
|
} }) }));
|
|
240
241
|
});
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
// Rating
|
|
244
|
+
/** The five-pointed star, as a path in a unit box. */
|
|
245
|
+
const STAR_PATH = "M12 2.4l2.95 5.98 6.6.96-4.78 4.66 1.13 6.57L12 17.46l-5.9 3.11 1.13-6.57L2.45 9.34l6.6-.96z";
|
|
246
|
+
/**
|
|
247
|
+
* A star rating.
|
|
248
|
+
*
|
|
249
|
+
* The stars are drawn as SVG paths from the resolver, so nothing is a
|
|
250
|
+
* platform control. A fractional value fills part of a star: 3.5 draws three
|
|
251
|
+
* full stars and one half, the half produced by clipping the filled star at the
|
|
252
|
+
* fraction's width rather than by rounding — a 4.5-star average must look like
|
|
253
|
+
* a 4.5-star average.
|
|
254
|
+
*
|
|
255
|
+
* Read-only unless `onChange` is given. With it, each star is tappable, the
|
|
256
|
+
* value is exposed as an adjustable control (increment/decrement through
|
|
257
|
+
* accessibility actions), and each star has its own label so a screen reader
|
|
258
|
+
* can name the exact rating it sets.
|
|
259
|
+
*/
|
|
260
|
+
exports.Rating = (0, react_1.forwardRef)(function Rating({ value, max = 5, size = "md", onChange, disabled = false, accessibilityLabel = "Rating", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
261
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
262
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
263
|
+
const { View, Pressable, Svg, Path, Defs, ClipPath, Rect } = (0, primitives_1.primitives)();
|
|
264
|
+
const starSize = tokens_1.controlSizes.star[size];
|
|
265
|
+
const interactive = Boolean(onChange) && !disabled;
|
|
266
|
+
const clamped = Math.max(0, Math.min(value, max));
|
|
267
|
+
const setValue = (next) => {
|
|
268
|
+
const bounded = Math.max(0, Math.min(next, max));
|
|
269
|
+
onChange?.(bounded);
|
|
270
|
+
};
|
|
271
|
+
const star = (index) => {
|
|
272
|
+
// How much of this star is filled: 1 for a full star, 0 for empty, and the
|
|
273
|
+
// remainder for the one the value lands inside.
|
|
274
|
+
const filled = Math.max(0, Math.min(1, clamped - index));
|
|
275
|
+
const half = filled > 0 && filled < 1;
|
|
276
|
+
const glyph = ((0, jsx_runtime_1.jsxs)(Svg, { width: starSize, height: starSize, viewBox: "0 0 24 24", children: [half ? ((0, jsx_runtime_1.jsx)(Defs, { children: (0, jsx_runtime_1.jsx)(ClipPath, { id: `rating-clip-${index}`, children: (0, jsx_runtime_1.jsx)(Rect, { x: "0", y: "0", width: 24 * filled, height: 24 }) }) })) : null, (0, jsx_runtime_1.jsx)(Path, { d: STAR_PATH, fill: theme.separator }), filled > 0 ? ((0, jsx_runtime_1.jsx)(Path, { d: STAR_PATH, fill: theme.fill, ...(half ? { clipPath: `url(#rating-clip-${index})` } : {}) })) : null] }));
|
|
277
|
+
if (!interactive)
|
|
278
|
+
return (0, jsx_runtime_1.jsx)(View, { children: glyph }, index);
|
|
279
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: `${index + 1} of ${max} stars`, accessibilityState: { selected: clamped === index + 1 }, onPress: () => setValue(index + 1), hitSlop: 4, children: glyph }, index));
|
|
280
|
+
};
|
|
281
|
+
const stars = Array.from({ length: Math.max(1, max) }, (_unused, index) => star(index));
|
|
282
|
+
if (!interactive && !onChange) {
|
|
283
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: `${accessibilityLabel}, ${clamped} of ${max}`, style: { flexDirection: "row", alignItems: "center", gap: 2, ...style }, ...props, children: stars }));
|
|
284
|
+
}
|
|
285
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "adjustable", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled }, accessibilityValue: { min: 0, max, now: clamped }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => {
|
|
286
|
+
if (disabled)
|
|
287
|
+
return;
|
|
288
|
+
if (event?.nativeEvent?.actionName === "increment")
|
|
289
|
+
setValue(clamped + 1);
|
|
290
|
+
if (event?.nativeEvent?.actionName === "decrement")
|
|
291
|
+
setValue(clamped - 1);
|
|
292
|
+
}, style: { flexDirection: "row", alignItems: "center", gap: 2, opacity: disabled ? 0.38 : 1, ...style }, ...props, children: stars }));
|
|
293
|
+
});
|
|
294
|
+
/**
|
|
295
|
+
* A plain image, with the loading and error states every app ends up writing.
|
|
296
|
+
*
|
|
297
|
+
* Three states, because an image on a phone is three states: loading (a
|
|
298
|
+
* Skeleton behind it), loaded (a fade in), and failed (the caller's fallback).
|
|
299
|
+
* Aspect ratio comes from `style`, so a caller sets `aspectRatio` and the height
|
|
300
|
+
* follows.
|
|
301
|
+
*
|
|
302
|
+
* This is the plain one; `NativeImageGeneration` is the AI-specific cousin and
|
|
303
|
+
* keeps its own state machine.
|
|
304
|
+
*/
|
|
305
|
+
exports.NativeImage = (0, react_1.forwardRef)(function NativeImage({ source, accessibilityLabel, placeholder, fallback, fadeIn = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
306
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
307
|
+
const { View, Image: RNImage, Animated } = (0, primitives_1.primitives)();
|
|
308
|
+
const [failed, setFailed] = (0, react_1.useState)(false);
|
|
309
|
+
const [loaded, setLoaded] = (0, react_1.useState)(false);
|
|
310
|
+
const { value: fade, animated } = (0, motion_1.useSpring)(loaded ? 1 : 0, "gentle");
|
|
311
|
+
const boxStyle = { overflow: "hidden", ...style };
|
|
312
|
+
if (failed && fallback) {
|
|
313
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: boxStyle, ...props, children: fallback }));
|
|
314
|
+
}
|
|
315
|
+
const imageStyle = { width: "100%", height: "100%" };
|
|
316
|
+
const opacity = fadeIn && animated ? fade : 1;
|
|
317
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: boxStyle, ...props, children: [!loaded ? (0, jsx_runtime_1.jsx)(View, { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 }, children: placeholder ?? (0, jsx_runtime_1.jsx)(exports.Skeleton, { shape: "rect", isDark: isDark }) }) : null, (0, jsx_runtime_1.jsx)(RNImage, { accessibilityRole: "image", accessibilityLabel: accessibilityLabel, source: source, onLoad: () => setLoaded(true), onError: () => setFailed(true), style: [imageStyle, animated ? { opacity } : null] })] }));
|
|
318
|
+
});
|