@marktiderman/genesis-ui-native 2.0.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/dist/chunk-BAU4YQZV.js +760 -0
- package/dist/chunk-BAU4YQZV.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-HNIEFTEL.js +43 -0
- package/dist/chunk-HNIEFTEL.js.map +1 -0
- package/dist/chunk-N4WHTQIO.js +20 -0
- package/dist/chunk-N4WHTQIO.js.map +1 -0
- package/dist/chunk-OHZD7KRO.js +11 -0
- package/dist/chunk-OHZD7KRO.js.map +1 -0
- package/dist/chunk-PTJ2KCLM.js +160 -0
- package/dist/chunk-PTJ2KCLM.js.map +1 -0
- package/dist/chunk-TXJT55JC.js +2213 -0
- package/dist/chunk-TXJT55JC.js.map +1 -0
- package/dist/chunk-ULS7I6ZS.js +183 -0
- package/dist/chunk-ULS7I6ZS.js.map +1 -0
- package/dist/chunk-ZVF6PONU.js +522 -0
- package/dist/chunk-ZVF6PONU.js.map +1 -0
- package/dist/components/index.d.ts +908 -0
- package/dist/components/index.js +8 -0
- package/dist/components/index.js.map +1 -0
- package/dist/data/index.d.ts +117 -0
- package/dist/data/index.js +770 -0
- package/dist/data/index.js.map +1 -0
- package/dist/hooks/index.d.ts +31 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts/index.d.ts +364 -0
- package/dist/layouts/index.js +8 -0
- package/dist/layouts/index.js.map +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +4 -0
- package/dist/utils.js.map +1 -0
- package/package.json +127 -0
- package/src/components/__tests__/accordion.test.tsx +122 -0
- package/src/components/__tests__/chip-group.test.tsx +45 -0
- package/src/components/__tests__/combobox.test.tsx +97 -0
- package/src/components/__tests__/drawer.test.tsx +98 -0
- package/src/components/__tests__/empty-state.test.tsx +66 -0
- package/src/components/__tests__/header-card.test.tsx +31 -0
- package/src/components/__tests__/layout.test.tsx +109 -0
- package/src/components/__tests__/list-item.test.tsx +31 -0
- package/src/components/__tests__/number-input.test.tsx +46 -0
- package/src/components/__tests__/pagination.test.tsx +43 -0
- package/src/components/__tests__/search-bar.test.tsx +41 -0
- package/src/components/__tests__/segmented-empty-alert.test.tsx +79 -0
- package/src/components/__tests__/slider.test.tsx +134 -0
- package/src/components/__tests__/stepper.test.tsx +25 -0
- package/src/components/__tests__/toast.test.tsx +63 -0
- package/src/components/accordion.tsx +223 -0
- package/src/components/alert.tsx +131 -0
- package/src/components/avatar.tsx +68 -0
- package/src/components/badge.tsx +80 -0
- package/src/components/button.tsx +118 -0
- package/src/components/card.tsx +120 -0
- package/src/components/checkbox.tsx +60 -0
- package/src/components/chip-group.tsx +127 -0
- package/src/components/combobox.tsx +137 -0
- package/src/components/date-time-picker.tsx +127 -0
- package/src/components/dialog.tsx +131 -0
- package/src/components/drawer.tsx +131 -0
- package/src/components/dropdown-menu.tsx +133 -0
- package/src/components/empty-state.tsx +161 -0
- package/src/components/header-card.tsx +116 -0
- package/src/components/index.ts +259 -0
- package/src/components/inline-alert.tsx +150 -0
- package/src/components/input.tsx +51 -0
- package/src/components/label.tsx +35 -0
- package/src/components/layout/box.tsx +115 -0
- package/src/components/layout/flex.ts +24 -0
- package/src/components/layout/grid.tsx +73 -0
- package/src/components/layout/index.ts +27 -0
- package/src/components/layout/inline.tsx +63 -0
- package/src/components/layout/spacing.ts +116 -0
- package/src/components/layout/stack.tsx +58 -0
- package/src/components/list-item.tsx +108 -0
- package/src/components/number-input.tsx +119 -0
- package/src/components/pagination.tsx +132 -0
- package/src/components/popover.tsx +198 -0
- package/src/components/progress.tsx +50 -0
- package/src/components/radio-group.tsx +92 -0
- package/src/components/refresh-control.tsx +73 -0
- package/src/components/search-bar.tsx +128 -0
- package/src/components/section-list.tsx +54 -0
- package/src/components/segmented-control.tsx +79 -0
- package/src/components/select.tsx +178 -0
- package/src/components/separator.tsx +31 -0
- package/src/components/sheet.tsx +192 -0
- package/src/components/skeleton.tsx +104 -0
- package/src/components/slider.tsx +223 -0
- package/src/components/stepper.tsx +96 -0
- package/src/components/switch.tsx +35 -0
- package/src/components/tabs.tsx +147 -0
- package/src/components/text.tsx +62 -0
- package/src/components/textarea.tsx +52 -0
- package/src/components/toast.tsx +228 -0
- package/src/components/toggle.tsx +85 -0
- package/src/components/tooltip.tsx +104 -0
- package/src/data/NativeDataFilters.tsx +100 -0
- package/src/data/NativeDataPageShell.tsx +111 -0
- package/src/data/NativeDetailPanel.tsx +130 -0
- package/src/data/NativeEmptyState.tsx +46 -0
- package/src/data/NativeResourceForm.tsx +157 -0
- package/src/data/NativeResourceFormField.tsx +280 -0
- package/src/data/NativeResourcePage.tsx +505 -0
- package/src/data/index.ts +9 -0
- package/src/hooks/index.ts +16 -0
- package/src/hooks/use-genesis-extension.ts +81 -0
- package/src/hooks/use-reduced-motion.ts +32 -0
- package/src/hooks/use-theme-mode.ts +31 -0
- package/src/index.ts +5 -0
- package/src/layouts/__tests__/auth.test.tsx +150 -0
- package/src/layouts/__tests__/nav-bar.test.tsx +86 -0
- package/src/layouts/__tests__/notifications-page.test.tsx +94 -0
- package/src/layouts/__tests__/screen-container.test.tsx +79 -0
- package/src/layouts/__tests__/settings-page.test.tsx +107 -0
- package/src/layouts/__tests__/settings-sub-page.test.tsx +53 -0
- package/src/layouts/auth.tsx +352 -0
- package/src/layouts/index.ts +61 -0
- package/src/layouts/nav-bar.tsx +200 -0
- package/src/layouts/notifications-page.tsx +274 -0
- package/src/layouts/screen-container.tsx +213 -0
- package/src/layouts/settings-page.tsx +195 -0
- package/src/layouts/settings-sub-page.tsx +183 -0
- package/src/nativewind.d.ts +40 -0
- package/src/utils.ts +6 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drawer — side-anchored panel that slides in from left or right.
|
|
3
|
+
*
|
|
4
|
+
* Use for navigation menus, account switchers, and supplementary
|
|
5
|
+
* controls that should not consume the main canvas. Backdrop dismisses
|
|
6
|
+
* on tap; on supported platforms a horizontal swipe also dismisses.
|
|
7
|
+
*
|
|
8
|
+
* For full-screen modal flows, prefer a navigation route. For a single
|
|
9
|
+
* action confirmation, prefer <NativeDialog>.
|
|
10
|
+
*
|
|
11
|
+
* @stability Beta
|
|
12
|
+
*/
|
|
13
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
14
|
+
import {
|
|
15
|
+
AccessibilityInfo,
|
|
16
|
+
Animated,
|
|
17
|
+
Dimensions,
|
|
18
|
+
Modal,
|
|
19
|
+
PanResponder,
|
|
20
|
+
Pressable,
|
|
21
|
+
View,
|
|
22
|
+
} from "react-native";
|
|
23
|
+
import { cn } from "../utils";
|
|
24
|
+
|
|
25
|
+
export interface NativeDrawerProps {
|
|
26
|
+
open: boolean;
|
|
27
|
+
onOpenChange: (open: boolean) => void;
|
|
28
|
+
/** Side the drawer slides in from. Default "left". */
|
|
29
|
+
side?: "left" | "right";
|
|
30
|
+
/** Drawer width. Default 80% of screen, capped at 360. */
|
|
31
|
+
width?: number;
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
className?: string;
|
|
34
|
+
testID?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function NativeDrawer({
|
|
38
|
+
open,
|
|
39
|
+
onOpenChange,
|
|
40
|
+
side = "left",
|
|
41
|
+
width,
|
|
42
|
+
children,
|
|
43
|
+
className,
|
|
44
|
+
testID,
|
|
45
|
+
}: NativeDrawerProps) {
|
|
46
|
+
const screen = Dimensions.get("window");
|
|
47
|
+
const drawerWidth = width ?? Math.min(screen.width * 0.8, 360);
|
|
48
|
+
const [reducedMotion, setReducedMotion] = useState(false);
|
|
49
|
+
const translate = useRef(new Animated.Value(side === "left" ? -drawerWidth : drawerWidth)).current;
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
AccessibilityInfo.isReduceMotionEnabled().then(setReducedMotion);
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
Animated.timing(translate, {
|
|
57
|
+
toValue: open ? 0 : side === "left" ? -drawerWidth : drawerWidth,
|
|
58
|
+
duration: reducedMotion ? 0 : 220,
|
|
59
|
+
useNativeDriver: true,
|
|
60
|
+
}).start();
|
|
61
|
+
}, [drawerWidth, open, reducedMotion, side, translate]);
|
|
62
|
+
|
|
63
|
+
// useMemo (not useRef.current) so the responder always closes over the
|
|
64
|
+
// current `side` / `drawerWidth` / `onOpenChange` values. Otherwise the
|
|
65
|
+
// gesture handler keeps reading mount-time values forever.
|
|
66
|
+
const panResponder = useMemo(
|
|
67
|
+
() =>
|
|
68
|
+
PanResponder.create({
|
|
69
|
+
onMoveShouldSetPanResponder: (_, g) => Math.abs(g.dx) > 8,
|
|
70
|
+
onPanResponderMove: (_, g) => {
|
|
71
|
+
if (side === "left") {
|
|
72
|
+
translate.setValue(Math.min(0, g.dx));
|
|
73
|
+
} else {
|
|
74
|
+
translate.setValue(Math.max(0, g.dx));
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
onPanResponderRelease: (_, g) => {
|
|
78
|
+
const dismiss =
|
|
79
|
+
side === "left" ? g.dx < -drawerWidth / 3 : g.dx > drawerWidth / 3;
|
|
80
|
+
if (dismiss) {
|
|
81
|
+
onOpenChange(false);
|
|
82
|
+
} else {
|
|
83
|
+
Animated.timing(translate, {
|
|
84
|
+
toValue: 0,
|
|
85
|
+
duration: 180,
|
|
86
|
+
useNativeDriver: true,
|
|
87
|
+
}).start();
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
[drawerWidth, onOpenChange, side, translate]
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Modal
|
|
96
|
+
visible={open}
|
|
97
|
+
transparent
|
|
98
|
+
animationType="none"
|
|
99
|
+
onRequestClose={() => onOpenChange(false)}
|
|
100
|
+
>
|
|
101
|
+
<Pressable
|
|
102
|
+
accessibilityLabel="Close drawer"
|
|
103
|
+
className="flex-1 bg-black/40"
|
|
104
|
+
onPress={() => onOpenChange(false)}
|
|
105
|
+
>
|
|
106
|
+
<Pressable onPress={() => {}} style={{ flex: 1 }}>
|
|
107
|
+
<Animated.View
|
|
108
|
+
testID={testID ?? "native-drawer"}
|
|
109
|
+
accessibilityViewIsModal
|
|
110
|
+
{...panResponder.panHandlers}
|
|
111
|
+
style={{
|
|
112
|
+
position: "absolute",
|
|
113
|
+
top: 0,
|
|
114
|
+
bottom: 0,
|
|
115
|
+
[side]: 0,
|
|
116
|
+
width: drawerWidth,
|
|
117
|
+
transform: [{ translateX: translate }],
|
|
118
|
+
}}
|
|
119
|
+
className={cn(
|
|
120
|
+
"border-border bg-background p-4 shadow-lg",
|
|
121
|
+
side === "left" ? "border-r" : "border-l",
|
|
122
|
+
className
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
<View className="flex-1">{children}</View>
|
|
126
|
+
</Animated.View>
|
|
127
|
+
</Pressable>
|
|
128
|
+
</Pressable>
|
|
129
|
+
</Modal>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DropdownMenu — contextual list anchored to a trigger.
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import React, { createContext, useContext, useState } from "react";
|
|
7
|
+
import { Modal, Pressable, Text, View } from "react-native";
|
|
8
|
+
import { cn } from "../utils";
|
|
9
|
+
|
|
10
|
+
interface DropdownMenuContextValue {
|
|
11
|
+
open: boolean;
|
|
12
|
+
setOpen: (v: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const DropdownMenuContext = createContext<DropdownMenuContextValue | null>(null);
|
|
16
|
+
|
|
17
|
+
function useDropdownMenuContext() {
|
|
18
|
+
const ctx = useContext(DropdownMenuContext);
|
|
19
|
+
if (!ctx) throw new Error("DropdownMenu compound components must be used within NativeDropdownMenu");
|
|
20
|
+
return ctx;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface NativeDropdownMenuProps {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function NativeDropdownMenu({ children }: NativeDropdownMenuProps) {
|
|
28
|
+
const [open, setOpen] = useState(false);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<DropdownMenuContext.Provider value={{ open, setOpen }}>
|
|
32
|
+
<View>{children}</View>
|
|
33
|
+
</DropdownMenuContext.Provider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface NativeDropdownMenuTriggerProps {
|
|
38
|
+
className?: string;
|
|
39
|
+
children: React.ReactNode;
|
|
40
|
+
testID?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function NativeDropdownMenuTrigger({
|
|
44
|
+
className,
|
|
45
|
+
children,
|
|
46
|
+
...props
|
|
47
|
+
}: NativeDropdownMenuTriggerProps) {
|
|
48
|
+
const { setOpen } = useDropdownMenuContext();
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Pressable className={cn(className)} onPress={() => setOpen(true)} {...props}>
|
|
52
|
+
{children}
|
|
53
|
+
</Pressable>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface NativeDropdownMenuContentProps {
|
|
58
|
+
className?: string;
|
|
59
|
+
children: React.ReactNode;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function NativeDropdownMenuContent({
|
|
63
|
+
className,
|
|
64
|
+
children,
|
|
65
|
+
}: NativeDropdownMenuContentProps) {
|
|
66
|
+
const { open, setOpen } = useDropdownMenuContext();
|
|
67
|
+
|
|
68
|
+
if (!open) return null;
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<Modal transparent animationType="fade" onRequestClose={() => setOpen(false)}>
|
|
72
|
+
<Pressable className="flex-1" onPress={() => setOpen(false)}>
|
|
73
|
+
<View className="flex-1 items-center justify-center">
|
|
74
|
+
{/* Captures touch to prevent backdrop press from closing menu when tapping content */}
|
|
75
|
+
<Pressable onPress={() => {}}>
|
|
76
|
+
<View
|
|
77
|
+
className={cn(
|
|
78
|
+
"min-w-[8rem] rounded-md border border-border bg-popover p-1 shadow-md",
|
|
79
|
+
className
|
|
80
|
+
)}
|
|
81
|
+
>
|
|
82
|
+
{children}
|
|
83
|
+
</View>
|
|
84
|
+
</Pressable>
|
|
85
|
+
</View>
|
|
86
|
+
</Pressable>
|
|
87
|
+
</Modal>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface NativeDropdownMenuItemProps {
|
|
92
|
+
className?: string;
|
|
93
|
+
children: React.ReactNode;
|
|
94
|
+
onPress?: () => void;
|
|
95
|
+
disabled?: boolean;
|
|
96
|
+
testID?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function NativeDropdownMenuItem({
|
|
100
|
+
className,
|
|
101
|
+
children,
|
|
102
|
+
onPress,
|
|
103
|
+
disabled,
|
|
104
|
+
...props
|
|
105
|
+
}: NativeDropdownMenuItemProps) {
|
|
106
|
+
return (
|
|
107
|
+
<Pressable
|
|
108
|
+
className={cn(
|
|
109
|
+
"flex-row items-center rounded-sm px-2 py-1.5",
|
|
110
|
+
disabled && "opacity-50",
|
|
111
|
+
className
|
|
112
|
+
)}
|
|
113
|
+
onPress={onPress}
|
|
114
|
+
disabled={disabled}
|
|
115
|
+
accessibilityRole="menuitem"
|
|
116
|
+
accessibilityState={{ disabled }}
|
|
117
|
+
{...props}
|
|
118
|
+
>
|
|
119
|
+
{typeof children === "string" ? (
|
|
120
|
+
<Text className="text-sm text-popover-foreground">{children}</Text>
|
|
121
|
+
) : (
|
|
122
|
+
children
|
|
123
|
+
)}
|
|
124
|
+
</Pressable>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
NativeDropdownMenu,
|
|
130
|
+
NativeDropdownMenuTrigger,
|
|
131
|
+
NativeDropdownMenuContent,
|
|
132
|
+
NativeDropdownMenuItem,
|
|
133
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EmptyState — what to show when a list / screen has no data.
|
|
3
|
+
*
|
|
4
|
+
* Three semantic variants drive default messaging:
|
|
5
|
+
* - "first-run": user has never had data here. Optimistic.
|
|
6
|
+
* - "no-results": user filtered/searched and got nothing. Suggest reset.
|
|
7
|
+
* - "error": fetching failed. Suggest retry.
|
|
8
|
+
*
|
|
9
|
+
* The variant only sets sensible defaults for `title` and tone — pass
|
|
10
|
+
* your own `title`, `body`, `primaryAction`, `secondaryAction`, etc. to
|
|
11
|
+
* override. Mirrors the @marktiderman/genesis-ui web `<EmptyState>` API where
|
|
12
|
+
* possible (illustration vs icon slot, primary/secondary actions).
|
|
13
|
+
*
|
|
14
|
+
* @stability Beta
|
|
15
|
+
*/
|
|
16
|
+
import { Text, View } from "react-native";
|
|
17
|
+
import { cn } from "../utils";
|
|
18
|
+
|
|
19
|
+
export type NativeEmptyStateVariant = "first-run" | "no-results" | "error";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Action descriptor for primary/secondary CTAs. Either pass a structured
|
|
23
|
+
* object (renders a Pressable button via the consumer's button slot) or
|
|
24
|
+
* pass an arbitrary node via `action` for maximum flexibility.
|
|
25
|
+
*/
|
|
26
|
+
export interface NativeEmptyStateAction {
|
|
27
|
+
label: string;
|
|
28
|
+
onPress: () => void;
|
|
29
|
+
testID?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface NativeEmptyStateProps {
|
|
33
|
+
/** Variant drives default tone + default title. Default "first-run". */
|
|
34
|
+
variant?: NativeEmptyStateVariant;
|
|
35
|
+
/** Headline. Falls back to a variant-specific default. */
|
|
36
|
+
title?: string;
|
|
37
|
+
/** Body copy shown below the title. (Alias: `description`.) */
|
|
38
|
+
body?: string;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Prefer `body`. `description` remains for back-compat with
|
|
41
|
+
* the original C3 API; both are accepted but `body` wins if both passed.
|
|
42
|
+
*/
|
|
43
|
+
description?: string;
|
|
44
|
+
/** Optional illustration (artwork node) above the title. */
|
|
45
|
+
illustration?: React.ReactNode;
|
|
46
|
+
/** Optional icon node above the title (use either icon or illustration). */
|
|
47
|
+
icon?: React.ReactNode;
|
|
48
|
+
/**
|
|
49
|
+
* Primary CTA. When provided, the consumer is responsible for rendering
|
|
50
|
+
* the button itself (we accept a node, not a label) so brand + token
|
|
51
|
+
* styling is honored. The web API takes a `{label, onPress}` descriptor;
|
|
52
|
+
* on native, prefer to pass a `<NativeButton>` directly to avoid
|
|
53
|
+
* cross-package coupling.
|
|
54
|
+
*/
|
|
55
|
+
primaryAction?: React.ReactNode;
|
|
56
|
+
/** Secondary CTA, rendered below the primary. */
|
|
57
|
+
secondaryAction?: React.ReactNode;
|
|
58
|
+
/**
|
|
59
|
+
* Free-form action slot. Equivalent to `primaryAction`; accepted for
|
|
60
|
+
* back-compat with the C3 API. If both `action` and `primaryAction` are
|
|
61
|
+
* passed, `primaryAction` wins.
|
|
62
|
+
*/
|
|
63
|
+
action?: React.ReactNode;
|
|
64
|
+
/**
|
|
65
|
+
* Developer-facing error details. Only rendered when __DEV__ is true at
|
|
66
|
+
* runtime (we infer by reading `process.env.NODE_ENV !== "production"`).
|
|
67
|
+
*/
|
|
68
|
+
details?: string;
|
|
69
|
+
className?: string;
|
|
70
|
+
testID?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const defaults: Record<NativeEmptyStateVariant, { title: string; tone: string }> = {
|
|
74
|
+
"first-run": { title: "Nothing here yet", tone: "text-muted-foreground" },
|
|
75
|
+
"no-results": { title: "No results", tone: "text-muted-foreground" },
|
|
76
|
+
error: { title: "Something went wrong", tone: "text-destructive" },
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export function NativeEmptyState({
|
|
80
|
+
variant = "first-run",
|
|
81
|
+
title,
|
|
82
|
+
body,
|
|
83
|
+
description,
|
|
84
|
+
illustration,
|
|
85
|
+
icon,
|
|
86
|
+
primaryAction,
|
|
87
|
+
secondaryAction,
|
|
88
|
+
action,
|
|
89
|
+
details,
|
|
90
|
+
className,
|
|
91
|
+
testID,
|
|
92
|
+
}: NativeEmptyStateProps) {
|
|
93
|
+
const meta = defaults[variant];
|
|
94
|
+
const resolvedBody = body ?? description;
|
|
95
|
+
const resolvedPrimary = primaryAction ?? action;
|
|
96
|
+
// Read NODE_ENV defensively — some bundlers don't define `process` at
|
|
97
|
+
// runtime (e.g., RN classic), so we guard via globalThis. The `details`
|
|
98
|
+
// slot is dev-only; we explicitly enumerate non-production values so an
|
|
99
|
+
// undefined NODE_ENV doesn't accidentally leak diagnostic strings.
|
|
100
|
+
const proc = (globalThis as { process?: { env?: { NODE_ENV?: string } } })
|
|
101
|
+
.process;
|
|
102
|
+
const nodeEnv = proc?.env?.NODE_ENV;
|
|
103
|
+
const isDev = nodeEnv === "development" || nodeEnv === "test";
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<View
|
|
107
|
+
testID={testID ?? `empty-state-${variant}`}
|
|
108
|
+
accessibilityRole="summary"
|
|
109
|
+
className={cn(
|
|
110
|
+
"items-center justify-center gap-3 px-8 py-12",
|
|
111
|
+
className
|
|
112
|
+
)}
|
|
113
|
+
>
|
|
114
|
+
{illustration ? <View accessibilityElementsHidden>{illustration}</View> : null}
|
|
115
|
+
{icon && !illustration ? (
|
|
116
|
+
<View accessibilityElementsHidden>{icon}</View>
|
|
117
|
+
) : null}
|
|
118
|
+
<Text
|
|
119
|
+
testID={testID ? `${testID}-title` : undefined}
|
|
120
|
+
className={cn(
|
|
121
|
+
"text-center text-lg font-semibold",
|
|
122
|
+
variant === "error" ? "text-destructive" : "text-foreground"
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
{title ?? meta.title}
|
|
126
|
+
</Text>
|
|
127
|
+
{resolvedBody ? (
|
|
128
|
+
<Text
|
|
129
|
+
testID={testID ? `${testID}-body` : undefined}
|
|
130
|
+
className={cn("max-w-sm text-center text-sm", meta.tone)}
|
|
131
|
+
>
|
|
132
|
+
{resolvedBody}
|
|
133
|
+
</Text>
|
|
134
|
+
) : null}
|
|
135
|
+
{resolvedPrimary ? (
|
|
136
|
+
<View
|
|
137
|
+
testID={testID ? `${testID}-primary-action` : undefined}
|
|
138
|
+
className="mt-2"
|
|
139
|
+
>
|
|
140
|
+
{resolvedPrimary}
|
|
141
|
+
</View>
|
|
142
|
+
) : null}
|
|
143
|
+
{secondaryAction ? (
|
|
144
|
+
<View
|
|
145
|
+
testID={testID ? `${testID}-secondary-action` : undefined}
|
|
146
|
+
className="mt-1"
|
|
147
|
+
>
|
|
148
|
+
{secondaryAction}
|
|
149
|
+
</View>
|
|
150
|
+
) : null}
|
|
151
|
+
{details && isDev ? (
|
|
152
|
+
<Text
|
|
153
|
+
testID={testID ? `${testID}-details` : undefined}
|
|
154
|
+
className="mt-2 max-w-sm text-center text-xs text-muted-foreground"
|
|
155
|
+
>
|
|
156
|
+
{details}
|
|
157
|
+
</Text>
|
|
158
|
+
) : null}
|
|
159
|
+
</View>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HeaderCard — structured card with title + body + footer slots.
|
|
3
|
+
*
|
|
4
|
+
* Use this when you want a card with the same recurring "title above body
|
|
5
|
+
* above optional actions" shape and don't want to assemble Card +
|
|
6
|
+
* CardHeader + CardTitle + CardContent + CardFooter at every call site.
|
|
7
|
+
* The flat `<Card>{children}</Card>` form remains the 90% case — see
|
|
8
|
+
* standards/usage-doctrine.md for when to reach for HeaderCard.
|
|
9
|
+
*
|
|
10
|
+
* @stability Beta
|
|
11
|
+
*/
|
|
12
|
+
import { Text, View } from "react-native";
|
|
13
|
+
import { cn } from "../utils";
|
|
14
|
+
|
|
15
|
+
export interface NativeHeaderCardProps {
|
|
16
|
+
/** Heading rendered at the top of the card. Required. */
|
|
17
|
+
title: React.ReactNode;
|
|
18
|
+
/** Optional secondary line under the title. */
|
|
19
|
+
description?: React.ReactNode;
|
|
20
|
+
/** Main body content. Pass any node tree (text, list, form fields). */
|
|
21
|
+
body?: React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* Footer node (typically a row of buttons). When provided, renders a
|
|
24
|
+
* row-direction footer with internal padding. Skipped entirely when
|
|
25
|
+
* undefined to keep the card compact.
|
|
26
|
+
*/
|
|
27
|
+
footer?: React.ReactNode;
|
|
28
|
+
/** Override the root container styling. */
|
|
29
|
+
className?: string;
|
|
30
|
+
/** Override the title text styling. */
|
|
31
|
+
titleClassName?: string;
|
|
32
|
+
/** Override the description text styling. */
|
|
33
|
+
descriptionClassName?: string;
|
|
34
|
+
/** Override the body container styling. */
|
|
35
|
+
bodyClassName?: string;
|
|
36
|
+
/** Override the footer container styling. */
|
|
37
|
+
footerClassName?: string;
|
|
38
|
+
/** testID on the root container. Required for instrumented screens. */
|
|
39
|
+
testID?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function NativeHeaderCard({
|
|
43
|
+
title,
|
|
44
|
+
description,
|
|
45
|
+
body,
|
|
46
|
+
footer,
|
|
47
|
+
className,
|
|
48
|
+
titleClassName,
|
|
49
|
+
descriptionClassName,
|
|
50
|
+
bodyClassName,
|
|
51
|
+
footerClassName,
|
|
52
|
+
testID,
|
|
53
|
+
}: NativeHeaderCardProps) {
|
|
54
|
+
return (
|
|
55
|
+
<View
|
|
56
|
+
testID={testID}
|
|
57
|
+
accessibilityRole="summary"
|
|
58
|
+
className={cn(
|
|
59
|
+
"rounded-xl border border-border bg-card shadow-sm",
|
|
60
|
+
className
|
|
61
|
+
)}
|
|
62
|
+
>
|
|
63
|
+
<View className="flex-col gap-1.5 p-6">
|
|
64
|
+
{typeof title === "string" ? (
|
|
65
|
+
<Text
|
|
66
|
+
testID={testID ? `${testID}-title` : undefined}
|
|
67
|
+
className={cn(
|
|
68
|
+
"text-2xl font-semibold leading-none tracking-tight text-card-foreground",
|
|
69
|
+
titleClassName
|
|
70
|
+
)}
|
|
71
|
+
>
|
|
72
|
+
{title}
|
|
73
|
+
</Text>
|
|
74
|
+
) : (
|
|
75
|
+
title
|
|
76
|
+
)}
|
|
77
|
+
{description !== undefined && description !== null
|
|
78
|
+
? typeof description === "string"
|
|
79
|
+
? (
|
|
80
|
+
<Text
|
|
81
|
+
testID={testID ? `${testID}-description` : undefined}
|
|
82
|
+
className={cn(
|
|
83
|
+
"text-sm text-muted-foreground",
|
|
84
|
+
descriptionClassName
|
|
85
|
+
)}
|
|
86
|
+
>
|
|
87
|
+
{description}
|
|
88
|
+
</Text>
|
|
89
|
+
)
|
|
90
|
+
: description
|
|
91
|
+
: null}
|
|
92
|
+
</View>
|
|
93
|
+
{body !== undefined && body !== null ? (
|
|
94
|
+
<View
|
|
95
|
+
testID={testID ? `${testID}-body` : undefined}
|
|
96
|
+
className={cn("px-6 pb-6", bodyClassName)}
|
|
97
|
+
>
|
|
98
|
+
{body}
|
|
99
|
+
</View>
|
|
100
|
+
) : null}
|
|
101
|
+
{footer !== undefined && footer !== null ? (
|
|
102
|
+
<View
|
|
103
|
+
testID={testID ? `${testID}-footer` : undefined}
|
|
104
|
+
className={cn(
|
|
105
|
+
"flex-row items-center gap-2 border-t border-border px-6 py-4",
|
|
106
|
+
footerClassName
|
|
107
|
+
)}
|
|
108
|
+
>
|
|
109
|
+
{footer}
|
|
110
|
+
</View>
|
|
111
|
+
) : null}
|
|
112
|
+
</View>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { NativeHeaderCard };
|