@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,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Popover — supplemental content anchored to a trigger.
|
|
3
|
+
*
|
|
4
|
+
* Use for inline supplemental info, picker UIs, and micro-menus that
|
|
5
|
+
* don't warrant a Sheet or Dialog. Tap-outside dismisses. The popover
|
|
6
|
+
* positions above or below the anchor based on available space.
|
|
7
|
+
*
|
|
8
|
+
* Compose: <NativePopover><NativePopoverTrigger /><NativePopoverContent />
|
|
9
|
+
* </NativePopover>. Only one popover is open per <NativePopover>.
|
|
10
|
+
*
|
|
11
|
+
* @stability Beta
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
createContext,
|
|
15
|
+
useCallback,
|
|
16
|
+
useContext,
|
|
17
|
+
useMemo,
|
|
18
|
+
useRef,
|
|
19
|
+
useState,
|
|
20
|
+
} from "react";
|
|
21
|
+
import { Modal, Pressable, View } from "react-native";
|
|
22
|
+
import { cn } from "../utils";
|
|
23
|
+
|
|
24
|
+
// React Native's View instance type — uses .measureInWindow().
|
|
25
|
+
type ViewHandle = {
|
|
26
|
+
measureInWindow: (
|
|
27
|
+
cb: (x: number, y: number, width: number, height: number) => void
|
|
28
|
+
) => void;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
interface PopoverContextValue {
|
|
32
|
+
open: boolean;
|
|
33
|
+
setOpen: (open: boolean) => void;
|
|
34
|
+
anchorRef: React.RefObject<ViewHandle | null>;
|
|
35
|
+
anchorRect: AnchorRect | null;
|
|
36
|
+
measureAnchor: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface AnchorRect {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const PopoverContext = createContext<PopoverContextValue | null>(null);
|
|
47
|
+
|
|
48
|
+
export interface NativePopoverProps {
|
|
49
|
+
open?: boolean;
|
|
50
|
+
defaultOpen?: boolean;
|
|
51
|
+
onOpenChange?: (open: boolean) => void;
|
|
52
|
+
children: React.ReactNode;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function NativePopover({
|
|
56
|
+
open: controlled,
|
|
57
|
+
defaultOpen,
|
|
58
|
+
onOpenChange,
|
|
59
|
+
children,
|
|
60
|
+
}: NativePopoverProps) {
|
|
61
|
+
const [uncontrolled, setUncontrolled] = useState(defaultOpen ?? false);
|
|
62
|
+
const open = controlled ?? uncontrolled;
|
|
63
|
+
const anchorRef = useRef<ViewHandle | null>(null);
|
|
64
|
+
const [anchorRect, setAnchorRect] = useState<AnchorRect | null>(null);
|
|
65
|
+
|
|
66
|
+
const setOpen = useCallback(
|
|
67
|
+
(next: boolean) => {
|
|
68
|
+
if (controlled === undefined) setUncontrolled(next);
|
|
69
|
+
onOpenChange?.(next);
|
|
70
|
+
},
|
|
71
|
+
[controlled, onOpenChange]
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const measureAnchor = useCallback(() => {
|
|
75
|
+
anchorRef.current?.measureInWindow((x, y, width, height) => {
|
|
76
|
+
setAnchorRect({ x, y, width, height });
|
|
77
|
+
});
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
const value = useMemo<PopoverContextValue>(
|
|
81
|
+
() => ({ open, setOpen, anchorRef, anchorRect, measureAnchor }),
|
|
82
|
+
[open, setOpen, anchorRect, measureAnchor]
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<PopoverContext.Provider value={value}>{children}</PopoverContext.Provider>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface NativePopoverTriggerProps {
|
|
91
|
+
children: React.ReactNode;
|
|
92
|
+
asChild?: boolean;
|
|
93
|
+
testID?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function NativePopoverTrigger({
|
|
97
|
+
children,
|
|
98
|
+
testID,
|
|
99
|
+
}: NativePopoverTriggerProps) {
|
|
100
|
+
const ctx = useContext(PopoverContext);
|
|
101
|
+
if (!ctx)
|
|
102
|
+
throw new Error("NativePopoverTrigger must be used inside <NativePopover>.");
|
|
103
|
+
|
|
104
|
+
// We attach the ref to a wrapping View — Pressable's ref shape varies
|
|
105
|
+
// across RN versions; View's measureInWindow is stable everywhere.
|
|
106
|
+
return (
|
|
107
|
+
<View
|
|
108
|
+
ref={(instance) => {
|
|
109
|
+
ctx.anchorRef.current = (instance as unknown as ViewHandle | null) ?? null;
|
|
110
|
+
}}
|
|
111
|
+
collapsable={false}
|
|
112
|
+
>
|
|
113
|
+
<Pressable
|
|
114
|
+
testID={testID ?? "native-popover-trigger"}
|
|
115
|
+
accessibilityRole="button"
|
|
116
|
+
accessibilityHint="Opens a popover"
|
|
117
|
+
onPress={() => {
|
|
118
|
+
ctx.measureAnchor();
|
|
119
|
+
ctx.setOpen(!ctx.open);
|
|
120
|
+
}}
|
|
121
|
+
className="min-h-[44px] min-w-[44px] items-center justify-center"
|
|
122
|
+
>
|
|
123
|
+
{children}
|
|
124
|
+
</Pressable>
|
|
125
|
+
</View>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface NativePopoverContentProps {
|
|
130
|
+
className?: string;
|
|
131
|
+
children: React.ReactNode;
|
|
132
|
+
/** Force a side ("top"|"bottom"). Default: auto-resolve. */
|
|
133
|
+
side?: "top" | "bottom";
|
|
134
|
+
/** Pixel offset from the anchor edge. Default 8. */
|
|
135
|
+
sideOffset?: number;
|
|
136
|
+
testID?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function NativePopoverContent({
|
|
140
|
+
className,
|
|
141
|
+
children,
|
|
142
|
+
side,
|
|
143
|
+
sideOffset = 8,
|
|
144
|
+
testID,
|
|
145
|
+
}: NativePopoverContentProps) {
|
|
146
|
+
const ctx = useContext(PopoverContext);
|
|
147
|
+
if (!ctx)
|
|
148
|
+
throw new Error("NativePopoverContent must be used inside <NativePopover>.");
|
|
149
|
+
if (!ctx.open || !ctx.anchorRect) return null;
|
|
150
|
+
|
|
151
|
+
const { x, y, width, height } = ctx.anchorRect;
|
|
152
|
+
// Resolve side: prefer below; flip when we'd run off the bottom (heuristic 600px).
|
|
153
|
+
const resolvedSide: "top" | "bottom" =
|
|
154
|
+
side ?? (y > 500 ? "top" : "bottom");
|
|
155
|
+
|
|
156
|
+
const computedTop =
|
|
157
|
+
resolvedSide === "bottom"
|
|
158
|
+
? y + height + sideOffset
|
|
159
|
+
: Math.max(0, y - sideOffset - 8);
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<Modal
|
|
163
|
+
visible={ctx.open}
|
|
164
|
+
transparent
|
|
165
|
+
animationType="fade"
|
|
166
|
+
onRequestClose={() => ctx.setOpen(false)}
|
|
167
|
+
>
|
|
168
|
+
<Pressable
|
|
169
|
+
accessibilityLabel="Close popover"
|
|
170
|
+
className="flex-1"
|
|
171
|
+
onPress={() => ctx.setOpen(false)}
|
|
172
|
+
>
|
|
173
|
+
<View
|
|
174
|
+
pointerEvents="box-none"
|
|
175
|
+
style={{
|
|
176
|
+
position: "absolute",
|
|
177
|
+
left: x,
|
|
178
|
+
top: computedTop,
|
|
179
|
+
minWidth: width,
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
<Pressable onPress={() => {}}>
|
|
183
|
+
<View
|
|
184
|
+
testID={testID ?? "native-popover-content"}
|
|
185
|
+
accessibilityViewIsModal
|
|
186
|
+
className={cn(
|
|
187
|
+
"max-w-[280px] rounded-md border border-border bg-popover p-3 shadow-md",
|
|
188
|
+
className
|
|
189
|
+
)}
|
|
190
|
+
>
|
|
191
|
+
{children}
|
|
192
|
+
</View>
|
|
193
|
+
</Pressable>
|
|
194
|
+
</View>
|
|
195
|
+
</Pressable>
|
|
196
|
+
</Modal>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Progress — determinate horizontal progress indicator.
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { View } from "react-native";
|
|
7
|
+
import { cn } from "../utils";
|
|
8
|
+
|
|
9
|
+
export interface NativeProgressProps {
|
|
10
|
+
className?: string;
|
|
11
|
+
/** Progress value between 0 and 100 */
|
|
12
|
+
value?: number;
|
|
13
|
+
/** Track color class. Defaults to bg-muted */
|
|
14
|
+
trackClassName?: string;
|
|
15
|
+
/** Indicator color class. Defaults to bg-primary */
|
|
16
|
+
indicatorClassName?: string;
|
|
17
|
+
testID?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function NativeProgress({
|
|
21
|
+
className,
|
|
22
|
+
value = 0,
|
|
23
|
+
trackClassName,
|
|
24
|
+
indicatorClassName,
|
|
25
|
+
...props
|
|
26
|
+
}: NativeProgressProps) {
|
|
27
|
+
const safeValue = Number.isFinite(value) ? value : 0;
|
|
28
|
+
const clampedValue = Math.min(100, Math.max(0, safeValue));
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<View
|
|
32
|
+
className={cn(
|
|
33
|
+
"h-2 w-full overflow-hidden rounded-full bg-muted",
|
|
34
|
+
trackClassName,
|
|
35
|
+
className
|
|
36
|
+
)}
|
|
37
|
+
accessibilityRole="progressbar"
|
|
38
|
+
accessibilityLabel={`${clampedValue}% complete`}
|
|
39
|
+
accessibilityValue={{ min: 0, max: 100, now: clampedValue }}
|
|
40
|
+
{...props}
|
|
41
|
+
>
|
|
42
|
+
<View
|
|
43
|
+
className={cn("h-full rounded-full bg-primary", indicatorClassName)}
|
|
44
|
+
style={{ width: `${clampedValue}%` }}
|
|
45
|
+
/>
|
|
46
|
+
</View>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { NativeProgress };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RadioGroup — single-selection list of radio items.
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { createContext, useContext, useState } from "react";
|
|
7
|
+
import { Pressable, View } from "react-native";
|
|
8
|
+
import { cn } from "../utils";
|
|
9
|
+
|
|
10
|
+
interface RadioGroupContextValue {
|
|
11
|
+
value: string;
|
|
12
|
+
onValueChange: (value: string) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const RadioGroupContext = createContext<RadioGroupContextValue | null>(null);
|
|
16
|
+
|
|
17
|
+
function useRadioGroup() {
|
|
18
|
+
const context = useContext(RadioGroupContext);
|
|
19
|
+
if (!context)
|
|
20
|
+
throw new Error("RadioGroup components must be used within <NativeRadioGroup>");
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NativeRadioGroupProps {
|
|
25
|
+
className?: string;
|
|
26
|
+
value?: string;
|
|
27
|
+
defaultValue?: string;
|
|
28
|
+
onValueChange?: (value: string) => void;
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
testID?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function NativeRadioGroup({
|
|
34
|
+
className,
|
|
35
|
+
value: controlledValue,
|
|
36
|
+
defaultValue = "",
|
|
37
|
+
onValueChange: controlledOnValueChange,
|
|
38
|
+
children,
|
|
39
|
+
...props
|
|
40
|
+
}: NativeRadioGroupProps) {
|
|
41
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
42
|
+
const value = controlledValue ?? uncontrolledValue;
|
|
43
|
+
const onValueChange = controlledValue !== undefined
|
|
44
|
+
? (controlledOnValueChange ?? (() => {}))
|
|
45
|
+
: (v: string) => { setUncontrolledValue(v); controlledOnValueChange?.(v); };
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<RadioGroupContext.Provider value={{ value, onValueChange }}>
|
|
49
|
+
<View className={cn("gap-2", className)} {...props}>
|
|
50
|
+
{children}
|
|
51
|
+
</View>
|
|
52
|
+
</RadioGroupContext.Provider>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface NativeRadioGroupItemProps {
|
|
57
|
+
className?: string;
|
|
58
|
+
value: string;
|
|
59
|
+
disabled?: boolean;
|
|
60
|
+
testID?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function NativeRadioGroupItem({
|
|
64
|
+
className,
|
|
65
|
+
value,
|
|
66
|
+
disabled,
|
|
67
|
+
...props
|
|
68
|
+
}: NativeRadioGroupItemProps) {
|
|
69
|
+
const { value: selectedValue, onValueChange } = useRadioGroup();
|
|
70
|
+
const isSelected = selectedValue === value;
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<Pressable
|
|
74
|
+
className={cn(
|
|
75
|
+
"h-5 w-5 items-center justify-center rounded-full border border-primary",
|
|
76
|
+
disabled && "opacity-50",
|
|
77
|
+
className
|
|
78
|
+
)}
|
|
79
|
+
onPress={() => onValueChange(value)}
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
accessibilityRole="radio"
|
|
82
|
+
accessibilityState={{ checked: isSelected, disabled }}
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
{isSelected ? (
|
|
86
|
+
<View className="h-2.5 w-2.5 rounded-full bg-primary" />
|
|
87
|
+
) : null}
|
|
88
|
+
</Pressable>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { NativeRadioGroup, NativeRadioGroupItem };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RefreshControl wrapper — token-aware tint over RN's RefreshControl.
|
|
3
|
+
*
|
|
4
|
+
* Use as the `refreshControl` prop on ScrollView / FlatList / SectionList.
|
|
5
|
+
* The tint defaults to a CSS-variable resolved at runtime via the theme
|
|
6
|
+
* provider; consumers can override per-call. We re-export RN's
|
|
7
|
+
* RefreshControl shape so the API mirrors what consumers already know.
|
|
8
|
+
*
|
|
9
|
+
* @stability Beta
|
|
10
|
+
*/
|
|
11
|
+
// Lazy resolve of the RN export so we don't break in environments where
|
|
12
|
+
// react-native isn't fully bundled (e.g. metro server warm-up).
|
|
13
|
+
function resolveRefreshControl(): React.ComponentType<NativeRefreshControlProps> | null {
|
|
14
|
+
try {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
16
|
+
const rn = require("react-native");
|
|
17
|
+
return rn.RefreshControl as React.ComponentType<NativeRefreshControlProps>;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface NativeRefreshControlProps {
|
|
24
|
+
refreshing: boolean;
|
|
25
|
+
onRefresh: () => void;
|
|
26
|
+
/** Hex / RGB color override. Falls back to the theme primary. */
|
|
27
|
+
tintColor?: string;
|
|
28
|
+
/** Title shown under the iOS spinner. */
|
|
29
|
+
title?: string;
|
|
30
|
+
/** Color of the iOS title text. */
|
|
31
|
+
titleColor?: string;
|
|
32
|
+
/** Android colors prop (an array of progress colors). */
|
|
33
|
+
colors?: string[];
|
|
34
|
+
/** Android progress background. */
|
|
35
|
+
progressBackgroundColor?: string;
|
|
36
|
+
testID?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Resolves the active theme's primary color for use as the RefreshControl
|
|
41
|
+
* tint. Returns undefined on platforms where the theme provider isn't
|
|
42
|
+
* mounted (consumer can still pass `tintColor` explicitly).
|
|
43
|
+
*/
|
|
44
|
+
// Keep the design-system hook resolution outside the render path. We
|
|
45
|
+
// resolve the hook reference once at module load; if the consumer isn't
|
|
46
|
+
// using genesis-design-system, we fall back to undefined and only the
|
|
47
|
+
// caller-provided tintColor / colors apply. Using a ref-style closure
|
|
48
|
+
// avoids conditional hooks (which would violate the rules of hooks).
|
|
49
|
+
const useGenesisThemeRef: (() => { colors?: { primary?: string } }) | null =
|
|
50
|
+
(() => {
|
|
51
|
+
try {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
53
|
+
const provider = require("@marktiderman/genesis-design-system/providers/native");
|
|
54
|
+
return provider.useGenesisTheme ?? null;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
})();
|
|
59
|
+
|
|
60
|
+
export function NativeRefreshControl(props: NativeRefreshControlProps) {
|
|
61
|
+
const RC = resolveRefreshControl();
|
|
62
|
+
const theme = useGenesisThemeRef ? useGenesisThemeRef() : null;
|
|
63
|
+
const themePrimary = theme?.colors?.primary;
|
|
64
|
+
if (!RC) return null;
|
|
65
|
+
return (
|
|
66
|
+
<RC
|
|
67
|
+
tintColor={props.tintColor ?? themePrimary}
|
|
68
|
+
colors={props.colors ?? (themePrimary ? [themePrimary] : undefined)}
|
|
69
|
+
{...props}
|
|
70
|
+
testID={props.testID ?? "native-refresh-control"}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SearchBar — text input with cancel + clear + optional voice trigger.
|
|
3
|
+
*
|
|
4
|
+
* Use as the search affordance for lists and result screens. iOS-style
|
|
5
|
+
* "Cancel" button slides in only when the input is focused and clears
|
|
6
|
+
* focus on press. The clear "✕" appears whenever there's a value.
|
|
7
|
+
*
|
|
8
|
+
* Voice support is opt-in: pass `onVoicePress` to render the voice
|
|
9
|
+
* button. The actual STT integration is the consumer's responsibility
|
|
10
|
+
* (e.g., expo-speech-recognition); this primitive only renders the
|
|
11
|
+
* trigger affordance.
|
|
12
|
+
*
|
|
13
|
+
* @stability Beta
|
|
14
|
+
*/
|
|
15
|
+
import { useRef, useState } from "react";
|
|
16
|
+
import { Pressable, Text, TextInput, View } from "react-native";
|
|
17
|
+
import { cn } from "../utils";
|
|
18
|
+
|
|
19
|
+
export interface NativeSearchBarProps {
|
|
20
|
+
value: string;
|
|
21
|
+
onChange: (value: string) => void;
|
|
22
|
+
/** Submit handler (return key on the keyboard). */
|
|
23
|
+
onSubmit?: (value: string) => void;
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Color used for the placeholder text. Defaults to a token-aware muted
|
|
27
|
+
* value that matches NativeWind's `text-muted-foreground` resolution.
|
|
28
|
+
* Override per-call when an alternate brand demands a different shade.
|
|
29
|
+
*/
|
|
30
|
+
placeholderTextColor?: string;
|
|
31
|
+
/** When provided, renders a microphone trigger. */
|
|
32
|
+
onVoicePress?: () => void;
|
|
33
|
+
/** Show the "Cancel" button when focused. Default true. */
|
|
34
|
+
showCancel?: boolean;
|
|
35
|
+
/** Cancel button label. Default "Cancel". */
|
|
36
|
+
cancelLabel?: string;
|
|
37
|
+
className?: string;
|
|
38
|
+
testID?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function NativeSearchBar({
|
|
42
|
+
value,
|
|
43
|
+
onChange,
|
|
44
|
+
onSubmit,
|
|
45
|
+
placeholder = "Search",
|
|
46
|
+
placeholderTextColor,
|
|
47
|
+
onVoicePress,
|
|
48
|
+
showCancel = true,
|
|
49
|
+
cancelLabel = "Cancel",
|
|
50
|
+
className,
|
|
51
|
+
testID,
|
|
52
|
+
}: NativeSearchBarProps) {
|
|
53
|
+
const [focused, setFocused] = useState(false);
|
|
54
|
+
const inputRef = useRef<React.ComponentRef<typeof TextInput>>(null);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<View
|
|
58
|
+
testID={testID ?? "native-search-bar"}
|
|
59
|
+
className={cn("flex-row items-center gap-2", className)}
|
|
60
|
+
>
|
|
61
|
+
<View className="flex-1 flex-row items-center rounded-md border border-input bg-background px-3">
|
|
62
|
+
<Text accessibilityElementsHidden className="text-sm text-muted-foreground">
|
|
63
|
+
{"\u{1F50D}"}
|
|
64
|
+
</Text>
|
|
65
|
+
<TextInput
|
|
66
|
+
ref={inputRef}
|
|
67
|
+
testID={testID ? `${testID}-input` : "search-input"}
|
|
68
|
+
value={value}
|
|
69
|
+
onChangeText={onChange}
|
|
70
|
+
onFocus={() => setFocused(true)}
|
|
71
|
+
onBlur={() => setFocused(false)}
|
|
72
|
+
onSubmitEditing={() => onSubmit?.(value)}
|
|
73
|
+
placeholder={placeholder}
|
|
74
|
+
placeholderTextColor={placeholderTextColor}
|
|
75
|
+
accessibilityLabel={placeholder}
|
|
76
|
+
returnKeyType="search"
|
|
77
|
+
autoCorrect={false}
|
|
78
|
+
autoCapitalize="none"
|
|
79
|
+
clearButtonMode="never"
|
|
80
|
+
className="ml-2 min-h-[44px] flex-1 text-base text-foreground"
|
|
81
|
+
/>
|
|
82
|
+
{value.length > 0 ? (
|
|
83
|
+
<Pressable
|
|
84
|
+
testID={testID ? `${testID}-clear` : "search-clear"}
|
|
85
|
+
accessibilityRole="button"
|
|
86
|
+
accessibilityLabel="Clear search"
|
|
87
|
+
hitSlop={8}
|
|
88
|
+
onPress={() => onChange("")}
|
|
89
|
+
className="ml-1 min-h-[24px] min-w-[24px] items-center justify-center"
|
|
90
|
+
>
|
|
91
|
+
<Text className="text-sm text-muted-foreground">✕</Text>
|
|
92
|
+
</Pressable>
|
|
93
|
+
) : null}
|
|
94
|
+
{onVoicePress ? (
|
|
95
|
+
<Pressable
|
|
96
|
+
testID={testID ? `${testID}-voice` : "search-voice"}
|
|
97
|
+
accessibilityRole="button"
|
|
98
|
+
accessibilityLabel="Voice search"
|
|
99
|
+
hitSlop={8}
|
|
100
|
+
onPress={onVoicePress}
|
|
101
|
+
className="ml-2 min-h-[24px] min-w-[24px] items-center justify-center"
|
|
102
|
+
>
|
|
103
|
+
<Text className="text-sm text-muted-foreground">{"\u{1F3A4}"}</Text>
|
|
104
|
+
</Pressable>
|
|
105
|
+
) : null}
|
|
106
|
+
</View>
|
|
107
|
+
{showCancel && focused ? (
|
|
108
|
+
<Pressable
|
|
109
|
+
testID={testID ? `${testID}-cancel` : "search-cancel"}
|
|
110
|
+
accessibilityRole="button"
|
|
111
|
+
accessibilityLabel={cancelLabel}
|
|
112
|
+
onPress={() => {
|
|
113
|
+
onChange("");
|
|
114
|
+
// Dismiss the keyboard along with the cancel — matches iOS native
|
|
115
|
+
// behavior. setFocused(false) will be triggered by the resulting
|
|
116
|
+
// onBlur as well, but call it eagerly to hide the cancel button
|
|
117
|
+
// immediately for snappier UX.
|
|
118
|
+
inputRef.current?.blur();
|
|
119
|
+
setFocused(false);
|
|
120
|
+
}}
|
|
121
|
+
className="min-h-[44px] items-center justify-center px-2"
|
|
122
|
+
>
|
|
123
|
+
<Text className="text-base text-primary">{cancelLabel}</Text>
|
|
124
|
+
</Pressable>
|
|
125
|
+
) : null}
|
|
126
|
+
</View>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SectionList header pattern — opinionated header style for
|
|
3
|
+
* react-native SectionList rows.
|
|
4
|
+
*
|
|
5
|
+
* The full SectionList API stays with React Native; Genesis ships the
|
|
6
|
+
* header component so consumers can pass it as `renderSectionHeader`
|
|
7
|
+
* and get a consistent visual: muted background, uppercase tracking,
|
|
8
|
+
* sticky-friendly padding.
|
|
9
|
+
*
|
|
10
|
+
* Pattern:
|
|
11
|
+
*
|
|
12
|
+
* <SectionList
|
|
13
|
+
* sections={...}
|
|
14
|
+
* renderItem={({ item }) => <NativeListItem title={item.label} />}
|
|
15
|
+
* renderSectionHeader={({ section }) => (
|
|
16
|
+
* <NativeSectionListHeader title={section.title} />
|
|
17
|
+
* )}
|
|
18
|
+
* />
|
|
19
|
+
*
|
|
20
|
+
* @stability Beta
|
|
21
|
+
*/
|
|
22
|
+
import { Text, View } from "react-native";
|
|
23
|
+
import { cn } from "../utils";
|
|
24
|
+
|
|
25
|
+
export interface NativeSectionListHeaderProps {
|
|
26
|
+
title: string;
|
|
27
|
+
/** Optional trailing content (e.g., a count badge). */
|
|
28
|
+
trailing?: React.ReactNode;
|
|
29
|
+
className?: string;
|
|
30
|
+
testID?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function NativeSectionListHeader({
|
|
34
|
+
title,
|
|
35
|
+
trailing,
|
|
36
|
+
className,
|
|
37
|
+
testID,
|
|
38
|
+
}: NativeSectionListHeaderProps) {
|
|
39
|
+
return (
|
|
40
|
+
<View
|
|
41
|
+
testID={testID ?? "native-section-header"}
|
|
42
|
+
accessibilityRole="header"
|
|
43
|
+
className={cn(
|
|
44
|
+
"flex-row items-center justify-between border-b border-border bg-muted px-4 py-2",
|
|
45
|
+
className
|
|
46
|
+
)}
|
|
47
|
+
>
|
|
48
|
+
<Text className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
|
|
49
|
+
{title}
|
|
50
|
+
</Text>
|
|
51
|
+
{trailing}
|
|
52
|
+
</View>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SegmentedControl — iOS-style horizontal segmented picker.
|
|
3
|
+
*
|
|
4
|
+
* Use for 2-5 mutually exclusive options that fit on one line. For more
|
|
5
|
+
* than 5, prefer <NativeTabs> or <NativeSelect>. Renders an Android-
|
|
6
|
+
* acceptable filled-pill variant; the visual remains compact on both
|
|
7
|
+
* platforms.
|
|
8
|
+
*
|
|
9
|
+
* @stability Beta
|
|
10
|
+
*/
|
|
11
|
+
import { Pressable, Text, View } from "react-native";
|
|
12
|
+
import { cn } from "../utils";
|
|
13
|
+
|
|
14
|
+
export interface NativeSegmentedControlOption<T = string> {
|
|
15
|
+
value: T;
|
|
16
|
+
label: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface NativeSegmentedControlProps<T = string> {
|
|
20
|
+
options: NativeSegmentedControlOption<T>[];
|
|
21
|
+
value: T;
|
|
22
|
+
onChange: (value: T) => void;
|
|
23
|
+
/** Disable the entire control. */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
testID?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function NativeSegmentedControl<T = string>({
|
|
30
|
+
options,
|
|
31
|
+
value,
|
|
32
|
+
onChange,
|
|
33
|
+
disabled,
|
|
34
|
+
className,
|
|
35
|
+
testID,
|
|
36
|
+
}: NativeSegmentedControlProps<T>) {
|
|
37
|
+
return (
|
|
38
|
+
<View
|
|
39
|
+
testID={testID ?? "native-segmented"}
|
|
40
|
+
accessibilityRole="radiogroup"
|
|
41
|
+
className={cn(
|
|
42
|
+
"flex-row rounded-md border border-border bg-muted p-0.5",
|
|
43
|
+
disabled && "opacity-50",
|
|
44
|
+
className
|
|
45
|
+
)}
|
|
46
|
+
>
|
|
47
|
+
{options.map((opt) => {
|
|
48
|
+
const selected = opt.value === value;
|
|
49
|
+
return (
|
|
50
|
+
<Pressable
|
|
51
|
+
key={String(opt.value)}
|
|
52
|
+
testID={
|
|
53
|
+
testID
|
|
54
|
+
? `${testID}-option-${String(opt.value)}`
|
|
55
|
+
: `segmented-option-${String(opt.value)}`
|
|
56
|
+
}
|
|
57
|
+
disabled={disabled}
|
|
58
|
+
accessibilityRole="radio"
|
|
59
|
+
accessibilityState={{ selected, disabled }}
|
|
60
|
+
onPress={() => onChange(opt.value)}
|
|
61
|
+
className={cn(
|
|
62
|
+
"min-h-[36px] flex-1 items-center justify-center rounded px-3 py-1",
|
|
63
|
+
selected && "bg-background shadow-sm"
|
|
64
|
+
)}
|
|
65
|
+
>
|
|
66
|
+
<Text
|
|
67
|
+
className={cn(
|
|
68
|
+
"text-sm",
|
|
69
|
+
selected ? "font-semibold text-foreground" : "text-muted-foreground"
|
|
70
|
+
)}
|
|
71
|
+
>
|
|
72
|
+
{opt.label}
|
|
73
|
+
</Text>
|
|
74
|
+
</Pressable>
|
|
75
|
+
);
|
|
76
|
+
})}
|
|
77
|
+
</View>
|
|
78
|
+
);
|
|
79
|
+
}
|