glacia-native 0.3.3 → 0.3.4
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/Dialog.js +128 -0
- package/lib/module/Form.js +125 -0
- package/lib/module/Input.js +64 -0
- package/lib/module/Table.js +81 -0
- package/lib/module/ai.js +246 -0
- package/lib/module/charts/AreaChart.js +32 -0
- package/lib/module/charts/BarChart.js +65 -0
- package/lib/module/charts/FunnelChart.js +48 -0
- package/lib/module/charts/HeatmapChart.js +69 -0
- package/lib/module/charts/LineChart.js +79 -0
- package/lib/module/charts/PlotChart.js +44 -0
- package/lib/module/charts/RadarChart.js +76 -0
- package/lib/module/charts/RingChart.js +50 -0
- package/lib/module/charts/ScatterChart.js +78 -0
- package/lib/module/charts/WaterfallChart.js +76 -0
- package/lib/module/charts/advanced.js +307 -0
- package/lib/module/charts/extra.js +105 -0
- package/lib/module/charts/index.js +50 -0
- package/lib/module/charts/primitives.js +212 -0
- package/lib/module/charts/scales.js +140 -0
- package/lib/module/index.js +48 -1
- package/lib/module/internal/tokens.js +3 -0
- package/lib/typescript/Dialog.d.ts +71 -0
- package/lib/typescript/Form.d.ts +81 -0
- package/lib/typescript/Input.d.ts +47 -0
- package/lib/typescript/Table.d.ts +55 -0
- package/lib/typescript/ai.d.ts +163 -0
- package/lib/typescript/charts/AreaChart.d.ts +44 -0
- package/lib/typescript/charts/BarChart.d.ts +19 -0
- package/lib/typescript/charts/FunnelChart.d.ts +25 -0
- package/lib/typescript/charts/HeatmapChart.d.ts +23 -0
- package/lib/typescript/charts/LineChart.d.ts +30 -0
- package/lib/typescript/charts/PlotChart.d.ts +31 -0
- package/lib/typescript/charts/RadarChart.d.ts +27 -0
- package/lib/typescript/charts/RingChart.d.ts +28 -0
- package/lib/typescript/charts/ScatterChart.d.ts +34 -0
- package/lib/typescript/charts/WaterfallChart.d.ts +22 -0
- package/lib/typescript/charts/advanced.d.ts +107 -0
- package/lib/typescript/charts/extra.d.ts +63 -0
- package/lib/typescript/charts/index.d.ts +13 -0
- package/lib/typescript/charts/primitives.d.ts +23 -0
- package/lib/typescript/charts/scales.d.ts +35 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/internal/tokens.d.ts +2 -0
- package/package.json +10 -3
- package/src/Dialog.tsx +345 -0
- package/src/Form.tsx +360 -0
- package/src/Input.tsx +172 -0
- package/src/Table.tsx +207 -0
- package/src/ai.tsx +655 -0
- package/src/charts/AreaChart.tsx +73 -0
- package/src/charts/BarChart.tsx +181 -0
- package/src/charts/FunnelChart.tsx +123 -0
- package/src/charts/HeatmapChart.tsx +153 -0
- package/src/charts/LineChart.tsx +245 -0
- package/src/charts/PlotChart.tsx +148 -0
- package/src/charts/RadarChart.tsx +206 -0
- package/src/charts/RingChart.tsx +131 -0
- package/src/charts/ScatterChart.tsx +202 -0
- package/src/charts/WaterfallChart.tsx +183 -0
- package/src/charts/advanced.tsx +670 -0
- package/src/charts/extra.tsx +239 -0
- package/src/charts/index.ts +86 -0
- package/src/charts/primitives.ts +262 -0
- package/src/charts/scales.ts +163 -0
- package/src/index.ts +68 -0
- package/src/internal/tokens.ts +3 -0
package/src/Table.tsx
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import { colors } from "./internal/tokens";
|
|
4
|
+
import { primitives } from "./charts/primitives";
|
|
5
|
+
|
|
6
|
+
export interface NativeTableColumn {
|
|
7
|
+
key: string;
|
|
8
|
+
header: string;
|
|
9
|
+
/** Relative width. Columns without one share the remainder. */
|
|
10
|
+
width?: number;
|
|
11
|
+
/** Right-align numeric columns so digits line up. */
|
|
12
|
+
align?: "left" | "right" | "center";
|
|
13
|
+
/** Renders the cell as a caption under the row on a narrow screen. */
|
|
14
|
+
primary?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NativeTableRow {
|
|
18
|
+
id: string;
|
|
19
|
+
cells: Record<string, ReactNode>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface NativeTableProps {
|
|
23
|
+
columns: NativeTableColumn[];
|
|
24
|
+
rows: NativeTableRow[];
|
|
25
|
+
/** Tap handler for a whole row. */
|
|
26
|
+
onRowPress?: (row: NativeTableRow) => void;
|
|
27
|
+
/** Text direction for right-aligned columns; defaults to left. */
|
|
28
|
+
caption?: string;
|
|
29
|
+
isDark?: boolean;
|
|
30
|
+
style?: any;
|
|
31
|
+
emptyMessage?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Tabular data laid out for a phone.
|
|
36
|
+
*
|
|
37
|
+
* A wide table cannot simply shrink: at phone width the columns become
|
|
38
|
+
* unreadable. Instead the first column is promoted to a row title and the rest
|
|
39
|
+
* are laid out as labelled pairs beneath it, which keeps every value readable
|
|
40
|
+
* without horizontal scrolling.
|
|
41
|
+
*/
|
|
42
|
+
export function NativeTable({
|
|
43
|
+
columns,
|
|
44
|
+
rows,
|
|
45
|
+
onRowPress,
|
|
46
|
+
caption,
|
|
47
|
+
isDark = false,
|
|
48
|
+
style,
|
|
49
|
+
emptyMessage = "No rows to display",
|
|
50
|
+
}: NativeTableProps) {
|
|
51
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
52
|
+
const { View, Text, Pressable } = primitives();
|
|
53
|
+
|
|
54
|
+
if (rows.length === 0) {
|
|
55
|
+
return (
|
|
56
|
+
<View style={[{ paddingVertical: 20, alignItems: "center" }, style]}>
|
|
57
|
+
<Text style={{ fontSize: 12, color: theme.muted }}>{emptyMessage}</Text>
|
|
58
|
+
</View>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The first column becomes the row's title when the caller marks none.
|
|
63
|
+
const primaryKey = columns.find((column) => column.primary)?.key ?? columns[0]?.key;
|
|
64
|
+
const primaryColumn = columns.find((column) => column.key === primaryKey);
|
|
65
|
+
const detailColumns = columns.filter((column) => column.key !== primaryKey);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<View style={style}>
|
|
69
|
+
{caption && (
|
|
70
|
+
<Text style={{ fontSize: 11, color: theme.muted, marginBottom: 8 }}>{caption}</Text>
|
|
71
|
+
)}
|
|
72
|
+
|
|
73
|
+
{rows.map((row) => {
|
|
74
|
+
const RowWrapper: any = onRowPress ? Pressable : View;
|
|
75
|
+
const wrapperProps = onRowPress
|
|
76
|
+
? {
|
|
77
|
+
accessibilityRole: "button",
|
|
78
|
+
accessibilityLabel: String(row.cells[primaryKey ?? ""] ?? ""),
|
|
79
|
+
onPress: () => onRowPress(row),
|
|
80
|
+
}
|
|
81
|
+
: { accessibilityRole: "text" };
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<RowWrapper
|
|
85
|
+
key={row.id}
|
|
86
|
+
{...wrapperProps}
|
|
87
|
+
style={{
|
|
88
|
+
paddingVertical: 10,
|
|
89
|
+
borderBottomWidth: 1,
|
|
90
|
+
borderBottomColor: theme.edge,
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
{primaryColumn && (
|
|
94
|
+
<Text
|
|
95
|
+
style={{
|
|
96
|
+
fontSize: 14,
|
|
97
|
+
fontWeight: "600",
|
|
98
|
+
color: theme.foreground,
|
|
99
|
+
textAlign: primaryColumn.align ?? "left",
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
{row.cells[primaryColumn.key] ?? ""}
|
|
103
|
+
</Text>
|
|
104
|
+
)}
|
|
105
|
+
|
|
106
|
+
{detailColumns.length > 0 && (
|
|
107
|
+
<View style={{ marginTop: 6, gap: 4 }}>
|
|
108
|
+
{detailColumns.map((column) => (
|
|
109
|
+
<View
|
|
110
|
+
key={column.key}
|
|
111
|
+
style={{
|
|
112
|
+
flexDirection: "row",
|
|
113
|
+
justifyContent: "space-between",
|
|
114
|
+
alignItems: "baseline",
|
|
115
|
+
gap: 12,
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<Text style={{ fontSize: 11, color: theme.muted }}>{column.header}</Text>
|
|
119
|
+
<Text
|
|
120
|
+
style={{
|
|
121
|
+
fontSize: 12,
|
|
122
|
+
color: theme.foreground,
|
|
123
|
+
textAlign: column.align ?? "left",
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
{row.cells[column.key] ?? ""}
|
|
127
|
+
</Text>
|
|
128
|
+
</View>
|
|
129
|
+
))}
|
|
130
|
+
</View>
|
|
131
|
+
)}
|
|
132
|
+
</RowWrapper>
|
|
133
|
+
);
|
|
134
|
+
})}
|
|
135
|
+
</View>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface NativeScrollAreaProps {
|
|
140
|
+
children?: ReactNode;
|
|
141
|
+
/** Fixed height. Without one the area grows with its content. */
|
|
142
|
+
maxHeight?: number;
|
|
143
|
+
/** Adds a bordered, tinted frame around the content. */
|
|
144
|
+
bordered?: boolean;
|
|
145
|
+
horizontal?: boolean;
|
|
146
|
+
isDark?: boolean;
|
|
147
|
+
style?: any;
|
|
148
|
+
/** Announced to screen readers. */
|
|
149
|
+
accessibilityLabel?: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A bounded scroll region.
|
|
154
|
+
*
|
|
155
|
+
* Uses the platform ScrollView rather than drawing a custom scrollbar: the OS
|
|
156
|
+
* scroll indicator is the one users already recognise, and it stays correct
|
|
157
|
+
* under momentum, bouncing and accessibility settings.
|
|
158
|
+
*/
|
|
159
|
+
export function NativeScrollArea({
|
|
160
|
+
children,
|
|
161
|
+
maxHeight,
|
|
162
|
+
bordered = false,
|
|
163
|
+
horizontal = false,
|
|
164
|
+
isDark = false,
|
|
165
|
+
style,
|
|
166
|
+
accessibilityLabel,
|
|
167
|
+
}: NativeScrollAreaProps) {
|
|
168
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
169
|
+
const { View, getScrollView } = primitives();
|
|
170
|
+
|
|
171
|
+
const ScrollView = getScrollView();
|
|
172
|
+
|
|
173
|
+
const containerStyle = {
|
|
174
|
+
maxHeight,
|
|
175
|
+
borderRadius: bordered ? 12 : undefined,
|
|
176
|
+
borderWidth: bordered ? 1 : 0,
|
|
177
|
+
borderColor: theme.edge,
|
|
178
|
+
overflow: "hidden",
|
|
179
|
+
...style,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
if (!ScrollView) {
|
|
183
|
+
// Off-device there is no ScrollView; render the content in a clipped box so
|
|
184
|
+
// layout still matches instead of dropping children.
|
|
185
|
+
return (
|
|
186
|
+
<View
|
|
187
|
+
accessibilityLabel={accessibilityLabel}
|
|
188
|
+
style={{ ...containerStyle, overflow: "auto" }}
|
|
189
|
+
>
|
|
190
|
+
{children}
|
|
191
|
+
</View>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<View style={containerStyle}>
|
|
197
|
+
<ScrollView
|
|
198
|
+
horizontal={horizontal}
|
|
199
|
+
showsVerticalScrollIndicator
|
|
200
|
+
showsHorizontalScrollIndicator={horizontal}
|
|
201
|
+
accessibilityLabel={accessibilityLabel}
|
|
202
|
+
>
|
|
203
|
+
{children}
|
|
204
|
+
</ScrollView>
|
|
205
|
+
</View>
|
|
206
|
+
);
|
|
207
|
+
}
|