glacia-native 0.4.0 → 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.
- package/lib/module/Bars.js +176 -0
- package/lib/module/Carousel.js +103 -0
- package/lib/module/Display.js +240 -0
- package/lib/module/Feedback.js +172 -0
- package/lib/module/Forms2.js +227 -0
- package/lib/module/Overlays.js +166 -0
- package/lib/module/Pickers.js +243 -0
- package/lib/module/Text.js +37 -0
- package/lib/module/index.js +58 -1
- package/lib/module/internal/GlassView.js +23 -7
- package/lib/module/internal/primitives.js +7 -2
- package/lib/module/internal/tokens.js +55 -1
- package/lib/typescript/Bars.d.ts +121 -0
- package/lib/typescript/Carousel.d.ts +47 -0
- package/lib/typescript/Display.d.ts +119 -0
- package/lib/typescript/Feedback.d.ts +138 -0
- package/lib/typescript/Forms2.d.ts +128 -0
- package/lib/typescript/Glass.d.ts +1 -1
- package/lib/typescript/Overlays.d.ts +105 -0
- package/lib/typescript/Pickers.d.ts +105 -0
- package/lib/typescript/Text.d.ts +28 -0
- package/lib/typescript/index.d.ts +9 -1
- package/lib/typescript/internal/GlassView.d.ts +10 -1
- package/lib/typescript/internal/tokens.d.ts +61 -0
- package/package.json +2 -2
- package/src/Bars.tsx +570 -0
- package/src/Carousel.tsx +233 -0
- package/src/Display.tsx +550 -0
- package/src/Feedback.tsx +579 -0
- package/src/Forms2.tsx +608 -0
- package/src/Overlays.tsx +474 -0
- package/src/Pickers.tsx +590 -0
- package/src/Text.tsx +83 -0
- package/src/index.ts +101 -1
- package/src/internal/GlassView.tsx +29 -7
- package/src/internal/primitives.ts +7 -2
- package/src/internal/tokens.ts +62 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppBar = exports.IconButton = exports.FAB = exports.Chip = exports.SearchBar = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const Glass_1 = require("./Glass");
|
|
7
|
+
const tokens_1 = require("./internal/tokens");
|
|
8
|
+
const primitives_1 = require("./internal/primitives");
|
|
9
|
+
const motion_1 = require("./internal/motion");
|
|
10
|
+
/**
|
|
11
|
+
* A search field for a bar or a screen header.
|
|
12
|
+
*
|
|
13
|
+
* Distinct from NativeAIInput: that is an AI composer with send semantics, this
|
|
14
|
+
* is ordinary app search — magnifier, themed placeholder, and a clear button
|
|
15
|
+
* once there is something to clear.
|
|
16
|
+
*/
|
|
17
|
+
exports.SearchBar = (0, react_1.forwardRef)(function SearchBar({ value: valueProp, defaultValue = "", onChangeText, onSubmit, placeholder = "Search", showCancel = false, onCancel, accessibilityLabel = "Search", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
18
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
19
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
20
|
+
const { View, Text: RNText, TextInput, Pressable } = (0, primitives_1.primitives)();
|
|
21
|
+
const [internal, setInternal] = (0, react_1.useState)(defaultValue);
|
|
22
|
+
const value = valueProp !== undefined ? valueProp : internal;
|
|
23
|
+
const handleChange = (next) => {
|
|
24
|
+
if (valueProp === undefined)
|
|
25
|
+
setInternal(next);
|
|
26
|
+
onChangeText?.(next);
|
|
27
|
+
};
|
|
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: {
|
|
30
|
+
flex: 1,
|
|
31
|
+
flexDirection: "row",
|
|
32
|
+
alignItems: "center",
|
|
33
|
+
gap: 8,
|
|
34
|
+
height: 36,
|
|
35
|
+
borderRadius: tokens_1.radii.pill,
|
|
36
|
+
paddingHorizontal: 12,
|
|
37
|
+
}, children: [(0, jsx_runtime_1.jsx)(RNText, { accessibilityElementsHidden: true, importantForAccessibility: "no", style: { fontSize: 14, color: theme.muted }, children: "\u2315" }), (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, justifyContent: "center" }, children: [!value && placeholder ? (
|
|
38
|
+
// Themed placeholder: the OS default colour ignores the theme.
|
|
39
|
+
(0, jsx_runtime_1.jsx)(RNText, { pointerEvents: "none", numberOfLines: 1, style: { position: "absolute", left: 0, fontSize: 15, color: theme.muted }, children: placeholder })) : null, (0, jsx_runtime_1.jsx)(TextInput, { accessibilityRole: "search", accessibilityLabel: accessibilityLabel, value: value, onChangeText: handleChange, onSubmitEditing: () => onSubmit?.(value), returnKeyType: "search", autoCorrect: false, placeholder: "", style: {
|
|
40
|
+
fontSize: 15,
|
|
41
|
+
paddingVertical: 4,
|
|
42
|
+
color: theme.foreground,
|
|
43
|
+
// Transparent: the themed placeholder above provides the hint.
|
|
44
|
+
backgroundColor: "transparent",
|
|
45
|
+
} })] }), value.length > 0 && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Clear search", onPress: clear, hitSlop: 8, children: (0, jsx_runtime_1.jsx)(View, { style: {
|
|
46
|
+
width: 16,
|
|
47
|
+
height: 16,
|
|
48
|
+
// A circle from its own size: half the 16pt box.
|
|
49
|
+
borderRadius: 16 / 2,
|
|
50
|
+
backgroundColor: theme.separator,
|
|
51
|
+
alignItems: "center",
|
|
52
|
+
justifyContent: "center",
|
|
53
|
+
}, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 10, color: theme.muted }, children: "\u00D7" }) }) }))] }), showCancel && ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Cancel", onPress: () => {
|
|
54
|
+
clear();
|
|
55
|
+
onCancel?.();
|
|
56
|
+
}, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 15, color: theme.fill }, children: "Cancel" }) }))] }));
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* A filter or tag pill.
|
|
60
|
+
*
|
|
61
|
+
* Selected state is a glass pill tinted with `glassActive` — the same selected
|
|
62
|
+
* treatment SegmentedControl and TabBar use, rather than a new colour.
|
|
63
|
+
*/
|
|
64
|
+
exports.Chip = (0, react_1.forwardRef)(function Chip({ label, icon, onClose, onPress, selected: selectedProp, defaultSelected = false, onSelectedChange, disabled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
65
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
66
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
67
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
68
|
+
const [internalSelected, setInternalSelected] = (0, react_1.useState)(defaultSelected);
|
|
69
|
+
const selected = selectedProp !== undefined ? selectedProp : internalSelected;
|
|
70
|
+
const selectable = selectedProp !== undefined || onSelectedChange !== undefined || defaultSelected;
|
|
71
|
+
const handlePress = () => {
|
|
72
|
+
if (disabled)
|
|
73
|
+
return;
|
|
74
|
+
if (selectable) {
|
|
75
|
+
const next = !selected;
|
|
76
|
+
if (selectedProp === undefined)
|
|
77
|
+
setInternalSelected(next);
|
|
78
|
+
onSelectedChange?.(next);
|
|
79
|
+
}
|
|
80
|
+
onPress?.();
|
|
81
|
+
};
|
|
82
|
+
const pill = ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, tintColor: selected ? theme.glassActive : undefined, interactive: !disabled, style: {
|
|
83
|
+
flexDirection: "row",
|
|
84
|
+
alignItems: "center",
|
|
85
|
+
gap: 6,
|
|
86
|
+
height: 30,
|
|
87
|
+
paddingHorizontal: 12,
|
|
88
|
+
borderRadius: tokens_1.radii.pill,
|
|
89
|
+
opacity: disabled ? 0.38 : 1,
|
|
90
|
+
...style,
|
|
91
|
+
}, children: [icon ? (0, jsx_runtime_1.jsx)(View, { children: icon }) : null, (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: 13, 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
|
+
if (!onPress && !selectable) {
|
|
93
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: label, ...props, children: pill }));
|
|
94
|
+
}
|
|
95
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { selected: selectable ? selected : undefined, disabled }, disabled: disabled, onPress: handlePress, ...props, children: pill }));
|
|
96
|
+
});
|
|
97
|
+
const fabSizes = { md: 56, lg: 64 };
|
|
98
|
+
/**
|
|
99
|
+
* The floating action button.
|
|
100
|
+
*
|
|
101
|
+
* The flagship glass circle of the library: a round `Glass` with `interactive`
|
|
102
|
+
* so the material itself responds to touch. The caller positions it; the
|
|
103
|
+
* component does not assume an edge.
|
|
104
|
+
*/
|
|
105
|
+
exports.FAB = (0, react_1.forwardRef)(function FAB({ onPress, accessibilityLabel, icon, label, size = "md", disabled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
106
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
107
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
108
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
109
|
+
const dimension = fabSizes[size];
|
|
110
|
+
const extended = Boolean(label);
|
|
111
|
+
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
|
+
alignSelf: "flex-start",
|
|
113
|
+
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
|
+
height: dimension,
|
|
116
|
+
width: extended ? undefined : dimension,
|
|
117
|
+
minWidth: dimension,
|
|
118
|
+
borderRadius: extended ? dimension / 2 : dimension / 2,
|
|
119
|
+
paddingHorizontal: extended ? 20 : 0,
|
|
120
|
+
flexDirection: "row",
|
|
121
|
+
alignItems: "center",
|
|
122
|
+
justifyContent: "center",
|
|
123
|
+
gap: 8,
|
|
124
|
+
...style,
|
|
125
|
+
}, children: [icon ? (0, jsx_runtime_1.jsx)(View, { children: icon }) : null, label ? ((0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 15, fontWeight: "600", color: theme.foreground }, numberOfLines: 1, children: label })) : null] }) }));
|
|
126
|
+
});
|
|
127
|
+
const iconButtonSizes = { sm: 28, md: 36, lg: 44 };
|
|
128
|
+
/**
|
|
129
|
+
* An icon-only button on glass.
|
|
130
|
+
*
|
|
131
|
+
* Button takes an icon alongside a label; this is the icon-only form, which
|
|
132
|
+
* every kit ships for toolbars and bar actions.
|
|
133
|
+
*/
|
|
134
|
+
exports.IconButton = (0, react_1.forwardRef)(function IconButton({ accessibilityLabel, onPress, icon, size = "md", variant = "glass", disabled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
135
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
136
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
137
|
+
const { View, Pressable } = (0, primitives_1.primitives)();
|
|
138
|
+
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
|
+
width: dimension,
|
|
141
|
+
height: dimension,
|
|
142
|
+
borderRadius: dimension / 2,
|
|
143
|
+
alignItems: "center",
|
|
144
|
+
justifyContent: "center",
|
|
145
|
+
backgroundColor: variant === "ghost" ? "transparent" : undefined,
|
|
146
|
+
...style,
|
|
147
|
+
}, children: (0, jsx_runtime_1.jsx)(View, { style: { width: dimension * 0.5, height: dimension * 0.5, alignItems: "center", justifyContent: "center" }, children: icon }) }) }));
|
|
148
|
+
});
|
|
149
|
+
/**
|
|
150
|
+
* The top bar.
|
|
151
|
+
*
|
|
152
|
+
* A glass bar across the top of the screen with a leading action, a title and
|
|
153
|
+
* trailing actions — the counterpart to the existing bottom TabBar.
|
|
154
|
+
*/
|
|
155
|
+
exports.AppBar = (0, react_1.forwardRef)(function AppBar({ title, subtitle, leading, actions, topInset = 0, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
156
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
157
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
158
|
+
const { View, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
159
|
+
const actionCount = actions?.length ?? 0;
|
|
160
|
+
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: {
|
|
162
|
+
borderRadius: 0,
|
|
163
|
+
borderTopWidth: 0,
|
|
164
|
+
borderLeftWidth: 0,
|
|
165
|
+
borderRightWidth: 0,
|
|
166
|
+
...style,
|
|
167
|
+
}, ...props, children: (0, jsx_runtime_1.jsxs)(View, { style: {
|
|
168
|
+
paddingTop: topInset,
|
|
169
|
+
paddingHorizontal: 8,
|
|
170
|
+
paddingBottom: 8,
|
|
171
|
+
flexDirection: "row",
|
|
172
|
+
alignItems: "center",
|
|
173
|
+
gap: 4,
|
|
174
|
+
minHeight: 44 + topInset,
|
|
175
|
+
}, 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
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PageControl = exports.Carousel = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const tokens_1 = require("./internal/tokens");
|
|
7
|
+
const primitives_1 = require("./internal/primitives");
|
|
8
|
+
const motion_1 = require("./internal/motion");
|
|
9
|
+
/**
|
|
10
|
+
* A horizontally paging swiper.
|
|
11
|
+
*
|
|
12
|
+
* It rides the resolver's ScrollView with `pagingEnabled`, so the paging feel is
|
|
13
|
+
* the platform's own and the pages are plain content the caller supplies. The
|
|
14
|
+
* active page is derived from the scroll offset, which is also what reports
|
|
15
|
+
* `onIndexChange`.
|
|
16
|
+
*/
|
|
17
|
+
exports.Carousel = (0, react_1.forwardRef)(function Carousel({ slides, index: indexProp, defaultIndex = 0, onIndexChange, gap = 0, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
18
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
19
|
+
const { getScrollView } = (0, primitives_1.primitives)();
|
|
20
|
+
const ScrollView = getScrollView();
|
|
21
|
+
const { View } = (0, primitives_1.primitives)();
|
|
22
|
+
const [internalIndex, setInternalIndex] = (0, react_1.useState)(defaultIndex);
|
|
23
|
+
const index = indexProp !== undefined ? indexProp : internalIndex;
|
|
24
|
+
const viewportWidth = (0, react_1.useRef)(0);
|
|
25
|
+
const scrollRef = (0, react_1.useRef)(null);
|
|
26
|
+
// Derives the page from the offset rather than trusting a counter, so a
|
|
27
|
+
// fast swipe that skips pages still reports the page it landed on.
|
|
28
|
+
const handleScroll = (event) => {
|
|
29
|
+
const { contentOffset, layoutMeasurement } = event?.nativeEvent ?? {};
|
|
30
|
+
const width = layoutMeasurement?.width || viewportWidth.current;
|
|
31
|
+
if (!width || !contentOffset)
|
|
32
|
+
return;
|
|
33
|
+
const next = Math.round(contentOffset.x / width);
|
|
34
|
+
const clamped = Math.min(Math.max(next, 0), Math.max(slides.length - 1, 0));
|
|
35
|
+
if (clamped !== index) {
|
|
36
|
+
if (indexProp === undefined)
|
|
37
|
+
setInternalIndex(clamped);
|
|
38
|
+
onIndexChange?.(clamped);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const pages = slides.map((slide, i) => ((0, jsx_runtime_1.jsx)(View, { style: { width: viewportWidth.current || "100%", paddingRight: gap }, children: slide }, i)));
|
|
42
|
+
// Off-device there is no ScrollView; the pages still render in a row so the
|
|
43
|
+
// component mounts, and the tests drive `handleScroll` through onScroll.
|
|
44
|
+
if (!ScrollView) {
|
|
45
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: [{ flexDirection: "row", overflow: "hidden" }, style], ...props, children: pages }));
|
|
46
|
+
}
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, onLayout: (event) => {
|
|
48
|
+
viewportWidth.current = event?.nativeEvent?.layout?.width ?? 0;
|
|
49
|
+
}, style: style, ...props, children: (0, jsx_runtime_1.jsx)(ScrollView, { ref: scrollRef, horizontal: true, pagingEnabled: gap === 0, showsHorizontalScrollIndicator: false, onScroll: handleScroll, scrollEventThrottle: 16, accessibilityRole: "adjustable", accessibilityLabel: "Carousel", accessibilityValue: { min: 0, max: Math.max(slides.length - 1, 0), now: index }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => {
|
|
50
|
+
const step = event?.nativeEvent?.actionName === "increment" ? 1 : -1;
|
|
51
|
+
const next = Math.min(Math.max(index + step, 0), Math.max(slides.length - 1, 0));
|
|
52
|
+
if (next === index)
|
|
53
|
+
return;
|
|
54
|
+
if (indexProp === undefined)
|
|
55
|
+
setInternalIndex(next);
|
|
56
|
+
onIndexChange?.(next);
|
|
57
|
+
}, children: pages }) }));
|
|
58
|
+
});
|
|
59
|
+
const DOT = 7;
|
|
60
|
+
const ACTIVE_DOT = 18;
|
|
61
|
+
/**
|
|
62
|
+
* The page dots.
|
|
63
|
+
*
|
|
64
|
+
* The active dot elongates and the others stay narrow, which is how iOS reads
|
|
65
|
+
* "you are here". The width change runs on the springs token through Animated.
|
|
66
|
+
*/
|
|
67
|
+
exports.PageControl = (0, react_1.forwardRef)(function PageControl({ count, activeIndex: activeProp, defaultActiveIndex = 0, onChange, tint, hidesForSinglePage = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
68
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
69
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
70
|
+
const { View, Pressable } = (0, primitives_1.primitives)();
|
|
71
|
+
const [internalIndex, setInternalIndex] = (0, react_1.useState)(defaultActiveIndex);
|
|
72
|
+
const active = activeProp !== undefined ? activeProp : internalIndex;
|
|
73
|
+
if (hidesForSinglePage && count <= 1)
|
|
74
|
+
return null;
|
|
75
|
+
// The accent tints the active dot; the resting dots sit on `glassActive` so
|
|
76
|
+
// selection reads the same way it does in SegmentedControl and TabBar.
|
|
77
|
+
const accent = tint ?? theme.fill;
|
|
78
|
+
const resting = theme.glassActive;
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "tablist", style: [{ flexDirection: "row", alignItems: "center", gap: 6, alignSelf: "center" }, style], ...props, children: Array.from({ length: Math.max(count, 0) }, (_, index) => {
|
|
80
|
+
const isActive = index === active;
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "tab", accessibilityLabel: `Page ${index + 1} of ${count}`, accessibilityState: { selected: isActive }, onPress: () => {
|
|
82
|
+
if (activeProp === undefined)
|
|
83
|
+
setInternalIndex(index);
|
|
84
|
+
onChange?.(index);
|
|
85
|
+
}, hitSlop: 8, children: (0, jsx_runtime_1.jsx)(Dot, { active: isActive, accent: accent, muted: resting }) }, index));
|
|
86
|
+
}) }));
|
|
87
|
+
});
|
|
88
|
+
/** One dot, whose width springs between the resting and active lengths. */
|
|
89
|
+
function Dot({ active, accent, muted }) {
|
|
90
|
+
const { Animated, View } = (0, primitives_1.primitives)();
|
|
91
|
+
const { value: progress, animated } = (0, motion_1.useSpring)(active ? 1 : 0, "snappy");
|
|
92
|
+
const width = animated
|
|
93
|
+
? progress.interpolate({ inputRange: [0, 1], outputRange: [DOT, ACTIVE_DOT] })
|
|
94
|
+
: active
|
|
95
|
+
? ACTIVE_DOT
|
|
96
|
+
: DOT;
|
|
97
|
+
const style = {
|
|
98
|
+
height: DOT,
|
|
99
|
+
borderRadius: DOT / 2,
|
|
100
|
+
backgroundColor: active ? accent : muted,
|
|
101
|
+
};
|
|
102
|
+
return animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { style: { ...style, width } })) : ((0, jsx_runtime_1.jsx)(View, { style: { ...style, width: width } }));
|
|
103
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Progress = exports.Spinner = exports.Skeleton = exports.Separator = exports.Badge = exports.Avatar = void 0;
|
|
4
|
+
exports.initialsOf = initialsOf;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const Glass_1 = require("./Glass");
|
|
8
|
+
const tokens_1 = require("./internal/tokens");
|
|
9
|
+
const primitives_1 = require("./internal/primitives");
|
|
10
|
+
const motion_1 = require("./internal/motion");
|
|
11
|
+
const avatarSizes = { sm: 28, md: 40, lg: 64 };
|
|
12
|
+
/** First letters of the first and last word, as an avatar fallback. */
|
|
13
|
+
function initialsOf(name) {
|
|
14
|
+
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
15
|
+
if (words.length === 0)
|
|
16
|
+
return "";
|
|
17
|
+
if (words.length === 1)
|
|
18
|
+
return words[0].slice(0, 2).toUpperCase();
|
|
19
|
+
return (words[0][0] + words[words.length - 1][0]).toUpperCase();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A person or entity: their picture, or their initials when there is none.
|
|
23
|
+
*
|
|
24
|
+
* The frame is Glacia's glass so it belongs to the same family as the rest of
|
|
25
|
+
* the library; the initials sit on it in the theme's foreground colour.
|
|
26
|
+
*/
|
|
27
|
+
exports.Avatar = (0, react_1.forwardRef)(function Avatar({ source, name, size = "md", status, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
28
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
29
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
30
|
+
const { View, Text, Image } = (0, primitives_1.primitives)();
|
|
31
|
+
// A broken remote image falls back to initials rather than an empty circle.
|
|
32
|
+
const [failed, setFailed] = (0, react_1.useState)(false);
|
|
33
|
+
const dimension = avatarSizes[size];
|
|
34
|
+
const initials = name ? initialsOf(name) : "";
|
|
35
|
+
const statusColor = status === "online" ? theme.on : status === "busy" ? theme.destructive : theme.muted;
|
|
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: {
|
|
38
|
+
width: dimension,
|
|
39
|
+
height: dimension,
|
|
40
|
+
borderRadius: dimension / 2,
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
justifyContent: "center",
|
|
43
|
+
overflow: "hidden",
|
|
44
|
+
}, children: source && !failed ? ((0, jsx_runtime_1.jsx)(Image, { source: source, accessibilityLabel: name ?? "Avatar", onError: () => setFailed(true), style: { width: dimension, height: dimension } })) : ((0, jsx_runtime_1.jsx)(Text, { style: {
|
|
45
|
+
fontSize: Math.round(dimension * 0.38),
|
|
46
|
+
fontWeight: "600",
|
|
47
|
+
color: theme.foreground,
|
|
48
|
+
}, children: initials })) }), status && ((0, jsx_runtime_1.jsx)(View, { style: {
|
|
49
|
+
position: "absolute",
|
|
50
|
+
right: 0,
|
|
51
|
+
bottom: 0,
|
|
52
|
+
width: dot,
|
|
53
|
+
height: dot,
|
|
54
|
+
borderRadius: dot / 2,
|
|
55
|
+
backgroundColor: statusColor,
|
|
56
|
+
borderWidth: 1.5,
|
|
57
|
+
borderColor: theme.glassActive,
|
|
58
|
+
} }))] }));
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* A small count or dot.
|
|
62
|
+
*
|
|
63
|
+
* Deliberately not glass: a badge is a micro-element, and a translucent 16pt
|
|
64
|
+
* chip loses its contrast against whatever it sits on. It uses the solid theme
|
|
65
|
+
* tint instead, which is what makes it legible in both themes.
|
|
66
|
+
*/
|
|
67
|
+
exports.Badge = (0, react_1.forwardRef)(function Badge({ children, tone = "fill", overlay, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
68
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
69
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
70
|
+
const { View, Text } = (0, primitives_1.primitives)();
|
|
71
|
+
const background = tone === "destructive"
|
|
72
|
+
? theme.destructive
|
|
73
|
+
: tone === "success"
|
|
74
|
+
? theme.on
|
|
75
|
+
: tone === "muted"
|
|
76
|
+
? theme.muted
|
|
77
|
+
: theme.fill;
|
|
78
|
+
const isDot = children == null;
|
|
79
|
+
const height = isDot ? 10 : 18;
|
|
80
|
+
const badge = ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: isDot ? undefined : String(children), style: {
|
|
81
|
+
minWidth: height,
|
|
82
|
+
height,
|
|
83
|
+
borderRadius: height / 2,
|
|
84
|
+
paddingHorizontal: isDot ? 0 : 6,
|
|
85
|
+
alignItems: "center",
|
|
86
|
+
justifyContent: "center",
|
|
87
|
+
backgroundColor: background,
|
|
88
|
+
...style,
|
|
89
|
+
}, ...props, children: !isDot && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, fontWeight: "700", color: theme.onTint }, numberOfLines: 1, children: children })) }));
|
|
90
|
+
if (overlay === undefined)
|
|
91
|
+
return badge;
|
|
92
|
+
// Overlaid: the badge floats at the top-right of whatever it decorates, which
|
|
93
|
+
// needs a positioned box around the child rather than a bare fragment.
|
|
94
|
+
return ((0, jsx_runtime_1.jsxs)(View, { style: { alignSelf: "flex-start" }, children: [overlay, (0, jsx_runtime_1.jsx)(View, { style: { position: "absolute", top: -4, right: -4 }, children: badge })] }));
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* A hairline divider in the theme's separator colour.
|
|
98
|
+
*
|
|
99
|
+
* A plain View rather than a Glass: a 1pt rule is not a surface, and glass on
|
|
100
|
+
* a line has nothing to refract.
|
|
101
|
+
*/
|
|
102
|
+
exports.Separator = (0, react_1.forwardRef)(function Separator({ orientation = "horizontal", inset = 0, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
103
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
104
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
105
|
+
const { View } = (0, primitives_1.primitives)();
|
|
106
|
+
const separatorStyle = orientation === "horizontal"
|
|
107
|
+
? { height: 0.5, alignSelf: "stretch", marginLeft: inset, backgroundColor: theme.separator }
|
|
108
|
+
: { width: 0.5, alignSelf: "stretch", backgroundColor: theme.separator };
|
|
109
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "none", style: { ...separatorStyle, ...style }, ...props }));
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* A loading placeholder.
|
|
113
|
+
*
|
|
114
|
+
* The pulse is opacity only and slow, on the gentle spring, so it reads as
|
|
115
|
+
* "loading" without motion that could bother someone sensitive to movement.
|
|
116
|
+
* Nothing about it is essential to understanding the screen, so it is hidden
|
|
117
|
+
* from screen readers rather than announced.
|
|
118
|
+
*/
|
|
119
|
+
exports.Skeleton = (0, react_1.forwardRef)(function Skeleton({ shape = "rect", width, height, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
120
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
121
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
122
|
+
const { View, Animated } = (0, primitives_1.primitives)();
|
|
123
|
+
const { value: pulse, animated } = (0, motion_1.useSpring)(1, "gentle");
|
|
124
|
+
const opacity = animated
|
|
125
|
+
? pulse.interpolate({ inputRange: [0, 1], outputRange: [0.35, 1] })
|
|
126
|
+
: 1;
|
|
127
|
+
const resolvedWidth = width ?? (shape === "line" ? "100%" : shape === "circle" ? 40 : 120);
|
|
128
|
+
const resolvedHeight = height ?? (shape === "line" ? 12 : shape === "circle" ? 40 : 80);
|
|
129
|
+
const radius = shape === "circle" ? Math.min(resolvedHeight, 9999) / 2 : shape === "line" ? tokens_1.radii.sm : tokens_1.radii.md;
|
|
130
|
+
const skeletonStyle = {
|
|
131
|
+
width: resolvedWidth,
|
|
132
|
+
height: resolvedHeight,
|
|
133
|
+
borderRadius: radius,
|
|
134
|
+
backgroundColor: theme.skeleton,
|
|
135
|
+
...style,
|
|
136
|
+
};
|
|
137
|
+
const a11y = { accessibilityRole: "none", accessible: false, testID };
|
|
138
|
+
return animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { ref: ref, style: { ...skeletonStyle, opacity }, ...a11y, ...props })) : ((0, jsx_runtime_1.jsx)(View, { ref: ref, style: skeletonStyle, ...a11y, ...props }));
|
|
139
|
+
});
|
|
140
|
+
const spinnerSizes = { sm: 16, md: 22, lg: 32 };
|
|
141
|
+
/**
|
|
142
|
+
* A loading spinner, drawn by Glacia.
|
|
143
|
+
*
|
|
144
|
+
* An SVG arc that rotates on the gentle spring through Animated — not the
|
|
145
|
+
* platform's ActivityIndicator, so it looks the same on every platform and
|
|
146
|
+
* wears the theme's colour instead of inheriting the system tint.
|
|
147
|
+
*/
|
|
148
|
+
exports.Spinner = (0, react_1.forwardRef)(function Spinner({ size = "md", tint, accessibilityLabel = "Loading", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
149
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
150
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
151
|
+
const { View, Svg, Circle, Animated } = (0, primitives_1.primitives)();
|
|
152
|
+
const dimension = spinnerSizes[size];
|
|
153
|
+
const stroke = Math.max(2, Math.round(dimension / 9));
|
|
154
|
+
const color = tint ?? theme.muted;
|
|
155
|
+
// An arc, not a full ring: a complete circle rotating looks static.
|
|
156
|
+
const circumference = 2 * Math.PI * ((dimension - stroke) / 2);
|
|
157
|
+
const dash = circumference * 0.28;
|
|
158
|
+
// A continuous spin never settles, so it is driven by Animated.timing on a
|
|
159
|
+
// loop rather than the spring hook, which is built for one-off targets.
|
|
160
|
+
const { Animated: AnimatedAPI, isNative } = (0, primitives_1.primitives)();
|
|
161
|
+
const spinning = isNative && Boolean(AnimatedAPI?.timing);
|
|
162
|
+
const rotation = (0, react_1.useRef)(null);
|
|
163
|
+
if (rotation.current === null) {
|
|
164
|
+
rotation.current = spinning ? new AnimatedAPI.Value(0) : null;
|
|
165
|
+
}
|
|
166
|
+
(0, react_1.useEffect)(() => {
|
|
167
|
+
if (!spinning || !rotation.current)
|
|
168
|
+
return;
|
|
169
|
+
rotation.current.setValue(0);
|
|
170
|
+
const loop = AnimatedAPI.loop(AnimatedAPI.timing(rotation.current, {
|
|
171
|
+
toValue: 1,
|
|
172
|
+
duration: 900,
|
|
173
|
+
useNativeDriver: true,
|
|
174
|
+
}));
|
|
175
|
+
loop.start?.();
|
|
176
|
+
return () => loop.stop?.();
|
|
177
|
+
}, [AnimatedAPI, spinning]);
|
|
178
|
+
const spinStyle = spinning
|
|
179
|
+
? {
|
|
180
|
+
transform: [
|
|
181
|
+
{
|
|
182
|
+
rotate: rotation.current.interpolate({
|
|
183
|
+
inputRange: [0, 1],
|
|
184
|
+
outputRange: ["0deg", "360deg"],
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
}
|
|
189
|
+
: undefined;
|
|
190
|
+
const svg = ((0, jsx_runtime_1.jsxs)(Svg, { width: dimension, height: dimension, viewBox: `0 0 ${dimension} ${dimension}`, children: [(0, jsx_runtime_1.jsx)(Circle, { cx: dimension / 2, cy: dimension / 2, r: (dimension - stroke) / 2, stroke: theme.skeleton, strokeWidth: stroke, fill: "none" }), (0, jsx_runtime_1.jsx)(Circle, { cx: dimension / 2, cy: dimension / 2, r: (dimension - stroke) / 2, stroke: color, strokeWidth: stroke, fill: "none", strokeLinecap: "round", strokeDasharray: `${dash} ${circumference - dash}` })] }));
|
|
191
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "progressbar", accessibilityLabel: accessibilityLabel, style: [{ width: dimension, height: dimension }, style], ...props, children: spinning ? (0, jsx_runtime_1.jsx)(Animated.View, { style: spinStyle, children: svg }) : svg }));
|
|
192
|
+
});
|
|
193
|
+
const RING = 64;
|
|
194
|
+
/**
|
|
195
|
+
* Progress, linear or circular.
|
|
196
|
+
*
|
|
197
|
+
* The track is a glass surface, so it refracts what it sits on exactly like the
|
|
198
|
+
* rest of the library; the fill is the theme accent. Both forms report
|
|
199
|
+
* `progressbar` with a value, which is the contract NativeTask relies on
|
|
200
|
+
* internally — this component generalises it.
|
|
201
|
+
*/
|
|
202
|
+
exports.Progress = (0, react_1.forwardRef)(function Progress({ value, variant = "bar", tint, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
203
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
204
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
205
|
+
const { View, Text, Svg, Circle } = (0, primitives_1.primitives)();
|
|
206
|
+
const clamped = Math.min(Math.max(value, 0), 100);
|
|
207
|
+
const fill = tint ?? theme.fill;
|
|
208
|
+
const a11y = {
|
|
209
|
+
accessibilityRole: "progressbar",
|
|
210
|
+
accessibilityValue: { min: 0, max: 100, now: Math.round(clamped) },
|
|
211
|
+
accessibilityLabel,
|
|
212
|
+
testID,
|
|
213
|
+
};
|
|
214
|
+
if (variant === "ring") {
|
|
215
|
+
const stroke = 6;
|
|
216
|
+
const radius = (RING - stroke) / 2;
|
|
217
|
+
const circumference = 2 * Math.PI * radius;
|
|
218
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, style: [{ width: RING, height: RING }, style], ...a11y, ...props, children: [(0, jsx_runtime_1.jsxs)(Svg, { width: RING, height: RING, viewBox: `0 0 ${RING} ${RING}`, children: [(0, jsx_runtime_1.jsx)(Circle, { cx: RING / 2, cy: RING / 2, r: radius, stroke: theme.skeleton, strokeWidth: stroke, fill: "none" }), (0, jsx_runtime_1.jsx)(Circle, { cx: RING / 2, cy: RING / 2, r: radius, stroke: fill, strokeWidth: stroke, fill: "none", strokeLinecap: "round", strokeDasharray: `${(clamped / 100) * circumference} ${circumference}`,
|
|
219
|
+
// Start the arc at twelve o'clock, the way progress dials read.
|
|
220
|
+
transform: `rotate(-90 ${RING / 2} ${RING / 2})` })] }), (0, jsx_runtime_1.jsx)(View, { style: {
|
|
221
|
+
position: "absolute",
|
|
222
|
+
width: RING,
|
|
223
|
+
height: RING,
|
|
224
|
+
alignItems: "center",
|
|
225
|
+
justifyContent: "center",
|
|
226
|
+
}, children: (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 13, fontWeight: "600", color: theme.foreground }, children: `${Math.round(clamped)}%` }) })] }));
|
|
227
|
+
}
|
|
228
|
+
return ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, style: {
|
|
229
|
+
height: 8,
|
|
230
|
+
borderRadius: tokens_1.radii.pill,
|
|
231
|
+
overflow: "hidden",
|
|
232
|
+
justifyContent: "center",
|
|
233
|
+
...style,
|
|
234
|
+
}, ...a11y, ...props, children: (0, jsx_runtime_1.jsx)(View, { style: {
|
|
235
|
+
width: `${clamped}%`,
|
|
236
|
+
height: 8,
|
|
237
|
+
borderRadius: tokens_1.radii.pill,
|
|
238
|
+
backgroundColor: fill,
|
|
239
|
+
} }) }));
|
|
240
|
+
});
|