@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,183 @@
1
+ /**
2
+ * SettingsSubPage — drill-in detail layout.
3
+ *
4
+ * Composes a KeyboardAvoidingView + scroll + dirty-form leave warning +
5
+ * optimistic-save pattern. The save action is surfaced in the nav bar via
6
+ * a `<NavBarSaveButton>` rendered through `headerRight`.
7
+ *
8
+ * Why ship: the recurring shape is "form fields + nav-bar Save + leave
9
+ * guard"; consumers re-implement this every time. Genesis ships the
10
+ * shape so consumers focus on the form fields themselves.
11
+ *
12
+ * Layer-3 customization: pass `headerTitle`, `headerLeft`, OR a direct
13
+ * `headerOptions={...}`. Use `getSettingsSubPageStackOptions()` to get a
14
+ * `<Stack.Screen options={...}>` object (with the save button wired via
15
+ * `headerRight`).
16
+ *
17
+ * @stability Beta
18
+ */
19
+ import { useCallback, type ReactNode } from "react";
20
+ import { Alert, KeyboardAvoidingView, Platform, View } from "react-native";
21
+ import { cn } from "../utils";
22
+ import {
23
+ ScreenContainer,
24
+ composeHeaderOptions,
25
+ type ScreenHeaderProps,
26
+ } from "./screen-container";
27
+ import { NavBarSaveButton } from "./nav-bar";
28
+
29
+ export interface SettingsSubPageProps extends ScreenHeaderProps {
30
+ /** Form / detail body content. Pass any node tree. */
31
+ children: ReactNode;
32
+ /**
33
+ * When true, the Save button is enabled and the back-confirm guard
34
+ * fires when the user tries to leave. Mark `true` whenever the form
35
+ * has unsaved changes.
36
+ */
37
+ dirty?: boolean;
38
+ /** When true, the Save button shows a busy indicator and is non-pressable. */
39
+ saving?: boolean;
40
+ /** Save handler. Required to render a Save button in the nav bar. */
41
+ onSave?: () => void | Promise<void>;
42
+ /**
43
+ * Confirm-leave hook. Implementations should integrate with the
44
+ * navigator's `beforeRemove` listener (React Navigation) — Genesis
45
+ * provides a default `Alert` confirm helper via `confirmDiscardChanges()`.
46
+ * Pass null to opt OUT of the leave guard.
47
+ */
48
+ onConfirmLeave?: ((proceed: () => void) => void) | null;
49
+ /** Save button label. Default `"Save"`. */
50
+ saveLabel?: string;
51
+ /** Override root container styling. */
52
+ className?: string;
53
+ /** testID on the root container. Default `"settings-sub-page"`. */
54
+ testID?: string;
55
+ }
56
+
57
+ /**
58
+ * Default leave-guard helper. Pops a native Alert with Discard / Keep
59
+ * Editing buttons; calls `proceed()` only if the user opts to discard.
60
+ *
61
+ * <SettingsSubPage onConfirmLeave={confirmDiscardChanges} ... />
62
+ */
63
+ export function confirmDiscardChanges(proceed: () => void): void {
64
+ Alert.alert(
65
+ "Discard changes?",
66
+ "You have unsaved changes. Leave this screen and lose them?",
67
+ [
68
+ { text: "Keep editing", style: "cancel" },
69
+ {
70
+ text: "Discard",
71
+ style: "destructive",
72
+ onPress: () => proceed(),
73
+ },
74
+ ],
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Compose `<Stack.Screen options={...}>` for a SettingsSubPage. Wires
80
+ * the nav-bar Save button via `headerRight` automatically when `onSave`
81
+ * is passed.
82
+ */
83
+ export function getSettingsSubPageStackOptions(props: {
84
+ headerTitle?: string;
85
+ dirty?: boolean;
86
+ saving?: boolean;
87
+ onSave?: () => void | Promise<void>;
88
+ saveLabel?: string;
89
+ large?: boolean;
90
+ scrollEdgeBehavior?: ScreenHeaderProps["scrollEdgeBehavior"];
91
+ headerLeft?: ScreenHeaderProps["headerLeft"];
92
+ headerRight?: ScreenHeaderProps["headerRight"];
93
+ headerOptions?: ScreenHeaderProps["headerOptions"];
94
+ }): Record<string, unknown> {
95
+ const {
96
+ headerTitle,
97
+ dirty,
98
+ saving,
99
+ onSave,
100
+ saveLabel = "Save",
101
+ large = false,
102
+ scrollEdgeBehavior,
103
+ headerLeft,
104
+ headerRight,
105
+ headerOptions,
106
+ } = props;
107
+
108
+ // Auto-wire headerRight with save button if not overridden.
109
+ const resolvedHeaderRight =
110
+ headerRight ??
111
+ (onSave
112
+ ? () => (
113
+ <NavBarSaveButton
114
+ label={saveLabel}
115
+ onPress={() => {
116
+ void onSave();
117
+ }}
118
+ disabled={!dirty}
119
+ loading={saving}
120
+ />
121
+ )
122
+ : undefined);
123
+
124
+ return composeHeaderOptions({
125
+ headerTitle,
126
+ headerLeft,
127
+ headerRight: resolvedHeaderRight,
128
+ large,
129
+ scrollEdgeBehavior,
130
+ headerOptions,
131
+ });
132
+ }
133
+
134
+ export function SettingsSubPage({
135
+ children,
136
+ onConfirmLeave,
137
+ className,
138
+ testID = "settings-sub-page",
139
+ }: SettingsSubPageProps) {
140
+ // Note: dirty / saving / onSave / saveLabel / screen header props are
141
+ // consumed by getSettingsSubPageStackOptions() at the consumer level —
142
+ // SettingsSubPage itself is intentionally minimal so the same component
143
+ // works for both pure form pages AND screens with Stack.Screen options
144
+ // wired separately. We only render the body chrome here.
145
+ //
146
+ // The actual `beforeRemove` wire-up lives at the consumer's navigator
147
+ // level — they call `useNavigation().addListener('beforeRemove', ...)`
148
+ // and inside the callback they invoke `props.onConfirmLeave(proceed)`.
149
+ // We expose `confirmDiscardChanges()` as the canonical helper so
150
+ // consumers get the leave-guard semantics for free.
151
+ const _onConfirmLeave = useCallback(
152
+ (proceed: () => void) => {
153
+ if (onConfirmLeave === null) {
154
+ proceed();
155
+ return;
156
+ }
157
+ const fn = onConfirmLeave ?? confirmDiscardChanges;
158
+ fn(proceed);
159
+ },
160
+ [onConfirmLeave],
161
+ );
162
+ void _onConfirmLeave;
163
+
164
+ return (
165
+ <KeyboardAvoidingView
166
+ testID={`${testID}-kav`}
167
+ style={{ flex: 1 }}
168
+ behavior={Platform.OS === "ios" ? "padding" : undefined}
169
+ >
170
+ <ScreenContainer
171
+ scroll
172
+ safeAreaEdges={["left", "right", "bottom"]}
173
+ testID={testID}
174
+ contentClassName={cn("p-4", className)}
175
+ keyboardShouldPersistTaps="handled"
176
+ >
177
+ <View testID={`${testID}-form`} className="gap-4">
178
+ {children}
179
+ </View>
180
+ </ScreenContainer>
181
+ </KeyboardAvoidingView>
182
+ );
183
+ }
@@ -0,0 +1,40 @@
1
+ // NativeWind className augmentation for react-native types.
2
+ // This adds className to RN component props so ui-native components
3
+ // typecheck correctly both standalone and when consumed by apps.
4
+ // The top-level import makes this a module augmentation (not an ambient declaration),
5
+ // so it merges with the real react-native types rather than replacing them.
6
+
7
+ // This import is required to make this file a module augmentation (not an ambient declaration).
8
+ // Removing it silently changes the semantics from "merge with" to "replace" the react-native types.
9
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
+ import type { AnimatedProps } from "react-native";
11
+
12
+ declare module "react-native" {
13
+ interface ViewProps {
14
+ className?: string;
15
+ }
16
+ interface TextProps {
17
+ className?: string;
18
+ }
19
+ interface TextInputProps {
20
+ className?: string;
21
+ }
22
+ interface ImageProps {
23
+ className?: string;
24
+ }
25
+ interface ImagePropsBase {
26
+ className?: string;
27
+ }
28
+ interface PressableProps {
29
+ className?: string;
30
+ }
31
+ interface SwitchProps {
32
+ className?: string;
33
+ }
34
+ interface ScrollViewProps {
35
+ className?: string;
36
+ }
37
+ interface TouchableWithoutFeedbackProps {
38
+ className?: string;
39
+ }
40
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }