@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,27 @@
1
+ /**
2
+ * Genesis layout primitives (promoted from the Sanctiv incubator, PRD-46 WC-A4).
3
+ * The keystone the design-system research flags: "layout primitives own all
4
+ * spacing" (Braid rule). Stack / Inline / Box / Grid take all gap/padding/margin
5
+ * from the `spaceScale` design token via `spacingClass()` — composition stays
6
+ * fast and consistent.
7
+ *
8
+ * Static-surface composites (plain RN <View> + NativeWind classes, no native-
9
+ * driver imports), so they are barrel-safe.
10
+ */
11
+
12
+ export { Stack } from "./stack";
13
+ export type { StackProps } from "./stack";
14
+
15
+ export { Inline } from "./inline";
16
+ export type { InlineProps } from "./inline";
17
+
18
+ export { Box } from "./box";
19
+ export type { BoxProps, BoxBackground } from "./box";
20
+
21
+ export { Grid } from "./grid";
22
+ export type { GridProps } from "./grid";
23
+
24
+ export { spaceScale, spacingClass } from "./spacing";
25
+ export type { SpaceToken, SpacingPrefix } from "./spacing";
26
+
27
+ export type { FlexAlign, FlexJustify } from "./flex";
@@ -0,0 +1,63 @@
1
+ /**
2
+ * <Inline> — horizontal layout primitive. Lays children out in a row with a
3
+ * single `gap` design token and optional wrapping. Variant props
4
+ * (`gap` / `align` / `justify` / `wrap`), `className` escape hatch, children.
5
+ *
6
+ * Defaults to vertically-centered items (the common toolbar/row case).
7
+ * Tokens only — pure NativeWind v4 className strings, no inline pixel styles.
8
+ *
9
+ * @stability Beta
10
+ */
11
+
12
+ import { View, type ViewProps } from "react-native";
13
+ import { cn } from "../../utils";
14
+ import {
15
+ type FlexAlign,
16
+ type FlexJustify,
17
+ alignClasses,
18
+ justifyClasses,
19
+ } from "./flex";
20
+ import { type SpaceToken, spacingClass } from "./spacing";
21
+
22
+ export interface InlineProps extends ViewProps {
23
+ /** Horizontal spacing between children — resolved from the spacing token. */
24
+ gap?: SpaceToken;
25
+ /** Cross-axis (vertical) alignment of children. Defaults to `center`. */
26
+ align?: FlexAlign;
27
+ /** Main-axis (horizontal) distribution of children. */
28
+ justify?: FlexJustify;
29
+ /** Allow children to wrap onto multiple rows when they overflow. */
30
+ wrap?: boolean;
31
+ }
32
+
33
+ /**
34
+ * Render a horizontal (`flex-row`) `View` with token-driven `gap`, alignment, and optional wrap.
35
+ * @stability Beta
36
+ */
37
+ function Inline({
38
+ gap = "md",
39
+ align = "center",
40
+ justify,
41
+ wrap = false,
42
+ className,
43
+ children,
44
+ ...props
45
+ }: InlineProps) {
46
+ return (
47
+ <View
48
+ className={cn(
49
+ "flex-row",
50
+ wrap && "flex-wrap",
51
+ spacingClass("gap", gap),
52
+ alignClasses[align],
53
+ justify && justifyClasses[justify],
54
+ className,
55
+ )}
56
+ {...props}
57
+ >
58
+ {children}
59
+ </View>
60
+ );
61
+ }
62
+
63
+ export { Inline };
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Layout spacing scale — the single source of truth for gap / padding /
3
+ * margin across the Genesis layout primitives (Stack / Inline / Box / Grid).
4
+ *
5
+ * Semantic step names map to pixel values on the 4px Tailwind grid. The
6
+ * primitives NEVER inline a px value or hand-write a `gap-N` / `p-N` class —
7
+ * they always resolve through `spacingClass()` so spacing stays token-driven
8
+ * (the Braid rule the PRD-46 research flags: "layout primitives own all
9
+ * spacing"). When the design-system semantic spacing tier lands, this scale
10
+ * re-points to it additively — consumers keep the same `SpaceToken` API.
11
+ */
12
+ export const spaceScale = {
13
+ none: 0,
14
+ xs: 4,
15
+ sm: 8,
16
+ md: 12,
17
+ lg: 16,
18
+ xl: 24,
19
+ "2xl": 32,
20
+ "3xl": 48,
21
+ } as const;
22
+
23
+ export type SpaceToken = keyof typeof spaceScale;
24
+
25
+ /** One Tailwind spacing unit === 4px (the design grid). */
26
+ const TAILWIND_UNIT_PX = 4;
27
+
28
+ /** Spacing-bearing NativeWind utility prefixes the primitives emit. */
29
+ export type SpacingPrefix =
30
+ | "gap"
31
+ | "p"
32
+ | "px"
33
+ | "py"
34
+ | "pt"
35
+ | "pb"
36
+ | "pl"
37
+ | "pr"
38
+ | "m"
39
+ | "mx"
40
+ | "my"
41
+ | "mt"
42
+ | "mb"
43
+ | "ml"
44
+ | "mr";
45
+
46
+ /**
47
+ * The class strings MUST be static literals, not built at runtime.
48
+ * NativeWind/Tailwind compiles only the literal class names its content
49
+ * scanner finds in source — it never executes `spacingClass()`. A
50
+ * template-literal form (`${prefix}-${spaceScale[token] / 4}`) is invisible
51
+ * to the scanner, so any utility that doesn't independently appear as a
52
+ * literal elsewhere is a SILENT NO-OP at runtime (spacing simply doesn't
53
+ * apply). Verified empirically: with the runtime form, `gap-6` (xl),
54
+ * `gap-8` (2xl), and `gap-12` (3xl) were ABSENT from the compiled output,
55
+ * so `<Stack gap="xl">` rendered with no gap.
56
+ *
57
+ * This lookup keeps every emittable class as a scannable literal in the
58
+ * genesis source (which each consuming app already includes in its Tailwind
59
+ * `content` globs), so the full token range compiles. It is the substrate-
60
+ * correct fix — a per-app safelist would have to be duplicated in every
61
+ * consumer's Tailwind config. The map MUST stay in sync with `spaceScale`;
62
+ * the layout-primitives test asserts the round-trip.
63
+ */
64
+ const SPACING_CLASSES: Record<SpacingPrefix, Record<SpaceToken, string>> = {
65
+ gap: { none: "gap-0", xs: "gap-1", sm: "gap-2", md: "gap-3", lg: "gap-4", xl: "gap-6", "2xl": "gap-8", "3xl": "gap-12" },
66
+ p: { none: "p-0", xs: "p-1", sm: "p-2", md: "p-3", lg: "p-4", xl: "p-6", "2xl": "p-8", "3xl": "p-12" },
67
+ px: { none: "px-0", xs: "px-1", sm: "px-2", md: "px-3", lg: "px-4", xl: "px-6", "2xl": "px-8", "3xl": "px-12" },
68
+ py: { none: "py-0", xs: "py-1", sm: "py-2", md: "py-3", lg: "py-4", xl: "py-6", "2xl": "py-8", "3xl": "py-12" },
69
+ pt: { none: "pt-0", xs: "pt-1", sm: "pt-2", md: "pt-3", lg: "pt-4", xl: "pt-6", "2xl": "pt-8", "3xl": "pt-12" },
70
+ pb: { none: "pb-0", xs: "pb-1", sm: "pb-2", md: "pb-3", lg: "pb-4", xl: "pb-6", "2xl": "pb-8", "3xl": "pb-12" },
71
+ pl: { none: "pl-0", xs: "pl-1", sm: "pl-2", md: "pl-3", lg: "pl-4", xl: "pl-6", "2xl": "pl-8", "3xl": "pl-12" },
72
+ pr: { none: "pr-0", xs: "pr-1", sm: "pr-2", md: "pr-3", lg: "pr-4", xl: "pr-6", "2xl": "pr-8", "3xl": "pr-12" },
73
+ m: { none: "m-0", xs: "m-1", sm: "m-2", md: "m-3", lg: "m-4", xl: "m-6", "2xl": "m-8", "3xl": "m-12" },
74
+ mx: { none: "mx-0", xs: "mx-1", sm: "mx-2", md: "mx-3", lg: "mx-4", xl: "mx-6", "2xl": "mx-8", "3xl": "mx-12" },
75
+ my: { none: "my-0", xs: "my-1", sm: "my-2", md: "my-3", lg: "my-4", xl: "my-6", "2xl": "my-8", "3xl": "my-12" },
76
+ mt: { none: "mt-0", xs: "mt-1", sm: "mt-2", md: "mt-3", lg: "mt-4", xl: "mt-6", "2xl": "mt-8", "3xl": "mt-12" },
77
+ mb: { none: "mb-0", xs: "mb-1", sm: "mb-2", md: "mb-3", lg: "mb-4", xl: "mb-6", "2xl": "mb-8", "3xl": "mb-12" },
78
+ ml: { none: "ml-0", xs: "ml-1", sm: "ml-2", md: "ml-3", lg: "ml-4", xl: "ml-6", "2xl": "ml-8", "3xl": "ml-12" },
79
+ mr: { none: "mr-0", xs: "mr-1", sm: "mr-2", md: "mr-3", lg: "mr-4", xl: "mr-6", "2xl": "mr-8", "3xl": "mr-12" },
80
+ };
81
+
82
+ // `process` is declared locally because this package compiles against minimal
83
+ // RN stubs (no @types/node in `types`), so the ambient global isn't otherwise
84
+ // in scope. We guard the drift check on the LITERAL `process.env.NODE_ENV`
85
+ // expression on purpose: Metro/Babel's env inliner matches only that exact
86
+ // member path (not a `globalThis.process?.env?.NODE_ENV` lookup), so it's
87
+ // substituted at build time and the block below is dead-code-eliminated from
88
+ // RN production bundles instead of running on every render. In Node/Vitest
89
+ // `process.env.NODE_ENV` is defined, so the invariant still runs in dev/test.
90
+ declare const process: { env: { NODE_ENV?: string } };
91
+
92
+ /**
93
+ * Resolve a semantic spacing token to its NativeWind utility class for a
94
+ * given prefix — e.g. `spacingClass("gap", "md") === "gap-3"` (12px / 4).
95
+ *
96
+ * Returns a STATIC literal from `SPACING_CLASSES` (see the note there) so the
97
+ * Tailwind content scanner can compile it. The dev-only invariant check keeps
98
+ * the literal honest against `spaceScale` — if the map ever drifts from the
99
+ * token scale it throws in dev rather than silently shipping the wrong gap.
100
+ */
101
+ export function spacingClass(prefix: SpacingPrefix, token: SpaceToken): string {
102
+ const cls = SPACING_CLASSES[prefix][token];
103
+ // Literal `process.env.NODE_ENV` so Metro/Babel inlines it and strips this
104
+ // block from RN production bundles — keeping this hot render path minimal.
105
+ // It only throws on genuine map/scale drift, which never happens for the
106
+ // in-sync table.
107
+ if (process.env.NODE_ENV !== "production") {
108
+ const expected = `${prefix}-${spaceScale[token] / TAILWIND_UNIT_PX}`;
109
+ if (cls !== expected) {
110
+ throw new Error(
111
+ `spacingClass map drift: ${prefix}/${token} → "${cls}" but spaceScale implies "${expected}". Update SPACING_CLASSES.`,
112
+ );
113
+ }
114
+ }
115
+ return cls;
116
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * <Stack> — vertical layout primitive. Owns the vertical rhythm between its
3
+ * children via a single `gap` design token (no hard-coded spacing). Variant
4
+ * props (`gap` / `align` / `justify`), `className` escape hatch, and children.
5
+ *
6
+ * Tokens only — pure NativeWind v4 className strings, no inline pixel styles.
7
+ *
8
+ * @stability Beta
9
+ */
10
+
11
+ import { View, type ViewProps } from "react-native";
12
+ import { cn } from "../../utils";
13
+ import {
14
+ type FlexAlign,
15
+ type FlexJustify,
16
+ alignClasses,
17
+ justifyClasses,
18
+ } from "./flex";
19
+ import { type SpaceToken, spacingClass } from "./spacing";
20
+
21
+ export interface StackProps extends ViewProps {
22
+ /** Vertical spacing between children — resolved from the spacing token. */
23
+ gap?: SpaceToken;
24
+ /** Cross-axis (horizontal) alignment of children. */
25
+ align?: FlexAlign;
26
+ /** Main-axis (vertical) distribution of children. */
27
+ justify?: FlexJustify;
28
+ }
29
+
30
+ /**
31
+ * Render a vertical (`flex-col`) `View` with token-driven `gap` + alignment.
32
+ * @stability Beta
33
+ */
34
+ function Stack({
35
+ gap = "md",
36
+ align,
37
+ justify,
38
+ className,
39
+ children,
40
+ ...props
41
+ }: StackProps) {
42
+ return (
43
+ <View
44
+ className={cn(
45
+ "flex-col",
46
+ spacingClass("gap", gap),
47
+ align && alignClasses[align],
48
+ justify && justifyClasses[justify],
49
+ className,
50
+ )}
51
+ {...props}
52
+ >
53
+ {children}
54
+ </View>
55
+ );
56
+ }
57
+
58
+ export { Stack };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * ListItem — recurring row in a list (settings, contacts, results).
3
+ *
4
+ * Slots: leading (avatar / icon), title, subtitle, trailing
5
+ * (chevron / accessory / action). Supports pressable variants with
6
+ * automatic divider rendering between adjacent items via a wrapper
7
+ * pattern (see <NativeListItemDivider>).
8
+ *
9
+ * For platform-default chevrons, pass `showChevron`; the chevron uses
10
+ * the muted-foreground token.
11
+ *
12
+ * @stability Beta
13
+ */
14
+ import { Pressable, Text, View } from "react-native";
15
+ import { cn } from "../utils";
16
+
17
+ export interface NativeListItemProps {
18
+ title: string;
19
+ subtitle?: string;
20
+ /** Slot rendered to the left of the title (avatar / icon). */
21
+ leading?: React.ReactNode;
22
+ /** Slot rendered to the right of the title (badge / accessory). */
23
+ trailing?: React.ReactNode;
24
+ /** When true, renders a chevron-right at the end. */
25
+ showChevron?: boolean;
26
+ /** When provided, the row becomes pressable. */
27
+ onPress?: () => void;
28
+ disabled?: boolean;
29
+ className?: string;
30
+ testID?: string;
31
+ }
32
+
33
+ export function NativeListItem({
34
+ title,
35
+ subtitle,
36
+ leading,
37
+ trailing,
38
+ showChevron,
39
+ onPress,
40
+ disabled,
41
+ className,
42
+ testID,
43
+ }: NativeListItemProps) {
44
+ const inner = (
45
+ <>
46
+ {leading ? <View className="mr-3">{leading}</View> : null}
47
+ <View className="flex-1">
48
+ <Text className="text-base text-foreground" numberOfLines={1}>
49
+ {title}
50
+ </Text>
51
+ {subtitle ? (
52
+ <Text
53
+ className="mt-0.5 text-xs text-muted-foreground"
54
+ numberOfLines={2}
55
+ >
56
+ {subtitle}
57
+ </Text>
58
+ ) : null}
59
+ </View>
60
+ {trailing ? <View className="ml-3">{trailing}</View> : null}
61
+ {showChevron ? (
62
+ <Text
63
+ accessibilityElementsHidden
64
+ className="ml-2 text-base text-muted-foreground"
65
+ >
66
+ ›
67
+ </Text>
68
+ ) : null}
69
+ </>
70
+ );
71
+
72
+ if (onPress) {
73
+ return (
74
+ <Pressable
75
+ testID={testID ?? "native-list-item"}
76
+ accessibilityRole="button"
77
+ accessibilityLabel={subtitle ? `${title}, ${subtitle}` : title}
78
+ accessibilityState={{ disabled }}
79
+ disabled={disabled}
80
+ onPress={onPress}
81
+ className={cn(
82
+ "min-h-[44px] flex-row items-center bg-background px-4 py-3",
83
+ disabled && "opacity-50",
84
+ className
85
+ )}
86
+ >
87
+ {inner}
88
+ </Pressable>
89
+ );
90
+ }
91
+
92
+ return (
93
+ <View
94
+ testID={testID ?? "native-list-item"}
95
+ accessibilityLabel={subtitle ? `${title}, ${subtitle}` : title}
96
+ className={cn(
97
+ "min-h-[44px] flex-row items-center bg-background px-4 py-3",
98
+ className
99
+ )}
100
+ >
101
+ {inner}
102
+ </View>
103
+ );
104
+ }
105
+
106
+ export function NativeListItemDivider({ className }: { className?: string }) {
107
+ return <View className={cn("h-px bg-border", className)} />;
108
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * NumberInput — numeric input with stepper buttons and numeric keypad.
3
+ *
4
+ * Use for quantities, scores, durations — any context where the user
5
+ * picks a discrete number within a range. The − / + buttons are 44pt
6
+ * touch targets; the input itself uses the platform numeric keypad.
7
+ *
8
+ * Pass `min`, `max`, `step` to constrain. Pass `precision` to fix the
9
+ * decimal display (default 0). For free-form numeric entry without
10
+ * stepper UI, use <NativeInput keyboardType="numeric" />.
11
+ *
12
+ * @stability Beta
13
+ */
14
+ import { useCallback } from "react";
15
+ import { Pressable, Text, TextInput, View } from "react-native";
16
+ import { cn } from "../utils";
17
+
18
+ export interface NativeNumberInputProps {
19
+ value: number;
20
+ onChange: (next: number) => void;
21
+ min?: number;
22
+ max?: number;
23
+ /** Increment per stepper press. Default 1. */
24
+ step?: number;
25
+ /** Decimal places shown. Default 0 (integer). */
26
+ precision?: number;
27
+ /** Disable both stepper buttons and the input. */
28
+ disabled?: boolean;
29
+ /** Disable just the typed input; keep stepper. */
30
+ readOnlyInput?: boolean;
31
+ className?: string;
32
+ inputClassName?: string;
33
+ testID?: string;
34
+ }
35
+
36
+ function clamp(v: number, min?: number, max?: number) {
37
+ if (min !== undefined && v < min) return min;
38
+ if (max !== undefined && v > max) return max;
39
+ return v;
40
+ }
41
+
42
+ export function NativeNumberInput({
43
+ value,
44
+ onChange,
45
+ min,
46
+ max,
47
+ step = 1,
48
+ precision = 0,
49
+ disabled,
50
+ readOnlyInput,
51
+ className,
52
+ inputClassName,
53
+ testID,
54
+ }: NativeNumberInputProps) {
55
+ const setValue = useCallback(
56
+ (next: number) => {
57
+ if (Number.isNaN(next)) return;
58
+ onChange(clamp(next, min, max));
59
+ },
60
+ [max, min, onChange]
61
+ );
62
+
63
+ const decBlocked = disabled || (min !== undefined && value <= min);
64
+ const incBlocked = disabled || (max !== undefined && value >= max);
65
+
66
+ return (
67
+ <View
68
+ testID={testID ?? "native-number-input"}
69
+ accessibilityRole="adjustable"
70
+ accessibilityValue={{ now: value, min, max }}
71
+ className={cn(
72
+ "flex-row items-stretch overflow-hidden rounded-md border border-input bg-background",
73
+ className
74
+ )}
75
+ >
76
+ <Pressable
77
+ testID={testID ? `${testID}-decrement` : "number-input-decrement"}
78
+ accessibilityRole="button"
79
+ accessibilityLabel="Decrement"
80
+ disabled={decBlocked}
81
+ onPress={() => setValue(value - step)}
82
+ className={cn(
83
+ "min-h-[44px] min-w-[44px] items-center justify-center px-3",
84
+ decBlocked && "opacity-40"
85
+ )}
86
+ >
87
+ <Text className="text-xl font-semibold text-foreground">−</Text>
88
+ </Pressable>
89
+ <TextInput
90
+ testID={testID ? `${testID}-field` : "number-input-field"}
91
+ value={value.toFixed(precision)}
92
+ editable={!disabled && !readOnlyInput}
93
+ keyboardType="numeric"
94
+ accessibilityLabel="Numeric value"
95
+ onChangeText={(t) => {
96
+ const parsed = Number(t.replace(/[^0-9.\-]/g, ""));
97
+ setValue(parsed);
98
+ }}
99
+ className={cn(
100
+ "min-w-[64px] flex-1 border-x border-input bg-background text-center text-base text-foreground",
101
+ inputClassName
102
+ )}
103
+ />
104
+ <Pressable
105
+ testID={testID ? `${testID}-increment` : "number-input-increment"}
106
+ accessibilityRole="button"
107
+ accessibilityLabel="Increment"
108
+ disabled={incBlocked}
109
+ onPress={() => setValue(value + step)}
110
+ className={cn(
111
+ "min-h-[44px] min-w-[44px] items-center justify-center px-3",
112
+ incBlocked && "opacity-40"
113
+ )}
114
+ >
115
+ <Text className="text-xl font-semibold text-foreground">+</Text>
116
+ </Pressable>
117
+ </View>
118
+ );
119
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Pagination — numeric page navigator with prev / next.
3
+ *
4
+ * Use for paged lists with discoverable totals. For infinite-scroll
5
+ * patterns, prefer a load-more trigger or an inverted FlatList.
6
+ *
7
+ * Renders up to `maxVisible` numbered pages with leading/trailing
8
+ * ellipses when the page count exceeds the window.
9
+ *
10
+ * @stability Beta
11
+ */
12
+ import { Pressable, Text, View } from "react-native";
13
+ import { cn } from "../utils";
14
+
15
+ export interface NativePaginationProps {
16
+ /** Total page count (>= 1). */
17
+ pageCount: number;
18
+ /** Zero-indexed current page. */
19
+ page: number;
20
+ onChange: (page: number) => void;
21
+ /** Max numbered pages shown around the current page. Default 5. */
22
+ maxVisible?: number;
23
+ className?: string;
24
+ testID?: string;
25
+ }
26
+
27
+ function buildWindow(page: number, total: number, maxVisible: number) {
28
+ if (total <= maxVisible) return Array.from({ length: total }, (_, i) => i);
29
+ const half = Math.floor(maxVisible / 2);
30
+ let start = Math.max(0, page - half);
31
+ let end = Math.min(total, start + maxVisible);
32
+ if (end - start < maxVisible) start = Math.max(0, end - maxVisible);
33
+ return Array.from({ length: end - start }, (_, i) => start + i);
34
+ }
35
+
36
+ export function NativePagination({
37
+ pageCount,
38
+ page,
39
+ onChange,
40
+ maxVisible = 5,
41
+ className,
42
+ testID,
43
+ }: NativePaginationProps) {
44
+ // Empty data sets render nothing rather than an inert "Page 1 of 0" row.
45
+ if (pageCount <= 0) return null;
46
+ const window = buildWindow(page, pageCount, maxVisible);
47
+ const showLeadingEllipsis = window[0]! > 0;
48
+ const showTrailingEllipsis =
49
+ window[window.length - 1]! < pageCount - 1;
50
+
51
+ return (
52
+ <View
53
+ testID={testID ?? "native-pagination"}
54
+ accessibilityLabel={`Page ${page + 1} of ${pageCount}`}
55
+ className={cn("flex-row items-center gap-1", className)}
56
+ >
57
+ <PageButton
58
+ testID={testID ? `${testID}-prev` : "pagination-prev"}
59
+ label="‹"
60
+ a11y="Previous page"
61
+ disabled={page <= 0}
62
+ onPress={() => onChange(Math.max(0, page - 1))}
63
+ />
64
+ {showLeadingEllipsis ? <Ellipsis /> : null}
65
+ {window.map((i) => (
66
+ <PageButton
67
+ key={i}
68
+ testID={testID ? `${testID}-page-${i}` : `pagination-page-${i}`}
69
+ label={String(i + 1)}
70
+ a11y={`Page ${i + 1}`}
71
+ selected={i === page}
72
+ onPress={() => onChange(i)}
73
+ />
74
+ ))}
75
+ {showTrailingEllipsis ? <Ellipsis /> : null}
76
+ <PageButton
77
+ testID={testID ? `${testID}-next` : "pagination-next"}
78
+ label="›"
79
+ a11y="Next page"
80
+ disabled={page >= pageCount - 1}
81
+ onPress={() => onChange(Math.min(pageCount - 1, page + 1))}
82
+ />
83
+ </View>
84
+ );
85
+ }
86
+
87
+ interface PageButtonProps {
88
+ testID?: string;
89
+ label: string;
90
+ a11y: string;
91
+ selected?: boolean;
92
+ disabled?: boolean;
93
+ onPress: () => void;
94
+ }
95
+
96
+ function PageButton({ testID, label, a11y, selected, disabled, onPress }: PageButtonProps) {
97
+ return (
98
+ <Pressable
99
+ testID={testID}
100
+ accessibilityRole="button"
101
+ accessibilityLabel={a11y}
102
+ accessibilityState={{ selected, disabled }}
103
+ disabled={disabled}
104
+ onPress={onPress}
105
+ className={cn(
106
+ "min-h-[44px] min-w-[44px] items-center justify-center rounded-md border px-2",
107
+ selected ? "border-primary bg-primary" : "border-border bg-background",
108
+ disabled && "opacity-40"
109
+ )}
110
+ >
111
+ <Text
112
+ className={cn(
113
+ "text-sm font-medium",
114
+ selected ? "text-primary-foreground" : "text-foreground"
115
+ )}
116
+ >
117
+ {label}
118
+ </Text>
119
+ </Pressable>
120
+ );
121
+ }
122
+
123
+ function Ellipsis() {
124
+ return (
125
+ <Text
126
+ accessibilityElementsHidden
127
+ className="px-1 text-sm text-muted-foreground"
128
+ >
129
+ …
130
+ </Text>
131
+ );
132
+ }