glacia-native 0.3.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/Bars.js +176 -0
- package/lib/module/Button.js +15 -2
- package/lib/module/Card.js +29 -14
- package/lib/module/Carousel.js +103 -0
- package/lib/module/Dialog.js +43 -32
- package/lib/module/Display.js +240 -0
- package/lib/module/Feedback.js +172 -0
- package/lib/module/Form.js +51 -12
- package/lib/module/Forms2.js +227 -0
- package/lib/module/Glass.js +11 -2
- package/lib/module/Input.js +19 -7
- package/lib/module/Overlays.js +166 -0
- package/lib/module/Pickers.js +243 -0
- 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/Text.js +37 -0
- 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/index.js +58 -1
- package/lib/module/internal/GlassView.js +31 -17
- 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 +413 -0
- package/lib/module/internal/tokens.js +55 -1
- package/lib/typescript/Bars.d.ts +121 -0
- package/lib/typescript/Button.d.ts +11 -1
- package/lib/typescript/Card.d.ts +20 -8
- package/lib/typescript/Carousel.d.ts +47 -0
- package/lib/typescript/Dialog.d.ts +19 -6
- package/lib/typescript/Display.d.ts +119 -0
- package/lib/typescript/Feedback.d.ts +138 -0
- package/lib/typescript/Form.d.ts +27 -11
- package/lib/typescript/Forms2.d.ts +128 -0
- package/lib/typescript/Glass.d.ts +10 -1
- package/lib/typescript/Input.d.ts +11 -1
- package/lib/typescript/Overlays.d.ts +105 -0
- package/lib/typescript/Pickers.d.ts +105 -0
- 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/Text.d.ts +28 -0
- 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/index.d.ts +9 -1
- package/lib/typescript/internal/GlassView.d.ts +21 -4
- 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/lib/typescript/internal/tokens.d.ts +61 -0
- package/package.json +2 -2
- package/src/Bars.tsx +570 -0
- package/src/Button.tsx +47 -22
- package/src/Card.tsx +52 -31
- package/src/Carousel.tsx +233 -0
- package/src/Dialog.tsx +99 -64
- package/src/Display.tsx +550 -0
- package/src/Feedback.tsx +579 -0
- package/src/Form.tsx +90 -25
- package/src/Forms2.tsx +608 -0
- package/src/Glass.tsx +24 -1
- package/src/Input.tsx +33 -12
- package/src/Overlays.tsx +474 -0
- package/src/Pickers.tsx +590 -0
- 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/Text.tsx +83 -0
- 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/index.ts +101 -1
- package/src/internal/GlassView.tsx +51 -19
- 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 +482 -0
- package/src/internal/tokens.ts +62 -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
package/lib/module/TabBar.js
CHANGED
|
@@ -5,43 +5,81 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const Glass_1 = require("./Glass");
|
|
7
7
|
const tokens_1 = require("./internal/tokens");
|
|
8
|
-
|
|
8
|
+
const primitives_1 = require("./internal/primitives");
|
|
9
|
+
const motion_1 = require("./internal/motion");
|
|
10
|
+
const BAR_HEIGHT = 52;
|
|
11
|
+
/**
|
|
12
|
+
* The bottom bar of an app: a row of tabs on one glass surface.
|
|
13
|
+
*
|
|
14
|
+
* The platform rule is the point of this component. On iOS 26+ the surface is
|
|
15
|
+
* Apple's real Liquid Glass (`UIGlassEffect` via `@callstack/liquid-glass`)
|
|
16
|
+
* with Glacia's own items inside it; on older iOS and on Android it is
|
|
17
|
+
* Glacia's bar. The items are always our Pressables and Texts — no native tab
|
|
18
|
+
* bar is used on any platform.
|
|
19
|
+
*/
|
|
20
|
+
exports.TabBar = (0, react_1.forwardRef)(function TabBar({ items, activeId: activeProp, defaultActiveId, onTabChange, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
21
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
22
|
+
const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
23
|
+
const { View, Text, Pressable, Animated } = (0, primitives_1.primitives)();
|
|
9
24
|
const [internalId, setInternalId] = (0, react_1.useState)(defaultActiveId || items[0]?.id || "");
|
|
10
25
|
const activeId = activeProp !== undefined ? activeProp : internalId;
|
|
11
|
-
const
|
|
26
|
+
const activeIndex = Math.max(0, items.findIndex((item) => item.id === activeId));
|
|
27
|
+
// The active wash slides between equally wide items on the springs token.
|
|
28
|
+
const { value: slide, animated } = (0, motion_1.useSpring)(activeIndex, "snappy");
|
|
12
29
|
const handleSelect = (id) => {
|
|
13
|
-
if (activeProp === undefined)
|
|
30
|
+
if (activeProp === undefined)
|
|
14
31
|
setInternalId(id);
|
|
15
|
-
}
|
|
16
32
|
onTabChange?.(id);
|
|
17
33
|
};
|
|
18
34
|
const barStyle = {
|
|
19
|
-
position: "relative",
|
|
20
|
-
display: "flex",
|
|
21
35
|
flexDirection: "row",
|
|
22
36
|
alignItems: "center",
|
|
23
37
|
justifyContent: "space-around",
|
|
24
|
-
height:
|
|
38
|
+
height: BAR_HEIGHT,
|
|
25
39
|
paddingHorizontal: 8,
|
|
26
40
|
borderRadius: tokens_1.radii.xl,
|
|
27
41
|
...style,
|
|
28
42
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const count = Math.max(items.length, 1);
|
|
44
|
+
const itemWidth = `${100 / count}%`;
|
|
45
|
+
const indicatorStyle = {
|
|
46
|
+
position: "absolute",
|
|
47
|
+
top: 6,
|
|
48
|
+
bottom: 6,
|
|
49
|
+
left: 8,
|
|
50
|
+
width: itemWidth,
|
|
51
|
+
borderRadius: tokens_1.radii.lg,
|
|
52
|
+
backgroundColor: themeColors.glassActive,
|
|
53
|
+
opacity: 0.75,
|
|
54
|
+
};
|
|
55
|
+
return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, style: barStyle, testID: testID, ...props, children: [animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { pointerEvents: "none", style: {
|
|
56
|
+
...indicatorStyle,
|
|
57
|
+
transform: [
|
|
58
|
+
{
|
|
59
|
+
translateX: slide.interpolate({
|
|
60
|
+
inputRange: [0, Math.max(count - 1, 1)],
|
|
61
|
+
outputRange: [
|
|
62
|
+
"0%",
|
|
63
|
+
`${((count - 1) * 100) / count}%`,
|
|
64
|
+
],
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
} })) : ((0, jsx_runtime_1.jsx)(View, { pointerEvents: "none", style: { ...indicatorStyle, left: `${(activeIndex * 100) / count}%` } })), items.map((tab) => {
|
|
69
|
+
const isActive = tab.id === activeId;
|
|
70
|
+
return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "tab", accessibilityLabel: tab.label, accessibilityState: { selected: isActive }, onPress: () => handleSelect(tab.id), style: {
|
|
71
|
+
flex: 1,
|
|
72
|
+
height: "100%",
|
|
73
|
+
flexDirection: "column",
|
|
74
|
+
alignItems: "center",
|
|
75
|
+
justifyContent: "center",
|
|
76
|
+
gap: 2,
|
|
77
|
+
paddingHorizontal: 8,
|
|
78
|
+
paddingVertical: 4,
|
|
79
|
+
}, children: [tab.icon ?? null, (0, jsx_runtime_1.jsx)(Text, { numberOfLines: 1, style: {
|
|
80
|
+
fontSize: 11,
|
|
81
|
+
fontWeight: isActive ? "600" : "500",
|
|
82
|
+
color: isActive ? themeColors.fill : themeColors.muted,
|
|
83
|
+
}, children: tab.label })] }, tab.id));
|
|
84
|
+
})] }));
|
|
47
85
|
});
|
package/lib/module/Table.js
CHANGED
|
@@ -4,7 +4,8 @@ exports.NativeTable = NativeTable;
|
|
|
4
4
|
exports.NativeScrollArea = NativeScrollArea;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const tokens_1 = require("./internal/tokens");
|
|
7
|
-
const primitives_1 = require("./
|
|
7
|
+
const primitives_1 = require("./internal/primitives");
|
|
8
|
+
const motion_1 = require("./internal/motion");
|
|
8
9
|
/**
|
|
9
10
|
* Tabular data laid out for a phone.
|
|
10
11
|
*
|
|
@@ -13,7 +14,8 @@ const primitives_1 = require("./charts/primitives");
|
|
|
13
14
|
* are laid out as labelled pairs beneath it, which keeps every value readable
|
|
14
15
|
* without horizontal scrolling.
|
|
15
16
|
*/
|
|
16
|
-
function NativeTable({ columns, rows, onRowPress, caption, isDark
|
|
17
|
+
function NativeTable({ columns, rows, onRowPress, caption, isDark: isDarkProp, style, emptyMessage = "No rows to display", testID, }) {
|
|
18
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
17
19
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
18
20
|
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
19
21
|
if (rows.length === 0) {
|
|
@@ -23,12 +25,12 @@ function NativeTable({ columns, rows, onRowPress, caption, isDark = false, style
|
|
|
23
25
|
const primaryKey = columns.find((column) => column.primary)?.key ?? columns[0]?.key;
|
|
24
26
|
const primaryColumn = columns.find((column) => column.key === primaryKey);
|
|
25
27
|
const detailColumns = columns.filter((column) => column.key !== primaryKey);
|
|
26
|
-
return ((0, jsx_runtime_1.jsxs)(View, { style: style, children: [caption && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: theme.muted, marginBottom: 8 }, children: caption })), rows.map((row) => {
|
|
28
|
+
return ((0, jsx_runtime_1.jsxs)(View, { style: style, testID: testID, children: [caption && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: theme.muted, marginBottom: 8 }, children: caption })), rows.map((row) => {
|
|
27
29
|
const RowWrapper = onRowPress ? Pressable : View;
|
|
28
30
|
const wrapperProps = onRowPress
|
|
29
31
|
? {
|
|
30
32
|
accessibilityRole: "button",
|
|
31
|
-
accessibilityLabel:
|
|
33
|
+
accessibilityLabel: rowAccessibilityLabel(row, primaryKey),
|
|
32
34
|
onPress: () => onRowPress(row),
|
|
33
35
|
}
|
|
34
36
|
: { accessibilityRole: "text" };
|
|
@@ -53,6 +55,21 @@ function NativeTable({ columns, rows, onRowPress, caption, isDark = false, style
|
|
|
53
55
|
}, children: row.cells[column.key] ?? "" })] }, column.key))) }))] }, row.id));
|
|
54
56
|
})] }));
|
|
55
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* What screen readers announce for a pressable row.
|
|
60
|
+
*
|
|
61
|
+
* A cell can be any element, and `String(cell)` of an element announces
|
|
62
|
+
* "[object Object]". So: an explicit row label wins, then a textual primary
|
|
63
|
+
* cell, then a neutral fallback.
|
|
64
|
+
*/
|
|
65
|
+
function rowAccessibilityLabel(row, primaryKey) {
|
|
66
|
+
if (row.accessibilityLabel)
|
|
67
|
+
return row.accessibilityLabel;
|
|
68
|
+
const primary = primaryKey ? row.cells[primaryKey] : undefined;
|
|
69
|
+
if (typeof primary === "string" || typeof primary === "number")
|
|
70
|
+
return String(primary);
|
|
71
|
+
return "Row";
|
|
72
|
+
}
|
|
56
73
|
/**
|
|
57
74
|
* A bounded scroll region.
|
|
58
75
|
*
|
|
@@ -60,7 +77,8 @@ function NativeTable({ columns, rows, onRowPress, caption, isDark = false, style
|
|
|
60
77
|
* scroll indicator is the one users already recognise, and it stays correct
|
|
61
78
|
* under momentum, bouncing and accessibility settings.
|
|
62
79
|
*/
|
|
63
|
-
function NativeScrollArea({ children, maxHeight, bordered = false, horizontal = false, isDark
|
|
80
|
+
function NativeScrollArea({ children, maxHeight, bordered = false, horizontal = false, isDark: isDarkProp, style, accessibilityLabel, }) {
|
|
81
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
64
82
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
65
83
|
const { View, getScrollView } = (0, primitives_1.primitives)();
|
|
66
84
|
const ScrollView = getScrollView();
|
|
@@ -75,7 +93,7 @@ function NativeScrollArea({ children, maxHeight, bordered = false, horizontal =
|
|
|
75
93
|
if (!ScrollView) {
|
|
76
94
|
// Off-device there is no ScrollView; render the content in a clipped box so
|
|
77
95
|
// layout still matches instead of dropping children.
|
|
78
|
-
return ((0, jsx_runtime_1.jsx)(View, { accessibilityLabel: accessibilityLabel, style:
|
|
96
|
+
return ((0, jsx_runtime_1.jsx)(View, { accessibilityLabel: accessibilityLabel, style: containerStyle, children: children }));
|
|
79
97
|
}
|
|
80
98
|
return ((0, jsx_runtime_1.jsx)(View, { style: containerStyle, children: (0, jsx_runtime_1.jsx)(ScrollView, { horizontal: horizontal, showsVerticalScrollIndicator: true, showsHorizontalScrollIndicator: horizontal, accessibilityLabel: accessibilityLabel, children: children }) }));
|
|
81
99
|
}
|
package/lib/module/Tabs.js
CHANGED
|
@@ -5,55 +5,77 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const Glass_1 = require("./Glass");
|
|
7
7
|
const tokens_1 = require("./internal/tokens");
|
|
8
|
+
const primitives_1 = require("./internal/primitives");
|
|
9
|
+
const motion_1 = require("./internal/motion");
|
|
8
10
|
/**
|
|
9
11
|
* A row of tabs on a glass rail, in the reference implementation's style: the
|
|
10
12
|
* selected tab is a lifted inner pane rather than a flat highlight.
|
|
11
13
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Same conventions as every other component here — React Native primitives
|
|
15
|
+
* only, no browser APIs. The rail is Apple's real glass on iOS 26+ and
|
|
16
|
+
* Glacia's translucent fallback of the same shape on older iOS and Android, so
|
|
17
|
+
* the layout never shifts between platforms.
|
|
16
18
|
*/
|
|
17
|
-
exports.Tabs = (0, react_1.forwardRef)(function Tabs({ items, activeId: activeProp, defaultActiveId, onTabChange, style, isDark
|
|
19
|
+
exports.Tabs = (0, react_1.forwardRef)(function Tabs({ items, activeId: activeProp, defaultActiveId, onTabChange, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
20
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
21
|
+
const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
22
|
+
const { View, Text, Pressable, Animated } = (0, primitives_1.primitives)();
|
|
18
23
|
const [internalId, setInternalId] = (0, react_1.useState)(defaultActiveId || items[0]?.id || "");
|
|
19
24
|
const activeId = activeProp !== undefined ? activeProp : internalId;
|
|
20
|
-
const
|
|
25
|
+
const activeIndex = Math.max(0, items.findIndex((tab) => tab.id === activeId));
|
|
26
|
+
const { value: slide, animated } = (0, motion_1.useSpring)(activeIndex, "snappy");
|
|
21
27
|
const handleSelect = (id) => {
|
|
22
28
|
if (activeProp === undefined)
|
|
23
29
|
setInternalId(id);
|
|
24
30
|
onTabChange?.(id);
|
|
25
31
|
};
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
const count = Math.max(items.length, 1);
|
|
33
|
+
const itemWidth = `${100 / count}%`;
|
|
34
|
+
// The selection is a lens, not a fill: a lifted pane on the rail.
|
|
35
|
+
const paneStyle = {
|
|
36
|
+
position: "absolute",
|
|
37
|
+
top: 4,
|
|
38
|
+
bottom: 4,
|
|
39
|
+
left: 4,
|
|
40
|
+
width: itemWidth,
|
|
41
|
+
borderRadius: tokens_1.radii.pill,
|
|
42
|
+
backgroundColor: isDark ? "rgba(255,255,255,0.16)" : "rgba(255,255,255,0.72)",
|
|
43
|
+
borderWidth: 0.5,
|
|
44
|
+
borderColor: themeColors.edge,
|
|
45
|
+
};
|
|
46
|
+
return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { ref: ref, effect: "regular", isDark: isDark, style: {
|
|
28
47
|
flexDirection: "row",
|
|
29
48
|
alignItems: "center",
|
|
49
|
+
alignSelf: "flex-start",
|
|
30
50
|
gap: 2,
|
|
31
51
|
padding: 4,
|
|
32
52
|
borderRadius: tokens_1.radii.pill,
|
|
33
53
|
...style,
|
|
34
|
-
}, ...props, children:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
: "
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
}, testID: testID, ...props, children: [animated ? ((0, jsx_runtime_1.jsx)(Animated.View, { pointerEvents: "none", style: {
|
|
55
|
+
...paneStyle,
|
|
56
|
+
transform: [
|
|
57
|
+
{
|
|
58
|
+
translateX: slide.interpolate({
|
|
59
|
+
inputRange: [0, Math.max(count - 1, 1)],
|
|
60
|
+
outputRange: ["0%", `${((count - 1) * 100) / count}%`],
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
} })) : ((0, jsx_runtime_1.jsx)(View, { pointerEvents: "none", style: { ...paneStyle, left: `${(activeIndex * 100) / count}%` } })), items.map((tab) => {
|
|
65
|
+
const isActive = tab.id === activeId;
|
|
66
|
+
return ((0, jsx_runtime_1.jsxs)(Pressable, { accessibilityRole: "tab", accessibilityLabel: tab.label, accessibilityState: { selected: isActive }, onPress: () => handleSelect(tab.id), style: {
|
|
67
|
+
flex: 1,
|
|
68
|
+
height: 36,
|
|
69
|
+
flexDirection: "row",
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
justifyContent: "center",
|
|
72
|
+
gap: 6,
|
|
73
|
+
paddingHorizontal: 12,
|
|
74
|
+
borderRadius: tokens_1.radii.pill,
|
|
75
|
+
}, children: [tab.icon ?? null, (0, jsx_runtime_1.jsx)(Text, { numberOfLines: 1, style: {
|
|
76
|
+
fontSize: 13,
|
|
77
|
+
fontWeight: isActive ? "600" : "500",
|
|
78
|
+
color: isActive ? themeColors.foreground : themeColors.muted,
|
|
79
|
+
}, children: tab.label })] }, tab.id));
|
|
80
|
+
})] }));
|
|
59
81
|
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Text = 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
|
+
/** The accessibility role each variant announces. */
|
|
10
|
+
const roles = {
|
|
11
|
+
title: "heading",
|
|
12
|
+
heading: "heading",
|
|
13
|
+
body: "text",
|
|
14
|
+
caption: "text",
|
|
15
|
+
label: "text",
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Themed text.
|
|
19
|
+
*
|
|
20
|
+
* Every Glacia component that renders words uses this, so type, colour and
|
|
21
|
+
* contrast come from one place. It wraps the resolver's `Text`, which is React
|
|
22
|
+
* Native's own on a device.
|
|
23
|
+
*/
|
|
24
|
+
exports.Text = (0, react_1.forwardRef)(function Text({ variant = "body", muted = false, destructive = false, numberOfLines, children, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
25
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
26
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
27
|
+
const { Text: RNText } = (0, primitives_1.primitives)();
|
|
28
|
+
const scale = tokens_1.typeScale[variant];
|
|
29
|
+
const textStyle = {
|
|
30
|
+
fontSize: scale.fontSize,
|
|
31
|
+
lineHeight: scale.lineHeight,
|
|
32
|
+
fontWeight: scale.fontWeight,
|
|
33
|
+
color: destructive ? theme.destructive : muted ? theme.muted : theme.foreground,
|
|
34
|
+
...style,
|
|
35
|
+
};
|
|
36
|
+
return ((0, jsx_runtime_1.jsx)(RNText, { ref: ref, testID: testID, accessibilityRole: roles[variant], numberOfLines: numberOfLines, style: textStyle, ...props, children: children }));
|
|
37
|
+
});
|
package/lib/module/ai.js
CHANGED
|
@@ -12,14 +12,16 @@ exports.NativeImageGeneration = NativeImageGeneration;
|
|
|
12
12
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
13
|
const react_1 = require("react");
|
|
14
14
|
const tokens_1 = require("./internal/tokens");
|
|
15
|
-
const primitives_1 = require("./
|
|
15
|
+
const primitives_1 = require("./internal/primitives");
|
|
16
|
+
const motion_1 = require("./internal/motion");
|
|
16
17
|
/**
|
|
17
18
|
* The ordered steps a model intends to take.
|
|
18
19
|
*
|
|
19
20
|
* Each step carries its own status, so a half-finished plan is legible instead
|
|
20
21
|
* of appearing blank until the whole thing completes.
|
|
21
22
|
*/
|
|
22
|
-
function NativePlan({ title = "Plan", steps, isDark
|
|
23
|
+
function NativePlan({ title = "Plan", steps, isDark: isDarkProp, style }) {
|
|
24
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
23
25
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
24
26
|
const { View, Text } = (0, primitives_1.primitives)();
|
|
25
27
|
const done = steps.filter((step) => step.status === "done").length;
|
|
@@ -56,7 +58,8 @@ function NativePlan({ title = "Plan", steps, isDark = false, style }) {
|
|
|
56
58
|
* Native has no anchor element, so a row hands the source to the caller's
|
|
57
59
|
* `onSourcePress` instead of opening a browser the component cannot control.
|
|
58
60
|
*/
|
|
59
|
-
function NativeSources({ sources, title = "Sources", isDark
|
|
61
|
+
function NativeSources({ sources, title = "Sources", isDark: isDarkProp, style, onSourcePress, }) {
|
|
62
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
60
63
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
61
64
|
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
62
65
|
if (sources.length === 0)
|
|
@@ -78,7 +81,8 @@ function NativeSources({ sources, title = "Sources", isDark = false, style, onSo
|
|
|
78
81
|
* The caller owns the streaming clock (usually a network stream); this only
|
|
79
82
|
* renders the first `revealed` characters and shows a caret while incomplete.
|
|
80
83
|
*/
|
|
81
|
-
function NativeResponse({ text, revealed, streaming, isDark
|
|
84
|
+
function NativeResponse({ text, revealed, streaming, isDark: isDarkProp, style, }) {
|
|
85
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
82
86
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
83
87
|
const { View, Text } = (0, primitives_1.primitives)();
|
|
84
88
|
const shown = revealed == null ? text : text.slice(0, Math.max(0, revealed));
|
|
@@ -86,13 +90,17 @@ function NativeResponse({ text, revealed, streaming, isDark = false, style, }) {
|
|
|
86
90
|
return ((0, jsx_runtime_1.jsxs)(View, { style: style, children: [(0, jsx_runtime_1.jsxs)(Text, { accessibilityRole: "text", accessibilityLabel: shown, style: { fontSize: 14, lineHeight: 21, color: theme.foreground }, children: [shown, isStreaming ? "▍" : ""] }), (0, jsx_runtime_1.jsx)(Text, { accessibilityRole: "alert", style: { height: 0, opacity: 0, fontSize: 0 }, children: isStreaming ? "Response streaming" : "Response complete" })] }));
|
|
87
91
|
}
|
|
88
92
|
/** Progress of a long-running background task. */
|
|
89
|
-
function NativeTask({ task, isDark
|
|
93
|
+
function NativeTask({ task, isDark: isDarkProp, style }) {
|
|
94
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
90
95
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
91
96
|
const { View, Text } = (0, primitives_1.primitives)();
|
|
92
97
|
const percent = task.progress == null ? null : Math.round(Math.min(1, Math.max(0, task.progress)) * 100);
|
|
93
98
|
const status = task.status ?? "running";
|
|
94
99
|
const fillColor = status === "failed" ? theme.destructive : status === "done" ? "#34c759" : theme.fill;
|
|
95
|
-
return ((0, jsx_runtime_1.jsxs)(View, { accessibilityRole: "progressbar", accessibilityLabel: task.label ?? "Task progress",
|
|
100
|
+
return ((0, jsx_runtime_1.jsxs)(View, { accessibilityRole: "progressbar", accessibilityLabel: task.label ?? "Task progress",
|
|
101
|
+
// Without the value, a screen reader only reads the label and never says
|
|
102
|
+
// how far along the task is.
|
|
103
|
+
accessibilityValue: percent == null ? undefined : { min: 0, max: 100, now: percent }, accessibilityState: {
|
|
96
104
|
disabled: false,
|
|
97
105
|
}, style: style, children: [(0, jsx_runtime_1.jsxs)(View, { style: { flexDirection: "row", justifyContent: "space-between", marginBottom: 6 }, children: [(0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 12, fontWeight: "500", color: theme.foreground }, children: task.label ?? "Task" }), (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: theme.muted }, children: percent == null ? "…" : `${percent}%` })] }), (0, jsx_runtime_1.jsx)(View, { style: {
|
|
98
106
|
height: 6,
|
|
@@ -115,7 +123,8 @@ function NativeTask({ task, isDark = false, style }) {
|
|
|
115
123
|
* Without levels it rests at a low, static profile instead of animating:
|
|
116
124
|
* continuous motion with no audio behind it would be decorative noise.
|
|
117
125
|
*/
|
|
118
|
-
function NativeSoundwave({ levels, bars = 28, active = true, height = 40, color, isDark
|
|
126
|
+
function NativeSoundwave({ levels, bars = 28, active = true, height = 40, color, isDark: isDarkProp, style, label = "Audio level", }) {
|
|
127
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
119
128
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
120
129
|
const { View } = (0, primitives_1.primitives)();
|
|
121
130
|
const count = levels?.length || bars;
|
|
@@ -140,7 +149,8 @@ function NativeSoundwave({ levels, bars = 28, active = true, height = 40, color,
|
|
|
140
149
|
* Purely decorative, so it is hidden from screen readers and the label is
|
|
141
150
|
* exposed as text instead of relying on the motion being perceived.
|
|
142
151
|
*/
|
|
143
|
-
function NativeThinkingOrb({ label = "Thinking", size = 22, paused = false, isDark
|
|
152
|
+
function NativeThinkingOrb({ label = "Thinking", size = 22, paused = false, isDark: isDarkProp, style, }) {
|
|
153
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
144
154
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
145
155
|
const { View, Text } = (0, primitives_1.primitives)();
|
|
146
156
|
const [tick, setTick] = (0, react_1.useState)(0);
|
|
@@ -166,7 +176,8 @@ function NativeThinkingOrb({ label = "Thinking", size = 22, paused = false, isDa
|
|
|
166
176
|
* Selection is a press rather than navigation because the panel's content is
|
|
167
177
|
* client state; the caller decides what a selection means.
|
|
168
178
|
*/
|
|
169
|
-
function NativePanelside({ items, value, onValueChange, isDark
|
|
179
|
+
function NativePanelside({ items, value, onValueChange, isDark: isDarkProp, style, title, }) {
|
|
180
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
170
181
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
171
182
|
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
172
183
|
return ((0, jsx_runtime_1.jsxs)(View, { style: style, children: [title && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, fontWeight: "600", color: theme.muted, marginBottom: 6 }, children: title })), items.map((item) => {
|
|
@@ -193,10 +204,23 @@ function NativePanelside({ items, value, onValueChange, isDark = false, style, t
|
|
|
193
204
|
* Send stays disabled until there is non-whitespace to send, which is the rule
|
|
194
205
|
* that prevents empty submissions rather than a validation message afterwards.
|
|
195
206
|
*/
|
|
196
|
-
function NativeAIInput({ value
|
|
207
|
+
function NativeAIInput({ value: valueProp, defaultValue, onChangeText, onSubmit, placeholder = "Ask anything", disabled = false, busy = false, sendLabel = "Send", isDark: isDarkProp, style, footer, }) {
|
|
208
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
197
209
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
198
210
|
const { View, Text, TextInput, Pressable } = (0, primitives_1.primitives)();
|
|
211
|
+
// Uncontrolled support: the composer owns its text when no `value` is given,
|
|
212
|
+
// which is what makes typed text appear in plain uncontrolled use.
|
|
213
|
+
const [internalText, setInternalText] = (0, react_1.useState)(defaultValue ?? "");
|
|
214
|
+
const value = valueProp !== undefined ? valueProp : internalText;
|
|
215
|
+
const handleChangeText = (next) => {
|
|
216
|
+
if (valueProp === undefined)
|
|
217
|
+
setInternalText(next);
|
|
218
|
+
onChangeText?.(next);
|
|
219
|
+
};
|
|
199
220
|
const canSend = !disabled && !busy && value.trim().length > 0;
|
|
221
|
+
// The themed placeholder is drawn as a Text, matching Input: the OS default
|
|
222
|
+
// placeholder colour ignores the theme.
|
|
223
|
+
const showPlaceholder = !value && Boolean(placeholder);
|
|
200
224
|
return ((0, jsx_runtime_1.jsxs)(View, { style: style, children: [(0, jsx_runtime_1.jsxs)(View, { style: {
|
|
201
225
|
flexDirection: "row",
|
|
202
226
|
alignItems: "flex-end",
|
|
@@ -207,15 +231,19 @@ function NativeAIInput({ value = "", onChangeText, onSubmit, placeholder = "Ask
|
|
|
207
231
|
borderColor: theme.edge,
|
|
208
232
|
backgroundColor: theme.glass,
|
|
209
233
|
opacity: disabled ? 0.5 : 1,
|
|
210
|
-
}, children: [(0, jsx_runtime_1.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
234
|
+
}, children: [(0, jsx_runtime_1.jsxs)(View, { style: { flex: 1, justifyContent: "center" }, children: [showPlaceholder && ((0, jsx_runtime_1.jsx)(Text, { pointerEvents: "none", numberOfLines: 1, style: {
|
|
235
|
+
position: "absolute",
|
|
236
|
+
left: 6,
|
|
237
|
+
fontSize: 14,
|
|
238
|
+
color: theme.muted,
|
|
239
|
+
}, children: placeholder })), (0, jsx_runtime_1.jsx)(TextInput, { value: value, onChangeText: handleChangeText, editable: !disabled, multiline: true, numberOfLines: 3, accessibilityLabel: placeholder, accessibilityState: { disabled }, style: {
|
|
240
|
+
minHeight: 34,
|
|
241
|
+
maxHeight: 120,
|
|
242
|
+
paddingHorizontal: 6,
|
|
243
|
+
paddingVertical: 7,
|
|
244
|
+
fontSize: 14,
|
|
245
|
+
color: theme.foreground,
|
|
246
|
+
} })] }), (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: sendLabel, accessibilityState: { disabled: !canSend }, disabled: !canSend, onPress: () => canSend && onSubmit?.(), style: {
|
|
219
247
|
paddingVertical: 8,
|
|
220
248
|
paddingHorizontal: 14,
|
|
221
249
|
borderRadius: tokens_1.radii.pill,
|
|
@@ -228,7 +256,8 @@ function NativeAIInput({ value = "", onChangeText, onSubmit, placeholder = "Ask
|
|
|
228
256
|
* While generating, a placeholder with the same aspect ratio holds the space so
|
|
229
257
|
* the layout does not jump when the image arrives.
|
|
230
258
|
*/
|
|
231
|
-
function NativeImageGeneration({ image, prompt, status = "queued", isDark
|
|
259
|
+
function NativeImageGeneration({ image, prompt, status = "queued", isDark: isDarkProp, style, }) {
|
|
260
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
232
261
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
233
262
|
const { View, Text, Image } = (0, primitives_1.primitives)();
|
|
234
263
|
const width = image?.width ?? 320;
|
|
@@ -4,12 +4,14 @@ exports.NativeBarChart = NativeBarChart;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const tokens_1 = require("../internal/tokens");
|
|
7
|
-
const
|
|
7
|
+
const motion_1 = require("../internal/motion");
|
|
8
|
+
const primitives_1 = require("../internal/primitives");
|
|
8
9
|
const scales_1 = require("./scales");
|
|
9
10
|
const PADDING = { top: 12, right: 10, bottom: 24, left: 38 };
|
|
10
11
|
/** Grouped or stacked bars, drawn with react-native-svg. */
|
|
11
|
-
function NativeBarChart({ labels, series, width = 320, height = 200, stacked = false, radius = 4, isDark
|
|
12
|
+
function NativeBarChart({ labels, series, width = 320, height = 200, stacked = false, radius = 4, isDark: isDarkProp, palette, style, onBarPress, }) {
|
|
12
13
|
const [active, setActive] = (0, react_1.useState)(null);
|
|
14
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
13
15
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
14
16
|
const { View, Text, Pressable, Svg, G, Line, Rect, SvgText } = (0, primitives_1.primitives)();
|
|
15
17
|
const plot = {
|
|
@@ -4,7 +4,8 @@ exports.NativeFunnelChart = NativeFunnelChart;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const tokens_1 = require("../internal/tokens");
|
|
7
|
-
const
|
|
7
|
+
const motion_1 = require("../internal/motion");
|
|
8
|
+
const primitives_1 = require("../internal/primitives");
|
|
8
9
|
const scales_1 = require("./scales");
|
|
9
10
|
/**
|
|
10
11
|
* A sequence of stages where each narrows the one before it.
|
|
@@ -14,8 +15,9 @@ const scales_1 = require("./scales");
|
|
|
14
15
|
* shows its own value, its share of entry, and the step conversion — the three
|
|
15
16
|
* numbers a funnel is actually read for.
|
|
16
17
|
*/
|
|
17
|
-
function NativeFunnelChart({ stages, width = 320, stageHeight = 38, baseline, isDark
|
|
18
|
+
function NativeFunnelChart({ stages, width = 320, stageHeight = 38, baseline, isDark: isDarkProp, palette, style, onStagePress, }) {
|
|
18
19
|
const [active, setActive] = (0, react_1.useState)(null);
|
|
20
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
19
21
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
20
22
|
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
21
23
|
if (stages.length === 0) {
|
|
@@ -4,7 +4,8 @@ exports.NativeHeatmapChart = NativeHeatmapChart;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const tokens_1 = require("../internal/tokens");
|
|
7
|
-
const
|
|
7
|
+
const motion_1 = require("../internal/motion");
|
|
8
|
+
const primitives_1 = require("../internal/primitives");
|
|
8
9
|
const scales_1 = require("./scales");
|
|
9
10
|
/** Parses "#rrggbb" into channels; anything else falls back to grey. */
|
|
10
11
|
function parseHex(hex) {
|
|
@@ -28,8 +29,9 @@ function mix(from, to, t) {
|
|
|
28
29
|
* Cells are Views rather than SVG rects: the grid is uniform, so native layout
|
|
29
30
|
* positions it exactly and text stays crisp without vector text.
|
|
30
31
|
*/
|
|
31
|
-
function NativeHeatmapChart({ rows, columns, cellSize = 28, cellGap = 3, isDark
|
|
32
|
+
function NativeHeatmapChart({ rows, columns, cellSize = 28, cellGap = 3, isDark: isDarkProp, minColor = "#e8eef7", maxColor = "#0088ff", style, onCellPress, }) {
|
|
32
33
|
const [active, setActive] = (0, react_1.useState)(null);
|
|
34
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
33
35
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
34
36
|
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
35
37
|
if (rows.length === 0 || columns.length === 0) {
|
|
@@ -4,7 +4,8 @@ exports.NativeLineChart = NativeLineChart;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const tokens_1 = require("../internal/tokens");
|
|
7
|
-
const
|
|
7
|
+
const motion_1 = require("../internal/motion");
|
|
8
|
+
const primitives_1 = require("../internal/primitives");
|
|
8
9
|
const scales_1 = require("./scales");
|
|
9
10
|
const PADDING = { top: 12, right: 10, bottom: 24, left: 38 };
|
|
10
11
|
/**
|
|
@@ -14,8 +15,9 @@ const PADDING = { top: 12, right: 10, bottom: 24, left: 38 };
|
|
|
14
15
|
* the same axis values on both platforms. Touching a column selects that
|
|
15
16
|
* point, which is the touch equivalent of hovering on the web.
|
|
16
17
|
*/
|
|
17
|
-
function NativeLineChart({ labels, series, width = 320, height = 200, area = false, smooth = true, showDots = false, isDark
|
|
18
|
+
function NativeLineChart({ labels, series, width = 320, height = 200, area = false, smooth = true, showDots = false, isDark: isDarkProp, palette, style, onPointPress, }) {
|
|
18
19
|
const [active, setActive] = (0, react_1.useState)(null);
|
|
20
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
19
21
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
20
22
|
const { View, Text, Pressable, Svg, G, Line, Path, Circle, SvgText } = (0, primitives_1.primitives)();
|
|
21
23
|
const plot = {
|
|
@@ -4,9 +4,16 @@ exports.NativePlotChart = NativePlotChart;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const tokens_1 = require("../internal/tokens");
|
|
7
|
-
const
|
|
7
|
+
const motion_1 = require("../internal/motion");
|
|
8
|
+
const primitives_1 = require("../internal/primitives");
|
|
8
9
|
const scales_1 = require("./scales");
|
|
9
10
|
const PADDING = { top: 12, right: 12, bottom: 26, left: 44 };
|
|
11
|
+
/** Reads the chart as one sentence for a screen reader. */
|
|
12
|
+
function plotSummary(points, xDomain, yDomain) {
|
|
13
|
+
return (`Plot chart with ${points.length} points. ` +
|
|
14
|
+
`x from ${(0, scales_1.formatValue)(xDomain[0], { compact: true })} to ${(0, scales_1.formatValue)(xDomain[1], { compact: true })}, ` +
|
|
15
|
+
`y from ${(0, scales_1.formatValue)(yDomain[0], { compact: true })} to ${(0, scales_1.formatValue)(yDomain[1], { compact: true })}.`);
|
|
16
|
+
}
|
|
10
17
|
/**
|
|
11
18
|
* A numeric plot you supply the marks for.
|
|
12
19
|
*
|
|
@@ -14,7 +21,8 @@ const PADDING = { top: 12, right: 12, bottom: 26, left: 44 };
|
|
|
14
21
|
* pixel scales. That keeps stroke widths and text sizes honest regardless of
|
|
15
22
|
* the chart's width, instead of a scaled viewBox that would distort them.
|
|
16
23
|
*/
|
|
17
|
-
function NativePlotChart({ points, renderMark, width = 320, height = 200, xLabel, yLabel, isDark
|
|
24
|
+
function NativePlotChart({ points, renderMark, width = 320, height = 200, xLabel, yLabel, isDark: isDarkProp, style, }) {
|
|
25
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
18
26
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
19
27
|
const { View, Text, Svg, G, Line, Circle, SvgText } = (0, primitives_1.primitives)();
|
|
20
28
|
const plot = {
|
|
@@ -40,5 +48,5 @@ function NativePlotChart({ points, renderMark, width = 320, height = 200, xLabel
|
|
|
40
48
|
}
|
|
41
49
|
const yTicks = (0, scales_1.ticks)(yDomain, 4);
|
|
42
50
|
const xTicks = (0, scales_1.ticks)(xDomain, 4);
|
|
43
|
-
return ((0, jsx_runtime_1.jsxs)(View, { style: style, children: [(0, jsx_runtime_1.jsxs)(Svg, { width: width, height: height, children: [yTicks.map((tick, i) => ((0, jsx_runtime_1.jsx)(Line, { x1: plot.x, x2: right, y1: y(tick), y2: y(tick), stroke: theme.axis, strokeOpacity: 0.22, strokeWidth: 1 }, `grid-${i}`))), renderMark ? (renderMark({ x, y, points, width: plot.width, height: plot.height })) : ((0, jsx_runtime_1.jsx)(G, { children: points.map((point, index) => ((0, jsx_runtime_1.jsx)(Circle, { cx: x(point.x), cy: y(point.y), r: 3.5, fill: theme.fill }, index))) })), yTicks.map((tick, i) => ((0, jsx_runtime_1.jsx)(SvgText, { x: plot.x - 6, y: y(tick) + 3, fill: theme.muted, fontSize: 9, textAnchor: "end", children: (0, scales_1.formatValue)(tick, { compact: true }) }, `y-${i}`))), xTicks.map((tick, i) => ((0, jsx_runtime_1.jsx)(SvgText, { x: x(tick), y: height - 8, fill: theme.muted, fontSize: 9, textAnchor: "middle", children: (0, scales_1.formatValue)(tick, { compact: true }) }, `x-${i}`)))] }), (xLabel || yLabel) && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 9, color: theme.muted, marginTop: 2 }, children: [xLabel, yLabel].filter(Boolean).join(" · ") }))] }));
|
|
51
|
+
return ((0, jsx_runtime_1.jsxs)(View, { style: style, accessible: true, accessibilityRole: "image", accessibilityLabel: plotSummary(points, xDomain, yDomain), children: [(0, jsx_runtime_1.jsxs)(Svg, { width: width, height: height, children: [yTicks.map((tick, i) => ((0, jsx_runtime_1.jsx)(Line, { x1: plot.x, x2: right, y1: y(tick), y2: y(tick), stroke: theme.axis, strokeOpacity: 0.22, strokeWidth: 1 }, `grid-${i}`))), renderMark ? (renderMark({ x, y, points, width: plot.width, height: plot.height })) : ((0, jsx_runtime_1.jsx)(G, { children: points.map((point, index) => ((0, jsx_runtime_1.jsx)(Circle, { cx: x(point.x), cy: y(point.y), r: 3.5, fill: theme.fill }, index))) })), yTicks.map((tick, i) => ((0, jsx_runtime_1.jsx)(SvgText, { x: plot.x - 6, y: y(tick) + 3, fill: theme.muted, fontSize: 9, textAnchor: "end", children: (0, scales_1.formatValue)(tick, { compact: true }) }, `y-${i}`))), xTicks.map((tick, i) => ((0, jsx_runtime_1.jsx)(SvgText, { x: x(tick), y: height - 8, fill: theme.muted, fontSize: 9, textAnchor: "middle", children: (0, scales_1.formatValue)(tick, { compact: true }) }, `x-${i}`)))] }), (xLabel || yLabel) && ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 9, color: theme.muted, marginTop: 2 }, children: [xLabel, yLabel].filter(Boolean).join(" · ") }))] }));
|
|
44
52
|
}
|