@marktiderman/genesis-ui-native 2.5.0 → 2.6.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 (39) hide show
  1. package/dist/{chunk-IDHW2NOP.js → chunk-3S5XVER4.js} +231 -6
  2. package/dist/chunk-3S5XVER4.js.map +1 -0
  3. package/dist/chunk-56QLEHHV.js +1231 -0
  4. package/dist/chunk-56QLEHHV.js.map +1 -0
  5. package/dist/chunk-6JBNSW4D.js +479 -0
  6. package/dist/chunk-6JBNSW4D.js.map +1 -0
  7. package/dist/{chunk-YJV5MMZX.js → chunk-KZEIF4YI.js} +7 -741
  8. package/dist/chunk-KZEIF4YI.js.map +1 -0
  9. package/dist/{chunk-YI7XVY2D.js → chunk-VMSIKSU2.js} +13 -479
  10. package/dist/chunk-VMSIKSU2.js.map +1 -0
  11. package/dist/components/index.d.ts +3 -1
  12. package/dist/components/index.js +3 -4
  13. package/dist/data/index.d.ts +382 -4
  14. package/dist/data/index.js +1067 -19
  15. package/dist/data/index.js.map +1 -1
  16. package/dist/inbox-page-DZUR-PJ1.d.ts +199 -0
  17. package/dist/index.d.ts +2 -1
  18. package/dist/index.js +5 -5
  19. package/dist/layouts/index.d.ts +4 -195
  20. package/dist/layouts/index.js +3 -3
  21. package/package.json +2 -2
  22. package/src/components/image.tsx +5 -0
  23. package/src/data/NativeDetailPanel.tsx +8 -1
  24. package/src/data/index.ts +1 -0
  25. package/src/data/resource-view/NativeResourceFormSheet.tsx +305 -0
  26. package/src/data/resource-view/NativeResourceView.tsx +528 -0
  27. package/src/data/resource-view/__tests__/native-resource-view.test.tsx +870 -0
  28. package/src/data/resource-view/display.tsx +256 -0
  29. package/src/data/resource-view/index.ts +50 -0
  30. package/src/data/resource-view/mapping.ts +326 -0
  31. package/src/data/resource-view/messages.ts +121 -0
  32. package/src/data/resource-view/use-native-resource-view.ts +307 -0
  33. package/dist/chunk-EFXCJ5AN.js +0 -234
  34. package/dist/chunk-EFXCJ5AN.js.map +0 -1
  35. package/dist/chunk-FIITITXO.js +0 -492
  36. package/dist/chunk-FIITITXO.js.map +0 -1
  37. package/dist/chunk-IDHW2NOP.js.map +0 -1
  38. package/dist/chunk-YI7XVY2D.js.map +0 -1
  39. package/dist/chunk-YJV5MMZX.js.map +0 -1
@@ -0,0 +1,121 @@
1
+ // The words NativeResourceView shows. `common` matches genesis-ui's `uiMessages.common`, so a
2
+ // renderer written for one platform reads the same keys on the other. `{name}`-style placeholders
3
+ // are filled with `fill`.
4
+
5
+ export interface NativeResourceViewMessages {
6
+ common: {
7
+ /** Shown for an empty value. */
8
+ empty: string;
9
+ yes: string;
10
+ no: string;
11
+ cancel: string;
12
+ save: string;
13
+ edit: string;
14
+ close: string;
15
+ /** "New {noun}". */
16
+ create: string;
17
+ /** "Edit {noun}". */
18
+ editTitle: string;
19
+ /** "Search {nounPlural}". */
20
+ search: string;
21
+ };
22
+ delete: {
23
+ /** The action when a delete removes the row for good. */
24
+ action: string;
25
+ /** `{name}`: the row's title. */
26
+ confirmTitle: string;
27
+ confirmBody: string;
28
+ };
29
+ bin: {
30
+ /** The action when the provider moves deleted rows to a recycle bin (`softDelete`). */
31
+ action: string;
32
+ confirmTitle: string;
33
+ confirmBody: string;
34
+ };
35
+ list: {
36
+ /** `{nounPlural}`. */
37
+ emptyTitle: string;
38
+ emptyBody: string;
39
+ noResultsTitle: string;
40
+ noResultsBody: string;
41
+ loadingMore: string;
42
+ /** `{nounPlural}`. */
43
+ loadFailed: string;
44
+ retry: string;
45
+ /** A section for rows with no value in the group field. `{label}`: the field. */
46
+ noGroup: string;
47
+ };
48
+ form: {
49
+ /** `{label}`. */
50
+ required: string;
51
+ /** `{label}`, `{max}`. */
52
+ tooLong: string;
53
+ /** `{noun}`. A save failed with no message of its own. */
54
+ saveFailed: string;
55
+ /** An empty day field's button. */
56
+ pickDate: string;
57
+ /** An empty date-and-time field's button. */
58
+ pickDateTime: string;
59
+ /** Empties an optional date. `{label}`. */
60
+ clear: string;
61
+ loading: string;
62
+ };
63
+ refusal: {
64
+ /** `{noun}`. A delete failed with no message of its own. */
65
+ deleteFailed: string;
66
+ dismiss: string;
67
+ };
68
+ }
69
+
70
+ export const defaultNativeResourceViewMessages: NativeResourceViewMessages = {
71
+ common: {
72
+ empty: "—",
73
+ yes: "Yes",
74
+ no: "No",
75
+ cancel: "Cancel",
76
+ save: "Save",
77
+ edit: "Edit",
78
+ close: "Close",
79
+ create: "New {noun}",
80
+ editTitle: "Edit {noun}",
81
+ search: "Search {nounPlural}",
82
+ },
83
+ delete: {
84
+ action: "Delete",
85
+ confirmTitle: "Delete “{name}”?",
86
+ confirmBody: "This can't be undone.",
87
+ },
88
+ bin: {
89
+ action: "Move to Bin",
90
+ confirmTitle: "Move “{name}” to the bin?",
91
+ confirmBody: "You can restore it from the bin.",
92
+ },
93
+ list: {
94
+ emptyTitle: "No {nounPlural} yet",
95
+ emptyBody: "When there are some, they show up here.",
96
+ noResultsTitle: "No results",
97
+ noResultsBody: "Try a different search.",
98
+ loadingMore: "Loading more",
99
+ loadFailed: "These {nounPlural} couldn't be loaded.",
100
+ retry: "Try again",
101
+ noGroup: "No {label}",
102
+ },
103
+ form: {
104
+ required: "{label} is required.",
105
+ tooLong: "{label} can be at most {max} characters.",
106
+ saveFailed: "This {noun} couldn't be saved. Try again.",
107
+ pickDate: "Add a date",
108
+ pickDateTime: "Add a date and time",
109
+ clear: "Clear {label}",
110
+ loading: "Loading",
111
+ },
112
+ refusal: {
113
+ deleteFailed: "This {noun} couldn't be deleted. Try again.",
114
+ dismiss: "Dismiss",
115
+ },
116
+ };
117
+
118
+ /** Fill `{name}` placeholders. A placeholder with no value is left as it is. */
119
+ export function fill(template: string, values: Readonly<Record<string, string | number>>): string {
120
+ return template.replace(/\{(\w+)\}/g, (match, key: string) => (key in values ? String(values[key]) : match));
121
+ }
@@ -0,0 +1,307 @@
1
+ // useNativeResourceView: the headless NativeResourceView. Cursor paging through
2
+ // useInfiniteResource (onEndReached), search debounced 300 ms, writes through useResource (so they
3
+ // share its cache patching, rollback and refusal handling), and the view's rows, sections, swipe
4
+ // actions and form fields resolved once.
5
+
6
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
7
+ import type { BaseRecord, DataRow, FilterParam } from "@marktiderman/genesis-core";
8
+ import { useCapabilities, useInfiniteResource, useResource } from "@marktiderman/genesis-core/hooks";
9
+ import type { Allowed } from "@marktiderman/genesis-core/resource-view";
10
+ import { useNativeResourceViewMessages } from "./display";
11
+ import {
12
+ allowed,
13
+ formFieldsFor,
14
+ refusalFields,
15
+ refusalMessage,
16
+ rowItem,
17
+ sectionsFor,
18
+ swipeActionsFor,
19
+ validateValues,
20
+ writableValues,
21
+ type AnyResourceView,
22
+ type NativeFormField,
23
+ type NativeResourceRowItem,
24
+ type NativeResourceScreenCan,
25
+ type NativeResourceSection,
26
+ type NativeResourceSwipeAction,
27
+ } from "./mapping";
28
+ import { fill } from "./messages";
29
+
30
+ type Row = Record<string, unknown>;
31
+ type Filter = Readonly<Record<string, string | number | boolean | null>>;
32
+
33
+ /** How long typing waits before the search goes to the server. */
34
+ export const SEARCH_DEBOUNCE_MS = 300;
35
+
36
+ export interface NativeResourceViewOptions<T extends Row = Row> {
37
+ /** A tab the view defines: its server filter. */
38
+ preset?: string;
39
+ /**
40
+ * Equality filters sent to the server (`{ client_id: id }`); `null` means "is empty". A create
41
+ * also saves every non-null value here (a tab's filter too), even for read-only fields such as
42
+ * a required link: they come from the screen, never from an input. An edit never sends them.
43
+ */
44
+ filter?: Filter;
45
+ /** Rows per page. Default 25. */
46
+ perPage?: number;
47
+ /**
48
+ * Pages kept loaded when the provider pages by cursor (and serves `prevCursor`): scrolling far
49
+ * drops pages from the front, and scrolling back to the top loads them again (`loadPrevious` on
50
+ * the list's `onStartReached`, with `maintainVisibleContentPosition` so the rows on screen stay
51
+ * put). Offset paging never drops pages. Default 10.
52
+ */
53
+ maxPages?: number;
54
+ /** Fields the search box searches. Default: the view's `labelField`. */
55
+ searchFields?: string[];
56
+ /** The screen's own rule. It only narrows the view's guards. */
57
+ can?: NativeResourceScreenCan<T>;
58
+ /** Refetch loaded pages when the provider reports a change. */
59
+ live?: boolean;
60
+ }
61
+
62
+ export type SaveResult = { ok: true } | { ok: false; message?: string; fields: Record<string, string> };
63
+
64
+ export interface UseNativeResourceViewReturn<T extends Row = Row> {
65
+ rows: T[];
66
+ /** Rows in `groupBy` sections (one untitled section when the view doesn't group). */
67
+ sections: NativeResourceSection<T>[];
68
+ /** Rows matching the filters and search, when the provider counts them. */
69
+ total: number | undefined;
70
+ /** The first page is loading. */
71
+ loading: boolean;
72
+ /** The read failed: its message, in plain words. */
73
+ error: string | null;
74
+ refreshing: boolean;
75
+ refresh: () => Promise<void>;
76
+ /** Pass to the list's `onEndReached`: loads the next page by cursor. */
77
+ loadMore: () => void;
78
+ loadingMore: boolean;
79
+ hasMore: boolean;
80
+ /** Pass to the list's `onStartReached`: loads back a page `maxPages` dropped from the front. */
81
+ loadPrevious: () => void;
82
+ loadingPrevious: boolean;
83
+ hasPrevious: boolean;
84
+ /** What the search box shows (the server sees it 300 ms after the last keystroke). */
85
+ search: string;
86
+ setSearch: (text: string) => void;
87
+ /** The last refused write, in plain words, shown inline until dismissed or the next write. */
88
+ refusal: string | null;
89
+ dismissRefusal: () => void;
90
+ item: (row: T) => NativeResourceRowItem;
91
+ /** The row's swipe actions. Edit and delete call `onEdit` / `onDelete` you pass here. */
92
+ actions: (row: T, handlers: { onEdit: (row: T) => void; onDelete: (row: T) => void; onRefused: (label: string, reason: string) => void }) => NativeResourceSwipeAction[];
93
+ /** Whether a new row may be created: true, or the guard's reason. False when the screen turns it off or there's no form. */
94
+ canCreate: Allowed | false;
95
+ /** The form sheet's fields. */
96
+ formFields: (mode: "create" | "edit") => NativeFormField[];
97
+ /**
98
+ * Check and save the form's values. Sends only writable keys, and for an edit only the `dirty`
99
+ * ones (all writable keys when `dirty` is left out). Stays pessimistic so the sheet can show
100
+ * refusals.
101
+ */
102
+ save: (mode: "create" | "edit", values: Readonly<Record<string, unknown>>, row?: T, dirty?: ReadonlySet<string>) => Promise<SaveResult>;
103
+ /** Delete a row optimistically: it leaves the list at once and comes back if the server refuses. */
104
+ remove: (row: T) => void;
105
+ /** The provider bins deleted rows (they can be restored). */
106
+ softDelete: boolean;
107
+ }
108
+
109
+ function filterParams(filter: Filter | undefined): FilterParam[] {
110
+ return Object.entries(filter ?? {}).map(([field, value]) =>
111
+ value === null ? { field, operator: "is_null" as const } : { field, operator: "eq" as const, value },
112
+ );
113
+ }
114
+
115
+ /** The values a create takes from the screen: every non-null equality filter, the screen's over the tab's. */
116
+ export function screenValues(...filters: (Filter | undefined)[]): Record<string, string | number | boolean> {
117
+ const out: Record<string, string | number | boolean> = {};
118
+ for (const filter of filters) {
119
+ for (const [field, value] of Object.entries(filter ?? {})) if (value !== null) out[field] = value;
120
+ }
121
+ return out;
122
+ }
123
+
124
+ /** Pages kept loaded by default (cursor paging). */
125
+ export const DEFAULT_MAX_PAGES = 10;
126
+
127
+ /**
128
+ * The server sort: the `groupBy` field first, so every page arrives in section order and a later
129
+ * page never lands in the middle of an earlier section; else the view's `orderBy`. (A second sort
130
+ * key within a group needs `useInfiniteResource` to take several sorts.)
131
+ */
132
+ export function serverSort<T extends Row>(view: AnyResourceView<T>): { field: string; order: "asc" | "desc" } | undefined {
133
+ const groupBy = view.definition.groupBy as string | undefined;
134
+ const orderBy = view.definition.orderBy;
135
+ // TODO: within a group the view's orderBy is dropped (one sort only). Pass [groupBy, orderBy] once
136
+ // useInfiniteResource takes several sorts (the coming multi-sort, owned by core).
137
+ if (groupBy) return { field: groupBy, order: orderBy?.field === groupBy ? (orderBy.direction ?? "asc") : "asc" };
138
+ return orderBy ? { field: orderBy.field as string, order: orderBy.direction ?? "asc" } : undefined;
139
+ }
140
+
141
+ export function useNativeResourceView<T extends Row = Row>(
142
+ view: AnyResourceView<T>,
143
+ options: NativeResourceViewOptions<T> = {},
144
+ ): UseNativeResourceViewReturn<T> {
145
+ const { preset, filter, perPage, maxPages = DEFAULT_MAX_PAGES, searchFields: searchOption, can, live } = options;
146
+ const messages = useNativeResourceViewMessages();
147
+ const tab = preset ? view.definition.presets?.[preset] : undefined;
148
+ if (preset && !tab) throw new Error(`NativeResourceView(${view.resource}): no preset "${preset}"`);
149
+
150
+ // ── Reads: cursor pages, server filters, server search ──────────────────
151
+ const tabFilter = tab?.filter as Filter | undefined;
152
+ const defaultFilters = useMemo(() => [...filterParams(tabFilter), ...filterParams(filter)], [tabFilter, filter]);
153
+ // By value, so an inline `filter={{ client_id }}` doesn't rebuild the form every render.
154
+ const createKey = JSON.stringify(screenValues(tabFilter, filter));
155
+ const createDefaults = useMemo(() => JSON.parse(createKey) as Record<string, string | number | boolean>, [createKey]);
156
+ const sort = useMemo(() => serverSort(view), [view]);
157
+ const searchFields = useMemo(
158
+ () => searchOption ?? (view.labelField ? [view.labelField] : undefined),
159
+ [searchOption, view.labelField],
160
+ );
161
+ const pages = useInfiniteResource<T & BaseRecord>(view.resource, {
162
+ defaultFilters,
163
+ ...(sort ? { defaultSort: sort } : {}),
164
+ ...(perPage ? { perPage } : {}),
165
+ maxPages,
166
+ ...(searchFields ? { searchFields } : {}),
167
+ keepPreviousData: true,
168
+ ...(live ? { live } : {}),
169
+ });
170
+
171
+ const [search, setSearchText] = useState("");
172
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
173
+ const { setSearch: sendSearch } = pages;
174
+ const setSearch = useCallback(
175
+ (text: string) => {
176
+ setSearchText(text);
177
+ if (timer.current) clearTimeout(timer.current);
178
+ timer.current = setTimeout(() => sendSearch(text), SEARCH_DEBOUNCE_MS);
179
+ },
180
+ [sendSearch],
181
+ );
182
+ useEffect(() => () => {
183
+ if (timer.current) clearTimeout(timer.current);
184
+ }, []);
185
+
186
+ // ── Writes ────────────────────────────────────────────────────────────
187
+ const [refusal, setRefusal] = useState<string | null>(null);
188
+ const deleteFailed = fill(messages.refusal.deleteFailed, { noun: view.noun });
189
+ const optimistic = useResource<T & BaseRecord>(view.resource, {
190
+ enabled: false,
191
+ mutationMode: "optimistic",
192
+ // The row is already back in the list (the cache is put back); say why, inline.
193
+ onError: (error) => setRefusal(refusalMessage(error, deleteFailed)),
194
+ });
195
+ const pessimistic = useResource<T & BaseRecord>(view.resource, { enabled: false, onError: () => {} });
196
+ const capabilities = useCapabilities(view.resource);
197
+ const softDelete = capabilities.data?.softDelete === true;
198
+
199
+ // A create's form leaves out the fields the screen's filter fixes: the filter's value is what's
200
+ // saved, so an input for it would be overridden without a word (the web hides them too).
201
+ const formFields = useCallback(
202
+ (mode: "create" | "edit") =>
203
+ mode === "create" ? formFieldsFor(view, "create").filter((f) => !(f.key in createDefaults)) : formFieldsFor(view, "edit"),
204
+ [view, createDefaults],
205
+ );
206
+ const editable = useMemo(() => formFieldsFor(view, "edit").some((f) => !f.readOnly), [view]);
207
+ const canCreate = useMemo(
208
+ () => (formFieldsFor(view, "create").length ? allowed(view, "create", undefined, can) : false),
209
+ [view, can],
210
+ );
211
+
212
+ const writers = useRef(pessimistic);
213
+ writers.current = pessimistic;
214
+ const save = useCallback(
215
+ async (mode: "create" | "edit", values: Readonly<Record<string, unknown>>, row?: T, dirty?: ReadonlySet<string>): Promise<SaveResult> => {
216
+ const fields = formFields(mode);
217
+ const errors = validateValues(fields, values, messages);
218
+ if (Object.keys(errors).length) return { ok: false, fields: errors };
219
+ // A create is the person's writable values plus the screen's filter values, which win (the
220
+ // new row must land in this list). An edit sends only writable values. The server's
221
+ // WITH CHECK still decides.
222
+ const data = (
223
+ mode === "create"
224
+ ? { ...writableValues(view, mode, fields, values), ...createDefaults }
225
+ : writableValues(view, mode, fields, values, dirty)
226
+ ) as Partial<T & BaseRecord>;
227
+ setRefusal(null);
228
+ // Nothing changed: nothing to send.
229
+ if (mode === "edit" && Object.keys(data).length === 0) return { ok: true };
230
+ try {
231
+ if (mode === "create") await writers.current.create(data);
232
+ else await writers.current.update(row!.id as string, data);
233
+ return { ok: true };
234
+ } catch (error) {
235
+ return {
236
+ ok: false,
237
+ message: refusalMessage(error, fill(messages.form.saveFailed, { noun: view.noun })),
238
+ fields: refusalFields(error),
239
+ };
240
+ }
241
+ },
242
+ [view, messages, createDefaults, formFields],
243
+ );
244
+
245
+ // useResource's writers change identity every render; a ref keeps `remove` (and so every row's
246
+ // actions) stable, so typing in the search doesn't redraw the rows.
247
+ const removeRow = useRef(optimistic.remove);
248
+ removeRow.current = optimistic.remove;
249
+ const remove = useCallback((row: T) => {
250
+ setRefusal(null);
251
+ // Optimistic: resolves at once; a refusal arrives through onError after the rollback.
252
+ removeRow.current(row.id as string).catch(() => {});
253
+ }, []);
254
+
255
+ const item = useCallback((row: T) => rowItem(view, row), [view]);
256
+ const actions = useCallback<UseNativeResourceViewReturn<T>["actions"]>(
257
+ (row, handlers) => swipeActionsFor(view, row, { messages, softDelete, editable, screen: can, ...handlers }),
258
+ [view, messages, softDelete, editable, can],
259
+ );
260
+
261
+ const sections = useMemo(() => sectionsFor(view, pages.rows, messages), [view, pages.rows, messages]);
262
+
263
+ const { query } = pages;
264
+ const [refreshing, setRefreshing] = useState(false);
265
+ const refresh = useCallback(async () => {
266
+ setRefreshing(true);
267
+ try {
268
+ await query.refetch();
269
+ } finally {
270
+ setRefreshing(false);
271
+ }
272
+ }, [query]);
273
+
274
+ const error = query.isError
275
+ ? query.error?.name === "DataReadError" && query.error.message
276
+ ? query.error.message
277
+ : fill(messages.list.loadFailed, { nounPlural: view.nounPlural })
278
+ : null;
279
+
280
+ return {
281
+ rows: pages.rows as T[],
282
+ sections: sections as NativeResourceSection<T>[],
283
+ total: pages.total,
284
+ loading: query.isLoading,
285
+ error,
286
+ refreshing,
287
+ refresh,
288
+ loadMore: pages.fetchNextPage,
289
+ loadingMore: pages.isFetchingNextPage,
290
+ hasMore: pages.hasNextPage,
291
+ loadPrevious: pages.fetchPreviousPage,
292
+ loadingPrevious: query.isFetchingPreviousPage,
293
+ hasPrevious: pages.hasPreviousPage,
294
+ search,
295
+ setSearch,
296
+ refusal,
297
+ dismissRefusal: useCallback(() => setRefusal(null), []),
298
+ item,
299
+ actions,
300
+ canCreate,
301
+ formFields,
302
+ save,
303
+ remove,
304
+ softDelete,
305
+ };
306
+ }
307
+
@@ -1,234 +0,0 @@
1
- import { cn } from './chunk-OHZD7KRO.js';
2
- import { cva } from 'class-variance-authority';
3
- import { Text, Pressable, ActivityIndicator, View, TextInput } from 'react-native';
4
- import { jsx, jsxs } from 'react/jsx-runtime';
5
- import { createContext, useContext, useMemo, createElement } from 'react';
6
- import { nativeColors } from '@marktiderman/genesis-design-system/tokens/native';
7
-
8
- var textVariants = cva("text-foreground", {
9
- variants: {
10
- preset: {
11
- h1: "text-3xl font-bold leading-9",
12
- h2: "text-2xl font-bold leading-8",
13
- h3: "text-xl font-semibold leading-7",
14
- h4: "text-lg font-semibold leading-7",
15
- body: "text-base font-normal leading-6",
16
- "body-sm": "text-sm font-normal leading-5",
17
- caption: "text-xs font-normal leading-4",
18
- label: "text-sm font-medium leading-5"
19
- }
20
- },
21
- defaultVariants: {
22
- preset: "body"
23
- }
24
- });
25
- function NativeText({
26
- className,
27
- preset,
28
- children,
29
- ...props
30
- }) {
31
- return /* @__PURE__ */ jsx(
32
- Text,
33
- {
34
- className: cn(textVariants({ preset }), className),
35
- ...props,
36
- children
37
- }
38
- );
39
- }
40
- var buttonVariants = cva(
41
- "flex-row items-center justify-center rounded-md",
42
- {
43
- variants: {
44
- variant: {
45
- default: "bg-primary",
46
- secondary: "bg-secondary",
47
- outline: "border border-input bg-transparent",
48
- ghost: "bg-transparent",
49
- destructive: "bg-destructive"
50
- },
51
- size: {
52
- sm: "h-9 px-3 gap-1.5",
53
- md: "h-10 px-4 gap-2",
54
- lg: "h-11 px-8 gap-2"
55
- }
56
- },
57
- defaultVariants: {
58
- variant: "default",
59
- size: "md"
60
- }
61
- }
62
- );
63
- var buttonTextVariants = cva("font-medium text-center", {
64
- variants: {
65
- variant: {
66
- default: "text-primary-foreground",
67
- secondary: "text-secondary-foreground",
68
- outline: "text-foreground",
69
- ghost: "text-foreground",
70
- destructive: "text-destructive-foreground"
71
- },
72
- size: {
73
- sm: "text-sm",
74
- md: "text-sm",
75
- lg: "text-base"
76
- }
77
- },
78
- defaultVariants: {
79
- variant: "default",
80
- size: "md"
81
- }
82
- });
83
- function NativeButton({
84
- className,
85
- textClassName,
86
- variant,
87
- size,
88
- children,
89
- onPress,
90
- disabled,
91
- loading,
92
- ...props
93
- }) {
94
- const isDisabled = disabled || loading;
95
- return /* @__PURE__ */ jsxs(
96
- Pressable,
97
- {
98
- className: cn(
99
- buttonVariants({ variant, size }),
100
- isDisabled && "opacity-50",
101
- className
102
- ),
103
- onPress,
104
- disabled: isDisabled,
105
- accessibilityRole: "button",
106
- accessibilityState: { disabled: isDisabled, busy: loading },
107
- ...props,
108
- children: [
109
- loading ? /* @__PURE__ */ jsx(
110
- ActivityIndicator,
111
- {
112
- size: "small",
113
- color: variant === "outline" || variant === "ghost" ? void 0 : "white"
114
- }
115
- ) : null,
116
- typeof children === "string" ? /* @__PURE__ */ jsx(
117
- Text,
118
- {
119
- className: cn(
120
- buttonTextVariants({ variant, size }),
121
- textClassName
122
- ),
123
- children
124
- }
125
- ) : children
126
- ]
127
- }
128
- );
129
- }
130
- var EMPTY = Object.freeze({});
131
- var GenesisModulesContext = createContext(EMPTY);
132
- function GenesisModulesProvider({ modules, children }) {
133
- const outer = useContext(GenesisModulesContext);
134
- const value = useMemo(() => outer === EMPTY ? modules : { ...outer, ...modules }, [outer, modules]);
135
- return createElement(GenesisModulesContext.Provider, { value }, children);
136
- }
137
- function useGenesisModules() {
138
- return useContext(GenesisModulesContext);
139
- }
140
- var badgeVariants = cva(
141
- "flex-row items-center self-start rounded-full border px-2.5 py-0.5",
142
- {
143
- variants: {
144
- variant: {
145
- default: "border-transparent bg-primary",
146
- secondary: "border-transparent bg-secondary",
147
- destructive: "border-transparent bg-destructive",
148
- outline: "border-border bg-transparent",
149
- success: "border-transparent bg-success/15",
150
- warning: "border-transparent bg-warning/15",
151
- info: "border-transparent bg-info/15",
152
- muted: "border-transparent bg-muted"
153
- }
154
- },
155
- defaultVariants: {
156
- variant: "default"
157
- }
158
- }
159
- );
160
- var badgeTextVariants = cva("text-xs font-medium", {
161
- variants: {
162
- variant: {
163
- default: "text-primary-foreground",
164
- secondary: "text-secondary-foreground",
165
- destructive: "text-destructive-foreground",
166
- outline: "text-foreground",
167
- // AA-safe status text on the /15 tint. The bare status token
168
- // (text-success ~2.2:1) fails WCAG AA. The `-dark` stop is optional in
169
- // the brand schema (only `status.*.DEFAULT` is required) AND regresses
170
- // dark mode — a dark shade on the dark-surface tint drops to ~1.7–2.6:1.
171
- // Instead use the semantic Tailwind ramp (always present, brand-
172
- // independent, same hues as the Genesis status tokens) with a `dark:`
173
- // stop. Measured: light /15 tint emerald-700 4.76 / amber-800 6.32 /
174
- // blue-700 5.64; dark-surface tint emerald-300 ≥8.2 / amber-200 ≥10.8 /
175
- // blue-300 ≥8.2 — AA in both modes across the static preset and the
176
- // themeFromBrand() runtime dark map.
177
- success: "text-emerald-700 dark:text-emerald-300",
178
- warning: "text-amber-800 dark:text-amber-200",
179
- info: "text-blue-700 dark:text-blue-300",
180
- muted: "text-muted-foreground"
181
- }
182
- },
183
- defaultVariants: {
184
- variant: "default"
185
- }
186
- });
187
- function NativeBadge({
188
- className,
189
- textClassName,
190
- variant,
191
- children,
192
- ...props
193
- }) {
194
- return /* @__PURE__ */ jsx(View, { className: cn(badgeVariants({ variant }), className), accessibilityRole: "text", ...props, children: typeof children === "string" ? /* @__PURE__ */ jsx(
195
- Text,
196
- {
197
- className: cn(badgeTextVariants({ variant }), textClassName),
198
- children
199
- }
200
- ) : children });
201
- }
202
- function NativeInput({
203
- className,
204
- inputClassName,
205
- label,
206
- error,
207
- editable = true,
208
- placeholderTextColor,
209
- ...props
210
- }) {
211
- return /* @__PURE__ */ jsxs(View, { className: cn("gap-1.5", className), children: [
212
- label ? /* @__PURE__ */ jsx(Text, { className: "text-sm font-medium text-foreground", children: label }) : null,
213
- /* @__PURE__ */ jsx(
214
- TextInput,
215
- {
216
- className: cn(
217
- "h-10 rounded-md border border-input bg-background px-3 text-base text-foreground",
218
- !editable && "opacity-50",
219
- error && "border-destructive",
220
- inputClassName
221
- ),
222
- editable,
223
- placeholderTextColor: placeholderTextColor ?? nativeColors.neutral[400],
224
- accessibilityLabel: label,
225
- ...props
226
- }
227
- ),
228
- error ? /* @__PURE__ */ jsx(Text, { className: "text-sm text-destructive", children: error }) : null
229
- ] });
230
- }
231
-
232
- export { GenesisModulesProvider, NativeBadge, NativeButton, NativeInput, NativeText, badgeTextVariants, badgeVariants, buttonTextVariants, buttonVariants, textVariants, useGenesisModules };
233
- //# sourceMappingURL=chunk-EFXCJ5AN.js.map
234
- //# sourceMappingURL=chunk-EFXCJ5AN.js.map