@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,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slider + Range — single-thumb and dual-thumb sliders.
|
|
3
|
+
*
|
|
4
|
+
* NativeSlider: pick one value within [min, max].
|
|
5
|
+
* NativeRangeSlider: pick a [low, high] range.
|
|
6
|
+
*
|
|
7
|
+
* Built on PanResponder + measured layout — no native module dependency.
|
|
8
|
+
* Both honor 44pt thumb hit areas and expose accessibilityRole="adjustable"
|
|
9
|
+
* with accessibilityValue so VoiceOver / TalkBack gestures adjust the
|
|
10
|
+
* value via the platform's adjustable-rotor API.
|
|
11
|
+
*
|
|
12
|
+
* @stability Beta
|
|
13
|
+
*/
|
|
14
|
+
import { useMemo, useRef, useState } from "react";
|
|
15
|
+
import { PanResponder, View } from "react-native";
|
|
16
|
+
import { cn } from "../utils";
|
|
17
|
+
|
|
18
|
+
interface BaseProps {
|
|
19
|
+
min?: number;
|
|
20
|
+
max?: number;
|
|
21
|
+
step?: number;
|
|
22
|
+
className?: string;
|
|
23
|
+
trackClassName?: string;
|
|
24
|
+
fillClassName?: string;
|
|
25
|
+
thumbClassName?: string;
|
|
26
|
+
testID?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface NativeSliderProps extends BaseProps {
|
|
30
|
+
value: number;
|
|
31
|
+
onChange: (value: number) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function snap(v: number, step: number, min: number, max: number) {
|
|
35
|
+
const clamped = Math.min(max, Math.max(min, v));
|
|
36
|
+
if (step <= 0) return clamped;
|
|
37
|
+
// Snap relative to `min` so non-zero starts (e.g. min=1, step=2 → 1,3,5,...)
|
|
38
|
+
// produce the correct discrete grid. Then re-clamp because the stepped
|
|
39
|
+
// value can exceed max when (max - min) is not a multiple of step.
|
|
40
|
+
const stepped = Math.round((clamped - min) / step) * step + min;
|
|
41
|
+
return Math.min(max, Math.max(min, stepped));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function useTrackWidth() {
|
|
45
|
+
const [width, setWidth] = useState(0);
|
|
46
|
+
const onLayout = (e: { nativeEvent?: { layout?: { width?: number } } }) => {
|
|
47
|
+
const w = e.nativeEvent?.layout?.width;
|
|
48
|
+
if (typeof w === "number") setWidth(w);
|
|
49
|
+
};
|
|
50
|
+
return { width, onLayout };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function NativeSlider({
|
|
54
|
+
value,
|
|
55
|
+
onChange,
|
|
56
|
+
min = 0,
|
|
57
|
+
max = 100,
|
|
58
|
+
step = 1,
|
|
59
|
+
className,
|
|
60
|
+
trackClassName,
|
|
61
|
+
fillClassName,
|
|
62
|
+
thumbClassName,
|
|
63
|
+
testID,
|
|
64
|
+
}: NativeSliderProps) {
|
|
65
|
+
const { width, onLayout } = useTrackWidth();
|
|
66
|
+
const startValue = useRef(value);
|
|
67
|
+
|
|
68
|
+
// Recreate the PanResponder when any of the derivable inputs change so its
|
|
69
|
+
// closures never read a stale `value` / `width` / range. PanResponder
|
|
70
|
+
// returns a fresh object each call but reuses its handler implementation,
|
|
71
|
+
// so this is cheap.
|
|
72
|
+
const responder = useMemo(
|
|
73
|
+
() =>
|
|
74
|
+
PanResponder.create({
|
|
75
|
+
onStartShouldSetPanResponder: () => true,
|
|
76
|
+
onMoveShouldSetPanResponder: () => true,
|
|
77
|
+
onPanResponderGrant: () => {
|
|
78
|
+
startValue.current = value;
|
|
79
|
+
},
|
|
80
|
+
onPanResponderMove: (_e, g) => {
|
|
81
|
+
if (width <= 0) return;
|
|
82
|
+
const delta = (g.dx / width) * (max - min);
|
|
83
|
+
onChange(snap(startValue.current + delta, step, min, max));
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
[max, min, onChange, step, value, width]
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const ratio = width === 0 ? 0 : (value - min) / (max - min);
|
|
90
|
+
const fillWidth = Math.round(ratio * width);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<View
|
|
94
|
+
testID={testID ?? "native-slider"}
|
|
95
|
+
accessibilityRole="adjustable"
|
|
96
|
+
accessibilityValue={{ now: value, min, max }}
|
|
97
|
+
onLayout={onLayout}
|
|
98
|
+
className={cn("h-11 w-full justify-center", className)}
|
|
99
|
+
{...responder.panHandlers}
|
|
100
|
+
>
|
|
101
|
+
<View className={cn("h-1.5 rounded-full bg-muted", trackClassName)} />
|
|
102
|
+
<View
|
|
103
|
+
className={cn(
|
|
104
|
+
"absolute h-1.5 rounded-full bg-primary",
|
|
105
|
+
fillClassName
|
|
106
|
+
)}
|
|
107
|
+
style={{ width: fillWidth }}
|
|
108
|
+
/>
|
|
109
|
+
<View
|
|
110
|
+
testID={testID ? `${testID}-thumb` : undefined}
|
|
111
|
+
accessibilityElementsHidden
|
|
112
|
+
importantForAccessibility="no-hide-descendants"
|
|
113
|
+
className={cn(
|
|
114
|
+
"absolute h-6 w-6 rounded-full border-2 border-primary bg-background shadow",
|
|
115
|
+
thumbClassName
|
|
116
|
+
)}
|
|
117
|
+
style={{ left: Math.max(0, fillWidth - 12) }}
|
|
118
|
+
/>
|
|
119
|
+
</View>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface NativeRangeSliderProps extends BaseProps {
|
|
124
|
+
value: [number, number];
|
|
125
|
+
onChange: (value: [number, number]) => void;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function NativeRangeSlider({
|
|
129
|
+
value,
|
|
130
|
+
onChange,
|
|
131
|
+
min = 0,
|
|
132
|
+
max = 100,
|
|
133
|
+
step = 1,
|
|
134
|
+
className,
|
|
135
|
+
trackClassName,
|
|
136
|
+
fillClassName,
|
|
137
|
+
thumbClassName,
|
|
138
|
+
testID,
|
|
139
|
+
}: NativeRangeSliderProps) {
|
|
140
|
+
const { width, onLayout } = useTrackWidth();
|
|
141
|
+
const startLow = useRef(value[0]);
|
|
142
|
+
const startHigh = useRef(value[1]);
|
|
143
|
+
|
|
144
|
+
const lowResponder = useMemo(
|
|
145
|
+
() =>
|
|
146
|
+
PanResponder.create({
|
|
147
|
+
onStartShouldSetPanResponder: () => true,
|
|
148
|
+
onMoveShouldSetPanResponder: () => true,
|
|
149
|
+
onPanResponderGrant: () => {
|
|
150
|
+
startLow.current = value[0];
|
|
151
|
+
},
|
|
152
|
+
onPanResponderMove: (_e, g) => {
|
|
153
|
+
if (width <= 0) return;
|
|
154
|
+
const delta = (g.dx / width) * (max - min);
|
|
155
|
+
const next = snap(startLow.current + delta, step, min, value[1]);
|
|
156
|
+
onChange([next, value[1]]);
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
[max, min, onChange, step, value, width]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const highResponder = useMemo(
|
|
163
|
+
() =>
|
|
164
|
+
PanResponder.create({
|
|
165
|
+
onStartShouldSetPanResponder: () => true,
|
|
166
|
+
onMoveShouldSetPanResponder: () => true,
|
|
167
|
+
onPanResponderGrant: () => {
|
|
168
|
+
startHigh.current = value[1];
|
|
169
|
+
},
|
|
170
|
+
onPanResponderMove: (_e, g) => {
|
|
171
|
+
if (width <= 0) return;
|
|
172
|
+
const delta = (g.dx / width) * (max - min);
|
|
173
|
+
const next = snap(startHigh.current + delta, step, value[0], max);
|
|
174
|
+
onChange([value[0], next]);
|
|
175
|
+
},
|
|
176
|
+
}),
|
|
177
|
+
[max, min, onChange, step, value, width]
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const lowRatio = width === 0 ? 0 : (value[0] - min) / (max - min);
|
|
181
|
+
const highRatio = width === 0 ? 0 : (value[1] - min) / (max - min);
|
|
182
|
+
const lowX = Math.round(lowRatio * width);
|
|
183
|
+
const highX = Math.round(highRatio * width);
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<View
|
|
187
|
+
testID={testID ?? "native-range-slider"}
|
|
188
|
+
onLayout={onLayout}
|
|
189
|
+
className={cn("h-11 w-full justify-center", className)}
|
|
190
|
+
>
|
|
191
|
+
<View className={cn("h-1.5 rounded-full bg-muted", trackClassName)} />
|
|
192
|
+
<View
|
|
193
|
+
className={cn(
|
|
194
|
+
"absolute h-1.5 rounded-full bg-primary",
|
|
195
|
+
fillClassName
|
|
196
|
+
)}
|
|
197
|
+
style={{ left: lowX, width: highX - lowX }}
|
|
198
|
+
/>
|
|
199
|
+
<View
|
|
200
|
+
testID={testID ? `${testID}-thumb-low` : undefined}
|
|
201
|
+
accessibilityRole="adjustable"
|
|
202
|
+
accessibilityValue={{ now: value[0], min, max: value[1] }}
|
|
203
|
+
className={cn(
|
|
204
|
+
"absolute h-6 w-6 rounded-full border-2 border-primary bg-background shadow",
|
|
205
|
+
thumbClassName
|
|
206
|
+
)}
|
|
207
|
+
style={{ left: Math.max(0, lowX - 12) }}
|
|
208
|
+
{...lowResponder.panHandlers}
|
|
209
|
+
/>
|
|
210
|
+
<View
|
|
211
|
+
testID={testID ? `${testID}-thumb-high` : undefined}
|
|
212
|
+
accessibilityRole="adjustable"
|
|
213
|
+
accessibilityValue={{ now: value[1], min: value[0], max }}
|
|
214
|
+
className={cn(
|
|
215
|
+
"absolute h-6 w-6 rounded-full border-2 border-primary bg-background shadow",
|
|
216
|
+
thumbClassName
|
|
217
|
+
)}
|
|
218
|
+
style={{ left: Math.max(0, highX - 12) }}
|
|
219
|
+
{...highResponder.panHandlers}
|
|
220
|
+
/>
|
|
221
|
+
</View>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stepper — multi-step indicator showing the user's position in a flow.
|
|
3
|
+
*
|
|
4
|
+
* Use for onboarding, multi-page forms, and checkouts. Renders a
|
|
5
|
+
* horizontal row of step dots/numbers with connecting lines and labels.
|
|
6
|
+
*
|
|
7
|
+
* @stability Beta
|
|
8
|
+
*/
|
|
9
|
+
import { Text, View } from "react-native";
|
|
10
|
+
import { cn } from "../utils";
|
|
11
|
+
|
|
12
|
+
export interface NativeStepperStep {
|
|
13
|
+
label: string;
|
|
14
|
+
/** Optional second-line description. */
|
|
15
|
+
description?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface NativeStepperProps {
|
|
19
|
+
steps: NativeStepperStep[];
|
|
20
|
+
/** Zero-indexed current step. */
|
|
21
|
+
current: number;
|
|
22
|
+
className?: string;
|
|
23
|
+
testID?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function NativeStepper({
|
|
27
|
+
steps,
|
|
28
|
+
current,
|
|
29
|
+
className,
|
|
30
|
+
testID,
|
|
31
|
+
}: NativeStepperProps) {
|
|
32
|
+
return (
|
|
33
|
+
<View
|
|
34
|
+
testID={testID ?? "native-stepper"}
|
|
35
|
+
accessibilityRole="progressbar"
|
|
36
|
+
accessibilityValue={{ now: current + 1, min: 1, max: steps.length }}
|
|
37
|
+
className={cn("w-full", className)}
|
|
38
|
+
>
|
|
39
|
+
<View className="flex-row items-center">
|
|
40
|
+
{steps.map((s, i) => {
|
|
41
|
+
const isCompleted = i < current;
|
|
42
|
+
const isCurrent = i === current;
|
|
43
|
+
return (
|
|
44
|
+
<View key={i} className="flex-1 flex-row items-center">
|
|
45
|
+
<View
|
|
46
|
+
testID={testID ? `${testID}-dot-${i}` : undefined}
|
|
47
|
+
accessibilityLabel={`Step ${i + 1}: ${s.label}`}
|
|
48
|
+
accessibilityState={{ selected: isCurrent }}
|
|
49
|
+
className={cn(
|
|
50
|
+
"h-7 w-7 items-center justify-center rounded-full border",
|
|
51
|
+
isCompleted && "bg-primary border-primary",
|
|
52
|
+
isCurrent && "bg-background border-primary",
|
|
53
|
+
!isCompleted && !isCurrent && "bg-background border-border"
|
|
54
|
+
)}
|
|
55
|
+
>
|
|
56
|
+
<Text
|
|
57
|
+
className={cn(
|
|
58
|
+
"text-xs font-semibold",
|
|
59
|
+
isCompleted && "text-primary-foreground",
|
|
60
|
+
isCurrent && "text-primary",
|
|
61
|
+
!isCompleted && !isCurrent && "text-muted-foreground"
|
|
62
|
+
)}
|
|
63
|
+
>
|
|
64
|
+
{i + 1}
|
|
65
|
+
</Text>
|
|
66
|
+
</View>
|
|
67
|
+
{i < steps.length - 1 ? (
|
|
68
|
+
<View
|
|
69
|
+
className={cn(
|
|
70
|
+
"mx-1 h-0.5 flex-1",
|
|
71
|
+
isCompleted ? "bg-primary" : "bg-border"
|
|
72
|
+
)}
|
|
73
|
+
/>
|
|
74
|
+
) : null}
|
|
75
|
+
</View>
|
|
76
|
+
);
|
|
77
|
+
})}
|
|
78
|
+
</View>
|
|
79
|
+
<View className="mt-2 flex-row">
|
|
80
|
+
{steps.map((s, i) => (
|
|
81
|
+
<View key={i} className="flex-1 px-1">
|
|
82
|
+
<Text
|
|
83
|
+
className={cn(
|
|
84
|
+
"text-center text-xs",
|
|
85
|
+
i === current ? "font-semibold text-foreground" : "text-muted-foreground"
|
|
86
|
+
)}
|
|
87
|
+
numberOfLines={1}
|
|
88
|
+
>
|
|
89
|
+
{s.label}
|
|
90
|
+
</Text>
|
|
91
|
+
</View>
|
|
92
|
+
))}
|
|
93
|
+
</View>
|
|
94
|
+
</View>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Switch — boolean toggle (iOS-style).
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { Switch, type SwitchProps, View } from "react-native";
|
|
7
|
+
import { cn } from "../utils";
|
|
8
|
+
|
|
9
|
+
export interface NativeSwitchProps extends SwitchProps {
|
|
10
|
+
className?: string;
|
|
11
|
+
checked?: boolean;
|
|
12
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function NativeSwitch({
|
|
16
|
+
className,
|
|
17
|
+
checked,
|
|
18
|
+
onCheckedChange,
|
|
19
|
+
disabled,
|
|
20
|
+
...props
|
|
21
|
+
}: NativeSwitchProps) {
|
|
22
|
+
return (
|
|
23
|
+
<View className={cn(disabled && "opacity-50", className)}>
|
|
24
|
+
<Switch
|
|
25
|
+
value={checked}
|
|
26
|
+
onValueChange={onCheckedChange}
|
|
27
|
+
disabled={disabled}
|
|
28
|
+
accessibilityState={{ checked: checked, disabled }}
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
</View>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { NativeSwitch };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tabs — top-level navigation between sibling views.
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { createContext, useContext, useState } from "react";
|
|
7
|
+
import { Pressable, Text, View } from "react-native";
|
|
8
|
+
import { cn } from "../utils";
|
|
9
|
+
|
|
10
|
+
interface TabsContextValue {
|
|
11
|
+
value: string;
|
|
12
|
+
onValueChange: (value: string) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const TabsContext = createContext<TabsContextValue | null>(null);
|
|
16
|
+
|
|
17
|
+
function useTabs() {
|
|
18
|
+
const context = useContext(TabsContext);
|
|
19
|
+
if (!context)
|
|
20
|
+
throw new Error("Tabs components must be used within <NativeTabs>");
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NativeTabsProps {
|
|
25
|
+
className?: string;
|
|
26
|
+
defaultValue: string;
|
|
27
|
+
value?: string;
|
|
28
|
+
onValueChange?: (value: string) => void;
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
testID?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function NativeTabs({
|
|
34
|
+
className,
|
|
35
|
+
defaultValue,
|
|
36
|
+
value: controlledValue,
|
|
37
|
+
onValueChange: controlledOnValueChange,
|
|
38
|
+
children,
|
|
39
|
+
...props
|
|
40
|
+
}: NativeTabsProps) {
|
|
41
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
42
|
+
const value = controlledValue ?? uncontrolledValue;
|
|
43
|
+
const onValueChange = controlledOnValueChange ?? setUncontrolledValue;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<TabsContext.Provider value={{ value, onValueChange }}>
|
|
47
|
+
<View className={cn("w-full", className)} {...props}>
|
|
48
|
+
{children}
|
|
49
|
+
</View>
|
|
50
|
+
</TabsContext.Provider>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface NativeTabsListProps {
|
|
55
|
+
className?: string;
|
|
56
|
+
children: React.ReactNode;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function NativeTabsList({ className, children }: NativeTabsListProps) {
|
|
60
|
+
return (
|
|
61
|
+
<View
|
|
62
|
+
className={cn(
|
|
63
|
+
"flex-row items-center rounded-md bg-muted p-1",
|
|
64
|
+
className
|
|
65
|
+
)}
|
|
66
|
+
accessibilityRole="tablist"
|
|
67
|
+
>
|
|
68
|
+
{children}
|
|
69
|
+
</View>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface NativeTabsTriggerProps {
|
|
74
|
+
className?: string;
|
|
75
|
+
value: string;
|
|
76
|
+
children: React.ReactNode;
|
|
77
|
+
disabled?: boolean;
|
|
78
|
+
testID?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function NativeTabsTrigger({
|
|
82
|
+
className,
|
|
83
|
+
value,
|
|
84
|
+
children,
|
|
85
|
+
disabled,
|
|
86
|
+
...props
|
|
87
|
+
}: NativeTabsTriggerProps) {
|
|
88
|
+
const { value: selectedValue, onValueChange } = useTabs();
|
|
89
|
+
const isActive = selectedValue === value;
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Pressable
|
|
93
|
+
className={cn(
|
|
94
|
+
"flex-1 items-center justify-center rounded-sm px-3 py-1.5",
|
|
95
|
+
isActive && "bg-background shadow-sm",
|
|
96
|
+
disabled && "opacity-50",
|
|
97
|
+
className
|
|
98
|
+
)}
|
|
99
|
+
onPress={() => onValueChange(value)}
|
|
100
|
+
disabled={disabled}
|
|
101
|
+
accessibilityRole="tab"
|
|
102
|
+
accessibilityState={{ selected: isActive }}
|
|
103
|
+
{...props}
|
|
104
|
+
>
|
|
105
|
+
{typeof children === "string" ? (
|
|
106
|
+
<Text
|
|
107
|
+
className={cn(
|
|
108
|
+
"text-sm font-medium",
|
|
109
|
+
isActive ? "text-foreground" : "text-muted-foreground"
|
|
110
|
+
)}
|
|
111
|
+
>
|
|
112
|
+
{children}
|
|
113
|
+
</Text>
|
|
114
|
+
) : (
|
|
115
|
+
children
|
|
116
|
+
)}
|
|
117
|
+
</Pressable>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface NativeTabsContentProps {
|
|
122
|
+
className?: string;
|
|
123
|
+
value: string;
|
|
124
|
+
children: React.ReactNode;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function NativeTabsContent({
|
|
128
|
+
className,
|
|
129
|
+
value,
|
|
130
|
+
children,
|
|
131
|
+
}: NativeTabsContentProps) {
|
|
132
|
+
const { value: selectedValue } = useTabs();
|
|
133
|
+
if (selectedValue !== value) return null;
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<View className={cn("mt-2", className)}>
|
|
137
|
+
{children}
|
|
138
|
+
</View>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
NativeTabs,
|
|
144
|
+
NativeTabsList,
|
|
145
|
+
NativeTabsTrigger,
|
|
146
|
+
NativeTabsContent,
|
|
147
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text — typography primitive with semantic presets (h1, h2, body, caption, etc.).
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { type VariantProps, cva } from "class-variance-authority";
|
|
7
|
+
import { Text as RNText, type TextProps } from "react-native";
|
|
8
|
+
import { cn } from "../utils";
|
|
9
|
+
|
|
10
|
+
const textVariants = cva("text-foreground", {
|
|
11
|
+
variants: {
|
|
12
|
+
preset: {
|
|
13
|
+
h1: "text-3xl font-bold leading-9",
|
|
14
|
+
h2: "text-2xl font-bold leading-8",
|
|
15
|
+
h3: "text-xl font-semibold leading-7",
|
|
16
|
+
h4: "text-lg font-semibold leading-7",
|
|
17
|
+
body: "text-base font-normal leading-6",
|
|
18
|
+
"body-sm": "text-sm font-normal leading-5",
|
|
19
|
+
caption: "text-xs font-normal leading-4",
|
|
20
|
+
label: "text-sm font-medium leading-5",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
defaultVariants: {
|
|
24
|
+
preset: "body",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export interface NativeTextProps
|
|
29
|
+
extends TextProps,
|
|
30
|
+
VariantProps<typeof textVariants> {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Allowed `preset` values on {@link NativeText}. Re-exported as a named type
|
|
35
|
+
* so consumer brand packages can build preset-driven typography APIs without
|
|
36
|
+
* having to reach into `NativeTextProps['preset']` themselves.
|
|
37
|
+
*
|
|
38
|
+
* Example (consumer):
|
|
39
|
+
* ```ts
|
|
40
|
+
* import type { TextPreset } from "@marktiderman/genesis-ui-native";
|
|
41
|
+
* function Heading({ as }: { as: TextPreset }) { ... }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export type TextPreset = NonNullable<NativeTextProps["preset"]>;
|
|
45
|
+
|
|
46
|
+
function NativeText({
|
|
47
|
+
className,
|
|
48
|
+
preset,
|
|
49
|
+
children,
|
|
50
|
+
...props
|
|
51
|
+
}: NativeTextProps) {
|
|
52
|
+
return (
|
|
53
|
+
<RNText
|
|
54
|
+
className={cn(textVariants({ preset }), className)}
|
|
55
|
+
{...props}
|
|
56
|
+
>
|
|
57
|
+
{children}
|
|
58
|
+
</RNText>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { NativeText, textVariants };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Textarea — multi-line text field.
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { Text, TextInput, type TextInputProps, View } from "react-native";
|
|
7
|
+
import { cn } from "../utils";
|
|
8
|
+
|
|
9
|
+
export interface NativeTextareaProps extends TextInputProps {
|
|
10
|
+
className?: string;
|
|
11
|
+
inputClassName?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
rows?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function NativeTextarea({
|
|
18
|
+
className,
|
|
19
|
+
inputClassName,
|
|
20
|
+
label,
|
|
21
|
+
error,
|
|
22
|
+
editable = true,
|
|
23
|
+
rows = 4,
|
|
24
|
+
placeholderTextColor,
|
|
25
|
+
...props
|
|
26
|
+
}: NativeTextareaProps) {
|
|
27
|
+
return (
|
|
28
|
+
<View className={cn("gap-1.5", className)}>
|
|
29
|
+
{label ? (
|
|
30
|
+
<Text className="text-sm font-medium text-foreground">{label}</Text>
|
|
31
|
+
) : null}
|
|
32
|
+
<TextInput
|
|
33
|
+
className={cn(
|
|
34
|
+
"rounded-md border border-input bg-background px-3 py-2 text-base text-foreground",
|
|
35
|
+
!editable && "opacity-50",
|
|
36
|
+
error && "border-destructive",
|
|
37
|
+
inputClassName
|
|
38
|
+
)}
|
|
39
|
+
multiline
|
|
40
|
+
numberOfLines={rows}
|
|
41
|
+
editable={editable}
|
|
42
|
+
placeholderTextColor={placeholderTextColor ?? "#A1A1AA"}
|
|
43
|
+
{...props}
|
|
44
|
+
/>
|
|
45
|
+
{error ? (
|
|
46
|
+
<Text className="text-sm text-destructive">{error}</Text>
|
|
47
|
+
) : null}
|
|
48
|
+
</View>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { NativeTextarea };
|