@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,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toast / Snackbar — transient feedback message that auto-dismisses.
|
|
3
|
+
*
|
|
4
|
+
* Use for confirmation of completed actions ("Saved.", "Copied to
|
|
5
|
+
* clipboard."). Don't use for errors that need acknowledgment (use
|
|
6
|
+
* <NativeAlert> or <NativeBanner>) or for destructive confirmations
|
|
7
|
+
* (use <NativeDialog>).
|
|
8
|
+
*
|
|
9
|
+
* Wrap the app in <NativeToastProvider>. Components anywhere in the tree
|
|
10
|
+
* call `useToast()` and invoke `toast.show({ title, description, variant })`.
|
|
11
|
+
* Toasts are queued — the next one shows once the current one dismisses
|
|
12
|
+
* (or the user dismisses early).
|
|
13
|
+
*
|
|
14
|
+
* @stability Beta
|
|
15
|
+
*/
|
|
16
|
+
import {
|
|
17
|
+
createContext,
|
|
18
|
+
useCallback,
|
|
19
|
+
useContext,
|
|
20
|
+
useEffect,
|
|
21
|
+
useMemo,
|
|
22
|
+
useRef,
|
|
23
|
+
useState,
|
|
24
|
+
} from "react";
|
|
25
|
+
import {
|
|
26
|
+
AccessibilityInfo,
|
|
27
|
+
Animated,
|
|
28
|
+
Pressable,
|
|
29
|
+
Text,
|
|
30
|
+
View,
|
|
31
|
+
} from "react-native";
|
|
32
|
+
import { cn } from "../utils";
|
|
33
|
+
|
|
34
|
+
export type NativeToastVariant = "default" | "success" | "destructive";
|
|
35
|
+
|
|
36
|
+
export interface NativeToastOptions {
|
|
37
|
+
/** Bold first line. Required. */
|
|
38
|
+
title: string;
|
|
39
|
+
/** Optional second line for context. */
|
|
40
|
+
description?: string;
|
|
41
|
+
/** Visual variant. Default: "default". */
|
|
42
|
+
variant?: NativeToastVariant;
|
|
43
|
+
/** Auto-dismiss timeout (ms). Default 3500. Set 0 for sticky. */
|
|
44
|
+
duration?: number;
|
|
45
|
+
/** Optional testID forwarded to the toast root. */
|
|
46
|
+
testID?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface ToastInstance extends NativeToastOptions {
|
|
50
|
+
id: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface NativeToastContextValue {
|
|
54
|
+
show: (opts: NativeToastOptions) => number;
|
|
55
|
+
dismiss: (id?: number) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const ToastContext = createContext<NativeToastContextValue | null>(null);
|
|
59
|
+
|
|
60
|
+
let nextId = 1;
|
|
61
|
+
|
|
62
|
+
export interface NativeToastProviderProps {
|
|
63
|
+
children: React.ReactNode;
|
|
64
|
+
/** Position: "top" or "bottom". Default "bottom". */
|
|
65
|
+
position?: "top" | "bottom";
|
|
66
|
+
/** Disable entrance/exit animation. Default false. */
|
|
67
|
+
disableAnimation?: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function NativeToastProvider({
|
|
71
|
+
children,
|
|
72
|
+
position = "bottom",
|
|
73
|
+
disableAnimation = false,
|
|
74
|
+
}: NativeToastProviderProps) {
|
|
75
|
+
const [queue, setQueue] = useState<ToastInstance[]>([]);
|
|
76
|
+
const [reducedMotion, setReducedMotion] = useState(false);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
let mounted = true;
|
|
80
|
+
AccessibilityInfo.isReduceMotionEnabled().then((v) => {
|
|
81
|
+
if (mounted) setReducedMotion(v);
|
|
82
|
+
});
|
|
83
|
+
const sub = AccessibilityInfo.addEventListener(
|
|
84
|
+
"reduceMotionChanged",
|
|
85
|
+
(v) => mounted && setReducedMotion(v)
|
|
86
|
+
);
|
|
87
|
+
return () => {
|
|
88
|
+
mounted = false;
|
|
89
|
+
sub.remove();
|
|
90
|
+
};
|
|
91
|
+
}, []);
|
|
92
|
+
|
|
93
|
+
const dismiss = useCallback((id?: number) => {
|
|
94
|
+
setQueue((q) => (id == null ? q.slice(1) : q.filter((t) => t.id !== id)));
|
|
95
|
+
}, []);
|
|
96
|
+
|
|
97
|
+
const show = useCallback((opts: NativeToastOptions) => {
|
|
98
|
+
const id = nextId++;
|
|
99
|
+
setQueue((q) => [...q, { ...opts, id }]);
|
|
100
|
+
return id;
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
const value = useMemo(() => ({ show, dismiss }), [show, dismiss]);
|
|
104
|
+
|
|
105
|
+
const current = queue[0];
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<ToastContext.Provider value={value}>
|
|
109
|
+
{children}
|
|
110
|
+
{current ? (
|
|
111
|
+
<ToastView
|
|
112
|
+
key={current.id}
|
|
113
|
+
toast={current}
|
|
114
|
+
position={position}
|
|
115
|
+
animate={!disableAnimation && !reducedMotion}
|
|
116
|
+
onDismiss={() => dismiss(current.id)}
|
|
117
|
+
/>
|
|
118
|
+
) : null}
|
|
119
|
+
</ToastContext.Provider>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface ToastViewProps {
|
|
124
|
+
toast: ToastInstance;
|
|
125
|
+
position: "top" | "bottom";
|
|
126
|
+
animate: boolean;
|
|
127
|
+
onDismiss: () => void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function ToastView({ toast, position, animate, onDismiss }: ToastViewProps) {
|
|
131
|
+
const opacity = useRef(new Animated.Value(animate ? 0 : 1)).current;
|
|
132
|
+
const offset = useRef(new Animated.Value(animate ? 16 : 0)).current;
|
|
133
|
+
|
|
134
|
+
// Hold the latest onDismiss in a ref so the auto-dismiss timer below does
|
|
135
|
+
// not re-arm on every parent render (the inline `() => dismiss(current.id)`
|
|
136
|
+
// gets a fresh identity each render). Keying the timer effect off
|
|
137
|
+
// toast.duration alone keeps the timer stable for the toast's lifetime.
|
|
138
|
+
const onDismissRef = useRef(onDismiss);
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
onDismissRef.current = onDismiss;
|
|
141
|
+
}, [onDismiss]);
|
|
142
|
+
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (animate) {
|
|
145
|
+
Animated.parallel([
|
|
146
|
+
Animated.timing(opacity, {
|
|
147
|
+
toValue: 1,
|
|
148
|
+
duration: 180,
|
|
149
|
+
useNativeDriver: true,
|
|
150
|
+
}),
|
|
151
|
+
Animated.timing(offset, {
|
|
152
|
+
toValue: 0,
|
|
153
|
+
duration: 180,
|
|
154
|
+
useNativeDriver: true,
|
|
155
|
+
}),
|
|
156
|
+
]).start();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const duration = toast.duration ?? 3500;
|
|
160
|
+
if (duration > 0) {
|
|
161
|
+
const t = setTimeout(() => onDismissRef.current(), duration);
|
|
162
|
+
return () => clearTimeout(t);
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
}, [animate, offset, opacity, toast.duration]);
|
|
166
|
+
|
|
167
|
+
const variantClasses: Record<NativeToastVariant, string> = {
|
|
168
|
+
default: "bg-foreground",
|
|
169
|
+
success: "bg-primary",
|
|
170
|
+
destructive: "bg-destructive",
|
|
171
|
+
};
|
|
172
|
+
const textClass: Record<NativeToastVariant, string> = {
|
|
173
|
+
default: "text-background",
|
|
174
|
+
success: "text-primary-foreground",
|
|
175
|
+
destructive: "text-destructive-foreground",
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const variant = toast.variant ?? "default";
|
|
179
|
+
const positionClass =
|
|
180
|
+
position === "top" ? "top-12 self-center" : "bottom-10 self-center";
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<Animated.View
|
|
184
|
+
accessible
|
|
185
|
+
accessibilityRole="alert"
|
|
186
|
+
accessibilityLiveRegion="polite"
|
|
187
|
+
accessibilityLabel={
|
|
188
|
+
toast.description ? `${toast.title}. ${toast.description}` : toast.title
|
|
189
|
+
}
|
|
190
|
+
className={cn(
|
|
191
|
+
"absolute left-4 right-4 items-center",
|
|
192
|
+
positionClass
|
|
193
|
+
)}
|
|
194
|
+
style={{ opacity, transform: [{ translateY: offset }] }}
|
|
195
|
+
>
|
|
196
|
+
<Pressable
|
|
197
|
+
testID={toast.testID ?? "native-toast"}
|
|
198
|
+
accessibilityRole="button"
|
|
199
|
+
accessibilityLabel="Dismiss notification"
|
|
200
|
+
accessibilityHint="Dismisses this toast"
|
|
201
|
+
onPress={onDismiss}
|
|
202
|
+
className={cn(
|
|
203
|
+
"min-h-[44px] min-w-[200px] rounded-lg px-4 py-3 shadow-lg",
|
|
204
|
+
variantClasses[variant]
|
|
205
|
+
)}
|
|
206
|
+
>
|
|
207
|
+
<Text className={cn("text-base font-semibold", textClass[variant])}>
|
|
208
|
+
{toast.title}
|
|
209
|
+
</Text>
|
|
210
|
+
{toast.description ? (
|
|
211
|
+
<Text className={cn("mt-0.5 text-sm", textClass[variant], "opacity-90")}>
|
|
212
|
+
{toast.description}
|
|
213
|
+
</Text>
|
|
214
|
+
) : null}
|
|
215
|
+
</Pressable>
|
|
216
|
+
</Animated.View>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function useToast(): NativeToastContextValue {
|
|
221
|
+
const ctx = useContext(ToastContext);
|
|
222
|
+
if (!ctx) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
"useToast() must be used inside <NativeToastProvider>. Mount the provider near the root."
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
return ctx;
|
|
228
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toggle — pressable on/off button (used inside ToggleGroup-style patterns).
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { type VariantProps, cva } from "class-variance-authority";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { Pressable } from "react-native";
|
|
9
|
+
import { cn } from "../utils";
|
|
10
|
+
|
|
11
|
+
const toggleVariants = cva(
|
|
12
|
+
"items-center justify-center rounded-md",
|
|
13
|
+
{
|
|
14
|
+
variants: {
|
|
15
|
+
variant: {
|
|
16
|
+
default: "bg-transparent",
|
|
17
|
+
outline: "border border-input bg-transparent",
|
|
18
|
+
},
|
|
19
|
+
size: {
|
|
20
|
+
default: "h-10 px-3",
|
|
21
|
+
sm: "h-9 px-2.5",
|
|
22
|
+
lg: "h-11 px-5",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: {
|
|
26
|
+
variant: "default",
|
|
27
|
+
size: "default",
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export interface NativeToggleProps
|
|
33
|
+
extends VariantProps<typeof toggleVariants> {
|
|
34
|
+
className?: string;
|
|
35
|
+
pressed?: boolean;
|
|
36
|
+
defaultPressed?: boolean;
|
|
37
|
+
onPressedChange?: (pressed: boolean) => void;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
children: React.ReactNode;
|
|
40
|
+
testID?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function NativeToggle({
|
|
44
|
+
className,
|
|
45
|
+
variant,
|
|
46
|
+
size,
|
|
47
|
+
pressed: controlledPressed,
|
|
48
|
+
defaultPressed = false,
|
|
49
|
+
onPressedChange,
|
|
50
|
+
disabled,
|
|
51
|
+
children,
|
|
52
|
+
...props
|
|
53
|
+
}: NativeToggleProps) {
|
|
54
|
+
const [uncontrolledPressed, setUncontrolledPressed] =
|
|
55
|
+
useState(defaultPressed);
|
|
56
|
+
const isPressed = controlledPressed ?? uncontrolledPressed;
|
|
57
|
+
|
|
58
|
+
function handlePress() {
|
|
59
|
+
const next = !isPressed;
|
|
60
|
+
if (controlledPressed === undefined) {
|
|
61
|
+
setUncontrolledPressed(next);
|
|
62
|
+
}
|
|
63
|
+
onPressedChange?.(next);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Pressable
|
|
68
|
+
className={cn(
|
|
69
|
+
toggleVariants({ variant, size }),
|
|
70
|
+
isPressed && "bg-accent",
|
|
71
|
+
disabled && "opacity-50",
|
|
72
|
+
className
|
|
73
|
+
)}
|
|
74
|
+
onPress={handlePress}
|
|
75
|
+
disabled={disabled}
|
|
76
|
+
accessibilityRole="togglebutton"
|
|
77
|
+
accessibilityState={{ checked: isPressed, disabled }}
|
|
78
|
+
{...props}
|
|
79
|
+
>
|
|
80
|
+
{children}
|
|
81
|
+
</Pressable>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { NativeToggle, toggleVariants };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltip — supplemental hint anchored to a trigger.
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
7
|
+
import { Pressable, Text, View } from "react-native";
|
|
8
|
+
import { cn } from "../utils";
|
|
9
|
+
|
|
10
|
+
interface TooltipContextValue {
|
|
11
|
+
visible: boolean;
|
|
12
|
+
setVisible: (v: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const TooltipContext = createContext<TooltipContextValue | null>(null);
|
|
16
|
+
|
|
17
|
+
function useTooltipContext() {
|
|
18
|
+
const ctx = useContext(TooltipContext);
|
|
19
|
+
if (!ctx) throw new Error("Tooltip compound components must be used within NativeTooltip");
|
|
20
|
+
return ctx;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface NativeTooltipProps {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function NativeTooltip({ children }: NativeTooltipProps) {
|
|
28
|
+
const [visible, setVisible] = useState(false);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<TooltipContext.Provider value={{ visible, setVisible }}>
|
|
32
|
+
<View>{children}</View>
|
|
33
|
+
</TooltipContext.Provider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface NativeTooltipTriggerProps {
|
|
38
|
+
className?: string;
|
|
39
|
+
children: React.ReactNode;
|
|
40
|
+
testID?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function NativeTooltipTrigger({
|
|
44
|
+
className,
|
|
45
|
+
children,
|
|
46
|
+
...props
|
|
47
|
+
}: NativeTooltipTriggerProps) {
|
|
48
|
+
const { setVisible } = useTooltipContext();
|
|
49
|
+
const timerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
return () => {
|
|
53
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Pressable
|
|
59
|
+
className={cn(className)}
|
|
60
|
+
accessibilityRole="button"
|
|
61
|
+
accessibilityLabel="Show tooltip"
|
|
62
|
+
onLongPress={() => {
|
|
63
|
+
setVisible(true);
|
|
64
|
+
// Auto-hide after 2 seconds
|
|
65
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
66
|
+
timerRef.current = setTimeout(() => setVisible(false), 2000);
|
|
67
|
+
}}
|
|
68
|
+
{...props}
|
|
69
|
+
>
|
|
70
|
+
{children}
|
|
71
|
+
</Pressable>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface NativeTooltipContentProps {
|
|
76
|
+
className?: string;
|
|
77
|
+
children: React.ReactNode;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function NativeTooltipContent({
|
|
81
|
+
className,
|
|
82
|
+
children,
|
|
83
|
+
}: NativeTooltipContentProps) {
|
|
84
|
+
const { visible } = useTooltipContext();
|
|
85
|
+
|
|
86
|
+
if (!visible) return null;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<View
|
|
90
|
+
className={cn(
|
|
91
|
+
"absolute bottom-full left-0 mb-1 rounded-md bg-foreground px-3 py-1.5 shadow-md",
|
|
92
|
+
className
|
|
93
|
+
)}
|
|
94
|
+
>
|
|
95
|
+
{typeof children === "string" ? (
|
|
96
|
+
<Text className="text-xs text-background">{children}</Text>
|
|
97
|
+
) : (
|
|
98
|
+
children
|
|
99
|
+
)}
|
|
100
|
+
</View>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { NativeTooltip, NativeTooltipTrigger, NativeTooltipContent };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { Pressable, ScrollView, View } from "react-native";
|
|
3
|
+
import { NativeBadge } from "../components/badge";
|
|
4
|
+
import { NativeInput } from "../components/input";
|
|
5
|
+
|
|
6
|
+
export interface NativeDataFiltersProps {
|
|
7
|
+
search: string;
|
|
8
|
+
onSearchChange: (value: string) => void;
|
|
9
|
+
searchPlaceholder?: string;
|
|
10
|
+
statusChips?: {
|
|
11
|
+
options: string[];
|
|
12
|
+
selected: string[];
|
|
13
|
+
onChange: (values: string[]) => void;
|
|
14
|
+
};
|
|
15
|
+
sort?: {
|
|
16
|
+
value: string;
|
|
17
|
+
options: Array<{ value: string; label: string }>;
|
|
18
|
+
onChange: (sort: string) => void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function NativeDataFilters({
|
|
23
|
+
search,
|
|
24
|
+
onSearchChange,
|
|
25
|
+
searchPlaceholder = "Search...",
|
|
26
|
+
statusChips,
|
|
27
|
+
sort,
|
|
28
|
+
}: NativeDataFiltersProps) {
|
|
29
|
+
const handleStatusToggle = useCallback(
|
|
30
|
+
(option: string) => {
|
|
31
|
+
if (!statusChips) return;
|
|
32
|
+
const isSelected = statusChips.selected.includes(option);
|
|
33
|
+
const next = isSelected
|
|
34
|
+
? statusChips.selected.filter((s) => s !== option)
|
|
35
|
+
: [...statusChips.selected, option];
|
|
36
|
+
statusChips.onChange(next);
|
|
37
|
+
},
|
|
38
|
+
[statusChips]
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const handleSortToggle = useCallback(
|
|
42
|
+
(value: string) => {
|
|
43
|
+
sort?.onChange(value);
|
|
44
|
+
},
|
|
45
|
+
[sort]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<View style={{ gap: 12 }}>
|
|
50
|
+
<NativeInput
|
|
51
|
+
placeholder={searchPlaceholder}
|
|
52
|
+
value={search}
|
|
53
|
+
onChangeText={onSearchChange}
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
{statusChips && statusChips.options.length > 0 && (
|
|
57
|
+
<ScrollView
|
|
58
|
+
horizontal
|
|
59
|
+
showsHorizontalScrollIndicator={false}
|
|
60
|
+
contentContainerStyle={{ gap: 8 }}
|
|
61
|
+
>
|
|
62
|
+
{statusChips.options.map((option) => {
|
|
63
|
+
const isSelected = statusChips.selected.includes(option);
|
|
64
|
+
return (
|
|
65
|
+
<Pressable key={option} onPress={() => handleStatusToggle(option)}>
|
|
66
|
+
<NativeBadge variant={isSelected ? "default" : "outline"}>
|
|
67
|
+
{option}
|
|
68
|
+
</NativeBadge>
|
|
69
|
+
</Pressable>
|
|
70
|
+
);
|
|
71
|
+
})}
|
|
72
|
+
</ScrollView>
|
|
73
|
+
)}
|
|
74
|
+
|
|
75
|
+
{sort && sort.options.length > 0 && (
|
|
76
|
+
<ScrollView
|
|
77
|
+
horizontal
|
|
78
|
+
showsHorizontalScrollIndicator={false}
|
|
79
|
+
contentContainerStyle={{ gap: 8 }}
|
|
80
|
+
>
|
|
81
|
+
{sort.options.map((option) => {
|
|
82
|
+
const isSelected = sort.value === option.value;
|
|
83
|
+
return (
|
|
84
|
+
<Pressable
|
|
85
|
+
key={option.value}
|
|
86
|
+
onPress={() => handleSortToggle(option.value)}
|
|
87
|
+
>
|
|
88
|
+
<NativeBadge variant={isSelected ? "secondary" : "outline"}>
|
|
89
|
+
{option.label}
|
|
90
|
+
</NativeBadge>
|
|
91
|
+
</Pressable>
|
|
92
|
+
);
|
|
93
|
+
})}
|
|
94
|
+
</ScrollView>
|
|
95
|
+
)}
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { NativeDataFilters };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import { ScrollView, View } from "react-native";
|
|
4
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
5
|
+
import { NativeButton } from "../components/button";
|
|
6
|
+
import { NativeSkeleton } from "../components/skeleton";
|
|
7
|
+
import { NativeText } from "../components/text";
|
|
8
|
+
import { NativeEmptyState } from "./NativeEmptyState";
|
|
9
|
+
|
|
10
|
+
export interface NativeDataPageShellProps {
|
|
11
|
+
title: string;
|
|
12
|
+
subtitle?: string;
|
|
13
|
+
headerRight?: ReactNode;
|
|
14
|
+
isLoading?: boolean;
|
|
15
|
+
isEmpty?: boolean;
|
|
16
|
+
hasError?: boolean;
|
|
17
|
+
errorMessage?: string;
|
|
18
|
+
onRetry?: () => void;
|
|
19
|
+
emptyMessage?: string;
|
|
20
|
+
emptyState?: ReactNode;
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function NativeDataPageShell({
|
|
25
|
+
title,
|
|
26
|
+
subtitle,
|
|
27
|
+
headerRight,
|
|
28
|
+
isLoading,
|
|
29
|
+
isEmpty,
|
|
30
|
+
hasError,
|
|
31
|
+
errorMessage = "Something went wrong.",
|
|
32
|
+
onRetry,
|
|
33
|
+
emptyMessage,
|
|
34
|
+
emptyState,
|
|
35
|
+
children,
|
|
36
|
+
}: NativeDataPageShellProps) {
|
|
37
|
+
const renderContent = () => {
|
|
38
|
+
if (isLoading) {
|
|
39
|
+
return (
|
|
40
|
+
<View className="px-4 pt-4 gap-3">
|
|
41
|
+
{/* Search bar skeleton */}
|
|
42
|
+
<NativeSkeleton className="w-full h-10 rounded-lg" />
|
|
43
|
+
{/* Card skeletons */}
|
|
44
|
+
<NativeSkeleton className="w-full h-20 rounded-lg" />
|
|
45
|
+
<NativeSkeleton className="w-full h-20 rounded-lg" />
|
|
46
|
+
<NativeSkeleton className="w-full h-20 rounded-lg" />
|
|
47
|
+
</View>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (hasError) {
|
|
52
|
+
return (
|
|
53
|
+
<View className="flex-1 items-center justify-center px-4 py-12 gap-4">
|
|
54
|
+
<NativeText preset="body" className="text-destructive text-center">
|
|
55
|
+
{errorMessage}
|
|
56
|
+
</NativeText>
|
|
57
|
+
{onRetry ? (
|
|
58
|
+
<NativeButton variant="outline" size="sm" onPress={onRetry}>
|
|
59
|
+
Try Again
|
|
60
|
+
</NativeButton>
|
|
61
|
+
) : null}
|
|
62
|
+
</View>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isEmpty) {
|
|
67
|
+
if (emptyState) {
|
|
68
|
+
return <>{emptyState}</>;
|
|
69
|
+
}
|
|
70
|
+
return <NativeEmptyState message={emptyMessage} />;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return <>{children}</>;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<SafeAreaView edges={["left", "right"]} className="flex-1 bg-background">
|
|
78
|
+
{/* Header */}
|
|
79
|
+
<View className="px-4 pt-4 pb-2">
|
|
80
|
+
<View
|
|
81
|
+
style={{
|
|
82
|
+
flexDirection: "row",
|
|
83
|
+
alignItems: "center",
|
|
84
|
+
justifyContent: "space-between",
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
<View className="flex-1">
|
|
88
|
+
<NativeText preset="h2">{title}</NativeText>
|
|
89
|
+
{subtitle ? (
|
|
90
|
+
<NativeText preset="body-sm" className="text-muted-foreground mt-0.5">
|
|
91
|
+
{subtitle}
|
|
92
|
+
</NativeText>
|
|
93
|
+
) : null}
|
|
94
|
+
</View>
|
|
95
|
+
{headerRight ? <View className="ml-3">{headerRight}</View> : null}
|
|
96
|
+
</View>
|
|
97
|
+
</View>
|
|
98
|
+
|
|
99
|
+
{/* Content */}
|
|
100
|
+
<ScrollView
|
|
101
|
+
className="flex-1"
|
|
102
|
+
contentContainerStyle={{ flexGrow: 1 }}
|
|
103
|
+
keyboardShouldPersistTaps="handled"
|
|
104
|
+
>
|
|
105
|
+
{renderContent()}
|
|
106
|
+
</ScrollView>
|
|
107
|
+
</SafeAreaView>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { NativeDataPageShell };
|