@marktiderman/genesis-ui-native 3.11.0 → 3.12.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.
Files changed (78) hide show
  1. package/README.md +69 -0
  2. package/dist/{chunk-ZUR4PK77.js → chunk-47CDRP43.js} +45 -166
  3. package/dist/chunk-47CDRP43.js.map +1 -0
  4. package/dist/{chunk-SG7LYX7Z.js → chunk-BQYT6TH2.js} +14 -6
  5. package/dist/chunk-BQYT6TH2.js.map +1 -0
  6. package/dist/{chunk-EAHK7D7N.js → chunk-C2ARUGT7.js} +146 -42
  7. package/dist/chunk-C2ARUGT7.js.map +1 -0
  8. package/dist/{chunk-VEWSY4TZ.js → chunk-D4UU6KIF.js} +236 -21
  9. package/dist/chunk-D4UU6KIF.js.map +1 -0
  10. package/dist/{chunk-GGH3ZQNO.js → chunk-TUDJDIGC.js} +4 -4
  11. package/dist/{chunk-GGH3ZQNO.js.map → chunk-TUDJDIGC.js.map} +1 -1
  12. package/dist/{chunk-PMS2V46D.js → chunk-VHUUOH46.js} +2 -2
  13. package/dist/{chunk-PMS2V46D.js.map → chunk-VHUUOH46.js.map} +1 -1
  14. package/dist/{chunk-IWWXERKQ.js → chunk-X5CPLUPZ.js} +1236 -136
  15. package/dist/chunk-X5CPLUPZ.js.map +1 -0
  16. package/dist/components/index.d.ts +510 -25
  17. package/dist/components/index.js +5 -5
  18. package/dist/data/index.d.ts +167 -33
  19. package/dist/data/index.js +1082 -760
  20. package/dist/data/index.js.map +1 -1
  21. package/dist/hooks/index.d.ts +2 -2
  22. package/dist/hooks/index.js +1 -1
  23. package/dist/icons/lucide.d.ts +1 -1
  24. package/dist/index.d.ts +6 -3
  25. package/dist/index.js +7 -7
  26. package/dist/layouts/index.d.ts +79 -6
  27. package/dist/layouts/index.js +5 -5
  28. package/dist/{native-modules-Bkm1jHO-.d.ts → native-modules-6JnyeGR-.d.ts} +55 -1
  29. package/package.json +70 -4
  30. package/src/components/__tests__/combobox.test.tsx +20 -0
  31. package/src/components/__tests__/number-input.test.tsx +112 -1
  32. package/src/components/__tests__/parity-controls.test.tsx +366 -0
  33. package/src/components/__tests__/parity-display.test.tsx +295 -0
  34. package/src/components/__tests__/twin-props.test.tsx +114 -0
  35. package/src/components/badge.tsx +3 -0
  36. package/src/components/button-group.tsx +50 -0
  37. package/src/components/calendar.tsx +183 -0
  38. package/src/components/carousel.tsx +175 -0
  39. package/src/components/chart.tsx +268 -0
  40. package/src/components/chip-group.tsx +34 -14
  41. package/src/components/choice-card.tsx +56 -19
  42. package/src/components/combobox.tsx +6 -5
  43. package/src/components/empty-state.tsx +40 -0
  44. package/src/components/flatten-children.ts +13 -0
  45. package/src/components/index.ts +49 -1
  46. package/src/components/inline-alert.tsx +3 -1
  47. package/src/components/input-group.tsx +99 -0
  48. package/src/components/input-otp.tsx +124 -0
  49. package/src/components/input.tsx +40 -12
  50. package/src/components/list-item.tsx +20 -4
  51. package/src/components/number-input.tsx +45 -15
  52. package/src/components/radio-group.tsx +5 -0
  53. package/src/components/resource.tsx +227 -0
  54. package/src/components/settings-row.tsx +194 -0
  55. package/src/components/slider.tsx +3 -9
  56. package/src/components/sortable-list.tsx +287 -0
  57. package/src/components/stat-card.tsx +106 -0
  58. package/src/components/stepper.tsx +4 -2
  59. package/src/components/widget-tile.tsx +66 -0
  60. package/src/components/workspace-switcher.tsx +217 -0
  61. package/src/data/NativeCustomView.tsx +117 -0
  62. package/src/data/NativeFormFields.tsx +312 -0
  63. package/src/data/NativeRecordPeek.tsx +130 -0
  64. package/src/data/NativeResourceFormField.tsx +32 -0
  65. package/src/data/__tests__/parity-data.test.tsx +350 -0
  66. package/src/data/index.ts +13 -0
  67. package/src/layouts/__tests__/keyboard-scroll.test.tsx +58 -2
  68. package/src/layouts/__tests__/notifications-page.test.tsx +12 -0
  69. package/src/layouts/index.ts +13 -0
  70. package/src/layouts/keyboard.tsx +22 -2
  71. package/src/layouts/notifications-page.tsx +13 -35
  72. package/src/layouts/pages.tsx +262 -0
  73. package/src/native-modules.tsx +37 -0
  74. package/dist/chunk-EAHK7D7N.js.map +0 -1
  75. package/dist/chunk-IWWXERKQ.js.map +0 -1
  76. package/dist/chunk-SG7LYX7Z.js.map +0 -1
  77. package/dist/chunk-VEWSY4TZ.js.map +0 -1
  78. package/dist/chunk-ZUR4PK77.js.map +0 -1
@@ -0,0 +1,287 @@
1
+ /**
2
+ * SortableList — a vertical list the person rearranges (course steps, form fields): the twin of
3
+ * genesis-ui's SortableList, with the same `items`, `getKey`, `getItemLabel`, `renderItem` and
4
+ * `onReorder(from, to, { key })`.
5
+ *
6
+ * Every way to move an item does the same thing, so dragging is never the only one:
7
+ * - drag the row's handle (`context.handle`, render it in the row). Once a drag starts it keeps
8
+ * the gesture (a parent ScrollView can't take it over); `onDragChange` tells the screen, so it
9
+ * can also stop its scroll view (`scrollEnabled={!dragging}`), which iOS needs for a native one;
10
+ * - long press the row for a Move menu (up, down, to top, to bottom; `moveMenu`, on by default);
11
+ * - a screen reader's actions on the row (swipe up or down on it: the same four moves);
12
+ * - `moveUp` / `moveDown` / `moveTo` from the render context, for buttons of your own.
13
+ *
14
+ * The list shows the new order at once and keeps it until `onReorder`'s promise settles; a
15
+ * rejected promise puts the old order back and says the move failed. Moves are announced. The
16
+ * order arithmetic is genesis-core's (`moveItem`, `dropIndex`, `movedAnnouncement`), as on the web.
17
+ *
18
+ * The rows are plain views, not a virtualized list: for tens of items, not thousands.
19
+ *
20
+ * @stability Beta
21
+ */
22
+ import { useMemo, useRef, useState, type ReactNode } from "react";
23
+ import { AccessibilityInfo, PanResponder, Pressable, Text, View } from "react-native";
24
+ import { dropIndex, moveItem, movedAnnouncement } from "@marktiderman/genesis-core/headless";
25
+ import { NativeContextMenu } from "./context-menu";
26
+ import { cn } from "../utils";
27
+
28
+ export interface NativeSortableListItemContext {
29
+ /** The item's position as shown, from 0. */
30
+ index: number;
31
+ /** The drag handle: render it somewhere in the row. */
32
+ handle: ReactNode;
33
+ /** True while this item is being dragged. */
34
+ isDragging: boolean;
35
+ moveUp: () => void;
36
+ moveDown: () => void;
37
+ moveTo: (index: number) => void;
38
+ }
39
+
40
+ export interface NativeSortableListLabels {
41
+ /** `{name}`: the handle's label. Default "Reorder {name}". */
42
+ reorder?: string;
43
+ moveUp?: string;
44
+ moveDown?: string;
45
+ moveToTop?: string;
46
+ moveToBottom?: string;
47
+ /** `{name}`, `{n}`, `{total}`. Default "{name} moved to position {n} of {total}." */
48
+ moved?: string;
49
+ /** `{name}`. Default "Couldn’t move {name}." */
50
+ moveFailed?: string;
51
+ cancel?: string;
52
+ }
53
+
54
+ export interface NativeSortableListProps<T> {
55
+ items: readonly T[];
56
+ getKey: (item: T) => string;
57
+ getItemLabel: (item: T) => string;
58
+ renderItem: (item: T, context: NativeSortableListItemContext) => ReactNode;
59
+ /** Move the item at `from` to `to`; by the time a returned promise settles, `items` is in the new order. */
60
+ onReorder: (from: number, to: number, move: { key: string }) => void | Promise<void>;
61
+ /** The list's accessible name ("Course steps"). */
62
+ label: string;
63
+ disabled?: boolean;
64
+ /** The Move menu on a long press. Default true. */
65
+ moveMenu?: boolean;
66
+ /** A drag started (`true`) or ended (`false`): stop the screen's ScrollView while it runs. */
67
+ onDragChange?: (dragging: boolean) => void;
68
+ labels?: NativeSortableListLabels;
69
+ className?: string;
70
+ itemClassName?: string;
71
+ testID?: string;
72
+ }
73
+
74
+ const DEFAULT_LABELS: Required<NativeSortableListLabels> = {
75
+ reorder: "Reorder {name}",
76
+ moveUp: "Move up",
77
+ moveDown: "Move down",
78
+ moveToTop: "Move to top",
79
+ moveToBottom: "Move to bottom",
80
+ moved: "{name} moved to position {n} of {total}.",
81
+ moveFailed: "Couldn’t move {name}.",
82
+ cancel: "Cancel",
83
+ };
84
+
85
+ const announce = (text: string) => AccessibilityInfo.announceForAccessibility?.(text);
86
+
87
+ export function NativeSortableList<T>({
88
+ items,
89
+ getKey,
90
+ getItemLabel,
91
+ renderItem,
92
+ onReorder,
93
+ label,
94
+ disabled = false,
95
+ moveMenu = true,
96
+ onDragChange,
97
+ labels: labelsProp,
98
+ className,
99
+ itemClassName,
100
+ testID = "native-sortable-list",
101
+ }: NativeSortableListProps<T>) {
102
+ const t = { ...DEFAULT_LABELS, ...labelsProp };
103
+ const itemKeys = items.map(getKey);
104
+ const byKey = new Map(items.map((item) => [getKey(item), item] as const));
105
+ // The order shown until a committed move settles.
106
+ const [preview, setPreview] = useState<string[] | null>(null);
107
+ const pending = useRef(false);
108
+ const [drag, setDrag] = useState<{ key: string; from: number; dy: number } | null>(null);
109
+ const [menuFor, setMenuFor] = useState<string | null>(null);
110
+ const rowHeight = useRef(56);
111
+
112
+ const baseKeys = preview && preview.length === itemKeys.length && preview.every((k) => byKey.has(k)) ? preview : itemKeys;
113
+ const total = baseKeys.length;
114
+ const nameOf = (key: string) => {
115
+ const item = byKey.get(key);
116
+ return item === undefined ? key : getItemLabel(item);
117
+ };
118
+ const target = drag ? dropIndex(drag.from, drag.dy, rowHeight.current, total) : null;
119
+ const keys = drag && target !== null ? moveItem(baseKeys, drag.from, target) : baseKeys;
120
+
121
+ const move = (key: string, to: number) => {
122
+ if (disabled || pending.current) return;
123
+ const from = itemKeys.indexOf(key);
124
+ const dest = Math.max(0, Math.min(total - 1, Math.round(to)));
125
+ if (from < 0 || dest === from) return;
126
+ pending.current = true;
127
+ setPreview(moveItem(itemKeys, from, dest));
128
+ let result: void | Promise<void>;
129
+ try {
130
+ result = onReorder(from, dest, { key });
131
+ } catch (error) {
132
+ result = Promise.reject(error);
133
+ }
134
+ Promise.resolve(result)
135
+ .then(
136
+ () => announce(movedAnnouncement(nameOf(key), dest, total, t.moved)),
137
+ () => announce(t.moveFailed.replace("{name}", nameOf(key))),
138
+ )
139
+ .finally(() => {
140
+ pending.current = false;
141
+ setPreview(null);
142
+ });
143
+ };
144
+
145
+ // The responders are built once per order; what they call is read at release time, so a screen's
146
+ // `onReorder` that closes over newer state (a mutation's latest value) is the one that runs.
147
+ const latest = useRef({ move, onDragChange });
148
+ latest.current = { move, onDragChange };
149
+
150
+ const responders = useMemo(() => {
151
+ const map = new Map<string, ReturnType<typeof PanResponder.create>>();
152
+ for (const [i, key] of baseKeys.entries()) {
153
+ map.set(
154
+ key,
155
+ PanResponder.create({
156
+ onStartShouldSetPanResponder: () => !disabled && !pending.current,
157
+ onMoveShouldSetPanResponder: () => !disabled && !pending.current,
158
+ // A drag in progress keeps the gesture: a parent ScrollView asking for it is refused, and
159
+ // on Android the native scroll is blocked while the handle holds it.
160
+ onPanResponderTerminationRequest: () => false,
161
+ onShouldBlockNativeResponder: () => true,
162
+ onPanResponderGrant: () => {
163
+ setDrag({ key, from: i, dy: 0 });
164
+ latest.current.onDragChange?.(true);
165
+ },
166
+ onPanResponderMove: (_e, g) => setDrag({ key, from: i, dy: g.dy }),
167
+ onPanResponderRelease: (_e, g) => {
168
+ setDrag(null);
169
+ latest.current.onDragChange?.(false);
170
+ latest.current.move(key, dropIndex(i, g.dy, rowHeight.current, baseKeys.length));
171
+ },
172
+ onPanResponderTerminate: () => {
173
+ setDrag(null);
174
+ latest.current.onDragChange?.(false);
175
+ },
176
+ }),
177
+ );
178
+ }
179
+ return map;
180
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- rebuilt when the order or state changes
181
+ }, [baseKeys.join("\u0000"), disabled]);
182
+
183
+ const menuIndex = menuFor ? baseKeys.indexOf(menuFor) : -1;
184
+
185
+ return (
186
+ <View testID={testID} accessibilityRole="list" accessibilityLabel={label} className={cn("gap-2", className)}>
187
+ {keys.map((key, index) => {
188
+ const item = byKey.get(key);
189
+ if (item === undefined) return null;
190
+ const from = baseKeys.indexOf(key);
191
+ const isDragging = drag?.key === key;
192
+ const name = nameOf(key);
193
+ const handle = (
194
+ <View
195
+ testID={`${testID}-handle-${key}`}
196
+ accessible={false}
197
+ importantForAccessibility="no-hide-descendants"
198
+ className={cn("h-11 w-8 items-center justify-center", disabled && "opacity-40")}
199
+ {...(responders.get(key)?.panHandlers ?? {})}
200
+ >
201
+ <Text className="text-lg text-muted-foreground">⋮⋮</Text>
202
+ </View>
203
+ );
204
+ const actions = [
205
+ ...(from > 0 ? [{ name: "moveToTop", label: t.moveToTop }, { name: "moveUp", label: t.moveUp }] : []),
206
+ ...(from < total - 1 ? [{ name: "moveDown", label: t.moveDown }, { name: "moveToBottom", label: t.moveToBottom }] : []),
207
+ ];
208
+ return (
209
+ <View
210
+ key={key}
211
+ testID={`${testID}-item-${key}`}
212
+ accessible
213
+ accessibilityLabel={`${name}, ${index + 1} of ${total}`}
214
+ accessibilityHint={disabled ? undefined : t.reorder.replace("{name}", name)}
215
+ accessibilityActions={disabled ? [] : [...actions, ...(moveMenu ? [{ name: "longpress", label: t.reorder.replace("{name}", name) }] : [])]}
216
+ onAccessibilityAction={(e: { nativeEvent: { actionName: string } }) => {
217
+ const a = e.nativeEvent.actionName;
218
+ if (a === "moveUp") move(key, from - 1);
219
+ else if (a === "moveDown") move(key, from + 1);
220
+ else if (a === "moveToTop") move(key, 0);
221
+ else if (a === "moveToBottom") move(key, total - 1);
222
+ else if (a === "longpress" && moveMenu) setMenuFor(key);
223
+ }}
224
+ onLayout={
225
+ index === 0
226
+ ? (e: { nativeEvent?: { layout?: { height?: number } } }) => {
227
+ const h = e.nativeEvent?.layout?.height;
228
+ if (h) rowHeight.current = h + 8;
229
+ }
230
+ : undefined
231
+ }
232
+ className={cn(isDragging && "z-10 opacity-90 shadow-lg", itemClassName)}
233
+ style={isDragging && target !== null ? { transform: [{ translateY: drag!.dy - (target - drag!.from) * rowHeight.current }] } : undefined}
234
+ >
235
+ <LongPress enabled={moveMenu && !disabled} onLongPress={() => setMenuFor(key)} testID={`${testID}-row-${key}`}>
236
+ {renderItem(item, {
237
+ index,
238
+ handle,
239
+ isDragging,
240
+ moveUp: () => move(key, from - 1),
241
+ moveDown: () => move(key, from + 1),
242
+ moveTo: (to) => move(key, to),
243
+ })}
244
+ </LongPress>
245
+ </View>
246
+ );
247
+ })}
248
+ {moveMenu ? (
249
+ <NativeContextMenu
250
+ testID={`${testID}-menu`}
251
+ open={menuFor !== null}
252
+ onOpenChange={(open) => (open ? undefined : setMenuFor(null))}
253
+ title={menuFor ? nameOf(menuFor) : undefined}
254
+ cancelLabel={t.cancel}
255
+ actions={
256
+ menuFor === null
257
+ ? []
258
+ : [
259
+ ...(menuIndex > 0
260
+ ? [
261
+ { id: "top", label: t.moveToTop, onPress: () => move(menuFor, 0) },
262
+ { id: "up", label: t.moveUp, onPress: () => move(menuFor, menuIndex - 1) },
263
+ ]
264
+ : []),
265
+ ...(menuIndex < total - 1
266
+ ? [
267
+ { id: "down", label: t.moveDown, onPress: () => move(menuFor, menuIndex + 1) },
268
+ { id: "bottom", label: t.moveToBottom, onPress: () => move(menuFor, total - 1) },
269
+ ]
270
+ : []),
271
+ ]
272
+ }
273
+ />
274
+ ) : null}
275
+ </View>
276
+ );
277
+ }
278
+
279
+ /** A long press on the row's background opens the Move menu; presses inside the row stay the row's. */
280
+ function LongPress({ enabled, onLongPress, children, testID }: { enabled: boolean; onLongPress: () => void; children: ReactNode; testID: string }) {
281
+ if (!enabled) return <>{children}</>;
282
+ return (
283
+ <Pressable testID={testID} accessible={false} onLongPress={onLongPress} delayLongPress={350}>
284
+ {children}
285
+ </Pressable>
286
+ );
287
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * StatCard — a labelled number on a dashboard: the twin of genesis-ui's StatCard, with the same
3
+ * `label`, `value`, `color` and `trend`. `onPress` makes the tile a button (the web's `href`).
4
+ * The trend line ("+12% vs last week") is genesis-core's `formatTrend`, as on the web.
5
+ *
6
+ * StatusBadge — a goal or task status as a tinted badge: the twin of genesis-ui's StatusBadge,
7
+ * the status's tone from genesis-core's `STATUS_BADGE_TONES`, drawn by NativeBadge.
8
+ *
9
+ * UserAvatar — a person's photo, or their initials: the twin of genesis-ui's UserAvatar, on
10
+ * NativeAvatar, with initials from genesis-core's `initialsOf` and the person's name as the label.
11
+ *
12
+ * @stability Beta
13
+ */
14
+ import type { ReactNode } from "react";
15
+ import { formatTrend, STATUS_BADGE_TONES, statusBadgeLabel, type StatusBadgeStatus } from "@marktiderman/genesis-core/headless";
16
+ import { initialsOf } from "@marktiderman/genesis-core/resource-view";
17
+ import { NativeAvatar } from "./avatar";
18
+ import { NativeBadge } from "./badge";
19
+ import { WidgetTile } from "./widget-tile";
20
+ import { View } from "react-native";
21
+ import { cn } from "../utils";
22
+
23
+ export type NativeStatCardColor = "primary" | "success" | "warning" | "info" | "destructive" | "muted";
24
+
25
+ const ICON_TONE: Record<NativeStatCardColor, string> = {
26
+ primary: "text-primary-text",
27
+ success: "text-success",
28
+ warning: "text-warning",
29
+ info: "text-info",
30
+ destructive: "text-destructive",
31
+ muted: "text-muted-foreground",
32
+ };
33
+
34
+ export interface NativeStatCardProps {
35
+ label: string;
36
+ value: string | number;
37
+ /** An icon (a NativeIcon) beside the label. */
38
+ icon?: ReactNode;
39
+ /** The icon's tone. Default `primary`. */
40
+ color?: NativeStatCardColor;
41
+ trend?: { value: number; label: string };
42
+ /** Makes the tile a button (open the list behind the number). */
43
+ onPress?: () => void;
44
+ className?: string;
45
+ testID?: string;
46
+ }
47
+
48
+ export function NativeStatCard({ label, value, icon, color = "primary", trend, onPress, className, testID = "native-stat-card" }: NativeStatCardProps) {
49
+ const t = trend ? formatTrend(trend) : null;
50
+ return (
51
+ <WidgetTile
52
+ variant="stat"
53
+ label={label}
54
+ value={value}
55
+ icon={icon ? <View className={ICON_TONE[color]}>{icon}</View> : undefined}
56
+ detail={t?.text}
57
+ detailClassName={t ? (t.positive ? "text-primary-text" : "text-destructive") : undefined}
58
+ onPress={onPress}
59
+ className={className}
60
+ testID={testID}
61
+ />
62
+ );
63
+ }
64
+
65
+ export interface NativeStatusBadgeProps {
66
+ status: StatusBadgeStatus;
67
+ /** The words. Default the status's ("On track"). */
68
+ children?: ReactNode;
69
+ className?: string;
70
+ testID?: string;
71
+ }
72
+
73
+ export function NativeStatusBadge({ status, children, className, testID }: NativeStatusBadgeProps) {
74
+ return (
75
+ <NativeBadge variant={STATUS_BADGE_TONES[status]} className={className} testID={testID ?? `status-badge-${status}`}>
76
+ {children ?? statusBadgeLabel(status)}
77
+ </NativeBadge>
78
+ );
79
+ }
80
+
81
+ export interface NativeUserAvatarProps {
82
+ /** The person's full name: the initials and what a screen reader hears. */
83
+ name: string;
84
+ src?: string | null;
85
+ /** `sm` 32, `default` 40, `lg` 48 points, as the web's sizes. */
86
+ size?: "sm" | "default" | "lg";
87
+ /** In a list of people: two letters for a one-word name, as the web's `distinct`. */
88
+ distinct?: boolean;
89
+ className?: string;
90
+ testID?: string;
91
+ }
92
+
93
+ const AVATAR_SIZE = { sm: 32, default: 40, lg: 48 } as const;
94
+
95
+ export function NativeUserAvatar({ name, src, size = "default", distinct, className, testID }: NativeUserAvatarProps) {
96
+ return (
97
+ <NativeAvatar
98
+ src={src}
99
+ alt={name}
100
+ fallback={initialsOf(name, { distinct }) || "?"}
101
+ size={AVATAR_SIZE[size]}
102
+ className={cn(className)}
103
+ testID={testID ?? "native-user-avatar"}
104
+ />
105
+ );
106
+ }
@@ -7,6 +7,7 @@
7
7
  * @stability Beta
8
8
  */
9
9
  import { Text, View } from "react-native";
10
+ import { stepState } from "@marktiderman/genesis-core/headless";
10
11
  import { cn } from "../utils";
11
12
 
12
13
  export interface NativeStepperStep {
@@ -38,8 +39,9 @@ export function NativeStepper({
38
39
  >
39
40
  <View className="flex-row items-center">
40
41
  {steps.map((s, i) => {
41
- const isCompleted = i < current;
42
- const isCurrent = i === current;
42
+ const state = stepState(i, current);
43
+ const isCompleted = state === "complete";
44
+ const isCurrent = state === "current";
43
45
  return (
44
46
  <View key={i} className="flex-1 flex-row items-center">
45
47
  <View
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The one tile under the phone's stat card, headline numbers and summary cards, as genesis-ui's
3
+ * WidgetTile is on the web: a NativeCard with a label (and an icon or a line on the right), a
4
+ * value, a detail line and a body. Not exported: use NativeStatCard, NativeHeadlineNumbers or
5
+ * NativeSummaryCard, the components that name the job.
6
+ */
7
+ import type { ReactNode } from "react";
8
+ import { Pressable, Text, View } from "react-native";
9
+ import { NativeCard } from "./card";
10
+ import { cn } from "../utils";
11
+
12
+ export interface WidgetTileProps {
13
+ variant: "stat" | "headline" | "summary";
14
+ label: string;
15
+ value?: ReactNode;
16
+ detail?: ReactNode;
17
+ detailClassName?: string | undefined;
18
+ icon?: ReactNode;
19
+ meta?: ReactNode;
20
+ children?: ReactNode;
21
+ onPress?: (() => void) | undefined;
22
+ className?: string | undefined;
23
+ testID?: string | undefined;
24
+ }
25
+
26
+ const asText = (node: ReactNode, className: string) =>
27
+ typeof node === "string" || typeof node === "number" ? <Text className={className}>{node}</Text> : node;
28
+
29
+ export function WidgetTile({ variant, label, value, detail, detailClassName, icon, meta, children, onPress, className, testID }: WidgetTileProps) {
30
+ const spoken = [label, typeof value === "string" || typeof value === "number" ? String(value) : null, typeof detail === "string" ? detail : null]
31
+ .filter(Boolean)
32
+ .join(", ");
33
+ const body = (
34
+ <NativeCard className={cn("gap-1 p-4", className)} testID={testID}>
35
+ <View className="flex-row items-center justify-between gap-2">
36
+ <View className="min-w-0 flex-1 flex-row items-center gap-2">
37
+ {variant === "summary" && icon ? <View accessibilityElementsHidden>{icon}</View> : null}
38
+ <Text
39
+ numberOfLines={variant === "summary" ? 2 : 1}
40
+ className={variant === "summary" ? "flex-1 text-base font-semibold text-foreground" : "flex-1 text-sm font-medium text-muted-foreground"}
41
+ >
42
+ {label}
43
+ </Text>
44
+ </View>
45
+ {variant !== "summary" && icon ? <View accessibilityElementsHidden>{icon}</View> : null}
46
+ {meta ? asText(meta, "text-xs text-muted-foreground") : null}
47
+ </View>
48
+ {value !== undefined ? asText(value, variant === "headline" ? "text-3xl font-bold text-foreground" : "text-2xl font-bold text-foreground") : null}
49
+ {detail ? asText(detail, cn("text-xs text-muted-foreground", detailClassName)) : null}
50
+ {children ? <View className="mt-2">{children}</View> : null}
51
+ </NativeCard>
52
+ );
53
+ if (onPress) {
54
+ return (
55
+ <Pressable accessibilityRole="button" accessibilityLabel={spoken} onPress={onPress}>
56
+ {body}
57
+ </Pressable>
58
+ );
59
+ }
60
+ if (variant === "summary") return body;
61
+ return (
62
+ <View accessible accessibilityLabel={spoken}>
63
+ {body}
64
+ </View>
65
+ );
66
+ }