@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.
Files changed (129) hide show
  1. package/dist/chunk-BAU4YQZV.js +760 -0
  2. package/dist/chunk-BAU4YQZV.js.map +1 -0
  3. package/dist/chunk-DGUM43GV.js +10 -0
  4. package/dist/chunk-DGUM43GV.js.map +1 -0
  5. package/dist/chunk-HNIEFTEL.js +43 -0
  6. package/dist/chunk-HNIEFTEL.js.map +1 -0
  7. package/dist/chunk-N4WHTQIO.js +20 -0
  8. package/dist/chunk-N4WHTQIO.js.map +1 -0
  9. package/dist/chunk-OHZD7KRO.js +11 -0
  10. package/dist/chunk-OHZD7KRO.js.map +1 -0
  11. package/dist/chunk-PTJ2KCLM.js +160 -0
  12. package/dist/chunk-PTJ2KCLM.js.map +1 -0
  13. package/dist/chunk-TXJT55JC.js +2213 -0
  14. package/dist/chunk-TXJT55JC.js.map +1 -0
  15. package/dist/chunk-ULS7I6ZS.js +183 -0
  16. package/dist/chunk-ULS7I6ZS.js.map +1 -0
  17. package/dist/chunk-ZVF6PONU.js +522 -0
  18. package/dist/chunk-ZVF6PONU.js.map +1 -0
  19. package/dist/components/index.d.ts +908 -0
  20. package/dist/components/index.js +8 -0
  21. package/dist/components/index.js.map +1 -0
  22. package/dist/data/index.d.ts +117 -0
  23. package/dist/data/index.js +770 -0
  24. package/dist/data/index.js.map +1 -0
  25. package/dist/hooks/index.d.ts +31 -0
  26. package/dist/hooks/index.js +5 -0
  27. package/dist/hooks/index.js.map +1 -0
  28. package/dist/index.d.ts +11 -0
  29. package/dist/index.js +11 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/layouts/index.d.ts +364 -0
  32. package/dist/layouts/index.js +8 -0
  33. package/dist/layouts/index.js.map +1 -0
  34. package/dist/utils.d.ts +5 -0
  35. package/dist/utils.js +4 -0
  36. package/dist/utils.js.map +1 -0
  37. package/package.json +127 -0
  38. package/src/components/__tests__/accordion.test.tsx +122 -0
  39. package/src/components/__tests__/chip-group.test.tsx +45 -0
  40. package/src/components/__tests__/combobox.test.tsx +97 -0
  41. package/src/components/__tests__/drawer.test.tsx +98 -0
  42. package/src/components/__tests__/empty-state.test.tsx +66 -0
  43. package/src/components/__tests__/header-card.test.tsx +31 -0
  44. package/src/components/__tests__/layout.test.tsx +109 -0
  45. package/src/components/__tests__/list-item.test.tsx +31 -0
  46. package/src/components/__tests__/number-input.test.tsx +46 -0
  47. package/src/components/__tests__/pagination.test.tsx +43 -0
  48. package/src/components/__tests__/search-bar.test.tsx +41 -0
  49. package/src/components/__tests__/segmented-empty-alert.test.tsx +79 -0
  50. package/src/components/__tests__/slider.test.tsx +134 -0
  51. package/src/components/__tests__/stepper.test.tsx +25 -0
  52. package/src/components/__tests__/toast.test.tsx +63 -0
  53. package/src/components/accordion.tsx +223 -0
  54. package/src/components/alert.tsx +131 -0
  55. package/src/components/avatar.tsx +68 -0
  56. package/src/components/badge.tsx +80 -0
  57. package/src/components/button.tsx +118 -0
  58. package/src/components/card.tsx +120 -0
  59. package/src/components/checkbox.tsx +60 -0
  60. package/src/components/chip-group.tsx +127 -0
  61. package/src/components/combobox.tsx +137 -0
  62. package/src/components/date-time-picker.tsx +127 -0
  63. package/src/components/dialog.tsx +131 -0
  64. package/src/components/drawer.tsx +131 -0
  65. package/src/components/dropdown-menu.tsx +133 -0
  66. package/src/components/empty-state.tsx +161 -0
  67. package/src/components/header-card.tsx +116 -0
  68. package/src/components/index.ts +259 -0
  69. package/src/components/inline-alert.tsx +150 -0
  70. package/src/components/input.tsx +51 -0
  71. package/src/components/label.tsx +35 -0
  72. package/src/components/layout/box.tsx +115 -0
  73. package/src/components/layout/flex.ts +24 -0
  74. package/src/components/layout/grid.tsx +73 -0
  75. package/src/components/layout/index.ts +27 -0
  76. package/src/components/layout/inline.tsx +63 -0
  77. package/src/components/layout/spacing.ts +116 -0
  78. package/src/components/layout/stack.tsx +58 -0
  79. package/src/components/list-item.tsx +108 -0
  80. package/src/components/number-input.tsx +119 -0
  81. package/src/components/pagination.tsx +132 -0
  82. package/src/components/popover.tsx +198 -0
  83. package/src/components/progress.tsx +50 -0
  84. package/src/components/radio-group.tsx +92 -0
  85. package/src/components/refresh-control.tsx +73 -0
  86. package/src/components/search-bar.tsx +128 -0
  87. package/src/components/section-list.tsx +54 -0
  88. package/src/components/segmented-control.tsx +79 -0
  89. package/src/components/select.tsx +178 -0
  90. package/src/components/separator.tsx +31 -0
  91. package/src/components/sheet.tsx +192 -0
  92. package/src/components/skeleton.tsx +104 -0
  93. package/src/components/slider.tsx +223 -0
  94. package/src/components/stepper.tsx +96 -0
  95. package/src/components/switch.tsx +35 -0
  96. package/src/components/tabs.tsx +147 -0
  97. package/src/components/text.tsx +62 -0
  98. package/src/components/textarea.tsx +52 -0
  99. package/src/components/toast.tsx +228 -0
  100. package/src/components/toggle.tsx +85 -0
  101. package/src/components/tooltip.tsx +104 -0
  102. package/src/data/NativeDataFilters.tsx +100 -0
  103. package/src/data/NativeDataPageShell.tsx +111 -0
  104. package/src/data/NativeDetailPanel.tsx +130 -0
  105. package/src/data/NativeEmptyState.tsx +46 -0
  106. package/src/data/NativeResourceForm.tsx +157 -0
  107. package/src/data/NativeResourceFormField.tsx +280 -0
  108. package/src/data/NativeResourcePage.tsx +505 -0
  109. package/src/data/index.ts +9 -0
  110. package/src/hooks/index.ts +16 -0
  111. package/src/hooks/use-genesis-extension.ts +81 -0
  112. package/src/hooks/use-reduced-motion.ts +32 -0
  113. package/src/hooks/use-theme-mode.ts +31 -0
  114. package/src/index.ts +5 -0
  115. package/src/layouts/__tests__/auth.test.tsx +150 -0
  116. package/src/layouts/__tests__/nav-bar.test.tsx +86 -0
  117. package/src/layouts/__tests__/notifications-page.test.tsx +94 -0
  118. package/src/layouts/__tests__/screen-container.test.tsx +79 -0
  119. package/src/layouts/__tests__/settings-page.test.tsx +107 -0
  120. package/src/layouts/__tests__/settings-sub-page.test.tsx +53 -0
  121. package/src/layouts/auth.tsx +352 -0
  122. package/src/layouts/index.ts +61 -0
  123. package/src/layouts/nav-bar.tsx +200 -0
  124. package/src/layouts/notifications-page.tsx +274 -0
  125. package/src/layouts/screen-container.tsx +213 -0
  126. package/src/layouts/settings-page.tsx +195 -0
  127. package/src/layouts/settings-sub-page.tsx +183 -0
  128. package/src/nativewind.d.ts +40 -0
  129. package/src/utils.ts +6 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Card — flat container surface. The 90% case is `<Card>{children}</Card>`. See HeaderCard for structured layouts.
3
+ *
4
+ * @stability Stable
5
+ */
6
+ import { Text, View } from "react-native";
7
+ import { cn } from "../utils";
8
+
9
+ export interface NativeCardProps {
10
+ className?: string;
11
+ children?: React.ReactNode;
12
+ testID?: string;
13
+ }
14
+
15
+ function NativeCard({ className, children, ...props }: NativeCardProps) {
16
+ return (
17
+ <View
18
+ className={cn(
19
+ "rounded-xl border border-border bg-card p-0 shadow-sm",
20
+ className
21
+ )}
22
+ {...props}
23
+ >
24
+ {children}
25
+ </View>
26
+ );
27
+ }
28
+
29
+ function NativeCardHeader({
30
+ className,
31
+ children,
32
+ ...props
33
+ }: NativeCardProps) {
34
+ return (
35
+ <View className={cn("flex-col gap-1.5 p-6", className)} {...props}>
36
+ {children}
37
+ </View>
38
+ );
39
+ }
40
+
41
+ export interface NativeCardTitleProps {
42
+ className?: string;
43
+ children?: React.ReactNode;
44
+ testID?: string;
45
+ }
46
+
47
+ function NativeCardTitle({
48
+ className,
49
+ children,
50
+ ...props
51
+ }: NativeCardTitleProps) {
52
+ return (
53
+ <Text
54
+ className={cn(
55
+ "text-2xl font-semibold leading-none tracking-tight text-card-foreground",
56
+ className
57
+ )}
58
+ {...props}
59
+ >
60
+ {children}
61
+ </Text>
62
+ );
63
+ }
64
+
65
+ export interface NativeCardDescriptionProps {
66
+ className?: string;
67
+ children?: React.ReactNode;
68
+ testID?: string;
69
+ }
70
+
71
+ function NativeCardDescription({
72
+ className,
73
+ children,
74
+ ...props
75
+ }: NativeCardDescriptionProps) {
76
+ return (
77
+ <Text
78
+ className={cn("text-sm text-muted-foreground", className)}
79
+ {...props}
80
+ >
81
+ {children}
82
+ </Text>
83
+ );
84
+ }
85
+
86
+ function NativeCardContent({
87
+ className,
88
+ children,
89
+ ...props
90
+ }: NativeCardProps) {
91
+ return (
92
+ <View className={cn("p-6 pt-0", className)} {...props}>
93
+ {children}
94
+ </View>
95
+ );
96
+ }
97
+
98
+ function NativeCardFooter({
99
+ className,
100
+ children,
101
+ ...props
102
+ }: NativeCardProps) {
103
+ return (
104
+ <View
105
+ className={cn("flex-row items-center p-6 pt-0", className)}
106
+ {...props}
107
+ >
108
+ {children}
109
+ </View>
110
+ );
111
+ }
112
+
113
+ export {
114
+ NativeCard,
115
+ NativeCardHeader,
116
+ NativeCardTitle,
117
+ NativeCardDescription,
118
+ NativeCardContent,
119
+ NativeCardFooter,
120
+ };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Checkbox — binary on/off control with optional label.
3
+ *
4
+ * @stability Stable
5
+ */
6
+ import { useState } from "react";
7
+ import { Pressable, View } from "react-native";
8
+ import { cn } from "../utils";
9
+
10
+ export interface NativeCheckboxProps {
11
+ className?: string;
12
+ checked?: boolean;
13
+ defaultChecked?: boolean;
14
+ onCheckedChange?: (checked: boolean) => void;
15
+ disabled?: boolean;
16
+ testID?: string;
17
+ }
18
+
19
+ function NativeCheckbox({
20
+ className,
21
+ checked: controlledChecked,
22
+ defaultChecked = false,
23
+ onCheckedChange,
24
+ disabled,
25
+ ...props
26
+ }: NativeCheckboxProps) {
27
+ const [uncontrolledChecked, setUncontrolledChecked] =
28
+ useState(defaultChecked);
29
+ const isChecked = controlledChecked ?? uncontrolledChecked;
30
+
31
+ function handlePress() {
32
+ const next = !isChecked;
33
+ if (controlledChecked === undefined) {
34
+ setUncontrolledChecked(next);
35
+ }
36
+ onCheckedChange?.(next);
37
+ }
38
+
39
+ return (
40
+ <Pressable
41
+ className={cn(
42
+ "h-5 w-5 items-center justify-center rounded border border-border",
43
+ isChecked && "border-primary bg-primary",
44
+ disabled && "opacity-50",
45
+ className
46
+ )}
47
+ onPress={handlePress}
48
+ disabled={disabled}
49
+ accessibilityRole="checkbox"
50
+ accessibilityState={{ checked: isChecked }}
51
+ {...props}
52
+ >
53
+ {isChecked ? (
54
+ <View className="h-2.5 w-2.5 rounded-sm bg-primary-foreground" />
55
+ ) : null}
56
+ </Pressable>
57
+ );
58
+ }
59
+
60
+ export { NativeCheckbox };
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Chip + ChipGroup — wrapping row of selectable filter pills.
3
+ *
4
+ * Use for filters and multi-select tag pickers. Two modes:
5
+ * - "single": exactly one chip selected at a time.
6
+ * - "multiple": any subset selected.
7
+ *
8
+ * Compose: <NativeChipGroup value=... onChange=...>
9
+ * <NativeChip value="x">Label</NativeChip>
10
+ * </NativeChipGroup>.
11
+ *
12
+ * @stability Beta
13
+ */
14
+ import { createContext, useContext } from "react";
15
+ import { Pressable, Text, View } from "react-native";
16
+ import { cn } from "../utils";
17
+
18
+ export type NativeChipGroupMode = "single" | "multiple";
19
+
20
+ interface ChipContextValue {
21
+ mode: NativeChipGroupMode;
22
+ selected: Set<string>;
23
+ toggle: (value: string) => void;
24
+ disabled?: boolean;
25
+ }
26
+
27
+ const ChipContext = createContext<ChipContextValue | null>(null);
28
+
29
+ export interface NativeChipGroupProps {
30
+ mode?: NativeChipGroupMode;
31
+ value: string | string[];
32
+ onChange: (value: string | string[]) => void;
33
+ disabled?: boolean;
34
+ className?: string;
35
+ children: React.ReactNode;
36
+ testID?: string;
37
+ }
38
+
39
+ export function NativeChipGroup({
40
+ mode = "multiple",
41
+ value,
42
+ onChange,
43
+ disabled,
44
+ className,
45
+ children,
46
+ testID,
47
+ }: NativeChipGroupProps) {
48
+ const selected = new Set<string>(
49
+ mode === "single"
50
+ ? typeof value === "string"
51
+ ? [value]
52
+ : []
53
+ : Array.isArray(value)
54
+ ? value
55
+ : []
56
+ );
57
+ const toggle = (v: string) => {
58
+ if (mode === "single") {
59
+ onChange(v);
60
+ return;
61
+ }
62
+ const next = new Set(selected);
63
+ if (next.has(v)) next.delete(v);
64
+ else next.add(v);
65
+ onChange(Array.from(next));
66
+ };
67
+ return (
68
+ <ChipContext.Provider value={{ mode, selected, toggle, disabled }}>
69
+ <View
70
+ testID={testID ?? "native-chip-group"}
71
+ accessibilityRole={mode === "single" ? "radiogroup" : undefined}
72
+ className={cn("flex-row flex-wrap gap-2", className)}
73
+ >
74
+ {children}
75
+ </View>
76
+ </ChipContext.Provider>
77
+ );
78
+ }
79
+
80
+ export interface NativeChipProps {
81
+ value: string;
82
+ className?: string;
83
+ children: React.ReactNode;
84
+ testID?: string;
85
+ }
86
+
87
+ export function NativeChip({
88
+ value,
89
+ className,
90
+ children,
91
+ testID,
92
+ }: NativeChipProps) {
93
+ const ctx = useContext(ChipContext);
94
+ if (!ctx)
95
+ throw new Error("NativeChip must be used inside <NativeChipGroup>.");
96
+ const isSelected = ctx.selected.has(value);
97
+ return (
98
+ <Pressable
99
+ testID={testID ?? `chip-${value}`}
100
+ accessibilityRole={ctx.mode === "single" ? "radio" : "checkbox"}
101
+ accessibilityState={{ selected: isSelected, disabled: ctx.disabled }}
102
+ disabled={ctx.disabled}
103
+ onPress={() => ctx.toggle(value)}
104
+ className={cn(
105
+ "min-h-[44px] flex-row items-center rounded-full border px-3.5 py-1.5",
106
+ isSelected
107
+ ? "border-primary bg-primary/10"
108
+ : "border-border bg-background",
109
+ ctx.disabled && "opacity-50",
110
+ className
111
+ )}
112
+ >
113
+ {typeof children === "string" ? (
114
+ <Text
115
+ className={cn(
116
+ "text-sm",
117
+ isSelected ? "font-semibold text-primary" : "text-foreground"
118
+ )}
119
+ >
120
+ {children}
121
+ </Text>
122
+ ) : (
123
+ children
124
+ )}
125
+ </Pressable>
126
+ );
127
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Combobox / Autocomplete — text input that filters a fixed option list
3
+ * and lets the user pick one.
4
+ *
5
+ * Use when the user knows what they're looking for and the option list
6
+ * is too long for a Select. Filtering is case-insensitive substring by
7
+ * default; pass `filter` to override (e.g. fuzzy match).
8
+ *
9
+ * @stability Beta
10
+ */
11
+ import { useMemo, useState } from "react";
12
+ import { Pressable, ScrollView, Text, TextInput, View } from "react-native";
13
+ import { cn } from "../utils";
14
+
15
+ export interface NativeComboboxOption<T = string> {
16
+ /** Stable identifier passed to onChange. */
17
+ value: T;
18
+ /** Visible label. */
19
+ label: string;
20
+ /** Optional secondary line. */
21
+ description?: string;
22
+ }
23
+
24
+ export interface NativeComboboxProps<T = string> {
25
+ options: NativeComboboxOption<T>[];
26
+ value?: T;
27
+ onChange: (value: T) => void;
28
+ /** Placeholder for the input. */
29
+ placeholder?: string;
30
+ /**
31
+ * Color used for the placeholder text. Defaults to a token-aware muted
32
+ * value that matches NativeWind's `text-muted-foreground` resolution.
33
+ * Override per-call when an alternate brand demands a different shade.
34
+ */
35
+ placeholderTextColor?: string;
36
+ /** Override the substring filter. Return true to keep the option visible. */
37
+ filter?: (option: NativeComboboxOption<T>, query: string) => boolean;
38
+ /** Empty-state node when nothing matches. */
39
+ emptyContent?: React.ReactNode;
40
+ /** Initial query (uncontrolled mode). */
41
+ defaultQuery?: string;
42
+ className?: string;
43
+ testID?: string;
44
+ }
45
+
46
+ const defaultFilter = <T,>(o: NativeComboboxOption<T>, q: string) =>
47
+ o.label.toLowerCase().includes(q.toLowerCase()) ||
48
+ (o.description?.toLowerCase().includes(q.toLowerCase()) ?? false);
49
+
50
+ export function NativeCombobox<T = string>({
51
+ options,
52
+ value,
53
+ onChange,
54
+ placeholder,
55
+ placeholderTextColor,
56
+ filter = defaultFilter,
57
+ emptyContent,
58
+ defaultQuery = "",
59
+ className,
60
+ testID,
61
+ }: NativeComboboxProps<T>) {
62
+ const [query, setQuery] = useState<string>(() => {
63
+ if (defaultQuery) return defaultQuery;
64
+ const selected = options.find((o) => o.value === value);
65
+ return selected?.label ?? "";
66
+ });
67
+ const [open, setOpen] = useState(false);
68
+
69
+ const filtered = useMemo(
70
+ () => (query ? options.filter((o) => filter(o, query)) : options),
71
+ [filter, options, query]
72
+ );
73
+
74
+ return (
75
+ <View testID={testID} className={cn("relative", className)}>
76
+ <TextInput
77
+ testID={testID ? `${testID}-input` : "combobox-input"}
78
+ value={query}
79
+ onChangeText={(t) => {
80
+ setQuery(t);
81
+ if (!open) setOpen(true);
82
+ }}
83
+ onFocus={() => setOpen(true)}
84
+ // Delay close on blur so option-press can land first.
85
+ onBlur={() => {
86
+ setTimeout(() => setOpen(false), 120);
87
+ }}
88
+ placeholder={placeholder ?? "Search..."}
89
+ placeholderTextColor={placeholderTextColor}
90
+ accessibilityRole="search"
91
+ accessibilityLabel={placeholder ?? "Search"}
92
+ className={cn(
93
+ "min-h-[44px] rounded-md border border-input bg-background px-3 text-base text-foreground"
94
+ )}
95
+ />
96
+ {open ? (
97
+ <View
98
+ className={cn(
99
+ "mt-1 max-h-[280px] rounded-md border border-border bg-background shadow-md"
100
+ )}
101
+ >
102
+ {filtered.length === 0 ? (
103
+ <View className="p-3" testID={testID ? `${testID}-empty` : undefined}>
104
+ {emptyContent ?? (
105
+ <Text className="text-sm text-muted-foreground">No results.</Text>
106
+ )}
107
+ </View>
108
+ ) : (
109
+ <ScrollView keyboardShouldPersistTaps="handled">
110
+ {filtered.map((opt) => (
111
+ <Pressable
112
+ key={String(opt.value)}
113
+ testID={testID ? `${testID}-option-${String(opt.value)}` : undefined}
114
+ accessibilityRole="button"
115
+ accessibilityState={{ selected: opt.value === value }}
116
+ onPress={() => {
117
+ onChange(opt.value);
118
+ setQuery(opt.label);
119
+ setOpen(false);
120
+ }}
121
+ className="min-h-[44px] flex-col justify-center px-3 py-2"
122
+ >
123
+ <Text className="text-base text-foreground">{opt.label}</Text>
124
+ {opt.description ? (
125
+ <Text className="text-xs text-muted-foreground">
126
+ {opt.description}
127
+ </Text>
128
+ ) : null}
129
+ </Pressable>
130
+ ))}
131
+ </ScrollView>
132
+ )}
133
+ </View>
134
+ ) : null}
135
+ </View>
136
+ );
137
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * DatePicker / TimePicker — wraps @react-native-community/datetimepicker
3
+ * with platform-correct UX (iOS wheel, Android calendar/clock dialog).
4
+ *
5
+ * NativeDatePicker exposes a date as a Pressable button labeled with the
6
+ * formatted value; tapping presents the platform-native picker. Same
7
+ * pattern for NativeTimePicker.
8
+ *
9
+ * Consumers must install @react-native-community/datetimepicker (peer
10
+ * dep, marked optional). When the dep is missing, the component falls
11
+ * back to a read-only Text label so screens still render — useful for
12
+ * sample/demo apps without native module setup.
13
+ *
14
+ * @stability Beta
15
+ */
16
+ import { useMemo, useState } from "react";
17
+ import { Platform, Pressable, Text } from "react-native";
18
+ import { cn } from "../utils";
19
+
20
+ function resolveDateTimePicker(): React.ComponentType<{
21
+ value: Date;
22
+ mode: "date" | "time";
23
+ display?: string;
24
+ onChange: (e: unknown, d?: Date) => void;
25
+ testID?: string;
26
+ }> | null {
27
+ try {
28
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
29
+ return require("@react-native-community/datetimepicker").default;
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ interface BasePickerProps {
36
+ value: Date;
37
+ onChange: (next: Date) => void;
38
+ /** Disable the picker. */
39
+ disabled?: boolean;
40
+ /** Override the rendered button text. */
41
+ formatLabel?: (d: Date) => string;
42
+ className?: string;
43
+ testID?: string;
44
+ }
45
+
46
+ export type NativeDatePickerProps = BasePickerProps;
47
+ export type NativeTimePickerProps = BasePickerProps;
48
+
49
+ function PickerButton({
50
+ value,
51
+ onChange,
52
+ mode,
53
+ formatLabel,
54
+ disabled,
55
+ className,
56
+ testID,
57
+ }: BasePickerProps & { mode: "date" | "time" }) {
58
+ const Picker = resolveDateTimePicker();
59
+ const [showAndroid, setShowAndroid] = useState(false);
60
+ const isIOS = Platform.OS === "ios";
61
+
62
+ const label = useMemo(() => {
63
+ if (formatLabel) return formatLabel(value);
64
+ if (mode === "date") return value.toDateString();
65
+ return value.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
66
+ }, [formatLabel, mode, value]);
67
+
68
+ if (!Picker) {
69
+ return (
70
+ <Text
71
+ testID={testID}
72
+ className={cn(
73
+ "min-h-[44px] rounded-md border border-input bg-background px-3 py-3 text-base text-muted-foreground",
74
+ className
75
+ )}
76
+ >
77
+ {label} (picker module not installed)
78
+ </Text>
79
+ );
80
+ }
81
+
82
+ // iOS: render the inline picker directly when consumer wants it that
83
+ // way; default exposes a button that toggles a sheet-like dialog. For
84
+ // simplicity in this primitive we render the button + the picker inline.
85
+ return (
86
+ <>
87
+ <Pressable
88
+ testID={testID ?? `native-${mode}-picker`}
89
+ accessibilityRole="button"
90
+ accessibilityLabel={`Pick a ${mode}`}
91
+ accessibilityValue={{ text: label }}
92
+ accessibilityState={{ disabled }}
93
+ disabled={disabled}
94
+ onPress={() => {
95
+ if (!isIOS) setShowAndroid(true);
96
+ }}
97
+ className={cn(
98
+ "min-h-[44px] flex-row items-center rounded-md border border-input bg-background px-3",
99
+ disabled && "opacity-50",
100
+ className
101
+ )}
102
+ >
103
+ <Text className="flex-1 text-base text-foreground">{label}</Text>
104
+ </Pressable>
105
+ {(isIOS || showAndroid) ? (
106
+ <Picker
107
+ testID={testID ? `${testID}-picker` : undefined}
108
+ value={value}
109
+ mode={mode}
110
+ display={isIOS ? "compact" : "default"}
111
+ onChange={(_e, d) => {
112
+ if (!isIOS) setShowAndroid(false);
113
+ if (d) onChange(d);
114
+ }}
115
+ />
116
+ ) : null}
117
+ </>
118
+ );
119
+ }
120
+
121
+ export function NativeDatePicker(props: NativeDatePickerProps) {
122
+ return <PickerButton {...props} mode="date" />;
123
+ }
124
+
125
+ export function NativeTimePicker(props: NativeTimePickerProps) {
126
+ return <PickerButton {...props} mode="time" />;
127
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Dialog — modal overlay for confirmations and short forms.
3
+ *
4
+ * @stability Stable
5
+ */
6
+ import { Modal, Pressable, Text, View } from "react-native";
7
+ import { cn } from "../utils";
8
+
9
+ export interface NativeDialogProps {
10
+ open?: boolean;
11
+ onOpenChange?: (open: boolean) => void;
12
+ children: React.ReactNode;
13
+ }
14
+
15
+ function NativeDialog({ open, onOpenChange, children }: NativeDialogProps) {
16
+ return (
17
+ <Modal
18
+ visible={open}
19
+ transparent
20
+ animationType="fade"
21
+ onRequestClose={() => onOpenChange?.(false)}
22
+ >
23
+ <Pressable
24
+ className="flex-1 items-center justify-center bg-black/50"
25
+ onPress={() => onOpenChange?.(false)}
26
+ >
27
+ {/* Captures touch to prevent backdrop press from closing dialog when tapping content */}
28
+ <Pressable onPress={() => {}}>
29
+ {children}
30
+ </Pressable>
31
+ </Pressable>
32
+ </Modal>
33
+ );
34
+ }
35
+
36
+ export interface NativeDialogContentProps {
37
+ className?: string;
38
+ children: React.ReactNode;
39
+ testID?: string;
40
+ }
41
+
42
+ function NativeDialogContent({
43
+ className,
44
+ children,
45
+ ...props
46
+ }: NativeDialogContentProps) {
47
+ return (
48
+ <View
49
+ className={cn(
50
+ "w-80 gap-4 rounded-lg border border-border bg-background p-6 shadow-lg",
51
+ className
52
+ )}
53
+ {...props}
54
+ >
55
+ {children}
56
+ </View>
57
+ );
58
+ }
59
+
60
+ export interface NativeDialogHeaderProps {
61
+ className?: string;
62
+ children: React.ReactNode;
63
+ }
64
+
65
+ function NativeDialogHeader({
66
+ className,
67
+ children,
68
+ }: NativeDialogHeaderProps) {
69
+ return (
70
+ <View className={cn("gap-1.5", className)}>
71
+ {children}
72
+ </View>
73
+ );
74
+ }
75
+
76
+ export interface NativeDialogTitleProps {
77
+ className?: string;
78
+ children: React.ReactNode;
79
+ }
80
+
81
+ function NativeDialogTitle({
82
+ className,
83
+ children,
84
+ }: NativeDialogTitleProps) {
85
+ return (
86
+ <Text className={cn("text-lg font-semibold text-foreground", className)}>
87
+ {children}
88
+ </Text>
89
+ );
90
+ }
91
+
92
+ export interface NativeDialogDescriptionProps {
93
+ className?: string;
94
+ children: React.ReactNode;
95
+ }
96
+
97
+ function NativeDialogDescription({
98
+ className,
99
+ children,
100
+ }: NativeDialogDescriptionProps) {
101
+ return (
102
+ <Text className={cn("text-sm text-muted-foreground", className)}>
103
+ {children}
104
+ </Text>
105
+ );
106
+ }
107
+
108
+ export interface NativeDialogFooterProps {
109
+ className?: string;
110
+ children: React.ReactNode;
111
+ }
112
+
113
+ function NativeDialogFooter({
114
+ className,
115
+ children,
116
+ }: NativeDialogFooterProps) {
117
+ return (
118
+ <View className={cn("flex-row justify-end gap-2", className)}>
119
+ {children}
120
+ </View>
121
+ );
122
+ }
123
+
124
+ export {
125
+ NativeDialog,
126
+ NativeDialogContent,
127
+ NativeDialogHeader,
128
+ NativeDialogTitle,
129
+ NativeDialogDescription,
130
+ NativeDialogFooter,
131
+ };