glacia-native 0.3.5 → 0.4.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/Button.js +15 -2
- package/lib/module/Card.js +29 -14
- package/lib/module/Dialog.js +43 -32
- package/lib/module/Form.js +51 -12
- package/lib/module/Glass.js +11 -2
- package/lib/module/Input.js +19 -7
- package/lib/module/SegmentedControl.js +65 -21
- package/lib/module/Slider.js +121 -25
- package/lib/module/Switch.js +33 -15
- package/lib/module/TabBar.js +63 -25
- package/lib/module/Table.js +24 -6
- package/lib/module/Tabs.js +55 -33
- package/lib/module/ai.js +49 -20
- package/lib/module/charts/BarChart.js +4 -2
- package/lib/module/charts/FunnelChart.js +4 -2
- package/lib/module/charts/HeatmapChart.js +4 -2
- package/lib/module/charts/LineChart.js +4 -2
- package/lib/module/charts/PlotChart.js +11 -3
- package/lib/module/charts/RadarChart.js +4 -2
- package/lib/module/charts/RingChart.js +4 -2
- package/lib/module/charts/ScatterChart.js +20 -3
- package/lib/module/charts/WaterfallChart.js +12 -3
- package/lib/module/charts/advanced.js +12 -6
- package/lib/module/charts/extra.js +6 -3
- package/lib/module/internal/GlassView.js +17 -19
- package/lib/module/internal/fallback.js +14 -3
- package/lib/module/internal/glass-routing.js +56 -0
- package/lib/module/internal/motion.js +55 -0
- package/lib/module/internal/primitives.js +408 -0
- package/lib/typescript/Button.d.ts +11 -1
- package/lib/typescript/Card.d.ts +20 -8
- package/lib/typescript/Dialog.d.ts +19 -6
- package/lib/typescript/Form.d.ts +27 -11
- package/lib/typescript/Glass.d.ts +9 -0
- package/lib/typescript/Input.d.ts +11 -1
- package/lib/typescript/SegmentedControl.d.ts +11 -1
- package/lib/typescript/Slider.d.ts +13 -1
- package/lib/typescript/Switch.d.ts +12 -1
- package/lib/typescript/TabBar.d.ts +13 -1
- package/lib/typescript/Table.d.ts +14 -5
- package/lib/typescript/Tabs.d.ts +8 -5
- package/lib/typescript/ai.d.ts +12 -9
- package/lib/typescript/charts/BarChart.d.ts +1 -1
- package/lib/typescript/charts/FunnelChart.d.ts +1 -1
- package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
- package/lib/typescript/charts/LineChart.d.ts +1 -1
- package/lib/typescript/charts/PlotChart.d.ts +1 -1
- package/lib/typescript/charts/RadarChart.d.ts +1 -1
- package/lib/typescript/charts/RingChart.d.ts +1 -1
- package/lib/typescript/charts/ScatterChart.d.ts +1 -1
- package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
- package/lib/typescript/charts/advanced.d.ts +5 -5
- package/lib/typescript/charts/extra.d.ts +2 -2
- package/lib/typescript/internal/GlassView.d.ts +11 -3
- package/lib/typescript/internal/fallback.d.ts +10 -1
- package/lib/typescript/internal/glass-routing.d.ts +30 -0
- package/lib/typescript/internal/motion.d.ts +19 -0
- package/lib/typescript/internal/primitives.d.ts +41 -0
- package/package.json +2 -2
- package/src/Button.tsx +47 -22
- package/src/Card.tsx +52 -31
- package/src/Dialog.tsx +99 -64
- package/src/Form.tsx +90 -25
- package/src/Glass.tsx +24 -1
- package/src/Input.tsx +33 -12
- package/src/SegmentedControl.tsx +104 -32
- package/src/Slider.tsx +151 -47
- package/src/Switch.tsx +56 -32
- package/src/TabBar.tsx +100 -30
- package/src/Table.tsx +38 -14
- package/src/Tabs.tsx +85 -32
- package/src/ai.tsx +77 -31
- package/src/charts/BarChart.tsx +4 -2
- package/src/charts/FunnelChart.tsx +4 -2
- package/src/charts/HeatmapChart.tsx +4 -2
- package/src/charts/LineChart.tsx +4 -2
- package/src/charts/PlotChart.tsx +23 -3
- package/src/charts/RadarChart.tsx +4 -2
- package/src/charts/RingChart.tsx +4 -2
- package/src/charts/ScatterChart.tsx +24 -3
- package/src/charts/WaterfallChart.tsx +21 -3
- package/src/charts/advanced.tsx +12 -6
- package/src/charts/extra.tsx +6 -3
- package/src/internal/GlassView.tsx +31 -21
- package/src/internal/fallback.tsx +23 -8
- package/src/internal/glass-routing.ts +68 -0
- package/src/internal/motion.ts +60 -0
- package/src/internal/primitives.ts +477 -0
- package/lib/module/charts/primitives.js +0 -212
- package/lib/typescript/charts/primitives.d.ts +0 -23
- package/src/charts/primitives.ts +0 -262
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The glass switch — the law of this library.
|
|
3
|
+
//
|
|
4
|
+
// Every glass surface in every Glacia Native component goes through
|
|
5
|
+
// `GlassView`, which routes here. On iOS 26+ `@callstack/liquid-glass` reports
|
|
6
|
+
// `isLiquidGlassSupported === true` and the surface is rendered by Apple's
|
|
7
|
+
// real `UIGlassEffect` (`LiquidGlassView`). Everywhere else — older iOS,
|
|
8
|
+
// Android, Expo Go, or a build without the module — it is Glacia's own
|
|
9
|
+
// translucent fallback of identical shape.
|
|
10
|
+
//
|
|
11
|
+
// The decision is split out from the React component so both branches can be
|
|
12
|
+
// exercised in tests: `routerFor` takes the module as an argument, and the
|
|
13
|
+
// default export routes on whatever is installed. On a device the argument is
|
|
14
|
+
// always the installed module, so the routing logic is unchanged.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.routerFor = routerFor;
|
|
17
|
+
exports.loadLiquidGlass = loadLiquidGlass;
|
|
18
|
+
exports.defaultRouter = defaultRouter;
|
|
19
|
+
/**
|
|
20
|
+
* Reads a liquid-glass module and decides which branch renders.
|
|
21
|
+
*
|
|
22
|
+
* A module only counts as supported when it exports the view *and* reports
|
|
23
|
+
* support; a missing export falls back rather than crashing.
|
|
24
|
+
*/
|
|
25
|
+
function routerFor(module) {
|
|
26
|
+
const view = module?.LiquidGlassView ?? null;
|
|
27
|
+
return {
|
|
28
|
+
supported: Boolean(module?.isLiquidGlassSupported) && Boolean(view),
|
|
29
|
+
LiquidGlassView: view,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Loads `@callstack/liquid-glass` at runtime.
|
|
34
|
+
*
|
|
35
|
+
* Resolved through `require` rather than a static import so the package stays
|
|
36
|
+
* importable where the native module is absent (jsdom tests, web preview).
|
|
37
|
+
* `isLiquidGlassSupported` is a constant baked by the package's own platform
|
|
38
|
+
* resolution: its iOS build reads the native module and answers true only on
|
|
39
|
+
* iOS 26+; the default build answers false.
|
|
40
|
+
*/
|
|
41
|
+
function loadLiquidGlass() {
|
|
42
|
+
try {
|
|
43
|
+
const module = require("@callstack/liquid-glass");
|
|
44
|
+
if (module && (module.LiquidGlassView || module.isLiquidGlassSupported !== undefined)) {
|
|
45
|
+
return module;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The installed module's routing decision, computed once per process. */
|
|
54
|
+
function defaultRouter() {
|
|
55
|
+
return routerFor(loadLiquidGlass());
|
|
56
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Shared component plumbing: dark-mode defaulting and spring motion.
|
|
3
|
+
//
|
|
4
|
+
// Two rules apply to every Glacia component, so they live here instead of
|
|
5
|
+
// being repeated (and forgotten) in each file:
|
|
6
|
+
// - `useIsDark` falls back to the phone's own colour scheme when the caller
|
|
7
|
+
// does not pass `isDark`, so a theme-aware app needs no extra prop threading.
|
|
8
|
+
// - `useSpring` animates a number towards its target with the package's spring
|
|
9
|
+
// tokens through React Native's Animated API. No CSS, no timers of our own.
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.useIsDark = useIsDark;
|
|
12
|
+
exports.useSpring = useSpring;
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const primitives_1 = require("./primitives");
|
|
15
|
+
const tokens_1 = require("./tokens");
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the theme. An explicit `isDark` always wins; otherwise the phone's
|
|
18
|
+
* colour scheme decides, defaulting to light when it is unknown.
|
|
19
|
+
*/
|
|
20
|
+
function useIsDark(isDark) {
|
|
21
|
+
const { useColorScheme } = (0, primitives_1.primitives)();
|
|
22
|
+
const scheme = typeof useColorScheme === "function" ? useColorScheme() : null;
|
|
23
|
+
return isDark ?? scheme === "dark";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A value that springs towards `target` whenever it changes.
|
|
27
|
+
*
|
|
28
|
+
* Returns the `Animated.Value` to put in a style, plus whether motion is real
|
|
29
|
+
* on this platform. A caller that gets `animated === false` renders the target
|
|
30
|
+
* directly, so the DOM preview and tests show the settled state rather than an
|
|
31
|
+
* animation the environment cannot advance.
|
|
32
|
+
*/
|
|
33
|
+
function useSpring(target, spring = "snappy") {
|
|
34
|
+
const { Animated, isNative } = (0, primitives_1.primitives)();
|
|
35
|
+
const animated = Boolean(isNative && Animated?.Value && Animated?.spring);
|
|
36
|
+
// Off-device there is no Animated; a plain ref keeps the call sites identical.
|
|
37
|
+
const value = (0, react_1.useRef)(null);
|
|
38
|
+
if (value.current === null) {
|
|
39
|
+
value.current = animated ? new Animated.Value(target) : { value: target };
|
|
40
|
+
}
|
|
41
|
+
(0, react_1.useEffect)(() => {
|
|
42
|
+
if (!animated) {
|
|
43
|
+
value.current.value = target;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const animation = Animated.spring(value.current, {
|
|
47
|
+
toValue: target,
|
|
48
|
+
...tokens_1.springs[spring],
|
|
49
|
+
useNativeDriver: false,
|
|
50
|
+
});
|
|
51
|
+
animation.start();
|
|
52
|
+
return () => animation.stop?.();
|
|
53
|
+
}, [animated, spring, target]);
|
|
54
|
+
return { value: value.current, animated };
|
|
55
|
+
}
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// React Native component resolution.
|
|
3
|
+
//
|
|
4
|
+
// The package never imports `react-native` or `react-native-svg` statically:
|
|
5
|
+
// both ship Flow-typed sources that a plain JS bundler (and the jsdom test
|
|
6
|
+
// environment) cannot parse. Resolving them at runtime keeps the package
|
|
7
|
+
// importable everywhere, matching how GlassView locates the native liquid
|
|
8
|
+
// glass module.
|
|
9
|
+
//
|
|
10
|
+
// Every component in the package builds its structure from these primitives.
|
|
11
|
+
// On a device the resolver returns React Native's own View/Text/Pressable/…
|
|
12
|
+
// and react-native-svg's elements. The DOM stand-ins further down exist only
|
|
13
|
+
// for the case where React Native is genuinely absent: a jsdom test run or a
|
|
14
|
+
// web preview. They are the single place in the package allowed to emit DOM
|
|
15
|
+
// host elements, and their whole job is translating React Native props into
|
|
16
|
+
// DOM ones.
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.measurePreviewWidth = measurePreviewWidth;
|
|
19
|
+
exports.primitives = primitives;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves the primitives, falling back to pass-through DOM elements so the
|
|
22
|
+
* package can be rendered in a non-native environment (tests, web preview)
|
|
23
|
+
* without throwing.
|
|
24
|
+
*/
|
|
25
|
+
function resolve() {
|
|
26
|
+
let rn = null;
|
|
27
|
+
let svg = null;
|
|
28
|
+
try {
|
|
29
|
+
rn = require("react-native");
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Non-native environment: the DOM stand-ins below take over.
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
svg = require("react-native-svg");
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
svg = null;
|
|
39
|
+
}
|
|
40
|
+
// On a device the SVG elements are required: the DOM <svg> stand-ins would
|
|
41
|
+
// crash in a real app ("View config not found"), so say so loudly instead of
|
|
42
|
+
// silently degrading to something that cannot run.
|
|
43
|
+
if (rn && !svg) {
|
|
44
|
+
console.error("[glacia-native] react-native-svg is required by the Glacia charts but could not be " +
|
|
45
|
+
"resolved. Install it as a dependency of your app (npx expo install react-native-svg). " +
|
|
46
|
+
"Charts will not render until it is available.");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Adapts React Native props to the DOM preview used when RN is absent.
|
|
50
|
+
* Without this, `accessibilityRole` and `onPress` reach the DOM untranslated
|
|
51
|
+
* and the element is neither reachable nor clickable in tests.
|
|
52
|
+
*/
|
|
53
|
+
const fallback = (tag) => function Primitive(props) {
|
|
54
|
+
const { children, style, accessibilityRole, accessibilityLabel, accessible, accessibilityState, accessibilityValue, onPress, numberOfLines, onChangeText, value, editable: editableProp, nativeID, disabled, keyboardType: _keyboardType, returnKeyType: _returnKeyType, onSubmitEditing: _onSubmitEditing, secureTextEntry: _secureTextEntry, autoCapitalize: _autoCapitalize, autoCorrect: _autoCorrect, multiline, onFocus: _onFocus, onBlur: _onBlur, testID,
|
|
55
|
+
// Gesture handlers from PanResponder.panHandlers are plain DOM events
|
|
56
|
+
// off-device; let them reach the element so a drag is exercisable.
|
|
57
|
+
onMouseDown, onMouseMove, onMouseUp, onMouseLeave, onLayout: _onLayout, onAccessibilityAction, accessibilityActions: _accessibilityActions, ...rest } = props ?? {};
|
|
58
|
+
const { createElement } = require("react");
|
|
59
|
+
const editable = editableProp;
|
|
60
|
+
// RN accepts unitless numbers where the DOM requires "px"; convert the
|
|
61
|
+
// length properties so the preview lays out instead of throwing.
|
|
62
|
+
const domProps = { style: toDomStyle(style), ...rest };
|
|
63
|
+
// RN roles that already exist in ARIA pass straight through.
|
|
64
|
+
const ROLE_MAP = {
|
|
65
|
+
button: "button",
|
|
66
|
+
checkbox: "checkbox",
|
|
67
|
+
radio: "radio",
|
|
68
|
+
radiogroup: "radiogroup",
|
|
69
|
+
alert: "alert",
|
|
70
|
+
text: "text",
|
|
71
|
+
link: "link",
|
|
72
|
+
image: "img",
|
|
73
|
+
tab: "tab",
|
|
74
|
+
tablist: "tablist",
|
|
75
|
+
progressbar: "progressbar",
|
|
76
|
+
switch: "switch",
|
|
77
|
+
slider: "slider",
|
|
78
|
+
adjustable: "slider",
|
|
79
|
+
heading: "heading",
|
|
80
|
+
};
|
|
81
|
+
// "none" means presentational: emit no role rather than a misleading one.
|
|
82
|
+
if (accessibilityRole && accessibilityRole !== "none") {
|
|
83
|
+
domProps.role = ROLE_MAP[accessibilityRole] ?? "text";
|
|
84
|
+
}
|
|
85
|
+
if (accessibilityLabel != null)
|
|
86
|
+
domProps["aria-label"] = accessibilityLabel;
|
|
87
|
+
// RN's `accessible` groups children into one element; a role carries the
|
|
88
|
+
// same meaning in the DOM, so it is dropped rather than emitted raw.
|
|
89
|
+
if (accessible !== undefined && !domProps.role)
|
|
90
|
+
domProps.role = "group";
|
|
91
|
+
if (numberOfLines != null)
|
|
92
|
+
domProps["data-lines"] = numberOfLines;
|
|
93
|
+
if (nativeID != null)
|
|
94
|
+
domProps.id = nativeID;
|
|
95
|
+
if (testID != null)
|
|
96
|
+
domProps["data-testid"] = testID;
|
|
97
|
+
if (accessibilityState) {
|
|
98
|
+
const state = accessibilityState;
|
|
99
|
+
if (state.checked !== undefined)
|
|
100
|
+
domProps["aria-checked"] = state.checked;
|
|
101
|
+
if (state.selected !== undefined)
|
|
102
|
+
domProps["aria-selected"] = state.selected;
|
|
103
|
+
if (state.expanded !== undefined)
|
|
104
|
+
domProps["aria-expanded"] = state.expanded;
|
|
105
|
+
if (state.disabled !== undefined)
|
|
106
|
+
domProps["aria-disabled"] = state.disabled;
|
|
107
|
+
}
|
|
108
|
+
if (accessibilityValue) {
|
|
109
|
+
const value = accessibilityValue;
|
|
110
|
+
if (value.min !== undefined)
|
|
111
|
+
domProps["aria-valuemin"] = value.min;
|
|
112
|
+
if (value.max !== undefined)
|
|
113
|
+
domProps["aria-valuemax"] = value.max;
|
|
114
|
+
if (value.now !== undefined)
|
|
115
|
+
domProps["aria-valuenow"] = value.now;
|
|
116
|
+
if (value.text !== undefined)
|
|
117
|
+
domProps["aria-valuetext"] = value.text;
|
|
118
|
+
}
|
|
119
|
+
// Inputs: bridge the RN controlled-value contract to the DOM one.
|
|
120
|
+
if (tag === "input") {
|
|
121
|
+
// A multiline field must be a real textarea: an <input> cannot wrap.
|
|
122
|
+
if (multiline) {
|
|
123
|
+
tag = "textarea";
|
|
124
|
+
if (typeof numberOfLines === "number")
|
|
125
|
+
domProps.rows = numberOfLines;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (tag === "input" || tag === "textarea") {
|
|
129
|
+
if (value != null)
|
|
130
|
+
domProps.value = value;
|
|
131
|
+
if (onChangeText) {
|
|
132
|
+
domProps.onChange = (event) => onChangeText(event.target.value);
|
|
133
|
+
}
|
|
134
|
+
if (editable === false || disabled)
|
|
135
|
+
domProps.disabled = true;
|
|
136
|
+
}
|
|
137
|
+
// Accessibility actions are React Native's; off-device they are exposed
|
|
138
|
+
// as a handler so a test can drive them, matching the role translation.
|
|
139
|
+
if (onAccessibilityAction)
|
|
140
|
+
domProps.onAccessibilityAction = onAccessibilityAction;
|
|
141
|
+
if (onMouseDown)
|
|
142
|
+
domProps.onMouseDown = onMouseDown;
|
|
143
|
+
if (onMouseMove)
|
|
144
|
+
domProps.onMouseMove = onMouseMove;
|
|
145
|
+
if (onMouseUp)
|
|
146
|
+
domProps.onMouseUp = onMouseUp;
|
|
147
|
+
if (onMouseLeave)
|
|
148
|
+
domProps.onMouseLeave = onMouseLeave;
|
|
149
|
+
if (onPress) {
|
|
150
|
+
// Any element hosting a press handler needs a DOM click to fire it.
|
|
151
|
+
domProps.onClick = onPress;
|
|
152
|
+
if (domProps.role === "button" ||
|
|
153
|
+
domProps.role === "checkbox" ||
|
|
154
|
+
domProps.role === "radio" ||
|
|
155
|
+
domProps.role === "switch" ||
|
|
156
|
+
domProps.role === "tab" ||
|
|
157
|
+
domProps.role === "slider") {
|
|
158
|
+
domProps.tabIndex = 0;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (disabled)
|
|
162
|
+
domProps["aria-disabled"] = true;
|
|
163
|
+
return createElement(tag, domProps, children);
|
|
164
|
+
};
|
|
165
|
+
/** Resolves React Native's BackHandler, or null off-device. */
|
|
166
|
+
const getBackHandler = () => rn?.BackHandler ?? null;
|
|
167
|
+
/**
|
|
168
|
+
* A Modal that only mounts its children while visible.
|
|
169
|
+
*
|
|
170
|
+
* The generic fallback would render the content regardless of `visible`,
|
|
171
|
+
* which would surface every closed dialog in the DOM preview.
|
|
172
|
+
*/
|
|
173
|
+
const modalFallback = (tag) => function Primitive(props) {
|
|
174
|
+
const { children, visible, onRequestClose: _onRequestClose, ...rest } = props ?? {};
|
|
175
|
+
if (!visible)
|
|
176
|
+
return null;
|
|
177
|
+
const { createElement } = require("react");
|
|
178
|
+
return createElement(tag, { style: toDomStyle(rest.style) }, children);
|
|
179
|
+
};
|
|
180
|
+
/** An image that reads its remote source in the DOM preview. */
|
|
181
|
+
function imageFallback(props) {
|
|
182
|
+
const { source, accessibilityLabel, style } = props ?? {};
|
|
183
|
+
const { createElement } = require("react");
|
|
184
|
+
return createElement("img", {
|
|
185
|
+
src: source?.uri,
|
|
186
|
+
alt: accessibilityLabel ?? "",
|
|
187
|
+
style: toDomStyle(style),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
const SvgComponent = svg?.default ?? fallback("svg");
|
|
191
|
+
const SvgText = svg?.Text ?? fallback("text");
|
|
192
|
+
return {
|
|
193
|
+
View: rn?.View ?? fallback("div"),
|
|
194
|
+
Text: rn?.Text ?? fallback("span"),
|
|
195
|
+
Pressable: rn?.Pressable ?? fallback("button"),
|
|
196
|
+
Svg: SvgComponent,
|
|
197
|
+
G: svg?.G ?? fallback("g"),
|
|
198
|
+
Line: svg?.Line ?? fallback("line"),
|
|
199
|
+
Path: svg?.Path ?? fallback("path"),
|
|
200
|
+
Circle: svg?.Circle ?? fallback("circle"),
|
|
201
|
+
Rect: svg?.Rect ?? fallback("rect"),
|
|
202
|
+
Polygon: svg?.Polygon ?? fallback("polygon"),
|
|
203
|
+
// TextInput is not an SVG primitive, but resolving it here keeps every
|
|
204
|
+
// component on one runtime-resolution path instead of two.
|
|
205
|
+
TextInput: rn?.TextInput ?? fallback("input"),
|
|
206
|
+
// Modal is resolved the same way so dialogs degrade to a plain overlay
|
|
207
|
+
// outside a native runtime instead of failing to mount.
|
|
208
|
+
Modal: rn?.Modal ?? modalFallback("div"),
|
|
209
|
+
Image: rn?.Image ?? imageFallback,
|
|
210
|
+
// Animated comes from the same module; off-device the shim below keeps
|
|
211
|
+
// Animated.View/Value/spring from throwing in the DOM preview.
|
|
212
|
+
Animated: rn?.Animated ?? animationShim(require("react")),
|
|
213
|
+
Easing: rn?.Easing ?? easingShim(),
|
|
214
|
+
getScrollView: () => rn?.ScrollView ?? null,
|
|
215
|
+
getBackHandler,
|
|
216
|
+
SvgText,
|
|
217
|
+
isNative: Boolean(rn?.View),
|
|
218
|
+
PanResponder: rn?.PanResponder ?? panResponderShim(),
|
|
219
|
+
useColorScheme: rn?.useColorScheme ?? null,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* A stand-in for React Native's Animated API off-device.
|
|
224
|
+
*
|
|
225
|
+
* `Animated.Value` keeps the value it was given and `spring` snaps to the
|
|
226
|
+
* target immediately, so the preview renders the settled state instead of
|
|
227
|
+
* animating against a requestAnimationFrame loop that jsdom does not drive.
|
|
228
|
+
*/
|
|
229
|
+
function animationShim(reactModule) {
|
|
230
|
+
class Value {
|
|
231
|
+
current;
|
|
232
|
+
constructor(initial) {
|
|
233
|
+
this.current = initial;
|
|
234
|
+
}
|
|
235
|
+
setValue(next) {
|
|
236
|
+
this.current = next;
|
|
237
|
+
}
|
|
238
|
+
interpolate(config) {
|
|
239
|
+
const input = config?.inputRange;
|
|
240
|
+
const output = config?.outputRange;
|
|
241
|
+
if (!input || !output || input.length !== output.length)
|
|
242
|
+
return this.current;
|
|
243
|
+
for (let i = 0; i < input.length - 1; i += 1) {
|
|
244
|
+
if (this.current <= input[i + 1]) {
|
|
245
|
+
const span = input[i + 1] - input[i] || 1;
|
|
246
|
+
const ratio = (this.current - input[i]) / span;
|
|
247
|
+
return output[i] + (output[i + 1] - output[i]) * ratio;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return output[output.length - 1];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function AnimatedView(props) {
|
|
254
|
+
const { style, children, ...rest } = props ?? {};
|
|
255
|
+
return reactModule.createElement("div", { style: toDomStyle(resolveAnimatedStyle(style)), ...rest }, children);
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
Value,
|
|
259
|
+
View: AnimatedView,
|
|
260
|
+
Text: AnimatedView,
|
|
261
|
+
spring: (value, config) => {
|
|
262
|
+
value?.setValue?.(config?.toValue ?? 0);
|
|
263
|
+
return { start: (callback) => callback?.({ finished: true }), stop: () => { } };
|
|
264
|
+
},
|
|
265
|
+
timing: (value, config) => {
|
|
266
|
+
value?.setValue?.(config?.toValue ?? 0);
|
|
267
|
+
return { start: (callback) => callback?.({ finished: true }), stop: () => { } };
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* A stand-in for React Native's PanResponder off-device.
|
|
273
|
+
*
|
|
274
|
+
* It runs the handler hooks on DOM pointer events so a drag written against
|
|
275
|
+
* PanResponder is still exercisable in the preview and in tests. On a device
|
|
276
|
+
* the resolver returns React Native's own implementation.
|
|
277
|
+
*/
|
|
278
|
+
function panResponderShim() {
|
|
279
|
+
return {
|
|
280
|
+
create: (config) => {
|
|
281
|
+
let granted = false;
|
|
282
|
+
const start = (event) => {
|
|
283
|
+
if (!config?.onStartShouldSetPanResponder?.(event, gesture(event)))
|
|
284
|
+
return;
|
|
285
|
+
granted = true;
|
|
286
|
+
config?.onPanResponderGrant?.(event, gesture(event));
|
|
287
|
+
};
|
|
288
|
+
const move = (event) => {
|
|
289
|
+
if (!granted) {
|
|
290
|
+
if (!config?.onMoveShouldSetPanResponder?.(event, gesture(event)))
|
|
291
|
+
return;
|
|
292
|
+
granted = true;
|
|
293
|
+
config?.onPanResponderGrant?.(event, gesture(event));
|
|
294
|
+
}
|
|
295
|
+
config?.onPanResponderMove?.(event, gesture(event));
|
|
296
|
+
};
|
|
297
|
+
const end = (event) => {
|
|
298
|
+
if (!granted)
|
|
299
|
+
return;
|
|
300
|
+
granted = false;
|
|
301
|
+
config?.onPanResponderRelease?.(event, gesture(event));
|
|
302
|
+
};
|
|
303
|
+
return {
|
|
304
|
+
panHandlers: {
|
|
305
|
+
onMouseDown: start,
|
|
306
|
+
onMouseMove: move,
|
|
307
|
+
onMouseUp: end,
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
/** Reads a touch position the way React Native's gesture object does. */
|
|
314
|
+
function gesture(event) {
|
|
315
|
+
const target = event?.currentTarget;
|
|
316
|
+
const rect = target?.getBoundingClientRect?.();
|
|
317
|
+
const x = event?.clientX ?? 0;
|
|
318
|
+
const y = event?.clientY ?? 0;
|
|
319
|
+
const locationX = rect ? x - rect.left : x;
|
|
320
|
+
const locationY = rect ? y - rect.top : y;
|
|
321
|
+
if (event && !event.nativeEvent) {
|
|
322
|
+
event.nativeEvent = { locationX, locationY, pageX: x, pageY: y };
|
|
323
|
+
}
|
|
324
|
+
return { dx: 0, dy: 0, moveX: x, moveY: y, x0: x, y0: y, vx: 0, vy: 0 };
|
|
325
|
+
}
|
|
326
|
+
/** Stand-in for React Native's Easing curves. */
|
|
327
|
+
function easingShim() {
|
|
328
|
+
const identity = (t) => t;
|
|
329
|
+
return {
|
|
330
|
+
out: (fn) => fn,
|
|
331
|
+
inOut: (fn) => fn,
|
|
332
|
+
linear: identity,
|
|
333
|
+
ease: identity,
|
|
334
|
+
quad: identity,
|
|
335
|
+
bezier: () => identity,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
/** Reads a style value that may be an Animated.Value after the shim resolved it. */
|
|
339
|
+
function resolveAnimatedStyle(style) {
|
|
340
|
+
if (!style)
|
|
341
|
+
return style;
|
|
342
|
+
const list = Array.isArray(style) ? style : [style];
|
|
343
|
+
const merged = {};
|
|
344
|
+
for (const entry of list) {
|
|
345
|
+
if (!entry)
|
|
346
|
+
continue;
|
|
347
|
+
Object.assign(merged, entry);
|
|
348
|
+
}
|
|
349
|
+
return merged;
|
|
350
|
+
}
|
|
351
|
+
const LENGTH_PROPS = new Set([
|
|
352
|
+
"width",
|
|
353
|
+
"height",
|
|
354
|
+
"top",
|
|
355
|
+
"left",
|
|
356
|
+
"right",
|
|
357
|
+
"bottom",
|
|
358
|
+
"marginTop",
|
|
359
|
+
"marginBottom",
|
|
360
|
+
"marginLeft",
|
|
361
|
+
"marginRight",
|
|
362
|
+
"paddingTop",
|
|
363
|
+
"paddingBottom",
|
|
364
|
+
"paddingLeft",
|
|
365
|
+
"paddingRight",
|
|
366
|
+
"fontSize",
|
|
367
|
+
"borderRadius",
|
|
368
|
+
"gap",
|
|
369
|
+
]);
|
|
370
|
+
/** Converts an RN style object to DOM-compatible CSS. */
|
|
371
|
+
function toDomStyle(style) {
|
|
372
|
+
if (!style)
|
|
373
|
+
return style;
|
|
374
|
+
const list = Array.isArray(style) ? style : [style];
|
|
375
|
+
const merged = {};
|
|
376
|
+
for (const entry of list) {
|
|
377
|
+
if (!entry)
|
|
378
|
+
continue;
|
|
379
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
380
|
+
if (value == null)
|
|
381
|
+
continue;
|
|
382
|
+
// Animated values resolve to plain numbers off-device.
|
|
383
|
+
const resolved = typeof value?.interpolate === "function" ? value.__getValue?.() : value;
|
|
384
|
+
merged[key] =
|
|
385
|
+
typeof resolved === "number" && LENGTH_PROPS.has(key) ? `${resolved}px` : resolved;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return merged;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Records an element's width for gesture maths when the environment has no
|
|
392
|
+
* layout events (the DOM preview). A device never needs it: React Native
|
|
393
|
+
* reports width through `onLayout`.
|
|
394
|
+
*/
|
|
395
|
+
function measurePreviewWidth(node, widthRef) {
|
|
396
|
+
if (!node || typeof node.getBoundingClientRect !== "function")
|
|
397
|
+
return;
|
|
398
|
+
const width = node.getBoundingClientRect().width;
|
|
399
|
+
if (width > 0)
|
|
400
|
+
widthRef.current = width;
|
|
401
|
+
}
|
|
402
|
+
let cache = null;
|
|
403
|
+
/** The resolved primitives, computed once per process. */
|
|
404
|
+
function primitives() {
|
|
405
|
+
if (!cache)
|
|
406
|
+
cache = resolve();
|
|
407
|
+
return cache;
|
|
408
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
2
3
|
export interface ButtonProps {
|
|
3
4
|
variant?: "glass" | "filled" | "ghost";
|
|
4
5
|
size?: "sm" | "md" | "lg";
|
|
@@ -7,8 +8,17 @@ export interface ButtonProps {
|
|
|
7
8
|
accessibilityLabel: string;
|
|
8
9
|
icon?: ReactNode;
|
|
9
10
|
children?: ReactNode;
|
|
10
|
-
style?:
|
|
11
|
+
style?: StyleProp<ViewStyle>;
|
|
11
12
|
tint?: string;
|
|
12
13
|
isDark?: boolean;
|
|
14
|
+
/** Passed through to the pressable root so the button is testable. */
|
|
15
|
+
testID?: string;
|
|
13
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* A pressable button on Glacia's glass.
|
|
19
|
+
*
|
|
20
|
+
* The root is a Pressable so it gets the platform's own press semantics
|
|
21
|
+
* (focus, screen-reader activation, pressed feedback) while the material —
|
|
22
|
+
* Apple's glass on iOS 26+, Glacia's tint elsewhere — comes from `Glass`.
|
|
23
|
+
*/
|
|
14
24
|
export declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<any>>;
|
package/lib/typescript/Card.d.ts
CHANGED
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
2
3
|
export interface CardProps {
|
|
3
4
|
effect?: "clear" | "regular" | "none";
|
|
4
|
-
style?:
|
|
5
|
+
style?: StyleProp<ViewStyle>;
|
|
5
6
|
children?: ReactNode;
|
|
6
7
|
isDark?: boolean;
|
|
8
|
+
/** Passed through to the card's glass so it is testable. */
|
|
9
|
+
testID?: string;
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* A content panel on Glacia's glass: Apple's material on iOS 26+, Glacia's
|
|
13
|
+
* tint elsewhere. The padding, radius and stacking are ours on every platform.
|
|
14
|
+
*/
|
|
8
15
|
export declare const Card: import("react").ForwardRefExoticComponent<CardProps & import("react").RefAttributes<any>>;
|
|
16
|
+
/** The block holding a card's title and description. */
|
|
9
17
|
export declare function CardHeader({ style, children, ...props }: {
|
|
10
|
-
style?:
|
|
18
|
+
style?: StyleProp<ViewStyle>;
|
|
11
19
|
children?: ReactNode;
|
|
12
20
|
}): import("react").JSX.Element;
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
/** A card's heading, announced as a heading by screen readers. */
|
|
22
|
+
export declare function CardTitle({ style, children, isDark: isDarkProp, ...props }: {
|
|
23
|
+
style?: StyleProp<TextStyle>;
|
|
15
24
|
children?: ReactNode;
|
|
16
25
|
isDark?: boolean;
|
|
17
26
|
}): import("react").JSX.Element;
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
/** Supporting text under a card's title. */
|
|
28
|
+
export declare function CardDescription({ style, children, isDark: isDarkProp, ...props }: {
|
|
29
|
+
style?: StyleProp<TextStyle>;
|
|
20
30
|
children?: ReactNode;
|
|
21
31
|
isDark?: boolean;
|
|
22
32
|
}): import("react").JSX.Element;
|
|
33
|
+
/** The card's body. */
|
|
23
34
|
export declare function CardContent({ style, children, ...props }: {
|
|
24
|
-
style?:
|
|
35
|
+
style?: StyleProp<ViewStyle>;
|
|
25
36
|
children?: ReactNode;
|
|
26
37
|
}): import("react").JSX.Element;
|
|
27
38
|
export declare const CardBody: typeof CardContent;
|
|
39
|
+
/** The card's action row. */
|
|
28
40
|
export declare function CardFooter({ style, children, ...props }: {
|
|
29
|
-
style?:
|
|
41
|
+
style?: StyleProp<ViewStyle>;
|
|
30
42
|
children?: ReactNode;
|
|
31
43
|
}): import("react").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
2
3
|
export interface DialogProps {
|
|
3
|
-
/** Controlled visibility. Omit
|
|
4
|
+
/** Controlled visibility. Omit it and the dialog keeps its own state. */
|
|
4
5
|
open?: boolean;
|
|
5
6
|
onOpenChange?: (open: boolean) => void;
|
|
6
7
|
title?: string;
|
|
@@ -10,17 +11,25 @@ export interface DialogProps {
|
|
|
10
11
|
/** Tapping the backdrop dismisses. Off for destructive confirmations. */
|
|
11
12
|
dismissOnBackdropPress?: boolean;
|
|
12
13
|
isDark?: boolean;
|
|
13
|
-
style?:
|
|
14
|
+
style?: StyleProp<ViewStyle>;
|
|
15
|
+
/** Passed through to the dialog panel so it is testable. */
|
|
16
|
+
testID?: string;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
|
-
* A centred modal
|
|
19
|
+
* A centred modal panel above a dimmed backdrop.
|
|
20
|
+
*
|
|
21
|
+
* The panel is a glass surface, so it is Apple's real Liquid Glass on iOS 26+
|
|
22
|
+
* and Glacia's translucent tint elsewhere; the text sits on it with the
|
|
23
|
+
* theme's foreground colour, so contrast holds either way.
|
|
17
24
|
*
|
|
18
25
|
* React Native has no built-in focus trap, so this component covers what the
|
|
19
26
|
* platform can actually do: `Modal` blocks touches behind it, Android's back
|
|
20
27
|
* button routes to `onOpenChange(false)`, and the heading is marked as such so
|
|
21
28
|
* screen readers announce the dialog as it appears.
|
|
29
|
+
*
|
|
30
|
+
* To open a dialog from a button, use `DialogTrigger`.
|
|
22
31
|
*/
|
|
23
|
-
export declare function Dialog({ open: controlledOpen, onOpenChange, title, description, children, footer, dismissOnBackdropPress, isDark, style, }: DialogProps): import("react").JSX.Element;
|
|
32
|
+
export declare function Dialog({ open: controlledOpen, onOpenChange, title, description, children, footer, dismissOnBackdropPress, isDark: isDarkProp, style, testID, }: DialogProps): import("react").JSX.Element;
|
|
24
33
|
/** Opens the dialog without the caller tracking state. */
|
|
25
34
|
export declare function DialogTrigger({ label, children, ...dialogProps }: Omit<DialogProps, "open" | "onOpenChange"> & {
|
|
26
35
|
label: string;
|
|
@@ -38,6 +47,8 @@ export interface AlertDialogProps {
|
|
|
38
47
|
onConfirm?: () => void;
|
|
39
48
|
onCancel?: () => void;
|
|
40
49
|
isDark?: boolean;
|
|
50
|
+
/** Passed through to the dialog panel so it is testable. */
|
|
51
|
+
testID?: string;
|
|
41
52
|
}
|
|
42
53
|
/**
|
|
43
54
|
* A dialog that asks for confirmation.
|
|
@@ -46,7 +57,7 @@ export interface AlertDialogProps {
|
|
|
46
57
|
* should require a real answer, so the only ways out are the two buttons or the
|
|
47
58
|
* Android back button, which counts as cancel.
|
|
48
59
|
*/
|
|
49
|
-
export declare function AlertDialog({ open: controlledOpen, onOpenChange, title, description, confirmLabel, cancelLabel, destructive, onConfirm, onCancel, isDark, }: AlertDialogProps): import("react").JSX.Element;
|
|
60
|
+
export declare function AlertDialog({ open: controlledOpen, onOpenChange, title, description, confirmLabel, cancelLabel, destructive, onConfirm, onCancel, isDark: isDarkProp, testID, }: AlertDialogProps): import("react").JSX.Element;
|
|
50
61
|
export interface ActionSheetOption {
|
|
51
62
|
label: string;
|
|
52
63
|
/** Tints the row destructive, for delete actions. */
|
|
@@ -61,6 +72,8 @@ export interface ActionSheetProps {
|
|
|
61
72
|
options: ActionSheetOption[];
|
|
62
73
|
cancelLabel?: string;
|
|
63
74
|
isDark?: boolean;
|
|
75
|
+
/** Passed through to the sheet so it is testable. */
|
|
76
|
+
testID?: string;
|
|
64
77
|
}
|
|
65
78
|
/**
|
|
66
79
|
* A list of choices attached to the bottom of the screen.
|
|
@@ -68,4 +81,4 @@ export interface ActionSheetProps {
|
|
|
68
81
|
* Anchored to the bottom because that is where a thumb reaches, and it keeps a
|
|
69
82
|
* separate Cancel row so a mis-tap is always reversible.
|
|
70
83
|
*/
|
|
71
|
-
export declare function ActionSheet({ open: controlledOpen, onOpenChange, title, message, options, cancelLabel, isDark, }: ActionSheetProps): import("react").JSX.Element;
|
|
84
|
+
export declare function ActionSheet({ open: controlledOpen, onOpenChange, title, message, options, cancelLabel, isDark: isDarkProp, testID, }: ActionSheetProps): import("react").JSX.Element;
|