@marktiderman/genesis-ui-native 3.11.0 → 3.12.1
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/README.md +69 -0
- package/dist/{chunk-ZUR4PK77.js → chunk-47CDRP43.js} +45 -166
- package/dist/chunk-47CDRP43.js.map +1 -0
- package/dist/{chunk-SG7LYX7Z.js → chunk-BQYT6TH2.js} +14 -6
- package/dist/chunk-BQYT6TH2.js.map +1 -0
- package/dist/{chunk-EAHK7D7N.js → chunk-C2ARUGT7.js} +146 -42
- package/dist/chunk-C2ARUGT7.js.map +1 -0
- package/dist/{chunk-VEWSY4TZ.js → chunk-D4UU6KIF.js} +236 -21
- package/dist/chunk-D4UU6KIF.js.map +1 -0
- package/dist/{chunk-GGH3ZQNO.js → chunk-TUDJDIGC.js} +4 -4
- package/dist/{chunk-GGH3ZQNO.js.map → chunk-TUDJDIGC.js.map} +1 -1
- package/dist/{chunk-PMS2V46D.js → chunk-VHUUOH46.js} +2 -2
- package/dist/{chunk-PMS2V46D.js.map → chunk-VHUUOH46.js.map} +1 -1
- package/dist/{chunk-IWWXERKQ.js → chunk-X5CPLUPZ.js} +1236 -136
- package/dist/chunk-X5CPLUPZ.js.map +1 -0
- package/dist/components/index.d.ts +510 -25
- package/dist/components/index.js +5 -5
- package/dist/data/index.d.ts +167 -33
- package/dist/data/index.js +1082 -760
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +1 -1
- package/dist/icons/lucide.d.ts +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -7
- package/dist/layouts/index.d.ts +79 -6
- package/dist/layouts/index.js +5 -5
- package/dist/{native-modules-Bkm1jHO-.d.ts → native-modules-6JnyeGR-.d.ts} +55 -1
- package/package.json +70 -4
- package/src/components/__tests__/combobox.test.tsx +20 -0
- package/src/components/__tests__/number-input.test.tsx +112 -1
- package/src/components/__tests__/parity-controls.test.tsx +366 -0
- package/src/components/__tests__/parity-display.test.tsx +295 -0
- package/src/components/__tests__/twin-props.test.tsx +114 -0
- package/src/components/badge.tsx +3 -0
- package/src/components/button-group.tsx +50 -0
- package/src/components/calendar.tsx +183 -0
- package/src/components/carousel.tsx +175 -0
- package/src/components/chart.tsx +268 -0
- package/src/components/chip-group.tsx +34 -14
- package/src/components/choice-card.tsx +56 -19
- package/src/components/combobox.tsx +6 -5
- package/src/components/empty-state.tsx +40 -0
- package/src/components/flatten-children.ts +13 -0
- package/src/components/index.ts +49 -1
- package/src/components/inline-alert.tsx +3 -1
- package/src/components/input-group.tsx +99 -0
- package/src/components/input-otp.tsx +124 -0
- package/src/components/input.tsx +40 -12
- package/src/components/list-item.tsx +20 -4
- package/src/components/number-input.tsx +45 -15
- package/src/components/radio-group.tsx +5 -0
- package/src/components/resource.tsx +227 -0
- package/src/components/settings-row.tsx +194 -0
- package/src/components/slider.tsx +3 -9
- package/src/components/sortable-list.tsx +287 -0
- package/src/components/stat-card.tsx +106 -0
- package/src/components/stepper.tsx +4 -2
- package/src/components/widget-tile.tsx +66 -0
- package/src/components/workspace-switcher.tsx +217 -0
- package/src/data/NativeCustomView.tsx +117 -0
- package/src/data/NativeFormFields.tsx +312 -0
- package/src/data/NativeRecordPeek.tsx +130 -0
- package/src/data/NativeResourceFormField.tsx +32 -0
- package/src/data/__tests__/parity-data.test.tsx +350 -0
- package/src/data/index.ts +13 -0
- package/src/layouts/__tests__/keyboard-scroll.test.tsx +58 -2
- package/src/layouts/__tests__/notifications-page.test.tsx +12 -0
- package/src/layouts/index.ts +13 -0
- package/src/layouts/keyboard.tsx +22 -2
- package/src/layouts/notifications-page.tsx +13 -35
- package/src/layouts/pages.tsx +262 -0
- package/src/native-modules.tsx +37 -0
- package/dist/chunk-EAHK7D7N.js.map +0 -1
- package/dist/chunk-IWWXERKQ.js.map +0 -1
- package/dist/chunk-SG7LYX7Z.js.map +0 -1
- package/dist/chunk-VEWSY4TZ.js.map +0 -1
- package/dist/chunk-ZUR4PK77.js.map +0 -1
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChartContainer — a bar, line or area chart from rows and a chart config: the twin of
|
|
3
|
+
* genesis-ui's ChartContainer (recharts on the web), with the same `config` (each series' label
|
|
4
|
+
* and its `color`, or a colour per scheme in `theme`).
|
|
5
|
+
*
|
|
6
|
+
* The shaping is genesis-core's (`@marktiderman/genesis-core/headless`): the value axis and its
|
|
7
|
+
* round ticks (`chartDomain`), each series' colour for the scheme (`chartSeriesColor`, with
|
|
8
|
+
* `var(--chart-N)` read as the chart token) and what a screen reader hears (`chartSummary`, every
|
|
9
|
+
* series and its values, since it can't see the bars). Only the drawing is this file's.
|
|
10
|
+
*
|
|
11
|
+
* Bars are views and need nothing installed. Line and area charts draw their lines with
|
|
12
|
+
* react-native-svg, passed once as `GenesisModules.svg`; without it they show their points.
|
|
13
|
+
*
|
|
14
|
+
* @stability Beta
|
|
15
|
+
*/
|
|
16
|
+
import { useMemo, useState } from "react";
|
|
17
|
+
import { Text, View, type ColorValue } from "react-native";
|
|
18
|
+
import { nativeThemeDark, nativeThemeLight } from "@marktiderman/genesis-design-system/tokens";
|
|
19
|
+
import {
|
|
20
|
+
chartDomain,
|
|
21
|
+
chartPosition,
|
|
22
|
+
chartSeriesColor,
|
|
23
|
+
chartSummary,
|
|
24
|
+
chartTokenOf,
|
|
25
|
+
defaultChartToken,
|
|
26
|
+
type ChartSeriesConfig,
|
|
27
|
+
} from "@marktiderman/genesis-core/headless";
|
|
28
|
+
import { useThemeMode } from "../hooks/use-theme-mode";
|
|
29
|
+
import { useGenesisModules } from "../native-modules";
|
|
30
|
+
import { cn } from "../utils";
|
|
31
|
+
|
|
32
|
+
/** Each series by its key in the rows, as the web's `ChartConfig` (labels are text here). */
|
|
33
|
+
export type NativeChartConfig = Record<string, ChartSeriesConfig<string>>;
|
|
34
|
+
|
|
35
|
+
export interface NativeChartContainerProps {
|
|
36
|
+
config: NativeChartConfig;
|
|
37
|
+
/** The rows: one per point on the x axis. */
|
|
38
|
+
data: readonly Record<string, unknown>[];
|
|
39
|
+
/** The rows' field on the x axis ("month"). */
|
|
40
|
+
xKey: string;
|
|
41
|
+
/** Default `bar`. */
|
|
42
|
+
type?: "bar" | "line" | "area";
|
|
43
|
+
/** Bars on top of each other instead of side by side. */
|
|
44
|
+
stacked?: boolean;
|
|
45
|
+
/** The plot's height in points. Default 200. */
|
|
46
|
+
height?: number;
|
|
47
|
+
/** A legend under the chart. Default true with more than one series. */
|
|
48
|
+
showLegend?: boolean;
|
|
49
|
+
/** Lines at each tick. Default true. */
|
|
50
|
+
showGrid?: boolean;
|
|
51
|
+
/** How values read on the axis and to a screen reader. */
|
|
52
|
+
valueFormat?: (value: number) => string;
|
|
53
|
+
/** What the chart is, said before its values ("Visitors by month"). */
|
|
54
|
+
accessibilityLabel?: string;
|
|
55
|
+
className?: string;
|
|
56
|
+
testID?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const AXIS_WIDTH = 36;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A config colour the phone can draw. A theme variable the web resolves in CSS (`hsl(var(--primary))`,
|
|
63
|
+
* `var(--success)`) is read from the native theme's hex map; one the theme doesn't have is the
|
|
64
|
+
* foreground, so a series is never drawn in nothing. A plain colour (`#e11d48`, `rgb(…)`, `tomato`)
|
|
65
|
+
* is used as it is.
|
|
66
|
+
*/
|
|
67
|
+
export function nativeColor(color: string, tokens: Readonly<Record<string, string>>): string | undefined {
|
|
68
|
+
if (!color.includes("var(")) return color;
|
|
69
|
+
// Bounded and with one way to match, so a long string can't make it backtrack.
|
|
70
|
+
const name = /var\(\s*--([a-z0-9-]{1,40})\s*\)/i.exec(color.slice(0, 120))?.[1];
|
|
71
|
+
if (!name) return undefined;
|
|
72
|
+
const key = name.toLowerCase().replace(/-([a-z0-9])/g, (_, c: string) => c.toUpperCase());
|
|
73
|
+
return tokens[key] ?? (key === "primary" ? tokens.primaryText : undefined);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function NativeChartContainer({
|
|
77
|
+
config,
|
|
78
|
+
data,
|
|
79
|
+
xKey,
|
|
80
|
+
type = "bar",
|
|
81
|
+
stacked = false,
|
|
82
|
+
height = 200,
|
|
83
|
+
showLegend,
|
|
84
|
+
showGrid = true,
|
|
85
|
+
valueFormat = (v) => String(v),
|
|
86
|
+
accessibilityLabel,
|
|
87
|
+
className,
|
|
88
|
+
testID = "native-chart",
|
|
89
|
+
}: NativeChartContainerProps) {
|
|
90
|
+
const scheme = useThemeMode();
|
|
91
|
+
const { svg } = useGenesisModules();
|
|
92
|
+
const [width, setWidth] = useState(0);
|
|
93
|
+
const keys = Object.keys(config);
|
|
94
|
+
const tokens = scheme === "dark" ? nativeThemeDark : nativeThemeLight;
|
|
95
|
+
|
|
96
|
+
const series = useMemo(
|
|
97
|
+
() =>
|
|
98
|
+
keys.map((key, i) => {
|
|
99
|
+
const color = chartSeriesColor(config[key], scheme);
|
|
100
|
+
const token = chartTokenOf(color) ?? (color ? undefined : defaultChartToken(i));
|
|
101
|
+
const hex = token ? (tokens as Record<string, string>)[token.replace("-", "")] : nativeColor(color!, tokens);
|
|
102
|
+
return { key, label: config[key]?.label ?? key, color: (hex ?? tokens.foreground) as ColorValue };
|
|
103
|
+
}),
|
|
104
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- keys are config's
|
|
105
|
+
[config, scheme, tokens],
|
|
106
|
+
);
|
|
107
|
+
const domain = useMemo(() => chartDomain(data, keys, { stacked: stacked && type === "bar" }), [data, keys, stacked, type]);
|
|
108
|
+
const plotWidth = Math.max(0, width - AXIS_WIDTH);
|
|
109
|
+
const y = (v: number) => height - chartPosition(v, domain, height);
|
|
110
|
+
const zero = y(0);
|
|
111
|
+
const summary = chartSummary(data, xKey, series, valueFormat);
|
|
112
|
+
const legend = showLegend ?? series.length > 1;
|
|
113
|
+
const slot = data.length > 0 ? plotWidth / data.length : 0;
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<View
|
|
117
|
+
testID={testID}
|
|
118
|
+
className={cn("w-full", className)}
|
|
119
|
+
accessible
|
|
120
|
+
accessibilityRole="image"
|
|
121
|
+
accessibilityLabel={accessibilityLabel ? `${accessibilityLabel}. ${summary}` : summary}
|
|
122
|
+
>
|
|
123
|
+
<View className="flex-row" style={{ height }}>
|
|
124
|
+
<View style={{ width: AXIS_WIDTH, height }} importantForAccessibility="no-hide-descendants">
|
|
125
|
+
{domain.ticks.map((t) => (
|
|
126
|
+
<Text key={t} className="absolute right-1 text-[10px] text-muted-foreground" style={{ top: y(t) - 7 }}>
|
|
127
|
+
{valueFormat(t)}
|
|
128
|
+
</Text>
|
|
129
|
+
))}
|
|
130
|
+
</View>
|
|
131
|
+
<View
|
|
132
|
+
className="flex-1"
|
|
133
|
+
style={{ height }}
|
|
134
|
+
onLayout={(e: { nativeEvent?: { layout?: { width?: number } } }) => setWidth((e.nativeEvent?.layout?.width ?? 0) + AXIS_WIDTH)}
|
|
135
|
+
>
|
|
136
|
+
{showGrid
|
|
137
|
+
? domain.ticks.map((t) => <View key={t} className="absolute left-0 right-0 h-px bg-border/60" style={{ top: y(t) }} />)
|
|
138
|
+
: null}
|
|
139
|
+
{type === "bar"
|
|
140
|
+
? data.map((row, i) => (
|
|
141
|
+
<BarGroup key={i} testID={`${testID}-bar-${i}`} row={row} series={series} stacked={stacked} left={i * slot} width={slot} y={y} zero={zero} />
|
|
142
|
+
))
|
|
143
|
+
: (
|
|
144
|
+
<Lines svg={svg} data={data} series={series} area={type === "area"} slot={slot} width={plotWidth} height={height} y={y} zero={zero} testID={testID} />
|
|
145
|
+
)}
|
|
146
|
+
</View>
|
|
147
|
+
</View>
|
|
148
|
+
<View className="flex-row" style={{ marginLeft: AXIS_WIDTH }} importantForAccessibility="no-hide-descendants">
|
|
149
|
+
{data.map((row, i) => (
|
|
150
|
+
<Text key={i} numberOfLines={1} className="flex-1 text-center text-[10px] text-muted-foreground">
|
|
151
|
+
{String(row[xKey] ?? "")}
|
|
152
|
+
</Text>
|
|
153
|
+
))}
|
|
154
|
+
</View>
|
|
155
|
+
{legend ? (
|
|
156
|
+
<View className="mt-2 flex-row flex-wrap justify-center gap-3" importantForAccessibility="no-hide-descendants">
|
|
157
|
+
{series.map((s) => (
|
|
158
|
+
<View key={s.key} className="flex-row items-center gap-1.5">
|
|
159
|
+
<View className="h-2.5 w-2.5 rounded-sm" style={{ backgroundColor: s.color }} />
|
|
160
|
+
<Text className="text-xs text-muted-foreground">{s.label}</Text>
|
|
161
|
+
</View>
|
|
162
|
+
))}
|
|
163
|
+
</View>
|
|
164
|
+
) : null}
|
|
165
|
+
</View>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
type Series = { key: string; label: string; color: ColorValue };
|
|
170
|
+
|
|
171
|
+
function num(v: unknown): number {
|
|
172
|
+
return typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function BarGroup({ row, series, stacked, left, width, y, zero, testID }: { row: Record<string, unknown>; series: Series[]; stacked: boolean; left: number; width: number; y: (v: number) => number; zero: number; testID: string }) {
|
|
176
|
+
const inner = width * 0.7;
|
|
177
|
+
const pad = (width - inner) / 2;
|
|
178
|
+
if (stacked) {
|
|
179
|
+
let base = 0;
|
|
180
|
+
return (
|
|
181
|
+
<View testID={testID} className="absolute" style={{ left: left + pad, width: inner, top: 0, bottom: 0 }}>
|
|
182
|
+
{series.map((s) => {
|
|
183
|
+
const v = num(row[s.key]);
|
|
184
|
+
const top = y(base + v);
|
|
185
|
+
const bottom = y(base);
|
|
186
|
+
base += v;
|
|
187
|
+
return <View key={s.key} className="absolute left-0 right-0 rounded-sm" style={{ top: Math.min(top, bottom), height: Math.abs(bottom - top), backgroundColor: s.color }} />;
|
|
188
|
+
})}
|
|
189
|
+
</View>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
const bar = inner / Math.max(1, series.length);
|
|
193
|
+
return (
|
|
194
|
+
<View testID={testID} className="absolute" style={{ left: left + pad, width: inner, top: 0, bottom: 0 }}>
|
|
195
|
+
{series.map((s, j) => {
|
|
196
|
+
const top = y(num(row[s.key]));
|
|
197
|
+
return (
|
|
198
|
+
<View
|
|
199
|
+
key={s.key}
|
|
200
|
+
className="absolute rounded-sm"
|
|
201
|
+
style={{ left: j * bar + 1, width: Math.max(1, bar - 2), top: Math.min(top, zero), height: Math.abs(zero - top), backgroundColor: s.color }}
|
|
202
|
+
/>
|
|
203
|
+
);
|
|
204
|
+
})}
|
|
205
|
+
</View>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function Lines({
|
|
210
|
+
svg,
|
|
211
|
+
data,
|
|
212
|
+
series,
|
|
213
|
+
area,
|
|
214
|
+
slot,
|
|
215
|
+
width,
|
|
216
|
+
height,
|
|
217
|
+
y,
|
|
218
|
+
zero,
|
|
219
|
+
testID,
|
|
220
|
+
}: {
|
|
221
|
+
svg: ReturnType<typeof useGenesisModules>["svg"];
|
|
222
|
+
data: readonly Record<string, unknown>[];
|
|
223
|
+
series: Series[];
|
|
224
|
+
area: boolean;
|
|
225
|
+
slot: number;
|
|
226
|
+
width: number;
|
|
227
|
+
height: number;
|
|
228
|
+
y: (v: number) => number;
|
|
229
|
+
zero: number;
|
|
230
|
+
testID: string;
|
|
231
|
+
}) {
|
|
232
|
+
const x = (i: number) => i * slot + slot / 2;
|
|
233
|
+
const Root = svg?.Svg ?? svg?.default;
|
|
234
|
+
if (svg && Root && width > 0) {
|
|
235
|
+
const { Path } = svg;
|
|
236
|
+
return (
|
|
237
|
+
<View className="absolute inset-0" pointerEvents="none">
|
|
238
|
+
<Root width={width} height={height} testID={`${testID}-svg`}>
|
|
239
|
+
{series.map((s) => {
|
|
240
|
+
const points = data.map((row, i) => `${x(i).toFixed(1)},${y(num(row[s.key])).toFixed(1)}`);
|
|
241
|
+
const line = `M${points.join(" L")}`;
|
|
242
|
+
return [
|
|
243
|
+
area ? (
|
|
244
|
+
<Path key={`${s.key}-area`} d={`${line} L${x(data.length - 1).toFixed(1)},${zero.toFixed(1)} L${x(0).toFixed(1)},${zero.toFixed(1)} Z`} fill={s.color} fillOpacity={0.2} />
|
|
245
|
+
) : null,
|
|
246
|
+
<Path key={s.key} d={line} stroke={s.color} strokeWidth={2} fill="none" testID={`${testID}-line-${s.key}`} />,
|
|
247
|
+
];
|
|
248
|
+
})}
|
|
249
|
+
</Root>
|
|
250
|
+
</View>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
// No SVG module: the points alone.
|
|
254
|
+
return (
|
|
255
|
+
<>
|
|
256
|
+
{series.map((s) =>
|
|
257
|
+
data.map((row, i) => (
|
|
258
|
+
<View
|
|
259
|
+
key={`${s.key}-${i}`}
|
|
260
|
+
testID={`${testID}-point-${s.key}-${i}`}
|
|
261
|
+
className="absolute h-2 w-2 rounded-full"
|
|
262
|
+
style={{ left: x(i) - 4, top: y(num(row[s.key])) - 4, backgroundColor: s.color }}
|
|
263
|
+
/>
|
|
264
|
+
)),
|
|
265
|
+
)}
|
|
266
|
+
</>
|
|
267
|
+
);
|
|
268
|
+
}
|
|
@@ -26,49 +26,69 @@ interface ChipContextValue {
|
|
|
26
26
|
|
|
27
27
|
const ChipContext = createContext<ChipContextValue | null>(null);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
/** What a group of `mode` holds: one value in `single`, a list in `multiple`. */
|
|
30
|
+
export type NativeChipGroupValue<M extends NativeChipGroupMode> = M extends "single" ? string : string[];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The props, as the web's ChipGroup: with `mode="single"`, `onChange` gets one string; with
|
|
34
|
+
* `mode="multiple"`, a list. With `mode` left out the group is `multiple` and `onChange` is typed
|
|
35
|
+
* for either, as before. `value` is one string in `single` mode and a list in `multiple`; its type
|
|
36
|
+
* still takes either, so a screen's existing `string | string[]` state keeps compiling.
|
|
37
|
+
*/
|
|
38
|
+
export interface NativeChipGroupProps<M extends NativeChipGroupMode = NativeChipGroupMode> {
|
|
39
|
+
mode?: M;
|
|
40
|
+
value: string | readonly string[];
|
|
41
|
+
onChange: (value: NativeChipGroupValue<M>) => void;
|
|
42
|
+
/**
|
|
43
|
+
* In `single` mode, pressing the chosen chip clears it (`onChange("")`). Default false: pressing
|
|
44
|
+
* it calls `onChange` with its own value again, as it always has (the web's ChipGroup sends
|
|
45
|
+
* nothing then).
|
|
46
|
+
*/
|
|
47
|
+
allowEmpty?: boolean;
|
|
33
48
|
disabled?: boolean;
|
|
34
49
|
className?: string;
|
|
35
50
|
children: React.ReactNode;
|
|
36
51
|
testID?: string;
|
|
37
52
|
}
|
|
38
53
|
|
|
39
|
-
export function NativeChipGroup({
|
|
40
|
-
mode = "multiple",
|
|
54
|
+
export function NativeChipGroup<M extends NativeChipGroupMode = NativeChipGroupMode>({
|
|
55
|
+
mode = "multiple" as M,
|
|
41
56
|
value,
|
|
42
57
|
onChange,
|
|
58
|
+
allowEmpty = false,
|
|
43
59
|
disabled,
|
|
44
60
|
className,
|
|
45
61
|
children,
|
|
46
62
|
testID,
|
|
47
|
-
}: NativeChipGroupProps) {
|
|
63
|
+
}: NativeChipGroupProps<M>) {
|
|
64
|
+
const single = mode === "single";
|
|
48
65
|
const selected = new Set<string>(
|
|
49
|
-
|
|
50
|
-
? typeof value === "string"
|
|
66
|
+
single
|
|
67
|
+
? typeof value === "string" && value
|
|
51
68
|
? [value]
|
|
52
69
|
: []
|
|
53
70
|
: Array.isArray(value)
|
|
54
|
-
? value
|
|
71
|
+
? (value as readonly string[])
|
|
55
72
|
: []
|
|
56
73
|
);
|
|
74
|
+
const emit = onChange as (value: string | string[]) => void;
|
|
57
75
|
const toggle = (v: string) => {
|
|
58
|
-
if (
|
|
59
|
-
|
|
76
|
+
if (single) {
|
|
77
|
+
// Pressing the chosen chip again: cleared with `allowEmpty`; otherwise reported as it always
|
|
78
|
+
// was (`onChange` with the same value), so a screen's own handler can still decide.
|
|
79
|
+
emit(selected.has(v) && allowEmpty ? "" : v);
|
|
60
80
|
return;
|
|
61
81
|
}
|
|
62
82
|
const next = new Set(selected);
|
|
63
83
|
if (next.has(v)) next.delete(v);
|
|
64
84
|
else next.add(v);
|
|
65
|
-
|
|
85
|
+
emit(Array.from(next));
|
|
66
86
|
};
|
|
67
87
|
return (
|
|
68
88
|
<ChipContext.Provider value={{ mode, selected, toggle, disabled }}>
|
|
69
89
|
<View
|
|
70
90
|
testID={testID ?? "native-chip-group"}
|
|
71
|
-
accessibilityRole={
|
|
91
|
+
accessibilityRole={single ? "radiogroup" : undefined}
|
|
72
92
|
className={cn("flex-row flex-wrap gap-2", className)}
|
|
73
93
|
>
|
|
74
94
|
{children}
|
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
* radio or checkbox to VoiceOver and TalkBack, named "title, description".
|
|
8
8
|
* Selected, the border and indicator take the primary colour and the card a
|
|
9
9
|
* light primary wash; `invalid` draws the border in the destructive colour
|
|
10
|
-
* (and says "Needs an answer").
|
|
10
|
+
* (and says "Needs an answer").
|
|
11
|
+
*
|
|
12
|
+
* As the web's ChoiceCard: one of several is a card with a `value` inside a NativeRadioGroup, and
|
|
13
|
+
* with `multiple` it is a checkbox with `selected` and `onSelectedChange(next)`. The older
|
|
14
|
+
* `selected` with `onPress` still works in either mode.
|
|
11
15
|
*
|
|
12
16
|
* Use a column of them for a question with pictures or explanations per
|
|
13
17
|
* option; for a plain list of words use NativeRadioGroup or NativeChipGroup.
|
|
@@ -16,17 +20,14 @@
|
|
|
16
20
|
*/
|
|
17
21
|
import { Pressable, Text, View } from "react-native";
|
|
18
22
|
import { cn } from "../utils";
|
|
23
|
+
import { useNativeRadioGroupContext } from "./radio-group";
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
interface NativeChoiceCardBaseProps {
|
|
21
26
|
title: string;
|
|
22
27
|
/** A second line under the title, muted. */
|
|
23
28
|
description?: string;
|
|
24
29
|
/** Slot left of the text: a thumbnail (NativeImage), an icon. */
|
|
25
30
|
media?: React.ReactNode;
|
|
26
|
-
selected: boolean;
|
|
27
|
-
onPress: () => void;
|
|
28
|
-
/** A checkbox (several can be chosen) rather than a radio. */
|
|
29
|
-
multiple?: boolean;
|
|
30
31
|
disabled?: boolean;
|
|
31
32
|
/** The question still needs an answer: a destructive border and hint. */
|
|
32
33
|
invalid?: boolean;
|
|
@@ -36,6 +37,44 @@ export interface NativeChoiceCardProps {
|
|
|
36
37
|
testID?: string;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* One of several, inside a `NativeRadioGroup`, as the web's ChoiceCard sits in a RadioGroup: the
|
|
42
|
+
* group holds which is chosen (`value`, `onValueChange`), and the card is chosen when its `value` is.
|
|
43
|
+
*/
|
|
44
|
+
export interface NativeChoiceCardRadioProps extends NativeChoiceCardBaseProps {
|
|
45
|
+
multiple?: false;
|
|
46
|
+
/** This card's value in its NativeRadioGroup. */
|
|
47
|
+
value: string;
|
|
48
|
+
selected?: undefined;
|
|
49
|
+
onPress?: undefined;
|
|
50
|
+
onSelectedChange?: undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Any number can be chosen: a checkbox with its own state, as the web's `multiple` ChoiceCard. */
|
|
54
|
+
export interface NativeChoiceCardCheckboxProps extends NativeChoiceCardBaseProps {
|
|
55
|
+
multiple: true;
|
|
56
|
+
selected: boolean;
|
|
57
|
+
/** Called when it is pressed, with the new state. */
|
|
58
|
+
onSelectedChange: (selected: boolean) => void;
|
|
59
|
+
value?: undefined;
|
|
60
|
+
onPress?: undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The parent owns `selected` and answers `onPress` itself, in either mode.
|
|
65
|
+
* @deprecated Use `value` in a NativeRadioGroup, or `multiple` with `onSelectedChange`, as the web's ChoiceCard.
|
|
66
|
+
*/
|
|
67
|
+
export interface NativeChoiceCardPressProps extends NativeChoiceCardBaseProps {
|
|
68
|
+
/** A checkbox (several can be chosen) rather than a radio. */
|
|
69
|
+
multiple?: boolean;
|
|
70
|
+
selected: boolean;
|
|
71
|
+
onPress: () => void;
|
|
72
|
+
value?: undefined;
|
|
73
|
+
onSelectedChange?: undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type NativeChoiceCardProps = NativeChoiceCardRadioProps | NativeChoiceCardCheckboxProps | NativeChoiceCardPressProps;
|
|
77
|
+
|
|
39
78
|
function Indicator({ on, multiple, testID }: { on: boolean; multiple: boolean; testID?: string | undefined }) {
|
|
40
79
|
return (
|
|
41
80
|
<View
|
|
@@ -58,19 +97,17 @@ function Indicator({ on, multiple, testID }: { on: boolean; multiple: boolean; t
|
|
|
58
97
|
);
|
|
59
98
|
}
|
|
60
99
|
|
|
61
|
-
export function NativeChoiceCard({
|
|
62
|
-
title,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
testID = "native-choice-card",
|
|
73
|
-
}: NativeChoiceCardProps) {
|
|
100
|
+
export function NativeChoiceCard(props: NativeChoiceCardProps) {
|
|
101
|
+
const { title, description, media, disabled = false, invalid = false, hint, className, testID = "native-choice-card" } = props;
|
|
102
|
+
const group = useNativeRadioGroupContext();
|
|
103
|
+
if (props.value !== undefined && !group) throw new Error("A NativeChoiceCard with a `value` must be inside <NativeRadioGroup>.");
|
|
104
|
+
const multiple = props.multiple === true;
|
|
105
|
+
const selected = props.value !== undefined ? group!.value === props.value : props.selected;
|
|
106
|
+
const onPress = () => {
|
|
107
|
+
if (props.value !== undefined) group!.onValueChange(props.value);
|
|
108
|
+
else if (props.onSelectedChange) props.onSelectedChange(!props.selected);
|
|
109
|
+
else props.onPress?.();
|
|
110
|
+
};
|
|
74
111
|
const name = description ? `${title}, ${description}` : title;
|
|
75
112
|
const accessibilityHint = [hint, invalid ? "Needs an answer" : ""].filter(Boolean).join(". ") || undefined;
|
|
76
113
|
return (
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* and lets the user pick one.
|
|
4
4
|
*
|
|
5
5
|
* Use when the user knows what they're looking for and the option list
|
|
6
|
-
* is too long for a Select.
|
|
7
|
-
*
|
|
6
|
+
* is too long for a Select. By default every word typed must appear in an
|
|
7
|
+
* option's label or description, ignoring case and accents (genesis-core's
|
|
8
|
+
* `matchesQuery`, as the web's Combobox); pass `filter` to override.
|
|
8
9
|
*
|
|
9
10
|
* @stability Beta
|
|
10
11
|
*/
|
|
12
|
+
import { matchesQuery } from "@marktiderman/genesis-core/headless";
|
|
11
13
|
import { useMemo, useState } from "react";
|
|
12
14
|
import { Pressable, ScrollView, Text, TextInput, View } from "react-native";
|
|
13
15
|
import { cn } from "../utils";
|
|
@@ -43,9 +45,8 @@ export interface NativeComboboxProps<T = string> {
|
|
|
43
45
|
testID?: string;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
(o.description?.toLowerCase().includes(q.toLowerCase()) ?? false);
|
|
48
|
+
// Every word typed, ignoring case and accents: genesis-core's rule, as the web's Combobox.
|
|
49
|
+
const defaultFilter = <T,>(o: NativeComboboxOption<T>, q: string) => matchesQuery([o.label, o.description], q);
|
|
49
50
|
|
|
50
51
|
export function NativeCombobox<T = string>({
|
|
51
52
|
options,
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { Text, View } from "react-native";
|
|
17
17
|
import { cn } from "../utils";
|
|
18
|
+
import { NativeButton } from "./button";
|
|
18
19
|
|
|
19
20
|
export type NativeEmptyStateVariant = "first-run" | "no-results" | "error";
|
|
20
21
|
|
|
@@ -159,3 +160,42 @@ export function NativeEmptyState({
|
|
|
159
160
|
</View>
|
|
160
161
|
);
|
|
161
162
|
}
|
|
163
|
+
|
|
164
|
+
// Presets, the twins of genesis-ui's NoFeaturesFound, NoFeedbackFound and NoSearchResults: the
|
|
165
|
+
// same words on NativeEmptyState, so a phone screen doesn't retype them.
|
|
166
|
+
|
|
167
|
+
/** An empty roadmap or feature list. */
|
|
168
|
+
export function NativeNoFeaturesFound({ onCreate, testID = "no-features-found" }: { onCreate?: () => void; testID?: string }) {
|
|
169
|
+
return (
|
|
170
|
+
<NativeEmptyState
|
|
171
|
+
testID={testID}
|
|
172
|
+
title="No features found"
|
|
173
|
+
body="Start building your product roadmap by creating your first epic."
|
|
174
|
+
primaryAction={onCreate ? <NativeButton onPress={onCreate} testID={`${testID}-create`}>Create Epic</NativeButton> : undefined}
|
|
175
|
+
/>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** A feedback inbox with nothing in it yet. */
|
|
180
|
+
export function NativeNoFeedbackFound({ testID = "no-feedback-found" }: { testID?: string }) {
|
|
181
|
+
return <NativeEmptyState testID={testID} title="No feedback yet" body="Feedback from users will appear here as they use the app." />;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A search or filter that matched nothing. */
|
|
185
|
+
export function NativeNoSearchResults({ query, onClear, testID = "no-search-results" }: { query?: string; onClear?: () => void; testID?: string }) {
|
|
186
|
+
return (
|
|
187
|
+
<NativeEmptyState
|
|
188
|
+
testID={testID}
|
|
189
|
+
variant="no-results"
|
|
190
|
+
title="No results found"
|
|
191
|
+
body={query ? `No results found for "${query}". Try a different search term.` : "No results match your current filters."}
|
|
192
|
+
primaryAction={
|
|
193
|
+
onClear ? (
|
|
194
|
+
<NativeButton variant="ghost" onPress={onClear} testID={`${testID}-clear`}>
|
|
195
|
+
Clear search
|
|
196
|
+
</NativeButton>
|
|
197
|
+
) : undefined
|
|
198
|
+
}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The items in a slot's children, as a person wrote them: arrays and Fragments opened up (a
|
|
2
|
+
// screen's `<>{a}{b}</>` is two stat tiles, not one), and nothing (null, false, "") left out.
|
|
3
|
+
// `Children.toArray` alone opens arrays but keeps a Fragment as a single child.
|
|
4
|
+
import { Children, Fragment, isValidElement, type ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
export function flattenChildren(children: ReactNode): ReactNode[] {
|
|
7
|
+
const out: ReactNode[] = [];
|
|
8
|
+
for (const child of Children.toArray(children)) {
|
|
9
|
+
if (isValidElement<{ children?: ReactNode }>(child) && child.type === Fragment) out.push(...flattenChildren(child.props.children));
|
|
10
|
+
else if (child !== "") out.push(child);
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -94,6 +94,7 @@ export type {
|
|
|
94
94
|
NativeChipProps,
|
|
95
95
|
NativeChipGroupProps,
|
|
96
96
|
NativeChipGroupMode,
|
|
97
|
+
NativeChipGroupValue,
|
|
97
98
|
} from "./chip-group";
|
|
98
99
|
|
|
99
100
|
export { NativePagination } from "./pagination";
|
|
@@ -200,7 +201,7 @@ export { NativeLabel } from "./label";
|
|
|
200
201
|
export type { NativeLabelProps } from "./label";
|
|
201
202
|
|
|
202
203
|
export { NativeChoiceCard } from "./choice-card";
|
|
203
|
-
export type { NativeChoiceCardProps } from "./choice-card";
|
|
204
|
+
export type { NativeChoiceCardProps, NativeChoiceCardRadioProps, NativeChoiceCardCheckboxProps, NativeChoiceCardPressProps } from "./choice-card";
|
|
204
205
|
export { NativeRadioGroup, NativeRadioGroupItem } from "./radio-group";
|
|
205
206
|
export type {
|
|
206
207
|
NativeRadioGroupProps,
|
|
@@ -288,6 +289,9 @@ export type {
|
|
|
288
289
|
GenesisDatePickerProps,
|
|
289
290
|
GenesisNavigationModule,
|
|
290
291
|
GenesisNavigationTheme,
|
|
292
|
+
GenesisSvgModule,
|
|
293
|
+
GenesisFilePicker,
|
|
294
|
+
NativePickedFile,
|
|
291
295
|
KeyboardAvoidingLike,
|
|
292
296
|
} from "../native-modules";
|
|
293
297
|
|
|
@@ -357,3 +361,47 @@ export { NativeShareSheet } from "./share-sheet";
|
|
|
357
361
|
export type { NativeShareSheetProps } from "./share-sheet";
|
|
358
362
|
export { NativeWhatsNewSheet } from "./whats-new-sheet";
|
|
359
363
|
export type { NativeWhatsNewNote, NativeWhatsNewSheetProps } from "./whats-new-sheet";
|
|
364
|
+
|
|
365
|
+
// --- Web parity twins (ui-parity.json): the genesis-ui components' phone counterparts ---
|
|
366
|
+
|
|
367
|
+
export { NativeButtonGroup } from "./button-group";
|
|
368
|
+
export type { NativeButtonGroupProps } from "./button-group";
|
|
369
|
+
export { NativeInputGroup } from "./input-group";
|
|
370
|
+
export type { NativeInputGroupProps } from "./input-group";
|
|
371
|
+
export { NativePasswordToggleField } from "./input-group";
|
|
372
|
+
export type { NativePasswordToggleFieldProps } from "./input-group";
|
|
373
|
+
export { NativeInputOTP } from "./input-otp";
|
|
374
|
+
export type { NativeInputOTPProps } from "./input-otp";
|
|
375
|
+
export { NativeCalendar } from "./calendar";
|
|
376
|
+
export type { NativeCalendarProps, NativeCalendarRange } from "./calendar";
|
|
377
|
+
export { NativeCarousel } from "./carousel";
|
|
378
|
+
export type { NativeCarouselProps } from "./carousel";
|
|
379
|
+
export { NativeChartContainer } from "./chart";
|
|
380
|
+
export type { NativeChartContainerProps, NativeChartConfig } from "./chart";
|
|
381
|
+
export { NativeSortableList } from "./sortable-list";
|
|
382
|
+
export type { NativeSortableListProps, NativeSortableListItemContext, NativeSortableListLabels } from "./sortable-list";
|
|
383
|
+
export { NativeStatCard } from "./stat-card";
|
|
384
|
+
export type { NativeStatCardProps, NativeStatCardColor } from "./stat-card";
|
|
385
|
+
export { NativeStatusBadge } from "./stat-card";
|
|
386
|
+
export type { NativeStatusBadgeProps } from "./stat-card";
|
|
387
|
+
export { NativeUserAvatar } from "./stat-card";
|
|
388
|
+
export type { NativeUserAvatarProps } from "./stat-card";
|
|
389
|
+
export { NativeReadinessChip } from "./resource";
|
|
390
|
+
export type { NativeReadinessChipProps } from "./resource";
|
|
391
|
+
export { NativeHeadlineNumbers } from "./resource";
|
|
392
|
+
export type { NativeHeadlineNumbersProps } from "./resource";
|
|
393
|
+
export { NativeSummaryCard } from "./resource";
|
|
394
|
+
export type { NativeSummaryCardProps } from "./resource";
|
|
395
|
+
export { NativeFollowUpList } from "./resource";
|
|
396
|
+
export type { NativeFollowUpListProps, NativeFollowUpEntry } from "./resource";
|
|
397
|
+
export { NativeResponsesToolbar } from "./resource";
|
|
398
|
+
export type { NativeResponsesToolbarProps, NativeResponsesView } from "./resource";
|
|
399
|
+
export { NativeSettingsRow } from "./settings-row";
|
|
400
|
+
export type { NativeSettingsRowProps } from "./settings-row";
|
|
401
|
+
export { NativeToggleRow } from "./settings-row";
|
|
402
|
+
export type { NativeToggleRowProps } from "./settings-row";
|
|
403
|
+
export { NativeResourceSettingsPage } from "./settings-row";
|
|
404
|
+
export type { NativeResourceSettingsPageProps, NativeResourceSettingsSection } from "./settings-row";
|
|
405
|
+
export { NativeNoFeaturesFound, NativeNoFeedbackFound, NativeNoSearchResults } from "./empty-state";
|
|
406
|
+
export { NativeWorkspaceSwitcher } from "./workspace-switcher";
|
|
407
|
+
export type { NativeWorkspaceSwitcherProps } from "./workspace-switcher";
|
|
@@ -51,7 +51,9 @@ const variantClasses: Record<NativeInlineAlertVariant, string> = {
|
|
|
51
51
|
const titleClasses: Record<NativeInlineAlertVariant, string> = {
|
|
52
52
|
info: "text-foreground",
|
|
53
53
|
success: "text-primary-text",
|
|
54
|
-
warning:
|
|
54
|
+
// The warning token is an amber that reads at about 2:1 on the tint, under the 4.5:1 text
|
|
55
|
+
// needs: the tint and border carry the warning, as on the web's InlineAlert.
|
|
56
|
+
warning: "text-foreground",
|
|
55
57
|
destructive: "text-destructive",
|
|
56
58
|
};
|
|
57
59
|
|