From 56331662decd0a666a23ed1b11fd878a66587bf4 Mon Sep 17 00:00:00 2001 From: kasimkazmi Date: Thu, 5 Nov 2026 10:53:31 -0500 Subject: [PATCH 1/2] feat: Add React Native hooks, providers and theme tokens Co-Authored-By: Claude Sonnet 5.5 --- README.md | 3 + public/registry/index.json | 79 ++++++++++++++++++- public/registry/mode-provider.json | 15 ++++ public/registry/theme-colors.json | 15 ++++ public/registry/theme-globals.json | 15 ++++ public/registry/theme-provider.json | 15 ++++ public/registry/use-color-scheme.json | 15 ++++ public/registry/use-debounced-value.json | 15 ++++ public/registry/use-haptics.json | 15 ++++ public/registry/use-keyboard-height.json | 15 ++++ public/registry/use-reduce-motion.json | 15 ++++ src/app/components/[slug]/page.tsx | 14 +++- src/app/components/layout.tsx | 6 ++ src/content/docs/mode-provider.mdx | 58 ++++++++++++++ src/content/docs/theme-colors.mdx | 51 +++++++++++++ src/content/docs/theme-globals.mdx | 49 ++++++++++++ src/content/docs/theme-provider.mdx | 69 +++++++++++++++++ src/content/docs/use-color-scheme.mdx | 43 +++++++++++ src/content/docs/use-debounced-value.mdx | 51 +++++++++++++ src/content/docs/use-haptics.mdx | 48 ++++++++++++ src/content/docs/use-keyboard-height.mdx | 47 ++++++++++++ src/content/docs/use-reduce-motion.mdx | 55 ++++++++++++++ src/lib/registry.ts | 7 +- src/registry/demos.ts | 9 +++ src/registry/index.ts | 93 +++++++++++++++++++++++ src/registry/mode-provider-demo.tsx | 90 ++++++++++++++++++++++ src/registry/mode-provider.tsx | 61 +++++++++++++++ src/registry/theme-colors-demo.tsx | 62 +++++++++++++++ src/registry/theme-colors.ts | 48 ++++++++++++ src/registry/theme-globals-demo.tsx | 90 ++++++++++++++++++++++ src/registry/theme-globals.ts | 24 ++++++ src/registry/theme-provider-demo.tsx | 77 +++++++++++++++++++ src/registry/theme-provider.tsx | 84 ++++++++++++++++++++ src/registry/use-color-scheme-demo.tsx | 47 ++++++++++++ src/registry/use-color-scheme.ts | 12 +++ src/registry/use-debounced-value-demo.tsx | 50 ++++++++++++ src/registry/use-debounced-value.ts | 17 +++++ src/registry/use-haptics-demo.tsx | 72 ++++++++++++++++++ src/registry/use-haptics.ts | 33 ++++++++ src/registry/use-keyboard-height-demo.tsx | 50 ++++++++++++ src/registry/use-keyboard-height.ts | 27 +++++++ src/registry/use-reduce-motion-demo.tsx | 78 +++++++++++++++++++ src/registry/use-reduce-motion.ts | 19 +++++ tests/component-colors.test.ts | 6 +- tests/prop-docs.test.ts | 78 ++++++++++--------- tests/reduced-motion.test.ts | 15 ++-- 46 files changed, 1809 insertions(+), 48 deletions(-) create mode 100644 public/registry/mode-provider.json create mode 100644 public/registry/theme-colors.json create mode 100644 public/registry/theme-globals.json create mode 100644 public/registry/theme-provider.json create mode 100644 public/registry/use-color-scheme.json create mode 100644 public/registry/use-debounced-value.json create mode 100644 public/registry/use-haptics.json create mode 100644 public/registry/use-keyboard-height.json create mode 100644 public/registry/use-reduce-motion.json create mode 100644 src/content/docs/mode-provider.mdx create mode 100644 src/content/docs/theme-colors.mdx create mode 100644 src/content/docs/theme-globals.mdx create mode 100644 src/content/docs/theme-provider.mdx create mode 100644 src/content/docs/use-color-scheme.mdx create mode 100644 src/content/docs/use-debounced-value.mdx create mode 100644 src/content/docs/use-haptics.mdx create mode 100644 src/content/docs/use-keyboard-height.mdx create mode 100644 src/content/docs/use-reduce-motion.mdx create mode 100644 src/registry/mode-provider-demo.tsx create mode 100644 src/registry/mode-provider.tsx create mode 100644 src/registry/theme-colors-demo.tsx create mode 100644 src/registry/theme-colors.ts create mode 100644 src/registry/theme-globals-demo.tsx create mode 100644 src/registry/theme-globals.ts create mode 100644 src/registry/theme-provider-demo.tsx create mode 100644 src/registry/theme-provider.tsx create mode 100644 src/registry/use-color-scheme-demo.tsx create mode 100644 src/registry/use-color-scheme.ts create mode 100644 src/registry/use-debounced-value-demo.tsx create mode 100644 src/registry/use-debounced-value.ts create mode 100644 src/registry/use-haptics-demo.tsx create mode 100644 src/registry/use-haptics.ts create mode 100644 src/registry/use-keyboard-height-demo.tsx create mode 100644 src/registry/use-keyboard-height.ts create mode 100644 src/registry/use-reduce-motion-demo.tsx create mode 100644 src/registry/use-reduce-motion.ts diff --git a/README.md b/README.md index 3a61e7d..c3a4cf2 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,9 @@ For Cursor, Windsurf or VS Code setup, see [`packages/mcp`](packages/mcp). The d | **Typography** | Scroll Velocity, Text Pressure, True Focus, Gradient Text, Blur Text, Split Text, Decrypted Text, Shimmer Text, Floating Text | | **Components** | Scratch to Reveal, Stack, Star Border, Tilted Card, Pixel Card, Click Spark, Spotlight Card, Border Glow | | **React Native** | Swipe Actions, Snap Sheet, Glide Segments, Swipe Deck, Fan Menu, Pin Pad, Flick Toast, Fold Panel, Snap Carousel, Slide Switch, Shimmer Block, Parallax Header, Bubble Tab Bar, Roll Number, Star Rating, Value Slider, Expand Search, Intro Pager, Drag List, Long Press Menu, Slide Confirm, Calendar Strip, Step Tracker, Chip Input, Typing Dots, Marquee Ticker, Choice Chips, Hold Stepper, Action Tray, Confirm Dialog, Code Boxes, Hue Picker, Tab Pager, Wheel Picker, Avatar Stack, Stripe Progress, Range Slider, Tick Box, Notice Banner, Side Drawer, Expand Card, Suggest Input, Reaction Bar, Ring Meter, Count Badge, Float Field, Month Grid, Chat Bubble, Composer Bar, Pull Refresh, Story Bars, Setting List, Live Dot, Action Button, Spin Loader, Radio Group, Mode Toggle, Tip Popover, Data Table, Wave Bars, Page Dots, Password Meter, Timeline List, Empty State, Rating Histogram, Countdown Timer, Contact Index, Select Grid, Poll Bars, Card Field, Step Slider, Cart Quantity, Password Field, Resend Button, Gauge Meter, Undo Snackbar, Mood Picker, Expandable Text, Extended FAB, Swatch Picker, Like Button, Task Checklist, Spark Bars, Battery Meter, Compare Slider, Hold Confirm, Select Menu | +| **Hooks** | useColorScheme, useKeyboardHeight, useHaptics, useReduceMotion, useDebouncedValue | +| **Providers** | ModeProvider, ThemeProvider | +| **Theme** | Colors, Globals | **React Native** components are Expo files that import only `react-native`, so they need no extra packages. Install them the same way (`npx @modus-ui/cli add swipe-actions`); the docs preview them live in the browser through react-native-web. diff --git a/public/registry/index.json b/public/registry/index.json index 4751b12..aff6551 100644 --- a/public/registry/index.json +++ b/public/registry/index.json @@ -1,7 +1,7 @@ { "name": "Modus UI", "homepage": "https://modusui.kasimkazmi.com", - "count": 298, + "count": 307, "categories": [ "Navigation", "Actions", @@ -11,7 +11,10 @@ "Typography", "Sections", "Components", - "React Native" + "React Native", + "Hooks", + "Providers", + "Theme" ], "components": [ { @@ -3296,6 +3299,78 @@ "platform": "native", "description": "A React Native dropdown that opens in place, pushing content down instead of floating, with a turning chevron.", "dependencies": [] + }, + { + "name": "use-color-scheme", + "title": "useColorScheme", + "category": "Hooks", + "platform": "native", + "description": "A React Native hook that returns the system colour scheme as light or dark, never null.", + "dependencies": [] + }, + { + "name": "use-keyboard-height", + "title": "useKeyboardHeight", + "category": "Hooks", + "platform": "native", + "description": "A React Native hook that returns the on-screen keyboard height, or 0 while it is hidden.", + "dependencies": [] + }, + { + "name": "use-haptics", + "title": "useHaptics", + "category": "Hooks", + "platform": "native", + "description": "A React Native hook for touch feedback with tap, success, warning and error patterns that you can switch off.", + "dependencies": [] + }, + { + "name": "use-reduce-motion", + "title": "useReduceMotion", + "category": "Hooks", + "platform": "native", + "description": "A React Native hook that reports whether the system asks to reduce motion and follows later changes.", + "dependencies": [] + }, + { + "name": "use-debounced-value", + "title": "useDebouncedValue", + "category": "Hooks", + "platform": "native", + "description": "A React Native hook that returns a copy of a value which only updates after it stops changing.", + "dependencies": [] + }, + { + "name": "mode-provider", + "title": "ModeProvider", + "category": "Providers", + "platform": "native", + "description": "A React Native provider that holds the light, dark or system choice and exposes it through a useMode hook.", + "dependencies": [] + }, + { + "name": "theme-provider", + "title": "ThemeProvider", + "category": "Providers", + "platform": "native", + "description": "A React Native provider that supplies one colour palette to the tree through a useTheme hook, with per-colour overrides.", + "dependencies": [] + }, + { + "name": "theme-colors", + "title": "Colors", + "category": "Theme", + "platform": "native", + "description": "Light and dark colour palettes for React Native, named by role, with a helper that adds transparency to any colour.", + "dependencies": [] + }, + { + "name": "theme-globals", + "title": "Globals", + "category": "Theme", + "platform": "native", + "description": "Shared React Native design tokens for spacing, corner radius, type sizes, font weights and shadows.", + "dependencies": [] } ], "renamed": { diff --git a/public/registry/mode-provider.json b/public/registry/mode-provider.json new file mode 100644 index 0000000..fd8d769 --- /dev/null +++ b/public/registry/mode-provider.json @@ -0,0 +1,15 @@ +{ + "name": "mode-provider", + "title": "ModeProvider", + "category": "Providers", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/mode-provider.tsx", + "content": "import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from \"react\";\nimport { useColorScheme } from \"react-native\";\n\nexport type Mode = \"light\" | \"dark\" | \"system\";\n\nexport interface ModeValue {\n /** What the person chose: light, dark, or follow the system. */\n mode: Mode;\n /** The scheme actually in effect, with \"system\" resolved to light or dark. */\n scheme: \"light\" | \"dark\";\n setMode: (mode: Mode) => void;\n /** Switches to the opposite of the scheme in effect. */\n toggle: () => void;\n}\n\nconst ModeContext = createContext(null);\n\nexport interface ModeProviderProps {\n children: ReactNode;\n /** The mode to start in. */\n initialMode?: Mode;\n /** Called whenever the mode changes, so you can save it. */\n onModeChange?: (mode: Mode) => void;\n}\n\n/**\n * Holds the light, dark or system choice for the whole app. Read it anywhere below with `useMode()`.\n * \"system\" follows the device and updates when the device changes. The provider keeps the choice in\n * memory only; save it from `onModeChange` and pass it back as `initialMode` to remember it.\n */\nexport function ModeProvider({\n children,\n initialMode = \"system\",\n onModeChange,\n}: ModeProviderProps) {\n const system = useColorScheme() === \"dark\" ? \"dark\" : \"light\";\n const [mode, setModeState] = useState(initialMode);\n const scheme = mode === \"system\" ? system : mode;\n\n const setMode = useCallback(\n (next: Mode) => {\n setModeState(next);\n onModeChange?.(next);\n },\n [onModeChange],\n );\n const toggle = useCallback(\n () => setMode(scheme === \"dark\" ? \"light\" : \"dark\"),\n [scheme, setMode],\n );\n\n const value = useMemo(() => ({ mode, scheme, setMode, toggle }), [mode, scheme, setMode, toggle]);\n return {children};\n}\n\n/** The current mode and scheme. Throws when used outside a ModeProvider, so a missing one is caught early. */\nexport function useMode(): ModeValue {\n const value = useContext(ModeContext);\n if (!value) throw new Error(\"useMode must be used inside a ModeProvider\");\n return value;\n}\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/theme-colors.json b/public/registry/theme-colors.json new file mode 100644 index 0000000..a896f25 --- /dev/null +++ b/public/registry/theme-colors.json @@ -0,0 +1,15 @@ +{ + "name": "theme-colors", + "title": "Colors", + "category": "Theme", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/theme-colors.ts", + "content": "/** Every colour a screen needs, by role rather than by shade, so light and dark can swap freely. */\nexport interface ThemeColors {\n background: string;\n foreground: string;\n card: string;\n muted: string;\n mutedForeground: string;\n primary: string;\n primaryForeground: string;\n border: string;\n destructive: string;\n}\n\nexport const lightColors: ThemeColors = {\n background: \"#ffffff\",\n foreground: \"#111827\",\n card: \"#f9fafb\",\n muted: \"#f3f4f6\",\n mutedForeground: \"#6b7280\",\n primary: \"#4f46e5\",\n primaryForeground: \"#ffffff\",\n border: \"#e5e7eb\",\n destructive: \"#dc2626\",\n};\n\nexport const darkColors: ThemeColors = {\n background: \"#0b0b0f\",\n foreground: \"#f9fafb\",\n card: \"#16161d\",\n muted: \"#1f1f29\",\n mutedForeground: \"#9ca3af\",\n primary: \"#818cf8\",\n primaryForeground: \"#0b0b0f\",\n border: \"#2a2a36\",\n destructive: \"#f87171\",\n};\n\n/**\n * Adds transparency to a #rrggbb colour and returns an rgba() string. `alpha` runs from 0 to 1. Use it\n * for overlays and pressed states so they stay tied to the palette instead of being hard-coded.\n */\nexport function withAlpha(hex: string, alpha: number): string {\n const value = hex.replace(\"#\", \"\");\n const r = parseInt(value.slice(0, 2), 16);\n const g = parseInt(value.slice(2, 4), 16);\n const b = parseInt(value.slice(4, 6), 16);\n return `rgba(${r}, ${g}, ${b}, ${Math.max(0, Math.min(1, alpha))})`;\n}\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/theme-globals.json b/public/registry/theme-globals.json new file mode 100644 index 0000000..746c940 --- /dev/null +++ b/public/registry/theme-globals.json @@ -0,0 +1,15 @@ +{ + "name": "theme-globals", + "title": "Globals", + "category": "Theme", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/theme-globals.ts", + "content": "/** Space between things, in points. Pick from the scale instead of typing a number. */\nexport const spacing = { xs: 4, sm: 8, md: 12, lg: 16, xl: 24, xxl: 32 } as const;\n\n/** Corner radii, from slightly rounded to a full pill. */\nexport const radius = { sm: 8, md: 12, lg: 16, xl: 24, pill: 999 } as const;\n\n/** Type sizes with matching line heights. */\nexport const fontSize = {\n caption: { fontSize: 12, lineHeight: 16 },\n body: { fontSize: 16, lineHeight: 24 },\n title: { fontSize: 20, lineHeight: 28 },\n heading: { fontSize: 28, lineHeight: 34 },\n display: { fontSize: 40, lineHeight: 46 },\n} as const;\n\n/** Font weights as the string values React Native expects. */\nexport const fontWeight = { regular: \"400\", medium: \"500\", semibold: \"600\", bold: \"700\" } as const;\n\n/** Elevation levels as box shadows. */\nexport const shadow = {\n sm: \"0 1px 3px rgba(0, 0, 0, 0.12)\",\n md: \"0 4px 12px rgba(0, 0, 0, 0.16)\",\n lg: \"0 12px 32px rgba(0, 0, 0, 0.22)\",\n} as const;\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/theme-provider.json b/public/registry/theme-provider.json new file mode 100644 index 0000000..c07fca4 --- /dev/null +++ b/public/registry/theme-provider.json @@ -0,0 +1,15 @@ +{ + "name": "theme-provider", + "title": "ThemeProvider", + "category": "Providers", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/theme-provider.tsx", + "content": "import { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport { useColorScheme } from \"react-native\";\n\nexport interface ThemePalette {\n background: string;\n foreground: string;\n card: string;\n muted: string;\n mutedForeground: string;\n primary: string;\n primaryForeground: string;\n border: string;\n destructive: string;\n}\n\nexport interface ThemeColors {\n light: Partial;\n dark: Partial;\n}\n\nconst LIGHT: ThemePalette = {\n background: \"#ffffff\",\n foreground: \"#111827\",\n card: \"#f9fafb\",\n muted: \"#f3f4f6\",\n mutedForeground: \"#6b7280\",\n primary: \"#4f46e5\",\n primaryForeground: \"#ffffff\",\n border: \"#e5e7eb\",\n destructive: \"#dc2626\",\n};\n\nconst DARK: ThemePalette = {\n background: \"#0b0b0f\",\n foreground: \"#f9fafb\",\n card: \"#16161d\",\n muted: \"#1f1f29\",\n mutedForeground: \"#9ca3af\",\n primary: \"#818cf8\",\n primaryForeground: \"#0b0b0f\",\n border: \"#2a2a36\",\n destructive: \"#f87171\",\n};\n\nexport interface Theme {\n scheme: \"light\" | \"dark\";\n colors: ThemePalette;\n}\n\nconst ThemeContext = createContext(null);\n\nexport interface ThemeProviderProps {\n children: ReactNode;\n /** Which palette to use. Leave it out to follow the system; pass `useMode().scheme` to follow your own switch. */\n scheme?: \"light\" | \"dark\";\n /** Overrides for single colours in either palette. */\n colors?: Partial;\n}\n\n/**\n * Supplies one palette to everything below it. Components call `useTheme()` and read colours by role,\n * so switching between light and dark restyles the whole tree at once with no per-component logic.\n * Override individual colours with `colors`; anything you leave out keeps its default.\n */\nexport function ThemeProvider({ children, scheme, colors }: ThemeProviderProps) {\n const system = useColorScheme() === \"dark\" ? \"dark\" : \"light\";\n const active = scheme ?? system;\n\n const value = useMemo(\n () => ({\n scheme: active,\n colors: active === \"dark\" ? { ...DARK, ...colors?.dark } : { ...LIGHT, ...colors?.light },\n }),\n [active, colors],\n );\n return {children};\n}\n\n/** The active scheme and its colours. Throws when used outside a ThemeProvider. */\nexport function useTheme(): Theme {\n const value = useContext(ThemeContext);\n if (!value) throw new Error(\"useTheme must be used inside a ThemeProvider\");\n return value;\n}\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/use-color-scheme.json b/public/registry/use-color-scheme.json new file mode 100644 index 0000000..a8b0fa9 --- /dev/null +++ b/public/registry/use-color-scheme.json @@ -0,0 +1,15 @@ +{ + "name": "use-color-scheme", + "title": "useColorScheme", + "category": "Hooks", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/use-color-scheme.ts", + "content": "import { useColorScheme as useSystemScheme } from \"react-native\";\n\nexport type Scheme = \"light\" | \"dark\";\n\n/**\n * The system colour scheme, always \"light\" or \"dark\". React Native's own hook can return null before\n * the platform reports a value; this one falls back to light so styles never see a missing scheme.\n * It re-renders when the user switches appearance.\n */\nexport function useColorScheme(): Scheme {\n return useSystemScheme() === \"dark\" ? \"dark\" : \"light\";\n}\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/use-debounced-value.json b/public/registry/use-debounced-value.json new file mode 100644 index 0000000..16404dc --- /dev/null +++ b/public/registry/use-debounced-value.json @@ -0,0 +1,15 @@ +{ + "name": "use-debounced-value", + "title": "useDebouncedValue", + "category": "Hooks", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/use-debounced-value.ts", + "content": "import { useEffect, useState } from \"react\";\n\n/**\n * A copy of `value` that only updates after it has stopped changing for `delay` milliseconds. Use it\n * to wait out typing before searching: render with the live value, query with the debounced one. The\n * first render returns the value straight away.\n */\nexport function useDebouncedValue(value: T, delay = 300): T {\n const [debounced, setDebounced] = useState(value);\n\n useEffect(() => {\n const id = setTimeout(() => setDebounced(value), delay);\n return () => clearTimeout(id);\n }, [value, delay]);\n\n return debounced;\n}\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/use-haptics.json b/public/registry/use-haptics.json new file mode 100644 index 0000000..d3be6b7 --- /dev/null +++ b/public/registry/use-haptics.json @@ -0,0 +1,15 @@ +{ + "name": "use-haptics", + "title": "useHaptics", + "category": "Hooks", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/use-haptics.ts", + "content": "import { useMemo } from \"react\";\nimport { Vibration } from \"react-native\";\n\nexport interface Haptics {\n /** A light tick, for a press or a selection. */\n tap: () => void;\n /** Two short pulses, for something that worked. */\n success: () => void;\n /** Two firmer pulses, for something that needs attention. */\n warning: () => void;\n /** Three pulses, for something that failed. */\n error: () => void;\n}\n\n/**\n * Touch feedback built on React Native's Vibration, so it needs no extra package. Pass `enabled`\n * false, for example from a settings switch, and every call does nothing. Android follows the\n * patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback\n * swap the bodies for expo-haptics.\n */\nexport function useHaptics(enabled = true): Haptics {\n return useMemo(() => {\n const run = (pattern: number | number[]) => {\n if (enabled) Vibration.vibrate(pattern);\n };\n return {\n tap: () => run(10),\n success: () => run([0, 15, 60, 15]),\n warning: () => run([0, 30, 50, 30]),\n error: () => run([0, 50, 40, 50, 40, 50]),\n };\n }, [enabled]);\n}\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/use-keyboard-height.json b/public/registry/use-keyboard-height.json new file mode 100644 index 0000000..bb29c31 --- /dev/null +++ b/public/registry/use-keyboard-height.json @@ -0,0 +1,15 @@ +{ + "name": "use-keyboard-height", + "title": "useKeyboardHeight", + "category": "Hooks", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/use-keyboard-height.ts", + "content": "import { useEffect, useState } from \"react\";\nimport { Keyboard, Platform } from \"react-native\";\n\n/**\n * The height of the on-screen keyboard, or 0 while it is hidden. On iOS it updates as the keyboard\n * starts to move, so a view can slide up alongside it; on Android it updates once the keyboard has\n * finished appearing. Always 0 on the web, where there is no on-screen keyboard to measure.\n */\nexport function useKeyboardHeight(): number {\n const [height, setHeight] = useState(0);\n\n useEffect(() => {\n const ios = Platform.OS === \"ios\";\n const show = Keyboard.addListener(ios ? \"keyboardWillShow\" : \"keyboardDidShow\", (event) =>\n setHeight(event.endCoordinates.height),\n );\n const hide = Keyboard.addListener(ios ? \"keyboardWillHide\" : \"keyboardDidHide\", () =>\n setHeight(0),\n );\n return () => {\n show.remove();\n hide.remove();\n };\n }, []);\n\n return height;\n}\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/use-reduce-motion.json b/public/registry/use-reduce-motion.json new file mode 100644 index 0000000..69099ba --- /dev/null +++ b/public/registry/use-reduce-motion.json @@ -0,0 +1,15 @@ +{ + "name": "use-reduce-motion", + "title": "useReduceMotion", + "category": "Hooks", + "type": "components:ui", + "platform": "native", + "added": "2026-11-05", + "dependencies": [], + "files": [ + { + "path": "registry/use-reduce-motion.ts", + "content": "import { useEffect, useState } from \"react\";\nimport { AccessibilityInfo } from \"react-native\";\n\n/**\n * Whether the person has asked the system to reduce motion. It reads the setting once on mount and\n * follows later changes, so animated components can skip or shorten their motion. It starts as false\n * until the platform answers.\n */\nexport function useReduceMotion(): boolean {\n const [reduce, setReduce] = useState(false);\n\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const subscription = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => subscription.remove();\n }, []);\n\n return reduce;\n}\n" + } + ] +} \ No newline at end of file diff --git a/src/app/components/[slug]/page.tsx b/src/app/components/[slug]/page.tsx index f6a7a8f..c23471b 100644 --- a/src/app/components/[slug]/page.tsx +++ b/src/app/components/[slug]/page.tsx @@ -16,13 +16,16 @@ interface PageProps { }; } -const TOC_ITEMS = [ +const tocItems = (last: string) => [ { title: "Preview", id: "preview" }, { title: "Installation", id: "installation" }, { title: "Usage", id: "usage" }, - { title: "Props", id: "props" }, + { title: last, id: last.toLowerCase() }, ]; +// Hooks and theme tokens document an API rather than a props table. +const API_ONLY = ["Hooks", "Theme"]; + export async function generateMetadata({ params }: PageProps): Promise { const doc = await getDocBySlug(params.slug); if (!doc) return {}; @@ -30,10 +33,11 @@ export async function generateMetadata({ params }: PageProps): Promise const url = `/components/${params.slug}`; const entry = registry.find((item) => item.name === params.slug); const native = entry ? platformOf(entry) === "native" : false; + const kind = entry?.category === "Hooks" ? "hook" : "component"; const keywords = [ title, ...(native - ? [`${title} React Native`, "React Native component", "Expo component"] + ? [`${title} React Native`, `React Native ${kind}`, `Expo ${kind}`] : [`${title} React`, "React component"]), ...(entry ? [entry.category] : []), ...SITE.keywords.slice(0, 4), @@ -90,7 +94,9 @@ export default async function DocPage({ params }: PageProps) { ); diff --git a/src/app/components/layout.tsx b/src/app/components/layout.tsx index 18d6253..c60f453 100644 --- a/src/app/components/layout.tsx +++ b/src/app/components/layout.tsx @@ -17,6 +17,9 @@ import { Box, PanelsTopLeft, Smartphone, + Webhook, + Layers, + Palette, } from "lucide-react"; import { CATEGORIES, registry, type Category } from "@/registry"; import { isNew, platformOf } from "@/lib/registry"; @@ -31,6 +34,9 @@ const CATEGORY_ICONS: Record = { Sections: PanelsTopLeft, Components: LayoutTemplate, "React Native": Smartphone, + Hooks: Webhook, + Providers: Layers, + Theme: Palette, }; const DOC_CATEGORIES: SidebarCategory[] = [ diff --git a/src/content/docs/mode-provider.mdx b/src/content/docs/mode-provider.mdx new file mode 100644 index 0000000..8d6c13c --- /dev/null +++ b/src/content/docs/mode-provider.mdx @@ -0,0 +1,58 @@ +--- +title: ModeProvider +description: A React Native provider that holds the light, dark or system choice and exposes it through a useMode hook. +--- + +Holds the light, dark or system choice for the whole app. Read it anywhere below with `useMode()`. "system" follows the device and updates when the device changes. The provider keeps the choice in memory only; save it from `onModeChange` and pass it back as `initialMode` to remember it. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add mode-provider +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/mode-provider.tsx`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { Pressable, Text } from "react-native"; +import { ModeProvider, useMode } from "@/components/ui/mode-provider"; + +function ToggleButton() { + const { scheme, toggle } = useMode(); + + return ( + + Currently {scheme} + + ); +} + +export default function App() { + return ( + + + + ); +} +``` + +## Props + +| Prop | Type | Default | Description | +| :------------- | :--------------------- | :--------- | :---------------------------------------------------- | +| `initialMode` | `Mode` | `"system"` | The mode to start in. | +| `onModeChange` | `(mode: Mode) => void` | - | Called whenever the mode changes, so you can save it. | + +`useMode()` returns `mode`, the resolved `scheme`, `setMode(mode)` and `toggle()`, and throws outside a `ModeProvider`. diff --git a/src/content/docs/theme-colors.mdx b/src/content/docs/theme-colors.mdx new file mode 100644 index 0000000..4ed10cf --- /dev/null +++ b/src/content/docs/theme-colors.mdx @@ -0,0 +1,51 @@ +--- +title: Colors +description: Light and dark colour palettes for React Native, named by role, with a helper that adds transparency to any colour. +--- + +Every colour a screen needs, named by role rather than by shade, so light and dark can swap freely. `lightColors` and `darkColors` hold the same nine names, and `withAlpha` turns any #rrggbb colour into an rgba() string for overlays and pressed states. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add theme-colors +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/theme-colors.ts`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { Text, View } from "react-native"; +import { darkColors, lightColors, withAlpha } from "@/components/ui/theme-colors"; + +export default function Banner({ dark }: { dark: boolean }) { + const colors = dark ? darkColors : lightColors; + + return ( + + Heads up + + ); +} +``` + +## API + +| Export | Type | Description | +| :------------ | :--------------------------------------- | :--------------------------------------------------------------- | +| `lightColors` | `ThemeColors` | The light palette. | +| `darkColors` | `ThemeColors` | The dark palette. | +| `withAlpha` | `(hex: string, alpha: number) => string` | Adds transparency to a #rrggbb colour; `alpha` runs from 0 to 1. | + +The names are `background`, `foreground`, `card`, `muted`, `mutedForeground`, `primary`, `primaryForeground`, `border` and `destructive`. diff --git a/src/content/docs/theme-globals.mdx b/src/content/docs/theme-globals.mdx new file mode 100644 index 0000000..a9f65ef --- /dev/null +++ b/src/content/docs/theme-globals.mdx @@ -0,0 +1,49 @@ +--- +title: Globals +description: Shared React Native design tokens for spacing, corner radius, type sizes, font weights and shadows. +--- + +The numbers every screen repeats, in one place. Pick spacing, radius, type size and shadow from a scale instead of typing a value, and the whole app stays consistent when you change one. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add theme-globals +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/theme-globals.ts`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { Text, View } from "react-native"; +import { fontSize, radius, shadow, spacing } from "@/components/ui/theme-globals"; + +export default function Card() { + return ( + + Title + + ); +} +``` + +## API + +| Export | Description | +| :----------- | :--------------------------------------------------------------------------- | +| `spacing` | `xs` 4, `sm` 8, `md` 12, `lg` 16, `xl` 24, `xxl` 32. | +| `radius` | `sm` 8, `md` 12, `lg` 16, `xl` 24, `pill` 999. | +| `fontSize` | `caption`, `body`, `title`, `heading`, `display`, each with its line height. | +| `fontWeight` | `regular`, `medium`, `semibold`, `bold` as string weights. | +| `shadow` | `sm`, `md`, `lg` elevation levels as box shadows. | diff --git a/src/content/docs/theme-provider.mdx b/src/content/docs/theme-provider.mdx new file mode 100644 index 0000000..1872198 --- /dev/null +++ b/src/content/docs/theme-provider.mdx @@ -0,0 +1,69 @@ +--- +title: ThemeProvider +description: A React Native provider that supplies one colour palette to the tree through a useTheme hook, with per-colour overrides. +--- + +Supplies one palette to everything below it. Components call `useTheme()` and read colours by role, so switching between light and dark restyles the whole tree at once with no per-component logic. Override individual colours with `colors`; anything you leave out keeps its default. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add theme-provider +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/theme-provider.tsx`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { Text, View } from "react-native"; +import { ModeProvider, useMode } from "@/components/ui/mode-provider"; +import { ThemeProvider, useTheme } from "@/components/ui/theme-provider"; + +function Card() { + const { colors } = useTheme(); + + return ( + + Hello + + ); +} + +function Themed() { + const { scheme } = useMode(); + + return ( + + + + ); +} + +export default function App() { + return ( + + + + ); +} +``` + +## Props + +| Prop | Type | Default | Description | +| :------- | :--------------------- | :------ | :---------------------------------------------------------------------------------- | +| `scheme` | `"light" \| "dark"` | - | Which palette to use. Leave it out to follow the system. | +| `colors` | `Partial` | - | Overrides for single colours in either palette, as `{ light: {...}, dark: {...} }`. | + +`useTheme()` returns the active `scheme` and its `colors`, and throws outside a `ThemeProvider`. diff --git a/src/content/docs/use-color-scheme.mdx b/src/content/docs/use-color-scheme.mdx new file mode 100644 index 0000000..3a98607 --- /dev/null +++ b/src/content/docs/use-color-scheme.mdx @@ -0,0 +1,43 @@ +--- +title: useColorScheme +description: A React Native hook that returns the system colour scheme as light or dark, never null. +--- + +The system colour scheme, always "light" or "dark". React Native's own hook can return null before the platform reports a value; this one falls back to light so styles never see a missing scheme. It re-renders when the person switches appearance. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add use-color-scheme +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/use-color-scheme.ts`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { View } from "react-native"; +import { useColorScheme } from "@/components/ui/use-color-scheme"; + +export default function Screen() { + const scheme = useColorScheme(); + + return ; +} +``` + +## API + +| Part | Type | Description | +| :------ | :------------------ | :-------------------------------------------- | +| Returns | `"light" \| "dark"` | The scheme in effect, light when none is set. | diff --git a/src/content/docs/use-debounced-value.mdx b/src/content/docs/use-debounced-value.mdx new file mode 100644 index 0000000..407dcca --- /dev/null +++ b/src/content/docs/use-debounced-value.mdx @@ -0,0 +1,51 @@ +--- +title: useDebouncedValue +description: A React Native hook that returns a copy of a value which only updates after it stops changing. +--- + +A copy of `value` that only updates after it has stopped changing for `delay` milliseconds. Use it to wait out typing before searching: render with the live value, query with the debounced one. The first render returns the value straight away. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add use-debounced-value +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/use-debounced-value.ts`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { useEffect, useState } from "react"; +import { TextInput } from "react-native"; +import { useDebouncedValue } from "@/components/ui/use-debounced-value"; + +export default function Search() { + const [query, setQuery] = useState(""); + const debounced = useDebouncedValue(query, 400); + + useEffect(() => { + if (debounced) console.log("search for", debounced); + }, [debounced]); + + return ; +} +``` + +## API + +| Part | Type | Default | Description | +| :------ | :------- | :------ | :----------------------------------------------- | +| `value` | `T` | - | The value to debounce. | +| `delay` | `number` | `300` | Milliseconds the value must stay still. | +| Returns | `T` | - | The value as it was when the delay last ran out. | diff --git a/src/content/docs/use-haptics.mdx b/src/content/docs/use-haptics.mdx new file mode 100644 index 0000000..f8490dc --- /dev/null +++ b/src/content/docs/use-haptics.mdx @@ -0,0 +1,48 @@ +--- +title: useHaptics +description: A React Native hook for touch feedback with tap, success, warning and error patterns that you can switch off. +--- + +Touch feedback built on React Native's Vibration, so it needs no extra package. Pass `enabled` false, for example from a settings switch, and every call does nothing. Android follows the patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback swap the bodies for expo-haptics. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add use-haptics +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/use-haptics.ts`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { Pressable, Text } from "react-native"; +import { useHaptics } from "@/components/ui/use-haptics"; + +export default function SaveButton() { + const haptics = useHaptics(); + + return ( + haptics.success()}> + Save + + ); +} +``` + +## API + +| Part | Type | Default | Description | +| :-------- | :-------- | :------ | :------------------------------------------------------ | +| `enabled` | `boolean` | `true` | Pass false to turn every call into a no-op. | +| Returns | `Haptics` | - | An object with `tap`, `success`, `warning` and `error`. | diff --git a/src/content/docs/use-keyboard-height.mdx b/src/content/docs/use-keyboard-height.mdx new file mode 100644 index 0000000..4b4123d --- /dev/null +++ b/src/content/docs/use-keyboard-height.mdx @@ -0,0 +1,47 @@ +--- +title: useKeyboardHeight +description: A React Native hook that returns the on-screen keyboard height, or 0 while it is hidden. +--- + +The height of the on-screen keyboard, or 0 while it is hidden. On iOS it updates as the keyboard starts to move, so a view can slide up alongside it; on Android it updates once the keyboard has finished appearing. It is always 0 on the web, where there is no on-screen keyboard to measure. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add use-keyboard-height +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/use-keyboard-height.ts`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { TextInput, View } from "react-native"; +import { useKeyboardHeight } from "@/components/ui/use-keyboard-height"; + +export default function Composer() { + const keyboard = useKeyboardHeight(); + + return ( + + + + ); +} +``` + +## API + +| Part | Type | Description | +| :------ | :------- | :------------------------------------------- | +| Returns | `number` | Keyboard height in points, or 0 when hidden. | diff --git a/src/content/docs/use-reduce-motion.mdx b/src/content/docs/use-reduce-motion.mdx new file mode 100644 index 0000000..cc4d6ea --- /dev/null +++ b/src/content/docs/use-reduce-motion.mdx @@ -0,0 +1,55 @@ +--- +title: useReduceMotion +description: A React Native hook that reports whether the system asks to reduce motion and follows later changes. +--- + +Whether the person has asked the system to reduce motion. It reads the setting once on mount and follows later changes, so animated components can skip or shorten their motion. It starts as false until the platform answers. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. + + + +## Installation + +### CLI + +```bash +npx @modus-ui/cli add use-reduce-motion +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/use-reduce-motion.ts`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { useEffect, useRef } from "react"; +import { Animated } from "react-native"; +import { useReduceMotion } from "@/components/ui/use-reduce-motion"; + +export default function Fade({ show }: { show: boolean }) { + const reduce = useReduceMotion(); + const opacity = useRef(new Animated.Value(0)).current; + + useEffect(() => { + if (reduce) opacity.setValue(show ? 1 : 0); + else + Animated.timing(opacity, { + toValue: show ? 1 : 0, + duration: 200, + useNativeDriver: true, + }).start(); + }, [show, reduce, opacity]); + + return ; +} +``` + +## API + +| Part | Type | Description | +| :------ | :-------- | :------------------------------------------ | +| Returns | `boolean` | True when the system asks to reduce motion. | diff --git a/src/lib/registry.ts b/src/lib/registry.ts index cffdb0d..405d4dd 100644 --- a/src/lib/registry.ts +++ b/src/lib/registry.ts @@ -1,6 +1,11 @@ import fs from "fs"; import path from "path"; -import { registry, type RegistryItem } from "@/registry"; +import { registry, type Category, type RegistryItem } from "@/registry"; + +/** Hooks, providers and theme tokens are not visual components: they have no colours or motion of their own. */ +export const UTILITY_CATEGORIES: readonly Category[] = ["Hooks", "Providers", "Theme"]; + +export const isUtility = (item: RegistryItem) => UTILITY_CATEGORIES.includes(item.category); const NEW_FOR_MS = 30 * 24 * 60 * 60 * 1000; diff --git a/src/registry/demos.ts b/src/registry/demos.ts index daf5ac7..694c969 100644 --- a/src/registry/demos.ts +++ b/src/registry/demos.ts @@ -309,6 +309,15 @@ export const demos: Record = { "compare-slider": dynamic(() => import("./compare-slider-demo"), { ssr: false }), "hold-confirm": dynamic(() => import("./hold-confirm-demo"), { ssr: false }), "select-menu": dynamic(() => import("./select-menu-demo"), { ssr: false }), + "use-color-scheme": dynamic(() => import("./use-color-scheme-demo"), { ssr: false }), + "use-keyboard-height": dynamic(() => import("./use-keyboard-height-demo"), { ssr: false }), + "use-haptics": dynamic(() => import("./use-haptics-demo"), { ssr: false }), + "use-reduce-motion": dynamic(() => import("./use-reduce-motion-demo"), { ssr: false }), + "use-debounced-value": dynamic(() => import("./use-debounced-value-demo"), { ssr: false }), + "mode-provider": dynamic(() => import("./mode-provider-demo"), { ssr: false }), + "theme-provider": dynamic(() => import("./theme-provider-demo"), { ssr: false }), + "theme-colors": dynamic(() => import("./theme-colors-demo"), { ssr: false }), + "theme-globals": dynamic(() => import("./theme-globals-demo"), { ssr: false }), }; /** Looks up a demo by a slug from the URL, which may not be a known component. */ diff --git a/src/registry/index.ts b/src/registry/index.ts index b2acd3f..f5a679a 100644 --- a/src/registry/index.ts +++ b/src/registry/index.ts @@ -13,6 +13,9 @@ export const CATEGORIES = [ "Sections", "Components", "React Native", + "Hooks", + "Providers", + "Theme", ] as const; export type Category = (typeof CATEGORIES)[number]; @@ -5004,6 +5007,96 @@ export const registry = [ dependencies: [], files: ["registry/select-menu.tsx"], }, + { + name: "use-color-scheme", + title: "useColorScheme", + category: "Hooks", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/use-color-scheme.ts"], + }, + { + name: "use-keyboard-height", + title: "useKeyboardHeight", + category: "Hooks", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/use-keyboard-height.ts"], + }, + { + name: "use-haptics", + title: "useHaptics", + category: "Hooks", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/use-haptics.ts"], + }, + { + name: "use-reduce-motion", + title: "useReduceMotion", + category: "Hooks", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/use-reduce-motion.ts"], + }, + { + name: "use-debounced-value", + title: "useDebouncedValue", + category: "Hooks", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/use-debounced-value.ts"], + }, + { + name: "mode-provider", + title: "ModeProvider", + category: "Providers", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/mode-provider.tsx"], + }, + { + name: "theme-provider", + title: "ThemeProvider", + category: "Providers", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/theme-provider.tsx"], + }, + { + name: "theme-colors", + title: "Colors", + category: "Theme", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/theme-colors.ts"], + }, + { + name: "theme-globals", + title: "Globals", + category: "Theme", + type: "components:ui", + platform: "native", + added: "2026-11-05", + dependencies: [], + files: ["registry/theme-globals.ts"], + }, ] as const satisfies readonly RegistryItem[]; export type ComponentName = (typeof registry)[number]["name"]; diff --git a/src/registry/mode-provider-demo.tsx b/src/registry/mode-provider-demo.tsx new file mode 100644 index 0000000..09bc2f1 --- /dev/null +++ b/src/registry/mode-provider-demo.tsx @@ -0,0 +1,90 @@ +"use client"; + +import { Pressable, Text, View } from "react-native"; +import { ModeProvider, useMode, type Mode } from "./mode-provider"; +import { NativeStage } from "./native-stage"; + +const MODES: Mode[] = ["light", "dark", "system"]; + +function Panel() { + const { mode, scheme, setMode, toggle } = useMode(); + const dark = scheme === "dark"; + + return ( + + {(c) => ( + + + useMode() + + mode: {mode} · scheme: {scheme} + + + + {MODES.map((m) => ( + setMode(m)} + style={{ + paddingVertical: 10, + paddingHorizontal: 16, + borderRadius: 10, + backgroundColor: mode === m ? c.primary : c.muted, + }} + > + + {m} + + + ))} + + + toggle() + + + )} + + ); +} + +export function ModeProviderDemo() { + return ( + + + + ); +} + +export default ModeProviderDemo; diff --git a/src/registry/mode-provider.tsx b/src/registry/mode-provider.tsx new file mode 100644 index 0000000..b311c2c --- /dev/null +++ b/src/registry/mode-provider.tsx @@ -0,0 +1,61 @@ +import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from "react"; +import { useColorScheme } from "react-native"; + +export type Mode = "light" | "dark" | "system"; + +export interface ModeValue { + /** What the person chose: light, dark, or follow the system. */ + mode: Mode; + /** The scheme actually in effect, with "system" resolved to light or dark. */ + scheme: "light" | "dark"; + setMode: (mode: Mode) => void; + /** Switches to the opposite of the scheme in effect. */ + toggle: () => void; +} + +const ModeContext = createContext(null); + +export interface ModeProviderProps { + children: ReactNode; + /** The mode to start in. */ + initialMode?: Mode; + /** Called whenever the mode changes, so you can save it. */ + onModeChange?: (mode: Mode) => void; +} + +/** + * Holds the light, dark or system choice for the whole app. Read it anywhere below with `useMode()`. + * "system" follows the device and updates when the device changes. The provider keeps the choice in + * memory only; save it from `onModeChange` and pass it back as `initialMode` to remember it. + */ +export function ModeProvider({ + children, + initialMode = "system", + onModeChange, +}: ModeProviderProps) { + const system = useColorScheme() === "dark" ? "dark" : "light"; + const [mode, setModeState] = useState(initialMode); + const scheme = mode === "system" ? system : mode; + + const setMode = useCallback( + (next: Mode) => { + setModeState(next); + onModeChange?.(next); + }, + [onModeChange], + ); + const toggle = useCallback( + () => setMode(scheme === "dark" ? "light" : "dark"), + [scheme, setMode], + ); + + const value = useMemo(() => ({ mode, scheme, setMode, toggle }), [mode, scheme, setMode, toggle]); + return {children}; +} + +/** The current mode and scheme. Throws when used outside a ModeProvider, so a missing one is caught early. */ +export function useMode(): ModeValue { + const value = useContext(ModeContext); + if (!value) throw new Error("useMode must be used inside a ModeProvider"); + return value; +} diff --git a/src/registry/theme-colors-demo.tsx b/src/registry/theme-colors-demo.tsx new file mode 100644 index 0000000..e69a3c0 --- /dev/null +++ b/src/registry/theme-colors-demo.tsx @@ -0,0 +1,62 @@ +"use client"; + +import { Text, View } from "react-native"; +import { darkColors, lightColors, withAlpha, type ThemeColors } from "./theme-colors"; +import { NativeStage } from "./native-stage"; + +function Palette({ title, colors, ink }: { title: string; colors: ThemeColors; ink: string }) { + return ( + + {title} + {(Object.keys(colors) as (keyof ThemeColors)[]).map((name) => ( + + + {name} + + ))} + + ); +} + +export function ThemeColorsDemo() { + return ( + + {(c) => ( + + Colors + + + + + + {[1, 0.7, 0.4, 0.15].map((a) => ( + + ))} + + + withAlpha(primary, 1 → 0.15) + + + )} + + ); +} + +export default ThemeColorsDemo; diff --git a/src/registry/theme-colors.ts b/src/registry/theme-colors.ts new file mode 100644 index 0000000..49320b5 --- /dev/null +++ b/src/registry/theme-colors.ts @@ -0,0 +1,48 @@ +/** Every colour a screen needs, by role rather than by shade, so light and dark can swap freely. */ +export interface ThemeColors { + background: string; + foreground: string; + card: string; + muted: string; + mutedForeground: string; + primary: string; + primaryForeground: string; + border: string; + destructive: string; +} + +export const lightColors: ThemeColors = { + background: "#ffffff", + foreground: "#111827", + card: "#f9fafb", + muted: "#f3f4f6", + mutedForeground: "#6b7280", + primary: "#4f46e5", + primaryForeground: "#ffffff", + border: "#e5e7eb", + destructive: "#dc2626", +}; + +export const darkColors: ThemeColors = { + background: "#0b0b0f", + foreground: "#f9fafb", + card: "#16161d", + muted: "#1f1f29", + mutedForeground: "#9ca3af", + primary: "#818cf8", + primaryForeground: "#0b0b0f", + border: "#2a2a36", + destructive: "#f87171", +}; + +/** + * Adds transparency to a #rrggbb colour and returns an rgba() string. `alpha` runs from 0 to 1. Use it + * for overlays and pressed states so they stay tied to the palette instead of being hard-coded. + */ +export function withAlpha(hex: string, alpha: number): string { + const value = hex.replace("#", ""); + const r = parseInt(value.slice(0, 2), 16); + const g = parseInt(value.slice(2, 4), 16); + const b = parseInt(value.slice(4, 6), 16); + return `rgba(${r}, ${g}, ${b}, ${Math.max(0, Math.min(1, alpha))})`; +} diff --git a/src/registry/theme-globals-demo.tsx b/src/registry/theme-globals-demo.tsx new file mode 100644 index 0000000..b8e2152 --- /dev/null +++ b/src/registry/theme-globals-demo.tsx @@ -0,0 +1,90 @@ +"use client"; + +import { Text, View } from "react-native"; +import { fontSize, fontWeight, radius, shadow, spacing } from "./theme-globals"; +import { NativeStage } from "./native-stage"; + +export function ThemeGlobalsDemo() { + return ( + + {(c) => ( + + + Globals + + + spacing + + {Object.entries(spacing).map(([name, value]) => ( + + + {name} + + ))} + + + + radius + + {Object.entries(radius).map(([name, value]) => ( + + {name} + + ))} + + + + fontSize + {Object.entries(fontSize).map(([name, style]) => ( + + {name} + + ))} + + + shadow + + {Object.entries(shadow).map(([name, value]) => ( + + {name} + + ))} + + + + )} + + ); +} + +export default ThemeGlobalsDemo; diff --git a/src/registry/theme-globals.ts b/src/registry/theme-globals.ts new file mode 100644 index 0000000..eacafc7 --- /dev/null +++ b/src/registry/theme-globals.ts @@ -0,0 +1,24 @@ +/** Space between things, in points. Pick from the scale instead of typing a number. */ +export const spacing = { xs: 4, sm: 8, md: 12, lg: 16, xl: 24, xxl: 32 } as const; + +/** Corner radii, from slightly rounded to a full pill. */ +export const radius = { sm: 8, md: 12, lg: 16, xl: 24, pill: 999 } as const; + +/** Type sizes with matching line heights. */ +export const fontSize = { + caption: { fontSize: 12, lineHeight: 16 }, + body: { fontSize: 16, lineHeight: 24 }, + title: { fontSize: 20, lineHeight: 28 }, + heading: { fontSize: 28, lineHeight: 34 }, + display: { fontSize: 40, lineHeight: 46 }, +} as const; + +/** Font weights as the string values React Native expects. */ +export const fontWeight = { regular: "400", medium: "500", semibold: "600", bold: "700" } as const; + +/** Elevation levels as box shadows. */ +export const shadow = { + sm: "0 1px 3px rgba(0, 0, 0, 0.12)", + md: "0 4px 12px rgba(0, 0, 0, 0.16)", + lg: "0 12px 32px rgba(0, 0, 0, 0.22)", +} as const; diff --git a/src/registry/theme-provider-demo.tsx b/src/registry/theme-provider-demo.tsx new file mode 100644 index 0000000..009cc85 --- /dev/null +++ b/src/registry/theme-provider-demo.tsx @@ -0,0 +1,77 @@ +"use client"; + +import { Pressable, Text, View } from "react-native"; +import { ThemeProvider, useTheme } from "./theme-provider"; +import { ModeProvider, useMode } from "./mode-provider"; +import { NativeStage } from "./native-stage"; + +function Card() { + const { colors } = useTheme(); + const { toggle, scheme } = useMode(); + + return ( + + + + Themed card + + + Every colour here comes from useTheme(), not from the card itself. + + + + Switch to {scheme === "dark" ? "light" : "dark"} + + + + + ); +} + +function Themed() { + const { scheme } = useMode(); + return ( + + + + ); +} + +export function ThemeProviderDemo() { + return ( + + {() => ( + + + + )} + + ); +} + +export default ThemeProviderDemo; diff --git a/src/registry/theme-provider.tsx b/src/registry/theme-provider.tsx new file mode 100644 index 0000000..68050b9 --- /dev/null +++ b/src/registry/theme-provider.tsx @@ -0,0 +1,84 @@ +import { createContext, useContext, useMemo, type ReactNode } from "react"; +import { useColorScheme } from "react-native"; + +export interface ThemePalette { + background: string; + foreground: string; + card: string; + muted: string; + mutedForeground: string; + primary: string; + primaryForeground: string; + border: string; + destructive: string; +} + +export interface ThemeColors { + light: Partial; + dark: Partial; +} + +const LIGHT: ThemePalette = { + background: "#ffffff", + foreground: "#111827", + card: "#f9fafb", + muted: "#f3f4f6", + mutedForeground: "#6b7280", + primary: "#4f46e5", + primaryForeground: "#ffffff", + border: "#e5e7eb", + destructive: "#dc2626", +}; + +const DARK: ThemePalette = { + background: "#0b0b0f", + foreground: "#f9fafb", + card: "#16161d", + muted: "#1f1f29", + mutedForeground: "#9ca3af", + primary: "#818cf8", + primaryForeground: "#0b0b0f", + border: "#2a2a36", + destructive: "#f87171", +}; + +export interface Theme { + scheme: "light" | "dark"; + colors: ThemePalette; +} + +const ThemeContext = createContext(null); + +export interface ThemeProviderProps { + children: ReactNode; + /** Which palette to use. Leave it out to follow the system; pass `useMode().scheme` to follow your own switch. */ + scheme?: "light" | "dark"; + /** Overrides for single colours in either palette. */ + colors?: Partial; +} + +/** + * Supplies one palette to everything below it. Components call `useTheme()` and read colours by role, + * so switching between light and dark restyles the whole tree at once with no per-component logic. + * Override individual colours with `colors`; anything you leave out keeps its default. + */ +export function ThemeProvider({ children, scheme, colors }: ThemeProviderProps) { + const system = useColorScheme() === "dark" ? "dark" : "light"; + const active = scheme ?? system; + + const value = useMemo( + () => ({ + scheme: active, + colors: active === "dark" ? { ...DARK, ...colors?.dark } : { ...LIGHT, ...colors?.light }, + }), + [active, colors], + ); + return {children}; +} + +/** The active scheme and its colours. Throws when used outside a ThemeProvider. */ +export function useTheme(): Theme { + const value = useContext(ThemeContext); + if (!value) throw new Error("useTheme must be used inside a ThemeProvider"); + return value; +} diff --git a/src/registry/use-color-scheme-demo.tsx b/src/registry/use-color-scheme-demo.tsx new file mode 100644 index 0000000..06743e4 --- /dev/null +++ b/src/registry/use-color-scheme-demo.tsx @@ -0,0 +1,47 @@ +"use client"; + +import { Text, View } from "react-native"; +import { useColorScheme } from "./use-color-scheme"; +import { NativeStage } from "./native-stage"; + +function Readout() { + const scheme = useColorScheme(); + return ( + + {(c) => ( + + useColorScheme() returned + + + {scheme} + + + + It follows your device. Change your system appearance and the card flips. + + + )} + + ); +} + +export function UseColorSchemeDemo() { + return ; +} + +export default UseColorSchemeDemo; diff --git a/src/registry/use-color-scheme.ts b/src/registry/use-color-scheme.ts new file mode 100644 index 0000000..60838d9 --- /dev/null +++ b/src/registry/use-color-scheme.ts @@ -0,0 +1,12 @@ +import { useColorScheme as useSystemScheme } from "react-native"; + +export type Scheme = "light" | "dark"; + +/** + * The system colour scheme, always "light" or "dark". React Native's own hook can return null before + * the platform reports a value; this one falls back to light so styles never see a missing scheme. + * It re-renders when the user switches appearance. + */ +export function useColorScheme(): Scheme { + return useSystemScheme() === "dark" ? "dark" : "light"; +} diff --git a/src/registry/use-debounced-value-demo.tsx b/src/registry/use-debounced-value-demo.tsx new file mode 100644 index 0000000..d12487c --- /dev/null +++ b/src/registry/use-debounced-value-demo.tsx @@ -0,0 +1,50 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { Text, TextInput, View } from "react-native"; +import { useDebouncedValue } from "./use-debounced-value"; +import { NativeStage } from "./native-stage"; + +export function UseDebouncedValueDemo() { + const [query, setQuery] = useState(""); + const debounced = useDebouncedValue(query, 500); + const [searches, setSearches] = useState(0); + + useEffect(() => { + if (debounced) setSearches((n) => n + 1); + }, [debounced]); + + return ( + + {(c) => ( + + Search + + Live value: {query || "-"} + + Debounced value: {debounced || "-"} + + Searches run: {searches} + + )} + + ); +} + +export default UseDebouncedValueDemo; diff --git a/src/registry/use-debounced-value.ts b/src/registry/use-debounced-value.ts new file mode 100644 index 0000000..65d81b5 --- /dev/null +++ b/src/registry/use-debounced-value.ts @@ -0,0 +1,17 @@ +import { useEffect, useState } from "react"; + +/** + * A copy of `value` that only updates after it has stopped changing for `delay` milliseconds. Use it + * to wait out typing before searching: render with the live value, query with the debounced one. The + * first render returns the value straight away. + */ +export function useDebouncedValue(value: T, delay = 300): T { + const [debounced, setDebounced] = useState(value); + + useEffect(() => { + const id = setTimeout(() => setDebounced(value), delay); + return () => clearTimeout(id); + }, [value, delay]); + + return debounced; +} diff --git a/src/registry/use-haptics-demo.tsx b/src/registry/use-haptics-demo.tsx new file mode 100644 index 0000000..8d60acb --- /dev/null +++ b/src/registry/use-haptics-demo.tsx @@ -0,0 +1,72 @@ +"use client"; + +import { useState } from "react"; +import { Pressable, Text, View } from "react-native"; +import { useHaptics } from "./use-haptics"; +import { NativeStage } from "./native-stage"; + +export function UseHapticsDemo() { + const [enabled, setEnabled] = useState(true); + const [last, setLast] = useState("Nothing yet"); + const haptics = useHaptics(enabled); + + return ( + + {(c) => { + const button = (name: "tap" | "success" | "warning" | "error") => ( + { + haptics[name](); + setLast(enabled ? name : `${name} (off)`); + }} + style={{ + paddingVertical: 12, + paddingHorizontal: 16, + borderRadius: 12, + backgroundColor: c.primary, + }} + > + {name} + + ); + return ( + + Haptics + + {(["tap", "success", "warning", "error"] as const).map(button)} + + setEnabled(!enabled)} + style={{ + alignSelf: "flex-start", + paddingVertical: 8, + paddingHorizontal: 14, + borderRadius: 10, + borderWidth: 1, + borderColor: c.border, + }} + > + + Enabled: {enabled ? "on" : "off"} + + + + Last fired: {last}. You will feel it on a phone. + + + ); + }} + + ); +} + +export default UseHapticsDemo; diff --git a/src/registry/use-haptics.ts b/src/registry/use-haptics.ts new file mode 100644 index 0000000..cca21c8 --- /dev/null +++ b/src/registry/use-haptics.ts @@ -0,0 +1,33 @@ +import { useMemo } from "react"; +import { Vibration } from "react-native"; + +export interface Haptics { + /** A light tick, for a press or a selection. */ + tap: () => void; + /** Two short pulses, for something that worked. */ + success: () => void; + /** Two firmer pulses, for something that needs attention. */ + warning: () => void; + /** Three pulses, for something that failed. */ + error: () => void; +} + +/** + * Touch feedback built on React Native's Vibration, so it needs no extra package. Pass `enabled` + * false, for example from a settings switch, and every call does nothing. Android follows the + * patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback + * swap the bodies for expo-haptics. + */ +export function useHaptics(enabled = true): Haptics { + return useMemo(() => { + const run = (pattern: number | number[]) => { + if (enabled) Vibration.vibrate(pattern); + }; + return { + tap: () => run(10), + success: () => run([0, 15, 60, 15]), + warning: () => run([0, 30, 50, 30]), + error: () => run([0, 50, 40, 50, 40, 50]), + }; + }, [enabled]); +} diff --git a/src/registry/use-keyboard-height-demo.tsx b/src/registry/use-keyboard-height-demo.tsx new file mode 100644 index 0000000..7f35cb1 --- /dev/null +++ b/src/registry/use-keyboard-height-demo.tsx @@ -0,0 +1,50 @@ +"use client"; + +import { Text, TextInput, View } from "react-native"; +import { useKeyboardHeight } from "./use-keyboard-height"; +import { NativeStage } from "./native-stage"; + +export function UseKeyboardHeightDemo() { + const height = useKeyboardHeight(); + + return ( + + {(c) => ( + + + useKeyboardHeight() returned + + + {height} + + + On a phone this is the keyboard's height while it is open, so you can lift a bar + above it. It stays 0 on the web. + + + + + + )} + + ); +} + +export default UseKeyboardHeightDemo; diff --git a/src/registry/use-keyboard-height.ts b/src/registry/use-keyboard-height.ts new file mode 100644 index 0000000..fb5600e --- /dev/null +++ b/src/registry/use-keyboard-height.ts @@ -0,0 +1,27 @@ +import { useEffect, useState } from "react"; +import { Keyboard, Platform } from "react-native"; + +/** + * The height of the on-screen keyboard, or 0 while it is hidden. On iOS it updates as the keyboard + * starts to move, so a view can slide up alongside it; on Android it updates once the keyboard has + * finished appearing. Always 0 on the web, where there is no on-screen keyboard to measure. + */ +export function useKeyboardHeight(): number { + const [height, setHeight] = useState(0); + + useEffect(() => { + const ios = Platform.OS === "ios"; + const show = Keyboard.addListener(ios ? "keyboardWillShow" : "keyboardDidShow", (event) => + setHeight(event.endCoordinates.height), + ); + const hide = Keyboard.addListener(ios ? "keyboardWillHide" : "keyboardDidHide", () => + setHeight(0), + ); + return () => { + show.remove(); + hide.remove(); + }; + }, []); + + return height; +} diff --git a/src/registry/use-reduce-motion-demo.tsx b/src/registry/use-reduce-motion-demo.tsx new file mode 100644 index 0000000..82ab8a6 --- /dev/null +++ b/src/registry/use-reduce-motion-demo.tsx @@ -0,0 +1,78 @@ +"use client"; + +import { useEffect, useRef } from "react"; +import { Animated, Easing, Text, View } from "react-native"; +import { useReduceMotion } from "./use-reduce-motion"; +import { NativeStage } from "./native-stage"; + +export function UseReduceMotionDemo() { + const reduce = useReduceMotion(); + const t = useRef(new Animated.Value(0)).current; + + useEffect(() => { + if (reduce) { + t.setValue(0); + return; + } + const loop = Animated.loop( + Animated.sequence([ + Animated.timing(t, { + toValue: 1, + duration: 900, + easing: Easing.inOut(Easing.quad), + useNativeDriver: false, + }), + Animated.timing(t, { + toValue: 0, + duration: 900, + easing: Easing.inOut(Easing.quad), + useNativeDriver: false, + }), + ]), + ); + loop.start(); + return () => loop.stop(); + }, [reduce, t]); + + return ( + + {(c) => ( + + useReduceMotion() returned + + {String(reduce)} + + + + + + The dot slides back and forth, and stays put when your system asks to reduce motion. + + + )} + + ); +} + +export default UseReduceMotionDemo; diff --git a/src/registry/use-reduce-motion.ts b/src/registry/use-reduce-motion.ts new file mode 100644 index 0000000..1c37293 --- /dev/null +++ b/src/registry/use-reduce-motion.ts @@ -0,0 +1,19 @@ +import { useEffect, useState } from "react"; +import { AccessibilityInfo } from "react-native"; + +/** + * Whether the person has asked the system to reduce motion. It reads the setting once on mount and + * follows later changes, so animated components can skip or shorten their motion. It starts as false + * until the platform answers. + */ +export function useReduceMotion(): boolean { + const [reduce, setReduce] = useState(false); + + useEffect(() => { + AccessibilityInfo.isReduceMotionEnabled().then(setReduce); + const subscription = AccessibilityInfo.addEventListener("reduceMotionChanged", setReduce); + return () => subscription.remove(); + }, []); + + return reduce; +} diff --git a/tests/component-colors.test.ts b/tests/component-colors.test.ts index 5491db3..4a04c65 100644 --- a/tests/component-colors.test.ts +++ b/tests/component-colors.test.ts @@ -2,6 +2,7 @@ import { readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { registry, type RegistryItem } from "@/registry"; +import { isUtility } from "@/lib/registry"; /** * Components must take their colours from the theme tokens so they follow the @@ -73,7 +74,10 @@ describe("component colours", () => { }); describe("native component colours", () => { - const native = (registry as readonly RegistryItem[]).filter((item) => item.platform === "native"); + // Hooks, providers and theme tokens have no colours of their own to override. + const native = (registry as readonly RegistryItem[]).filter( + (item) => item.platform === "native" && !isUtility(item), + ); it.each(native)("$name can be themed through a colors prop", (item) => { const source = readFileSync(join(process.cwd(), "src", item.files[0]), "utf8"); diff --git a/tests/prop-docs.test.ts b/tests/prop-docs.test.ts index de1b32d..4b7645a 100644 --- a/tests/prop-docs.test.ts +++ b/tests/prop-docs.test.ts @@ -4,6 +4,9 @@ import ts from "typescript"; import { describe, expect, it } from "vitest"; import { registry } from "@/registry"; +// Hooks and theme tokens are plain functions and constants, documented under `## API`, not as components with props. +const API_ONLY = new Set(["Hooks", "Theme"]); + /** * Keeps each doc's `## Props` table in step with the component's real props, * using the TypeScript compiler API (the approach of React Bits' @@ -42,7 +45,9 @@ const config = ts.getParsedCommandLineOfConfigFile( {}, { ...ts.sys, onUnRecoverableConfigFileDiagnostic: () => {} }, )!; -const files = registry.map((item) => path.join(SRC, item.files[0])); +const files = registry + .filter((item) => !API_ONLY.has(item.category)) + .map((item) => path.join(SRC, item.files[0])); const program = ts.createProgram(files, { ...config.options, incremental: false }); const checker = program.getTypeChecker(); @@ -184,38 +189,41 @@ const normalize = (value: string) => .replace(/^`(.*)`$/, "$1") .replace(/^(["'])(.*)\1$/, "$2"); -describe.each(registry)("$name props table", (item) => { - const props = readComponent(path.join(SRC, item.files[0]), pascal(item.name)); - const mdx = fs.readFileSync(path.join(SRC, "content/docs", `${item.name}.mdx`), "utf8"); - const rows = readTable(mdx); - - // A component that takes no props needs no table. - const takesProps = [...props.declared].some((prop) => !UNDOCUMENTED.has(prop)); - it("has a props table if it takes props", () => { - if (takesProps) expect(rows, "missing `## Props` table").toBeDefined(); - }); - if (!rows) return; - const documented = new Set(rows.map((row) => row.prop)); - - it("only documents real props", () => { - expect(rows.map((row) => row.prop).filter((prop) => !props.accepted.has(prop))).toEqual([]); - }); - - it("documents every prop the component declares", () => { - expect( - [...props.declared].filter((prop) => !documented.has(prop) && !UNDOCUMENTED.has(prop)), - ).toEqual([]); - }); - - it("documents the real scalar defaults", () => { - const mismatches = rows.flatMap((row) => { - if (!props.defaults.has(row.prop)) return []; - // Docs write a newline in a string default as the escape `\n`. - const actual = String(props.defaults.get(row.prop)).replace(/\n/g, "\\n"); - return normalize(row.default) === actual - ? [] - : [`${row.prop}: doc ${row.default}, code ${actual}`]; +describe.each(registry.filter((item) => !API_ONLY.has(item.category)))( + "$name props table", + (item) => { + const props = readComponent(path.join(SRC, item.files[0]), pascal(item.name)); + const mdx = fs.readFileSync(path.join(SRC, "content/docs", `${item.name}.mdx`), "utf8"); + const rows = readTable(mdx); + + // A component that takes no props needs no table. + const takesProps = [...props.declared].some((prop) => !UNDOCUMENTED.has(prop)); + it("has a props table if it takes props", () => { + if (takesProps) expect(rows, "missing `## Props` table").toBeDefined(); + }); + if (!rows) return; + const documented = new Set(rows.map((row) => row.prop)); + + it("only documents real props", () => { + expect(rows.map((row) => row.prop).filter((prop) => !props.accepted.has(prop))).toEqual([]); + }); + + it("documents every prop the component declares", () => { + expect( + [...props.declared].filter((prop) => !documented.has(prop) && !UNDOCUMENTED.has(prop)), + ).toEqual([]); + }); + + it("documents the real scalar defaults", () => { + const mismatches = rows.flatMap((row) => { + if (!props.defaults.has(row.prop)) return []; + // Docs write a newline in a string default as the escape `\n`. + const actual = String(props.defaults.get(row.prop)).replace(/\n/g, "\\n"); + return normalize(row.default) === actual + ? [] + : [`${row.prop}: doc ${row.default}, code ${actual}`]; + }); + expect(mismatches).toEqual([]); }); - expect(mismatches).toEqual([]); - }); -}); + }, +); diff --git a/tests/reduced-motion.test.ts b/tests/reduced-motion.test.ts index aa0085e..cfefea9 100644 --- a/tests/reduced-motion.test.ts +++ b/tests/reduced-motion.test.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import path from "node:path"; import { describe, expect, it } from "vitest"; import { registry, type RegistryItem } from "@/registry"; +import { isUtility } from "@/lib/registry"; const PATTERN = { web: /useReducedMotion\(|motion-reduce:/, @@ -12,11 +13,15 @@ const PATTERN = { const read = (file: string) => fs.readFileSync(path.join(process.cwd(), "src", file), "utf8"); describe("reduced motion", () => { - it.each(registry)("$name consults prefers-reduced-motion", (item) => { - const source = read(item.files[0]); - // useReducedMotion for JS-driven motion; Tailwind's motion-reduce: for CSS-only motion. - expect(source).toMatch(PATTERN[(item as RegistryItem).platform ?? "web"]); - }); + // Hooks, providers and theme tokens draw nothing, so there is no motion to reduce. + it.each(registry.filter((item) => !isUtility(item as RegistryItem)))( + "$name consults prefers-reduced-motion", + (item) => { + const source = read(item.files[0]); + // useReducedMotion for JS-driven motion; Tailwind's motion-reduce: for CSS-only motion. + expect(source).toMatch(PATTERN[(item as RegistryItem).platform ?? "web"]); + }, + ); it.each(registry)("$name uses the value it reads", (item) => { const source = read(item.files[0]); From 4a13e8fd9ab25801926f3d2349538caa4e2059a5 Mon Sep 17 00:00:00 2001 From: kasimkazmi Date: Thu, 5 Nov 2026 12:08:28 -0500 Subject: [PATCH 2/2] feat: Make hooks, providers and theme work in React and React Native, and split React Native by purpose Co-Authored-By: Claude Sonnet 5.5 --- AGENTS.md | 3 +- README.md | 33 ++- packages/cli/src/add.test.ts | 41 ++++ packages/cli/src/commands/add.ts | 31 ++- packages/cli/src/project.ts | 6 + packages/cli/src/registry.ts | 2 + packages/mcp/src/catalogue.ts | 6 +- public/registry/action-button.json | 2 +- public/registry/action-tray.json | 2 +- public/registry/avatar-stack.json | 2 +- public/registry/battery-meter.json | 2 +- public/registry/bubble-tab-bar.json | 2 +- public/registry/calendar-strip.json | 2 +- public/registry/card-field.json | 2 +- public/registry/cart-quantity.json | 2 +- public/registry/chat-bubble.json | 2 +- public/registry/chip-input.json | 2 +- public/registry/choice-chips.json | 2 +- public/registry/code-boxes.json | 2 +- public/registry/compare-slider.json | 2 +- public/registry/composer-bar.json | 2 +- public/registry/confirm-dialog.json | 2 +- public/registry/contact-index.json | 2 +- public/registry/count-badge.json | 2 +- public/registry/countdown-timer.json | 2 +- public/registry/data-table.json | 2 +- public/registry/drag-list.json | 2 +- public/registry/empty-state.json | 2 +- public/registry/expand-card.json | 2 +- public/registry/expand-search.json | 2 +- public/registry/expandable-text.json | 2 +- public/registry/extended-fab.json | 2 +- public/registry/fan-menu.json | 2 +- public/registry/flick-toast.json | 2 +- public/registry/float-field.json | 2 +- public/registry/fold-panel.json | 2 +- public/registry/gauge-meter.json | 2 +- public/registry/glide-segments.json | 2 +- public/registry/hold-confirm.json | 2 +- public/registry/hold-stepper.json | 2 +- public/registry/hue-picker.json | 2 +- public/registry/index.json | 200 ++++++++-------- public/registry/intro-pager.json | 2 +- public/registry/like-button.json | 2 +- public/registry/live-dot.json | 2 +- public/registry/long-press-menu.json | 2 +- public/registry/marquee-ticker.json | 2 +- public/registry/mode-provider.json | 6 +- public/registry/mode-toggle.json | 2 +- public/registry/month-grid.json | 2 +- public/registry/mood-picker.json | 2 +- public/registry/notice-banner.json | 2 +- public/registry/page-dots.json | 2 +- public/registry/parallax-header.json | 2 +- public/registry/password-field.json | 2 +- public/registry/password-meter.json | 2 +- public/registry/pin-pad.json | 2 +- public/registry/poll-bars.json | 2 +- public/registry/pull-refresh.json | 2 +- public/registry/radio-group.json | 2 +- public/registry/range-slider.json | 2 +- public/registry/rating-histogram.json | 2 +- public/registry/reaction-bar.json | 2 +- public/registry/resend-button.json | 2 +- public/registry/ring-meter.json | 2 +- public/registry/roll-number.json | 2 +- public/registry/select-grid.json | 2 +- public/registry/select-menu.json | 2 +- public/registry/setting-list.json | 2 +- public/registry/shimmer-block.json | 2 +- public/registry/side-drawer.json | 2 +- public/registry/slide-confirm.json | 2 +- public/registry/slide-switch.json | 2 +- public/registry/snap-carousel.json | 2 +- public/registry/snap-sheet.json | 2 +- public/registry/spark-bars.json | 2 +- public/registry/spin-loader.json | 2 +- public/registry/star-rating.json | 2 +- public/registry/step-slider.json | 2 +- public/registry/step-tracker.json | 2 +- public/registry/story-bars.json | 2 +- public/registry/stripe-progress.json | 2 +- public/registry/suggest-input.json | 2 +- public/registry/swatch-picker.json | 2 +- public/registry/swipe-actions.json | 2 +- public/registry/swipe-deck.json | 2 +- public/registry/tab-pager.json | 2 +- public/registry/task-checklist.json | 2 +- public/registry/theme-colors.json | 2 +- public/registry/theme-globals.json | 2 +- public/registry/theme-provider.json | 6 +- public/registry/tick-box.json | 2 +- public/registry/timeline-list.json | 2 +- public/registry/tip-popover.json | 2 +- public/registry/typing-dots.json | 2 +- public/registry/undo-snackbar.json | 2 +- public/registry/use-color-scheme.json | 6 +- public/registry/use-debounced-value.json | 4 +- public/registry/use-haptics.json | 6 +- public/registry/use-keyboard-height.json | 6 +- public/registry/use-reduce-motion.json | 6 +- public/registry/value-slider.json | 2 +- public/registry/wave-bars.json | 2 +- public/registry/wheel-picker.json | 2 +- scripts/build-registry.ts | 7 +- src/app/components/layout.tsx | 16 +- src/components/component-preview-client.tsx | 46 +++- src/components/component-preview.tsx | 22 ++ src/components/platform-icon.tsx | 40 +++- src/components/registry-demo.tsx | 6 +- src/content/docs/mode-provider.mdx | 6 +- src/content/docs/theme-colors.mdx | 6 +- src/content/docs/theme-globals.mdx | 6 +- src/content/docs/theme-provider.mdx | 6 +- src/content/docs/use-color-scheme.mdx | 6 +- src/content/docs/use-debounced-value.mdx | 6 +- src/content/docs/use-haptics.mdx | 6 +- src/content/docs/use-keyboard-height.mdx | 6 +- src/content/docs/use-reduce-motion.mdx | 6 +- src/lib/agent-docs.ts | 7 +- src/lib/registry.ts | 18 +- src/registry/demos.ts | 15 ++ src/registry/index.ts | 216 +++++++++--------- src/registry/mode-provider-demo.tsx | 2 +- src/registry/mode-provider.native.tsx | 61 +++++ src/registry/mode-provider.tsx | 30 ++- src/registry/theme-provider-demo.tsx | 4 +- src/registry/theme-provider.native.tsx | 84 +++++++ src/registry/theme-provider.tsx | 22 +- src/registry/use-color-scheme-demo.tsx | 2 +- src/registry/use-color-scheme.native.ts | 12 + src/registry/use-color-scheme.ts | 24 +- src/registry/use-debounced-value.ts | 2 + src/registry/use-haptics-demo.tsx | 2 +- src/registry/use-haptics.native.ts | 33 +++ src/registry/use-haptics.ts | 12 +- src/registry/use-keyboard-height-demo.tsx | 2 +- src/registry/use-keyboard-height.native.ts | 27 +++ src/registry/use-keyboard-height.ts | 32 +-- src/registry/use-reduce-motion-demo.tsx | 2 +- src/registry/use-reduce-motion.native.ts | 19 ++ src/registry/use-reduce-motion.ts | 33 +-- src/registry/web-demos/mode-provider.tsx | 53 +++++ src/registry/web-demos/theme-provider.tsx | 54 +++++ src/registry/web-demos/use-color-scheme.tsx | 22 ++ src/registry/web-demos/use-haptics.tsx | 47 ++++ .../web-demos/use-keyboard-height.tsx | 25 ++ src/registry/web-demos/use-reduce-motion.tsx | 27 +++ tests/component-colors.test.ts | 9 +- tests/platforms.test.ts | 38 +++ tests/reduced-motion.test.ts | 4 +- 151 files changed, 1238 insertions(+), 433 deletions(-) create mode 100644 src/registry/mode-provider.native.tsx create mode 100644 src/registry/theme-provider.native.tsx create mode 100644 src/registry/use-color-scheme.native.ts create mode 100644 src/registry/use-haptics.native.ts create mode 100644 src/registry/use-keyboard-height.native.ts create mode 100644 src/registry/use-reduce-motion.native.ts create mode 100644 src/registry/web-demos/mode-provider.tsx create mode 100644 src/registry/web-demos/theme-provider.tsx create mode 100644 src/registry/web-demos/use-color-scheme.tsx create mode 100644 src/registry/web-demos/use-haptics.tsx create mode 100644 src/registry/web-demos/use-keyboard-height.tsx create mode 100644 src/registry/web-demos/use-reduce-motion.tsx create mode 100644 tests/platforms.test.ts diff --git a/AGENTS.md b/AGENTS.md index ef8320c..99d8365 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,4 +13,5 @@ When working in this repository, you MUST follow these rules: 3. **CLI**: Documentation must instruct users to use `npx @modus-ui/cli add `; write the npm form in the docs and the site shows pnpm, yarn and bun tabs for it (`src/lib/install.ts`). Do NOT use `npx shadcn`, `npx react-ui-component` or the unscoped `npx modus-ui` (that npm package belongs to someone else). 4. **Registration**: Start new components with `pnpm new:component --name --category `. Register a component in exactly two places: its entry (name, title, category, dependencies, files) in `src/registry/index.ts` and its demo in `src/registry/demos.ts`. The sidebar, components index and previews are derived from these; never hand-edit lists there. 5. **Theme colors**: Tokens are bare HSL channels, so use `hsl(var(--primary))`, never `var(--primary)`. On a ``, resolve colors through `getComputedStyle` first. -6. **React Native components**: Components in the `React Native` category are React Native (Expo), with `platform: "native"` and `dependencies: []` in the registry. Import only from `react-native`; use `Animated` and `PanResponder`, not `framer-motion`, `className` or `cn()`. Take colors through a `colors?: Partial<...>` prop with plain defaults (there are no CSS variables in React Native), and read the system setting with `AccessibilityInfo.isReduceMotionEnabled()`. Use `NATIVE_DRIVER = Platform.OS !== "web"` and `userSelect: "none"` on draggable surfaces so the docs preview works with a mouse. The demo wraps its content in `NativeStage` (`src/registry/native-stage.tsx`), which draws a phone frame around it; its `height` is the screen area between the status bar and the home indicator and is registered with `dynamic(..., { ssr: false })` in `demos.ts`. +6. **React Native components**: Components in the `React Native · …` categories (Inputs, Buttons, Navigation, Overlays, Feedback, Progress, Data) are React Native (Expo), with `platform: "native"` and `dependencies: []` in the registry. Import only from `react-native`; use `Animated` and `PanResponder`, not `framer-motion`, `className` or `cn()`. Take colors through a `colors?: Partial<...>` prop with plain defaults (there are no CSS variables in React Native), and read the system setting with `AccessibilityInfo.isReduceMotionEnabled()`. Use `NATIVE_DRIVER = Platform.OS !== "web"` and `userSelect: "none"` on draggable surfaces so the docs preview works with a mouse. The demo wraps its content in `NativeStage` (`src/registry/native-stage.tsx`), which draws a phone frame around it; its `height` is the screen area between the status bar and the home indicator and is registered with `dynamic(..., { ssr: false })` in `demos.ts`. +7. **Hooks, providers and theme tokens**: These live in the `Hooks`, `Providers` and `Theme` categories with `platform: "both"`. When React and React Native need different code, `files` lists the React file first and a `name.native.ts(x)` file second (Metro resolves it by itself), the React file starts with `"use client"`, and a demo for each goes in `demos.ts` and `src/registry/web-demos/`. When one file works on both, list just that file. They are exempt from the `colors` prop and reduced-motion rules and document an `## API` section instead of `## Props` (providers keep `## Props`). diff --git a/README.md b/README.md index c3a4cf2..6243cc2 100644 --- a/README.md +++ b/README.md @@ -92,18 +92,27 @@ For Cursor, Windsurf or VS Code setup, see [`packages/mcp`](packages/mcp). The d ## Components -| Category | Components | -| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| **Navigation** | Liquid Tabs, Flowing Menu, Morphing Navbar, Floating Dock, Notch Footer, Process Stepper | -| **Actions** | Magnet, Magic Button, Animated Button, Pulse Button | -| **Data Display** | Bounce Cards, Masonry Grid, Animated List, Kinetic Carousel, Expandable Showcase, Focus Card, Rotating Card, Tilt Card | -| **Backgrounds** | Cursor Grid, Waves, Letter Glitch, Aurora Background, Circuit Background, Grid Motion | -| **Typography** | Scroll Velocity, Text Pressure, True Focus, Gradient Text, Blur Text, Split Text, Decrypted Text, Shimmer Text, Floating Text | -| **Components** | Scratch to Reveal, Stack, Star Border, Tilted Card, Pixel Card, Click Spark, Spotlight Card, Border Glow | -| **React Native** | Swipe Actions, Snap Sheet, Glide Segments, Swipe Deck, Fan Menu, Pin Pad, Flick Toast, Fold Panel, Snap Carousel, Slide Switch, Shimmer Block, Parallax Header, Bubble Tab Bar, Roll Number, Star Rating, Value Slider, Expand Search, Intro Pager, Drag List, Long Press Menu, Slide Confirm, Calendar Strip, Step Tracker, Chip Input, Typing Dots, Marquee Ticker, Choice Chips, Hold Stepper, Action Tray, Confirm Dialog, Code Boxes, Hue Picker, Tab Pager, Wheel Picker, Avatar Stack, Stripe Progress, Range Slider, Tick Box, Notice Banner, Side Drawer, Expand Card, Suggest Input, Reaction Bar, Ring Meter, Count Badge, Float Field, Month Grid, Chat Bubble, Composer Bar, Pull Refresh, Story Bars, Setting List, Live Dot, Action Button, Spin Loader, Radio Group, Mode Toggle, Tip Popover, Data Table, Wave Bars, Page Dots, Password Meter, Timeline List, Empty State, Rating Histogram, Countdown Timer, Contact Index, Select Grid, Poll Bars, Card Field, Step Slider, Cart Quantity, Password Field, Resend Button, Gauge Meter, Undo Snackbar, Mood Picker, Expandable Text, Extended FAB, Swatch Picker, Like Button, Task Checklist, Spark Bars, Battery Meter, Compare Slider, Hold Confirm, Select Menu | -| **Hooks** | useColorScheme, useKeyboardHeight, useHaptics, useReduceMotion, useDebouncedValue | -| **Providers** | ModeProvider, ThemeProvider | -| **Theme** | Colors, Globals | +| Category | Components | +| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **Navigation** | Liquid Tabs, Flowing Menu, Morphing Navbar, Floating Dock, Notch Footer, Process Stepper | +| **Actions** | Magnet, Magic Button, Animated Button, Pulse Button | +| **Data Display** | Bounce Cards, Masonry Grid, Animated List, Kinetic Carousel, Expandable Showcase, Focus Card, Rotating Card, Tilt Card | +| **Backgrounds** | Cursor Grid, Waves, Letter Glitch, Aurora Background, Circuit Background, Grid Motion | +| **Typography** | Scroll Velocity, Text Pressure, True Focus, Gradient Text, Blur Text, Split Text, Decrypted Text, Shimmer Text, Floating Text | +| **Components** | Scratch to Reveal, Stack, Star Border, Tilted Card, Pixel Card, Click Spark, Spotlight Card, Border Glow | +| **React Native · Data** | Swipe Actions, Swipe Deck, Fold Panel, Snap Carousel, Parallax Header, Roll Number, Drag List, Marquee Ticker, Avatar Stack, Expand Card, Chat Bubble, Setting List, Data Table, Timeline List, Rating Histogram, Contact Index, Poll Bars, Expandable Text, Task Checklist, Spark Bars, Compare Slider | +| **React Native · Overlays** | Snap Sheet, Long Press Menu, Action Tray, Confirm Dialog, Tip Popover | +| **React Native · Navigation** | Glide Segments, Bubble Tab Bar, Intro Pager, Step Tracker, Tab Pager, Side Drawer, Page Dots | +| **React Native · Buttons** | Fan Menu, Slide Confirm, Reaction Bar, Action Button, Resend Button, Extended FAB, Like Button, Hold Confirm | +| **React Native · Inputs** | Pin Pad, Slide Switch, Star Rating, Value Slider, Expand Search, Calendar Strip, Chip Input, Choice Chips, Hold Stepper, Code Boxes, Hue Picker, Wheel Picker, Range Slider, Tick Box, Suggest Input, Float Field, Month Grid, Composer Bar, Radio Group, Mode Toggle, Select Grid, Card Field, Step Slider, Cart Quantity, Password Field, Mood Picker, Swatch Picker, Select Menu | +| **React Native · Feedback** | Flick Toast, Notice Banner, Count Badge, Live Dot, Pull Refresh, Empty State, Undo Snackbar | +| **React Native · Progress** | Shimmer Block, Typing Dots, Stripe Progress, Ring Meter, Story Bars, Spin Loader, Wave Bars, Password Meter, Countdown Timer, Gauge Meter, Battery Meter | +| **Hooks** | useColorScheme, useKeyboardHeight, useHaptics, useReduceMotion, useDebouncedValue | +| **Providers** | ModeProvider, ThemeProvider | +| **Theme** | Colors, Globals | +| **Hooks** | useColorScheme, useKeyboardHeight, useHaptics, useReduceMotion, useDebouncedValue | +| **Providers** | ModeProvider, ThemeProvider | +| **Theme** | Colors, Globals | **React Native** components are Expo files that import only `react-native`, so they need no extra packages. Install them the same way (`npx @modus-ui/cli add swipe-actions`); the docs preview them live in the browser through react-native-web. diff --git a/packages/cli/src/add.test.ts b/packages/cli/src/add.test.ts index f10991e..92a9106 100644 --- a/packages/cli/src/add.test.ts +++ b/packages/cli/src/add.test.ts @@ -12,6 +12,14 @@ const catalogue = { categories: ["Text"], renamed: { "fuzzy-text": "blur-text" }, components: [ + { + name: "use-flag", + title: "useFlag", + category: "Hooks", + platform: "both", + description: "d", + dependencies: [], + }, { name: "blur-text", title: "Blur Text", @@ -30,6 +38,20 @@ const catalogue = { }; function component(name: string) { + if (name === "use-flag") { + return { + name, + title: name, + category: "Hooks", + type: "registry:ui", + platform: "both", + dependencies: [], + files: [ + { path: "registry/use-flag.ts", content: "// react\n" }, + { path: "registry/use-flag.native.ts", content: "// react native\n" }, + ], + }; + } return { name, title: name, @@ -70,6 +92,25 @@ afterEach(async () => { await rm(dir, { recursive: true, force: true }); }); +describe("add for both platforms", () => { + it("installs the React Native file in an Expo app, with no cn helper or class packages", async () => { + await project({ dependencies: { expo: "55.0.0", "react-native": "0.88.0" } }); + await add(["use-flag"], { cwd: dir, run, log }); + expect(await readFile(join(dir, "components/ui/use-flag.ts"), "utf8")).toBe( + "// react native\n", + ); + expect(existsSync(join(dir, "lib/utils.ts"))).toBe(false); + expect(run).not.toHaveBeenCalled(); + }); + + it("installs the React file in a web app, also without the cn helper", async () => { + await project({ dependencies: { next: "14.0.0" } }); + await add(["use-flag"], { cwd: dir, run, log }); + expect(await readFile(join(dir, "components/ui/use-flag.ts"), "utf8")).toBe("// react\n"); + expect(existsSync(join(dir, "lib/utils.ts"))).toBe(false); + }); +}); + describe("add", () => { it("resolves a renamed component to its current name", async () => { await project(); diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index 75b126f..6f32ac4 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -10,6 +10,7 @@ import { findUtilsFile, installCommand, installedDependencies, + isReactNativeProject, readPackageJson, utilsFileTarget, } from "../project.js"; @@ -77,10 +78,16 @@ export async function add(names: string[], options: AddOptions): Promise { const componentsDir = options.path ? resolve(cwd, options.path) : defaultComponentsDir(cwd); const deps = new Set(); let wrote = false; + let usesCn = false; + const native = isReactNativeProject(pkg); for (const component of components) { - const file = component.files[0]; + // An item for both platforms ships a React file first and may add a `.native` one; an Expo or + // React Native app takes the `.native` file, anywhere else gets the React file. + const file = + (native && component.files.find((f) => /\.native\.tsx?$/.test(f.path))) || component.files[0]; if (!file) throw new Error(`Registry entry for ${component.name} has no files.`); - const target = join(componentsDir, `${component.name}.tsx`); + const extension = file.path.endsWith(".ts") ? ".ts" : ".tsx"; + const target = join(componentsDir, `${component.name}${extension}`); const shown = relative(cwd, target); if (existsSync(target) && !options.overwrite) { log(`Skipped ${shown} (already exists, pass --overwrite to replace it)`); @@ -90,20 +97,24 @@ export async function add(names: string[], options: AddOptions): Promise { await writeFile(target, file.content); log(`Added ${shown}`); wrote = true; + if (!component.platform || component.platform === "web") usesCn = true; for (const dep of component.dependencies) deps.add(dep); } if (!wrote) return; - // Every component imports cn from @/lib/utils, which needs clsx and tailwind-merge. - if (!findUtilsFile(cwd)) { - const utils = utilsFileTarget(cwd); - await mkdir(dirname(utils), { recursive: true }); - await writeFile(utils, CN_SOURCE); - log(`Created ${relative(cwd, utils)} with the cn() helper`); + // Web components import cn from @/lib/utils, which needs clsx and tailwind-merge. React Native files + // and the hooks, providers and theme tokens use neither. + if (usesCn) { + if (!findUtilsFile(cwd)) { + const utils = utilsFileTarget(cwd); + await mkdir(dirname(utils), { recursive: true }); + await writeFile(utils, CN_SOURCE); + log(`Created ${relative(cwd, utils)} with the cn() helper`); + } + deps.add("clsx"); + deps.add("tailwind-merge"); } - deps.add("clsx"); - deps.add("tailwind-merge"); const installed = installedDependencies(pkg); const missing = [...deps].filter((d) => !installed.has(d)).sort(); diff --git a/packages/cli/src/project.ts b/packages/cli/src/project.ts index a972267..cb5f9d1 100644 --- a/packages/cli/src/project.ts +++ b/packages/cli/src/project.ts @@ -29,6 +29,12 @@ export function installedDependencies(pkg: Record): Set return names; } +/** True for an Expo or React Native app, which wants the `.native` file of an item that has one. */ +export function isReactNativeProject(pkg: Record): boolean { + const deps = installedDependencies(pkg); + return deps.has("react-native") || deps.has("expo"); +} + export function hasSrcDir(cwd: string): boolean { return existsSync(join(cwd, "src")); } diff --git a/packages/cli/src/registry.ts b/packages/cli/src/registry.ts index c721148..91f1169 100644 --- a/packages/cli/src/registry.ts +++ b/packages/cli/src/registry.ts @@ -21,6 +21,8 @@ export interface RegistryComponent { title: string; category: string; type: string; + /** "native" is React Native only, "both" works in React and React Native, anything else is web. */ + platform?: "web" | "native" | "both"; dependencies: string[]; files: { path: string; content: string }[]; } diff --git a/packages/mcp/src/catalogue.ts b/packages/mcp/src/catalogue.ts index aac1000..f7d42b0 100644 --- a/packages/mcp/src/catalogue.ts +++ b/packages/mcp/src/catalogue.ts @@ -9,8 +9,8 @@ export interface CatalogueComponent { name: string; title: string; category: string; - /** "native" components are React Native (Expo); everything else is a web component. */ - platform?: "web" | "native"; + /** "native" components are React Native (Expo), "both" work in React and React Native; everything else is web. */ + platform?: "web" | "native" | "both"; description: string; dependencies: string[]; } @@ -99,7 +99,7 @@ export function fallbackMarkdown( "", entry.description, "", - `Category: ${entry.category}. ${entry.platform === "native" ? "Platform: React Native (Expo). " : ""}Docs: ${origin}/components/${entry.name}`, + `Category: ${entry.category}. ${entry.platform === "native" ? "Platform: React Native (Expo). " : entry.platform === "both" ? "Platform: React and React Native. " : ""}Docs: ${origin}/components/${entry.name}`, "", "## Installation", "", diff --git a/public/registry/action-button.json b/public/registry/action-button.json index 3d3e0c6..80172a6 100644 --- a/public/registry/action-button.json +++ b/public/registry/action-button.json @@ -1,7 +1,7 @@ { "name": "action-button", "title": "Action Button", - "category": "React Native", + "category": "React Native · Buttons", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/action-tray.json b/public/registry/action-tray.json index ac8c95a..f53937e 100644 --- a/public/registry/action-tray.json +++ b/public/registry/action-tray.json @@ -1,7 +1,7 @@ { "name": "action-tray", "title": "Action Tray", - "category": "React Native", + "category": "React Native · Overlays", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/avatar-stack.json b/public/registry/avatar-stack.json index a94aedc..46ba209 100644 --- a/public/registry/avatar-stack.json +++ b/public/registry/avatar-stack.json @@ -1,7 +1,7 @@ { "name": "avatar-stack", "title": "Avatar Stack", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/battery-meter.json b/public/registry/battery-meter.json index eaa0fd1..b1b2986 100644 --- a/public/registry/battery-meter.json +++ b/public/registry/battery-meter.json @@ -1,7 +1,7 @@ { "name": "battery-meter", "title": "Battery Meter", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/bubble-tab-bar.json b/public/registry/bubble-tab-bar.json index 18a02f1..d945a0f 100644 --- a/public/registry/bubble-tab-bar.json +++ b/public/registry/bubble-tab-bar.json @@ -1,7 +1,7 @@ { "name": "bubble-tab-bar", "title": "Bubble Tab Bar", - "category": "React Native", + "category": "React Native · Navigation", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/calendar-strip.json b/public/registry/calendar-strip.json index 88eaed0..74a1822 100644 --- a/public/registry/calendar-strip.json +++ b/public/registry/calendar-strip.json @@ -1,7 +1,7 @@ { "name": "calendar-strip", "title": "Calendar Strip", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/card-field.json b/public/registry/card-field.json index 664d7d9..59d900c 100644 --- a/public/registry/card-field.json +++ b/public/registry/card-field.json @@ -1,7 +1,7 @@ { "name": "card-field", "title": "Card Field", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/cart-quantity.json b/public/registry/cart-quantity.json index 62dd4c8..c7bca58 100644 --- a/public/registry/cart-quantity.json +++ b/public/registry/cart-quantity.json @@ -1,7 +1,7 @@ { "name": "cart-quantity", "title": "Cart Quantity", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/chat-bubble.json b/public/registry/chat-bubble.json index bf1e635..4d60a6e 100644 --- a/public/registry/chat-bubble.json +++ b/public/registry/chat-bubble.json @@ -1,7 +1,7 @@ { "name": "chat-bubble", "title": "Chat Bubble", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/chip-input.json b/public/registry/chip-input.json index acdef3a..d4b1377 100644 --- a/public/registry/chip-input.json +++ b/public/registry/chip-input.json @@ -1,7 +1,7 @@ { "name": "chip-input", "title": "Chip Input", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/choice-chips.json b/public/registry/choice-chips.json index 20c9623..f2d8cf8 100644 --- a/public/registry/choice-chips.json +++ b/public/registry/choice-chips.json @@ -1,7 +1,7 @@ { "name": "choice-chips", "title": "Choice Chips", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/code-boxes.json b/public/registry/code-boxes.json index 91ac2d1..5bfb963 100644 --- a/public/registry/code-boxes.json +++ b/public/registry/code-boxes.json @@ -1,7 +1,7 @@ { "name": "code-boxes", "title": "Code Boxes", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/compare-slider.json b/public/registry/compare-slider.json index eda0bf7..d14de25 100644 --- a/public/registry/compare-slider.json +++ b/public/registry/compare-slider.json @@ -1,7 +1,7 @@ { "name": "compare-slider", "title": "Compare Slider", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/composer-bar.json b/public/registry/composer-bar.json index 655ec71..53a6854 100644 --- a/public/registry/composer-bar.json +++ b/public/registry/composer-bar.json @@ -1,7 +1,7 @@ { "name": "composer-bar", "title": "Composer Bar", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/confirm-dialog.json b/public/registry/confirm-dialog.json index 61ee2fb..68f873f 100644 --- a/public/registry/confirm-dialog.json +++ b/public/registry/confirm-dialog.json @@ -1,7 +1,7 @@ { "name": "confirm-dialog", "title": "Confirm Dialog", - "category": "React Native", + "category": "React Native · Overlays", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/contact-index.json b/public/registry/contact-index.json index 0e8e0e8..97517a0 100644 --- a/public/registry/contact-index.json +++ b/public/registry/contact-index.json @@ -1,7 +1,7 @@ { "name": "contact-index", "title": "Contact Index", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/count-badge.json b/public/registry/count-badge.json index e11a3fe..02c05d2 100644 --- a/public/registry/count-badge.json +++ b/public/registry/count-badge.json @@ -1,7 +1,7 @@ { "name": "count-badge", "title": "Count Badge", - "category": "React Native", + "category": "React Native · Feedback", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/countdown-timer.json b/public/registry/countdown-timer.json index 9aacc50..26bdc2b 100644 --- a/public/registry/countdown-timer.json +++ b/public/registry/countdown-timer.json @@ -1,7 +1,7 @@ { "name": "countdown-timer", "title": "Countdown Timer", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/data-table.json b/public/registry/data-table.json index bb34e30..5a599e1 100644 --- a/public/registry/data-table.json +++ b/public/registry/data-table.json @@ -1,7 +1,7 @@ { "name": "data-table", "title": "Data Table", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/drag-list.json b/public/registry/drag-list.json index 059dbba..542748f 100644 --- a/public/registry/drag-list.json +++ b/public/registry/drag-list.json @@ -1,7 +1,7 @@ { "name": "drag-list", "title": "Drag List", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/empty-state.json b/public/registry/empty-state.json index 5e6b5a0..15ed54b 100644 --- a/public/registry/empty-state.json +++ b/public/registry/empty-state.json @@ -1,7 +1,7 @@ { "name": "empty-state", "title": "Empty State", - "category": "React Native", + "category": "React Native · Feedback", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/expand-card.json b/public/registry/expand-card.json index d235409..fb3ceac 100644 --- a/public/registry/expand-card.json +++ b/public/registry/expand-card.json @@ -1,7 +1,7 @@ { "name": "expand-card", "title": "Expand Card", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/expand-search.json b/public/registry/expand-search.json index 6d714eb..e2cbb5e 100644 --- a/public/registry/expand-search.json +++ b/public/registry/expand-search.json @@ -1,7 +1,7 @@ { "name": "expand-search", "title": "Expand Search", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/expandable-text.json b/public/registry/expandable-text.json index 275c2e3..f759620 100644 --- a/public/registry/expandable-text.json +++ b/public/registry/expandable-text.json @@ -1,7 +1,7 @@ { "name": "expandable-text", "title": "Expandable Text", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/extended-fab.json b/public/registry/extended-fab.json index d0981dc..1e2bfc1 100644 --- a/public/registry/extended-fab.json +++ b/public/registry/extended-fab.json @@ -1,7 +1,7 @@ { "name": "extended-fab", "title": "Extended FAB", - "category": "React Native", + "category": "React Native · Buttons", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/fan-menu.json b/public/registry/fan-menu.json index 746b4d2..b5f2475 100644 --- a/public/registry/fan-menu.json +++ b/public/registry/fan-menu.json @@ -1,7 +1,7 @@ { "name": "fan-menu", "title": "Fan Menu", - "category": "React Native", + "category": "React Native · Buttons", "type": "components:ui", "platform": "native", "added": "2026-10-30", diff --git a/public/registry/flick-toast.json b/public/registry/flick-toast.json index 834384e..efea47f 100644 --- a/public/registry/flick-toast.json +++ b/public/registry/flick-toast.json @@ -1,7 +1,7 @@ { "name": "flick-toast", "title": "Flick Toast", - "category": "React Native", + "category": "React Native · Feedback", "type": "components:ui", "platform": "native", "added": "2026-11-01", diff --git a/public/registry/float-field.json b/public/registry/float-field.json index 64fed9e..358319d 100644 --- a/public/registry/float-field.json +++ b/public/registry/float-field.json @@ -1,7 +1,7 @@ { "name": "float-field", "title": "Float Field", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/fold-panel.json b/public/registry/fold-panel.json index 4733143..f07a7a2 100644 --- a/public/registry/fold-panel.json +++ b/public/registry/fold-panel.json @@ -1,7 +1,7 @@ { "name": "fold-panel", "title": "Fold Panel", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-01", diff --git a/public/registry/gauge-meter.json b/public/registry/gauge-meter.json index baf3b89..14c326d 100644 --- a/public/registry/gauge-meter.json +++ b/public/registry/gauge-meter.json @@ -1,7 +1,7 @@ { "name": "gauge-meter", "title": "Gauge Meter", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/glide-segments.json b/public/registry/glide-segments.json index 1c68d0e..096fc75 100644 --- a/public/registry/glide-segments.json +++ b/public/registry/glide-segments.json @@ -1,7 +1,7 @@ { "name": "glide-segments", "title": "Glide Segments", - "category": "React Native", + "category": "React Native · Navigation", "type": "components:ui", "platform": "native", "added": "2026-10-30", diff --git a/public/registry/hold-confirm.json b/public/registry/hold-confirm.json index 2ca7b8e..6006f27 100644 --- a/public/registry/hold-confirm.json +++ b/public/registry/hold-confirm.json @@ -1,7 +1,7 @@ { "name": "hold-confirm", "title": "Hold Confirm", - "category": "React Native", + "category": "React Native · Buttons", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/hold-stepper.json b/public/registry/hold-stepper.json index 33cbcfb..b7c4bc9 100644 --- a/public/registry/hold-stepper.json +++ b/public/registry/hold-stepper.json @@ -1,7 +1,7 @@ { "name": "hold-stepper", "title": "Hold Stepper", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/hue-picker.json b/public/registry/hue-picker.json index 82177f6..0fed2a1 100644 --- a/public/registry/hue-picker.json +++ b/public/registry/hue-picker.json @@ -1,7 +1,7 @@ { "name": "hue-picker", "title": "Hue Picker", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/index.json b/public/registry/index.json index aff6551..dd0e64d 100644 --- a/public/registry/index.json +++ b/public/registry/index.json @@ -11,7 +11,13 @@ "Typography", "Sections", "Components", - "React Native", + "React Native · Inputs", + "React Native · Buttons", + "React Native · Navigation", + "React Native · Overlays", + "React Native · Feedback", + "React Native · Progress", + "React Native · Data", "Hooks", "Providers", "Theme" @@ -2607,7 +2613,7 @@ { "name": "swipe-actions", "title": "Swipe Actions", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native list row that slides left to reveal action buttons, with rubber-banding, flick detection and screen reader actions.", "dependencies": [] @@ -2615,7 +2621,7 @@ { "name": "snap-sheet", "title": "Snap Sheet", - "category": "React Native", + "category": "React Native · Overlays", "platform": "native", "description": "A React Native bottom sheet with snap points, flick momentum, dismiss-by-drag and an adjustable handle for screen readers.", "dependencies": [] @@ -2623,7 +2629,7 @@ { "name": "glide-segments", "title": "Glide Segments", - "category": "React Native", + "category": "React Native · Navigation", "platform": "native", "description": "A React Native segmented control whose thumb glides between options on a spring and stretches as it travels.", "dependencies": [] @@ -2631,7 +2637,7 @@ { "name": "swipe-deck", "title": "Swipe Deck", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native card stack swiped away one at a time, with tilt, a rising next card, like and pass stamps, and screen reader actions.", "dependencies": [] @@ -2639,7 +2645,7 @@ { "name": "fan-menu", "title": "Fan Menu", - "category": "React Native", + "category": "React Native · Buttons", "platform": "native", "description": "A React Native floating button that fans its actions out along an arc, springing them out one after another.", "dependencies": [] @@ -2647,7 +2653,7 @@ { "name": "pin-pad", "title": "Pin Pad", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native numeric keypad for PINs and passcodes, with popping dots, a shake on a wrong PIN and spoken progress.", "dependencies": [] @@ -2655,7 +2661,7 @@ { "name": "flick-toast", "title": "Flick Toast", - "category": "React Native", + "category": "React Native · Feedback", "platform": "native", "description": "A React Native stack of toasts you flick away, with a countdown line that waits while you hold, older toasts scaled back, and screen reader dismiss.", "dependencies": [] @@ -2663,7 +2669,7 @@ { "name": "fold-panel", "title": "Fold Panel", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native accordion whose panels grow to the measured height of their content, with a turning chevron and screen reader state.", "dependencies": [] @@ -2671,7 +2677,7 @@ { "name": "snap-carousel", "title": "Snap Carousel", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native carousel that settles on one card at a time, with neighbors that shrink and fade and dots that stretch to follow.", "dependencies": [] @@ -2679,7 +2685,7 @@ { "name": "slide-switch", "title": "Slide Switch", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native switch whose thumb can be dragged as well as tapped, stretching while held and settling on the nearer side.", "dependencies": [] @@ -2687,7 +2693,7 @@ { "name": "shimmer-block", "title": "Shimmer Block", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native loading placeholder with a soft highlight that sweeps across it, stacked lines that shimmer together, and one spoken \"Loading\" for the whole block.", "dependencies": [] @@ -2695,7 +2701,7 @@ { "name": "parallax-header", "title": "Parallax Header", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native scroll view whose hero stretches on overscroll, drifts at half speed, and collapses into a compact title bar.", "dependencies": [] @@ -2703,7 +2709,7 @@ { "name": "bubble-tab-bar", "title": "Bubble Tab Bar", - "category": "React Native", + "category": "React Native · Navigation", "platform": "native", "description": "A React Native bottom tab bar where a rounded pill slides behind the selected tab and the selected tab opens to show its label.", "dependencies": [] @@ -2711,7 +2717,7 @@ { "name": "roll-number", "title": "Roll Number", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native odometer whose digits roll to their new value, last digit first, with separators, decimals and negative numbers.", "dependencies": [] @@ -2719,7 +2725,7 @@ { "name": "star-rating", "title": "Star Rating", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native star rating you can tap or scrub, with half stars, popping fills and adjustable screen reader support.", "dependencies": [] @@ -2727,7 +2733,7 @@ { "name": "value-slider", "title": "Value Slider", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native slider with a value bubble, step snapping, tap-to-jump and adjustable screen reader support.", "dependencies": [] @@ -2735,7 +2741,7 @@ { "name": "expand-search", "title": "Expand Search", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native search field that starts as a round button and springs open to full width, with a clear button and a Cancel that folds it away.", "dependencies": [] @@ -2743,7 +2749,7 @@ { "name": "intro-pager", "title": "Intro Pager", - "category": "React Native", + "category": "React Native · Navigation", "platform": "native", "description": "A swipeable React Native onboarding pager where the art drifts against the text, the dots stretch, and Next turns into the final action.", "dependencies": [] @@ -2751,7 +2757,7 @@ { "name": "drag-list", "title": "Drag List", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native reorderable list where you drag a grip and the other rows spring out of the way, with move actions for screen readers.", "dependencies": [] @@ -2759,7 +2765,7 @@ { "name": "long-press-menu", "title": "Long Press Menu", - "category": "React Native", + "category": "React Native · Overlays", "platform": "native", "description": "A React Native menu that springs out from a trigger you press and hold, with every item also exposed as an accessibility action.", "dependencies": [] @@ -2767,7 +2773,7 @@ { "name": "slide-confirm", "title": "Slide Confirm", - "category": "React Native", + "category": "React Native · Buttons", "platform": "native", "description": "A React Native slide-to-confirm control. Drag the thumb to the end to confirm, release early to spring back, and confirm with a screen reader or keyboard action.", "dependencies": [] @@ -2775,7 +2781,7 @@ { "name": "calendar-strip", "title": "Calendar Strip", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native horizontal strip of days with a pill that glides to the selected day, event dots, and full dates read out to screen readers.", "dependencies": [] @@ -2783,7 +2789,7 @@ { "name": "step-tracker", "title": "Step Tracker", - "category": "React Native", + "category": "React Native · Navigation", "platform": "native", "description": "A React Native progress tracker built from plain Views, with popping checks, a pulsing current step and connectors that fill as you advance.", "dependencies": [] @@ -2791,7 +2797,7 @@ { "name": "chip-input", "title": "Chip Input", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native tag input where Enter or a comma turns text into chips that pop in, wrap, and can each be removed.", "dependencies": [] @@ -2799,7 +2805,7 @@ { "name": "typing-dots", "title": "Typing Dots", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native chat typing indicator whose dots bounce in a staggered wave, with a bubble behind them and a single spoken label.", "dependencies": [] @@ -2807,7 +2813,7 @@ { "name": "marquee-ticker", "title": "Marquee Ticker", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native endless scrolling strip with a seamless loop, either direction, press and hold to pause, and a still fallback for reduced motion.", "dependencies": [] @@ -2815,7 +2821,7 @@ { "name": "choice-chips", "title": "Choice Chips", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "React Native chips for one choice or several, blending to the selected color while a check mark opens in front of the label.", "dependencies": [] @@ -2823,7 +2829,7 @@ { "name": "hold-stepper", "title": "Hold Stepper", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native plus and minus stepper that repeats while held, speeding up the longer you hold, with the value sliding in from the direction it moved.", "dependencies": [] @@ -2831,7 +2837,7 @@ { "name": "action-tray", "title": "Action Tray", - "category": "React Native", + "category": "React Native · Overlays", "platform": "native", "description": "A React Native bottom action list that slides up over a dimmed backdrop, with grouped actions, a separate cancel button and drag to dismiss.", "dependencies": [] @@ -2839,7 +2845,7 @@ { "name": "confirm-dialog", "title": "Confirm Dialog", - "category": "React Native", + "category": "React Native · Overlays", "platform": "native", "description": "A React Native alert dialog that pops in on a spring, starts focus on Cancel so Enter never confirms by accident, and locks while work is under way.", "dependencies": [] @@ -2847,7 +2853,7 @@ { "name": "code-boxes", "title": "Code Boxes", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native one-time-code input drawn as separate boxes, with paste, SMS autofill, a blinking caret, a pop for each digit and a shake on error.", "dependencies": [] @@ -2855,7 +2861,7 @@ { "name": "hue-picker", "title": "Hue Picker", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native colour picker built from plain Views, with a hue strip, a lightness strip for the chosen hue, one-tap swatches and a live preview.", "dependencies": [] @@ -2863,7 +2869,7 @@ { "name": "tab-pager", "title": "Tab Pager", - "category": "React Native", + "category": "React Native · Navigation", "platform": "native", "description": "A React Native tab header over swipeable pages, with an underline that follows your finger and labels that blend as their page arrives.", "dependencies": [] @@ -2871,7 +2877,7 @@ { "name": "wheel-picker", "title": "Wheel Picker", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native scrolling wheel that snaps rows to the middle, fades them with distance, and settles reliably even when a mouse wheel stops.", "dependencies": [] @@ -2879,7 +2885,7 @@ { "name": "avatar-stack", "title": "Avatar Stack", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native stack of overlapping avatars that spreads apart on a press, collapses extras into a plus count, and reads out who is in it.", "dependencies": [] @@ -2887,7 +2893,7 @@ { "name": "stripe-progress", "title": "Stripe Progress", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native progress bar whose fill grows on a spring and whose diagonal stripes drift, with an indeterminate mode and no gradient packages.", "dependencies": [] @@ -2895,7 +2901,7 @@ { "name": "range-slider", "title": "Range Slider", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native slider with two thumbs for choosing a range, where the thumbs never cross, values snap to a step, and each thumb is adjustable for screen readers.", "dependencies": [] @@ -2903,7 +2909,7 @@ { "name": "tick-box", "title": "Tick Box", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native checkbox that pops its fill in on a spring, grows its tick, and has a mixed state for select-all boxes.", "dependencies": [] @@ -2911,7 +2917,7 @@ { "name": "notice-banner", "title": "Notice Banner", - "category": "React Native", + "category": "React Native · Feedback", "platform": "native", "description": "A React Native inline alert in four tones that slides in, collapses its height on the way out, and can be swiped away or closed with a button.", "dependencies": [] @@ -2919,7 +2925,7 @@ { "name": "side-drawer", "title": "Side Drawer", - "category": "React Native", + "category": "React Native · Navigation", "platform": "native", "description": "A React Native panel that slides in from the left or right edge, follows your finger as you drag it shut, and can be pulled open by a swipe from the screen edge.", "dependencies": [] @@ -2927,7 +2933,7 @@ { "name": "reaction-bar", "title": "Reaction Bar", - "category": "React Native", + "category": "React Native · Buttons", "platform": "native", "description": "A React Native row of emoji reactions whose emoji pops and wobbles when chosen, with counts that roll to their new number.", "dependencies": [] @@ -2935,7 +2941,7 @@ { "name": "suggest-input", "title": "Suggest Input", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native text field with a suggestion list that narrows as you type, bolds what matched, and works with arrow keys, Enter and Escape on the web.", "dependencies": [] @@ -2943,7 +2949,7 @@ { "name": "expand-card", "title": "Expand Card", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native card that grows from a compact row into a full detail view, with its picture swelling from a thumbnail to a banner and its details fading in.", "dependencies": [] @@ -2951,7 +2957,7 @@ { "name": "ring-meter", "title": "Ring Meter", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native circular progress ring drawn with plain views and no SVG package, that sweeps smoothly all the way round and holds any content in its middle.", "dependencies": [] @@ -2959,7 +2965,7 @@ { "name": "count-badge", "title": "Count Badge", - "category": "React Native", + "category": "React Native · Feedback", "platform": "native", "description": "A React Native notification count that sits on an icon's corner, pops in when it appears, pulses as the number changes, and reads out with its label.", "dependencies": [] @@ -2967,7 +2973,7 @@ { "name": "float-field", "title": "Float Field", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native text field whose label floats up from inside the box, with an animated focus border, an error shake, a clear button and a Show toggle for passwords.", "dependencies": [] @@ -2975,7 +2981,7 @@ { "name": "month-grid", "title": "Month Grid", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native month calendar with a pill that glides to the selected day, swipe to change month, event dots, and local dates that never shift across time zones.", "dependencies": [] @@ -2983,7 +2989,7 @@ { "name": "chat-bubble", "title": "Chat Bubble", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native chat message that springs in from its own corner, shows delivery ticks that turn blue when read, and becomes a retry button when it fails.", "dependencies": [] @@ -2991,7 +2997,7 @@ { "name": "live-dot", "title": "Live Dot", - "category": "React Native", + "category": "React Native · Feedback", "platform": "native", "description": "A React Native presence and broadcast indicator whose live or online dot sends a soft ring outward on a loop, and whose status is always spoken as well as coloured.", "dependencies": [] @@ -2999,7 +3005,7 @@ { "name": "composer-bar", "title": "Composer Bar", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native message composer whose field grows line by line, whose microphone turns into a send arrow as you type, and which sends on Enter on the web.", "dependencies": [] @@ -3007,7 +3013,7 @@ { "name": "setting-list", "title": "Setting List", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native grouped settings list with icon tiles, chevrons, values and animated switches, in the style of a phone's own settings screen.", "dependencies": [] @@ -3015,7 +3021,7 @@ { "name": "pull-refresh", "title": "Pull Refresh", - "category": "React Native", + "category": "React Native · Feedback", "platform": "native", "description": "A React Native scrolling list you refresh by pulling down from the top, with resistance, a turning arrow, a holding spinner, and a Refresh action for screen readers.", "dependencies": [] @@ -3023,7 +3029,7 @@ { "name": "story-bars", "title": "Story Bars", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "The React Native row of segmented progress bars from a story viewer, which fills each story in turn, holds in place when paused, and announces its position.", "dependencies": [] @@ -3031,7 +3037,7 @@ { "name": "action-button", "title": "Action Button", - "category": "React Native", + "category": "React Native · Buttons", "platform": "native", "description": "A React Native button that carries its own progress, turning its label into a spinner, then a tick or a cross with a shake, without ever changing size.", "dependencies": [] @@ -3039,7 +3045,7 @@ { "name": "spin-loader", "title": "Spin Loader", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "Four React Native loading spinners in one component, a ring, bouncing dots, rising bars and a spreading pulse, that stand still when motion is reduced.", "dependencies": [] @@ -3047,7 +3053,7 @@ { "name": "radio-group", "title": "Radio Group", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native radio group drawn as cards with a springing dot, a single tab stop and arrow-key navigation on the web.", "dependencies": [] @@ -3055,7 +3061,7 @@ { "name": "mode-toggle", "title": "Mode Toggle", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native light and dark switch where the sun slides across, turns into a moon and the sky fills with stars.", "dependencies": [] @@ -3063,7 +3069,7 @@ { "name": "tip-popover", "title": "Tip Popover", - "category": "React Native", + "category": "React Native · Overlays", "platform": "native", "description": "A React Native tip that points at its trigger, springs out from the arrow and closes on an outside tap or Escape.", "dependencies": [] @@ -3071,7 +3077,7 @@ { "name": "data-table", "title": "Data Table", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native table with sortable columns, a header that stays put while rows scroll and sideways scrolling for wide columns.", "dependencies": [] @@ -3079,7 +3085,7 @@ { "name": "wave-bars", "title": "Wave Bars", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native audio waveform made of bars that swell out of step while playing and tint as they are played.", "dependencies": [] @@ -3087,7 +3093,7 @@ { "name": "page-dots", "title": "Page Dots", - "category": "React Native", + "category": "React Native · Navigation", "platform": "native", "description": "React Native pager dots where the current page stretches into a pill and every dot can be tapped to jump.", "dependencies": [] @@ -3095,7 +3101,7 @@ { "name": "password-meter", "title": "Password Meter", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native strength meter whose four bars fill and change colour as a password gets stronger.", "dependencies": [] @@ -3103,7 +3109,7 @@ { "name": "timeline-list", "title": "Timeline List", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native vertical timeline with completed, current and upcoming steps and a pulsing dot on the step in progress.", "dependencies": [] @@ -3111,7 +3117,7 @@ { "name": "empty-state", "title": "Empty State", - "category": "React Native", + "category": "React Native · Feedback", "platform": "native", "description": "A React Native empty list placeholder with a floating badge, a message and an optional action button.", "dependencies": [] @@ -3119,7 +3125,7 @@ { "name": "rating-histogram", "title": "Rating Histogram", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native review breakdown with one animated bar per star level and the average beside them.", "dependencies": [] @@ -3127,7 +3133,7 @@ { "name": "countdown-timer", "title": "Countdown Timer", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native minutes and seconds countdown with a draining bar that pauses, resumes and fires once when time is up.", "dependencies": [] @@ -3135,7 +3141,7 @@ { "name": "contact-index", "title": "Contact Index", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native alphabetical list with a draggable letter rail that jumps between sections like a phone's contacts.", "dependencies": [] @@ -3143,7 +3149,7 @@ { "name": "select-grid", "title": "Select Grid", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native multi-select grid of cards where a tick springs in, with an optional limit that dims the rest.", "dependencies": [] @@ -3151,7 +3157,7 @@ { "name": "poll-bars", "title": "Poll Bars", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native poll whose options turn into animated result bars with percentages once a vote is cast.", "dependencies": [] @@ -3159,7 +3165,7 @@ { "name": "card-field", "title": "Card Field", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native payment card input that groups the number, names the brand, adds the expiry slash and shakes on a failed check.", "dependencies": [] @@ -3167,7 +3173,7 @@ { "name": "step-slider", "title": "Step Slider", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native slider with fixed stops whose thumb follows the finger and springs onto the nearest label.", "dependencies": [] @@ -3175,7 +3181,7 @@ { "name": "cart-quantity", "title": "Cart Quantity", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native quantity picker whose minus turns into a bin at one so the same tap removes the item.", "dependencies": [] @@ -3183,7 +3189,7 @@ { "name": "password-field", "title": "Password Field", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native password input with a Show and Hide button and a border that eases to the accent colour on focus.", "dependencies": [] @@ -3191,7 +3197,7 @@ { "name": "resend-button", "title": "Resend Button", - "category": "React Native", + "category": "React Native · Buttons", "platform": "native", "description": "A React Native resend code link that waits out a countdown, pulses when ready and starts over after each press.", "dependencies": [] @@ -3199,7 +3205,7 @@ { "name": "gauge-meter", "title": "Gauge Meter", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native half-circle gauge whose arc springs round to the value, built from clipped Views with no SVG package.", "dependencies": [] @@ -3207,7 +3213,7 @@ { "name": "undo-snackbar", "title": "Undo Snackbar", - "category": "React Native", + "category": "React Native · Feedback", "platform": "native", "description": "A React Native snackbar with an Undo button that slides up, shows a draining timer line and closes itself.", "dependencies": [] @@ -3215,7 +3221,7 @@ { "name": "mood-picker", "title": "Mood Picker", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native row of faces for rating how something felt, where the chosen face swells with a bounce and shows its name.", "dependencies": [] @@ -3223,7 +3229,7 @@ { "name": "expandable-text", "title": "Expandable Text", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native paragraph that clamps to a few lines with a Read more link that grows the box to the full text.", "dependencies": [] @@ -3231,7 +3237,7 @@ { "name": "extended-fab", "title": "Extended FAB", - "category": "React Native", + "category": "React Native · Buttons", "platform": "native", "description": "A React Native floating action button with a label that slides away to leave a circle when collapsed.", "dependencies": [] @@ -3239,7 +3245,7 @@ { "name": "swatch-picker", "title": "Swatch Picker", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native colour picker of circles where the chosen one gets a ring that springs out and a tick inside.", "dependencies": [] @@ -3247,7 +3253,7 @@ { "name": "like-button", "title": "Like Button", - "category": "React Native", + "category": "React Native · Buttons", "platform": "native", "description": "A React Native heart button that pops on like with a ring of sparks flying outward, and shrinks quietly when unliked.", "dependencies": [] @@ -3255,7 +3261,7 @@ { "name": "task-checklist", "title": "Task Checklist", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native to-do list with a progress bar, where ticking a task draws a strike-through line across its text.", "dependencies": [] @@ -3263,7 +3269,7 @@ { "name": "spark-bars", "title": "Spark Bars", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A tiny React Native bar chart for trends inside a card, whose bars grow up one after another and resize on change.", "dependencies": [] @@ -3271,7 +3277,7 @@ { "name": "battery-meter", "title": "Battery Meter", - "category": "React Native", + "category": "React Native · Progress", "platform": "native", "description": "A React Native battery gauge whose fill slides to the level, turns red when low and pulses a bolt while charging.", "dependencies": [] @@ -3279,7 +3285,7 @@ { "name": "compare-slider", "title": "Compare Slider", - "category": "React Native", + "category": "React Native · Data", "platform": "native", "description": "A React Native before and after slider where dragging a handle reveals more of one side, steppable by screen readers.", "dependencies": [] @@ -3287,7 +3293,7 @@ { "name": "hold-confirm", "title": "Hold Confirm", - "category": "React Native", + "category": "React Native · Buttons", "platform": "native", "description": "A React Native press and hold button for risky actions that fills while held and drains back if released early.", "dependencies": [] @@ -3295,7 +3301,7 @@ { "name": "select-menu", "title": "Select Menu", - "category": "React Native", + "category": "React Native · Inputs", "platform": "native", "description": "A React Native dropdown that opens in place, pushing content down instead of floating, with a turning chevron.", "dependencies": [] @@ -3304,7 +3310,7 @@ "name": "use-color-scheme", "title": "useColorScheme", "category": "Hooks", - "platform": "native", + "platform": "both", "description": "A React Native hook that returns the system colour scheme as light or dark, never null.", "dependencies": [] }, @@ -3312,7 +3318,7 @@ "name": "use-keyboard-height", "title": "useKeyboardHeight", "category": "Hooks", - "platform": "native", + "platform": "both", "description": "A React Native hook that returns the on-screen keyboard height, or 0 while it is hidden.", "dependencies": [] }, @@ -3320,7 +3326,7 @@ "name": "use-haptics", "title": "useHaptics", "category": "Hooks", - "platform": "native", + "platform": "both", "description": "A React Native hook for touch feedback with tap, success, warning and error patterns that you can switch off.", "dependencies": [] }, @@ -3328,7 +3334,7 @@ "name": "use-reduce-motion", "title": "useReduceMotion", "category": "Hooks", - "platform": "native", + "platform": "both", "description": "A React Native hook that reports whether the system asks to reduce motion and follows later changes.", "dependencies": [] }, @@ -3336,7 +3342,7 @@ "name": "use-debounced-value", "title": "useDebouncedValue", "category": "Hooks", - "platform": "native", + "platform": "both", "description": "A React Native hook that returns a copy of a value which only updates after it stops changing.", "dependencies": [] }, @@ -3344,7 +3350,7 @@ "name": "mode-provider", "title": "ModeProvider", "category": "Providers", - "platform": "native", + "platform": "both", "description": "A React Native provider that holds the light, dark or system choice and exposes it through a useMode hook.", "dependencies": [] }, @@ -3352,7 +3358,7 @@ "name": "theme-provider", "title": "ThemeProvider", "category": "Providers", - "platform": "native", + "platform": "both", "description": "A React Native provider that supplies one colour palette to the tree through a useTheme hook, with per-colour overrides.", "dependencies": [] }, @@ -3360,7 +3366,7 @@ "name": "theme-colors", "title": "Colors", "category": "Theme", - "platform": "native", + "platform": "both", "description": "Light and dark colour palettes for React Native, named by role, with a helper that adds transparency to any colour.", "dependencies": [] }, @@ -3368,7 +3374,7 @@ "name": "theme-globals", "title": "Globals", "category": "Theme", - "platform": "native", + "platform": "both", "description": "Shared React Native design tokens for spacing, corner radius, type sizes, font weights and shadows.", "dependencies": [] } diff --git a/public/registry/intro-pager.json b/public/registry/intro-pager.json index b8d429b..20fbc09 100644 --- a/public/registry/intro-pager.json +++ b/public/registry/intro-pager.json @@ -1,7 +1,7 @@ { "name": "intro-pager", "title": "Intro Pager", - "category": "React Native", + "category": "React Native · Navigation", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/like-button.json b/public/registry/like-button.json index e470db3..d1266dd 100644 --- a/public/registry/like-button.json +++ b/public/registry/like-button.json @@ -1,7 +1,7 @@ { "name": "like-button", "title": "Like Button", - "category": "React Native", + "category": "React Native · Buttons", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/live-dot.json b/public/registry/live-dot.json index 60bb7e2..da4428e 100644 --- a/public/registry/live-dot.json +++ b/public/registry/live-dot.json @@ -1,7 +1,7 @@ { "name": "live-dot", "title": "Live Dot", - "category": "React Native", + "category": "React Native · Feedback", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/long-press-menu.json b/public/registry/long-press-menu.json index eff1360..fc2f4ad 100644 --- a/public/registry/long-press-menu.json +++ b/public/registry/long-press-menu.json @@ -1,7 +1,7 @@ { "name": "long-press-menu", "title": "Long Press Menu", - "category": "React Native", + "category": "React Native · Overlays", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/marquee-ticker.json b/public/registry/marquee-ticker.json index 1acba43..f716248 100644 --- a/public/registry/marquee-ticker.json +++ b/public/registry/marquee-ticker.json @@ -1,7 +1,7 @@ { "name": "marquee-ticker", "title": "Marquee Ticker", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/mode-provider.json b/public/registry/mode-provider.json index fd8d769..0dc5896 100644 --- a/public/registry/mode-provider.json +++ b/public/registry/mode-provider.json @@ -3,12 +3,16 @@ "title": "ModeProvider", "category": "Providers", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ { "path": "registry/mode-provider.tsx", + "content": "\"use client\";\n\nimport {\n createContext,\n useCallback,\n useSyncExternalStore,\n useContext,\n useMemo,\n useState,\n type ReactNode,\n} from \"react\";\n\nconst QUERY = \"(prefers-color-scheme: dark)\";\n\n/** The system scheme from the prefers-color-scheme media query; \"light\" on the server so hydration matches. */\nfunction useSystemScheme(): \"light\" | \"dark\" {\n return useSyncExternalStore(\n (onChange) => {\n const media = window.matchMedia(QUERY);\n media.addEventListener(\"change\", onChange);\n return () => media.removeEventListener(\"change\", onChange);\n },\n () => (window.matchMedia(QUERY).matches ? \"dark\" : \"light\"),\n () => \"light\",\n );\n}\n\nexport type Mode = \"light\" | \"dark\" | \"system\";\n\nexport interface ModeValue {\n /** What the person chose: light, dark, or follow the system. */\n mode: Mode;\n /** The scheme actually in effect, with \"system\" resolved to light or dark. */\n scheme: \"light\" | \"dark\";\n setMode: (mode: Mode) => void;\n /** Switches to the opposite of the scheme in effect. */\n toggle: () => void;\n}\n\nconst ModeContext = createContext(null);\n\nexport interface ModeProviderProps {\n children: ReactNode;\n /** The mode to start in. */\n initialMode?: Mode;\n /** Called whenever the mode changes, so you can save it. */\n onModeChange?: (mode: Mode) => void;\n}\n\n/**\n * Holds the light, dark or system choice for the whole app. Read it anywhere below with `useMode()`.\n * \"system\" follows the device and updates when the device changes. The provider keeps the choice in\n * memory only; save it from `onModeChange` and pass it back as `initialMode` to remember it.\n */\nexport function ModeProvider({\n children,\n initialMode = \"system\",\n onModeChange,\n}: ModeProviderProps) {\n const system = useSystemScheme();\n const [mode, setModeState] = useState(initialMode);\n const scheme = mode === \"system\" ? system : mode;\n\n const setMode = useCallback(\n (next: Mode) => {\n setModeState(next);\n onModeChange?.(next);\n },\n [onModeChange],\n );\n const toggle = useCallback(\n () => setMode(scheme === \"dark\" ? \"light\" : \"dark\"),\n [scheme, setMode],\n );\n\n const value = useMemo(() => ({ mode, scheme, setMode, toggle }), [mode, scheme, setMode, toggle]);\n return {children};\n}\n\n/** The current mode and scheme. Throws when used outside a ModeProvider, so a missing one is caught early. */\nexport function useMode(): ModeValue {\n const value = useContext(ModeContext);\n if (!value) throw new Error(\"useMode must be used inside a ModeProvider\");\n return value;\n}\n" + }, + { + "path": "registry/mode-provider.native.tsx", "content": "import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from \"react\";\nimport { useColorScheme } from \"react-native\";\n\nexport type Mode = \"light\" | \"dark\" | \"system\";\n\nexport interface ModeValue {\n /** What the person chose: light, dark, or follow the system. */\n mode: Mode;\n /** The scheme actually in effect, with \"system\" resolved to light or dark. */\n scheme: \"light\" | \"dark\";\n setMode: (mode: Mode) => void;\n /** Switches to the opposite of the scheme in effect. */\n toggle: () => void;\n}\n\nconst ModeContext = createContext(null);\n\nexport interface ModeProviderProps {\n children: ReactNode;\n /** The mode to start in. */\n initialMode?: Mode;\n /** Called whenever the mode changes, so you can save it. */\n onModeChange?: (mode: Mode) => void;\n}\n\n/**\n * Holds the light, dark or system choice for the whole app. Read it anywhere below with `useMode()`.\n * \"system\" follows the device and updates when the device changes. The provider keeps the choice in\n * memory only; save it from `onModeChange` and pass it back as `initialMode` to remember it.\n */\nexport function ModeProvider({\n children,\n initialMode = \"system\",\n onModeChange,\n}: ModeProviderProps) {\n const system = useColorScheme() === \"dark\" ? \"dark\" : \"light\";\n const [mode, setModeState] = useState(initialMode);\n const scheme = mode === \"system\" ? system : mode;\n\n const setMode = useCallback(\n (next: Mode) => {\n setModeState(next);\n onModeChange?.(next);\n },\n [onModeChange],\n );\n const toggle = useCallback(\n () => setMode(scheme === \"dark\" ? \"light\" : \"dark\"),\n [scheme, setMode],\n );\n\n const value = useMemo(() => ({ mode, scheme, setMode, toggle }), [mode, scheme, setMode, toggle]);\n return {children};\n}\n\n/** The current mode and scheme. Throws when used outside a ModeProvider, so a missing one is caught early. */\nexport function useMode(): ModeValue {\n const value = useContext(ModeContext);\n if (!value) throw new Error(\"useMode must be used inside a ModeProvider\");\n return value;\n}\n" } ] diff --git a/public/registry/mode-toggle.json b/public/registry/mode-toggle.json index 8eab5a8..f5bd021 100644 --- a/public/registry/mode-toggle.json +++ b/public/registry/mode-toggle.json @@ -1,7 +1,7 @@ { "name": "mode-toggle", "title": "Mode Toggle", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/month-grid.json b/public/registry/month-grid.json index fb5248f..b9ab795 100644 --- a/public/registry/month-grid.json +++ b/public/registry/month-grid.json @@ -1,7 +1,7 @@ { "name": "month-grid", "title": "Month Grid", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/mood-picker.json b/public/registry/mood-picker.json index a1c48e6..f3336c7 100644 --- a/public/registry/mood-picker.json +++ b/public/registry/mood-picker.json @@ -1,7 +1,7 @@ { "name": "mood-picker", "title": "Mood Picker", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/notice-banner.json b/public/registry/notice-banner.json index 9bce04e..36dac0a 100644 --- a/public/registry/notice-banner.json +++ b/public/registry/notice-banner.json @@ -1,7 +1,7 @@ { "name": "notice-banner", "title": "Notice Banner", - "category": "React Native", + "category": "React Native · Feedback", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/page-dots.json b/public/registry/page-dots.json index 79eac0f..0293c87 100644 --- a/public/registry/page-dots.json +++ b/public/registry/page-dots.json @@ -1,7 +1,7 @@ { "name": "page-dots", "title": "Page Dots", - "category": "React Native", + "category": "React Native · Navigation", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/parallax-header.json b/public/registry/parallax-header.json index ae5e53f..cd86bc1 100644 --- a/public/registry/parallax-header.json +++ b/public/registry/parallax-header.json @@ -1,7 +1,7 @@ { "name": "parallax-header", "title": "Parallax Header", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-01", diff --git a/public/registry/password-field.json b/public/registry/password-field.json index 27a45b1..b00ccab 100644 --- a/public/registry/password-field.json +++ b/public/registry/password-field.json @@ -1,7 +1,7 @@ { "name": "password-field", "title": "Password Field", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/password-meter.json b/public/registry/password-meter.json index 1b4c1b3..73d9eab 100644 --- a/public/registry/password-meter.json +++ b/public/registry/password-meter.json @@ -1,7 +1,7 @@ { "name": "password-meter", "title": "Password Meter", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/pin-pad.json b/public/registry/pin-pad.json index c1ed9cc..decdbef 100644 --- a/public/registry/pin-pad.json +++ b/public/registry/pin-pad.json @@ -1,7 +1,7 @@ { "name": "pin-pad", "title": "Pin Pad", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-10-30", diff --git a/public/registry/poll-bars.json b/public/registry/poll-bars.json index db5e7fe..d24285d 100644 --- a/public/registry/poll-bars.json +++ b/public/registry/poll-bars.json @@ -1,7 +1,7 @@ { "name": "poll-bars", "title": "Poll Bars", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/pull-refresh.json b/public/registry/pull-refresh.json index b76a5d0..bcebfca 100644 --- a/public/registry/pull-refresh.json +++ b/public/registry/pull-refresh.json @@ -1,7 +1,7 @@ { "name": "pull-refresh", "title": "Pull Refresh", - "category": "React Native", + "category": "React Native · Feedback", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/radio-group.json b/public/registry/radio-group.json index 4887e16..a3a164c 100644 --- a/public/registry/radio-group.json +++ b/public/registry/radio-group.json @@ -1,7 +1,7 @@ { "name": "radio-group", "title": "Radio Group", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/range-slider.json b/public/registry/range-slider.json index b533cb4..1fd959c 100644 --- a/public/registry/range-slider.json +++ b/public/registry/range-slider.json @@ -1,7 +1,7 @@ { "name": "range-slider", "title": "Range Slider", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/rating-histogram.json b/public/registry/rating-histogram.json index 30c4a3a..62c521a 100644 --- a/public/registry/rating-histogram.json +++ b/public/registry/rating-histogram.json @@ -1,7 +1,7 @@ { "name": "rating-histogram", "title": "Rating Histogram", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/reaction-bar.json b/public/registry/reaction-bar.json index 953fa1a..fd2482a 100644 --- a/public/registry/reaction-bar.json +++ b/public/registry/reaction-bar.json @@ -1,7 +1,7 @@ { "name": "reaction-bar", "title": "Reaction Bar", - "category": "React Native", + "category": "React Native · Buttons", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/resend-button.json b/public/registry/resend-button.json index c88e539..a93cc91 100644 --- a/public/registry/resend-button.json +++ b/public/registry/resend-button.json @@ -1,7 +1,7 @@ { "name": "resend-button", "title": "Resend Button", - "category": "React Native", + "category": "React Native · Buttons", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/ring-meter.json b/public/registry/ring-meter.json index bb9de86..5ae44e6 100644 --- a/public/registry/ring-meter.json +++ b/public/registry/ring-meter.json @@ -1,7 +1,7 @@ { "name": "ring-meter", "title": "Ring Meter", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/roll-number.json b/public/registry/roll-number.json index 59699f2..48ef7e1 100644 --- a/public/registry/roll-number.json +++ b/public/registry/roll-number.json @@ -1,7 +1,7 @@ { "name": "roll-number", "title": "Roll Number", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/select-grid.json b/public/registry/select-grid.json index 1070672..22bc904 100644 --- a/public/registry/select-grid.json +++ b/public/registry/select-grid.json @@ -1,7 +1,7 @@ { "name": "select-grid", "title": "Select Grid", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/select-menu.json b/public/registry/select-menu.json index 80181c7..a94611e 100644 --- a/public/registry/select-menu.json +++ b/public/registry/select-menu.json @@ -1,7 +1,7 @@ { "name": "select-menu", "title": "Select Menu", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/setting-list.json b/public/registry/setting-list.json index 125c828..3cd396f 100644 --- a/public/registry/setting-list.json +++ b/public/registry/setting-list.json @@ -1,7 +1,7 @@ { "name": "setting-list", "title": "Setting List", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/shimmer-block.json b/public/registry/shimmer-block.json index bbd5b84..543b2da 100644 --- a/public/registry/shimmer-block.json +++ b/public/registry/shimmer-block.json @@ -1,7 +1,7 @@ { "name": "shimmer-block", "title": "Shimmer Block", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-01", diff --git a/public/registry/side-drawer.json b/public/registry/side-drawer.json index 4a60ccb..ee9a67c 100644 --- a/public/registry/side-drawer.json +++ b/public/registry/side-drawer.json @@ -1,7 +1,7 @@ { "name": "side-drawer", "title": "Side Drawer", - "category": "React Native", + "category": "React Native · Navigation", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/slide-confirm.json b/public/registry/slide-confirm.json index e1fd9b7..836339d 100644 --- a/public/registry/slide-confirm.json +++ b/public/registry/slide-confirm.json @@ -1,7 +1,7 @@ { "name": "slide-confirm", "title": "Slide Confirm", - "category": "React Native", + "category": "React Native · Buttons", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/slide-switch.json b/public/registry/slide-switch.json index 4c157a1..8edba83 100644 --- a/public/registry/slide-switch.json +++ b/public/registry/slide-switch.json @@ -1,7 +1,7 @@ { "name": "slide-switch", "title": "Slide Switch", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-01", diff --git a/public/registry/snap-carousel.json b/public/registry/snap-carousel.json index 33c497b..fa596ed 100644 --- a/public/registry/snap-carousel.json +++ b/public/registry/snap-carousel.json @@ -1,7 +1,7 @@ { "name": "snap-carousel", "title": "Snap Carousel", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-01", diff --git a/public/registry/snap-sheet.json b/public/registry/snap-sheet.json index 393f1ef..1b0d32c 100644 --- a/public/registry/snap-sheet.json +++ b/public/registry/snap-sheet.json @@ -1,7 +1,7 @@ { "name": "snap-sheet", "title": "Snap Sheet", - "category": "React Native", + "category": "React Native · Overlays", "type": "components:ui", "platform": "native", "added": "2026-10-30", diff --git a/public/registry/spark-bars.json b/public/registry/spark-bars.json index ece4694..64e8f64 100644 --- a/public/registry/spark-bars.json +++ b/public/registry/spark-bars.json @@ -1,7 +1,7 @@ { "name": "spark-bars", "title": "Spark Bars", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/spin-loader.json b/public/registry/spin-loader.json index a63d54d..e017f86 100644 --- a/public/registry/spin-loader.json +++ b/public/registry/spin-loader.json @@ -1,7 +1,7 @@ { "name": "spin-loader", "title": "Spin Loader", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/star-rating.json b/public/registry/star-rating.json index 3acb0af..e53ffbe 100644 --- a/public/registry/star-rating.json +++ b/public/registry/star-rating.json @@ -1,7 +1,7 @@ { "name": "star-rating", "title": "Star Rating", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/step-slider.json b/public/registry/step-slider.json index 5e60743..e29053a 100644 --- a/public/registry/step-slider.json +++ b/public/registry/step-slider.json @@ -1,7 +1,7 @@ { "name": "step-slider", "title": "Step Slider", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/step-tracker.json b/public/registry/step-tracker.json index ca4ae3f..2c43822 100644 --- a/public/registry/step-tracker.json +++ b/public/registry/step-tracker.json @@ -1,7 +1,7 @@ { "name": "step-tracker", "title": "Step Tracker", - "category": "React Native", + "category": "React Native · Navigation", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/story-bars.json b/public/registry/story-bars.json index 55a5e64..eaf5955 100644 --- a/public/registry/story-bars.json +++ b/public/registry/story-bars.json @@ -1,7 +1,7 @@ { "name": "story-bars", "title": "Story Bars", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/stripe-progress.json b/public/registry/stripe-progress.json index 3c9f3fa..ad2b1b7 100644 --- a/public/registry/stripe-progress.json +++ b/public/registry/stripe-progress.json @@ -1,7 +1,7 @@ { "name": "stripe-progress", "title": "Stripe Progress", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/suggest-input.json b/public/registry/suggest-input.json index cd58910..1994b8a 100644 --- a/public/registry/suggest-input.json +++ b/public/registry/suggest-input.json @@ -1,7 +1,7 @@ { "name": "suggest-input", "title": "Suggest Input", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/swatch-picker.json b/public/registry/swatch-picker.json index 89d5048..5693ae4 100644 --- a/public/registry/swatch-picker.json +++ b/public/registry/swatch-picker.json @@ -1,7 +1,7 @@ { "name": "swatch-picker", "title": "Swatch Picker", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/swipe-actions.json b/public/registry/swipe-actions.json index 9ee0e35..b9bf3ea 100644 --- a/public/registry/swipe-actions.json +++ b/public/registry/swipe-actions.json @@ -1,7 +1,7 @@ { "name": "swipe-actions", "title": "Swipe Actions", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-10-30", diff --git a/public/registry/swipe-deck.json b/public/registry/swipe-deck.json index 051a390..e04af44 100644 --- a/public/registry/swipe-deck.json +++ b/public/registry/swipe-deck.json @@ -1,7 +1,7 @@ { "name": "swipe-deck", "title": "Swipe Deck", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-10-30", diff --git a/public/registry/tab-pager.json b/public/registry/tab-pager.json index d1c7bc6..9699898 100644 --- a/public/registry/tab-pager.json +++ b/public/registry/tab-pager.json @@ -1,7 +1,7 @@ { "name": "tab-pager", "title": "Tab Pager", - "category": "React Native", + "category": "React Native · Navigation", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/task-checklist.json b/public/registry/task-checklist.json index c9167cc..f155fb9 100644 --- a/public/registry/task-checklist.json +++ b/public/registry/task-checklist.json @@ -1,7 +1,7 @@ { "name": "task-checklist", "title": "Task Checklist", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/theme-colors.json b/public/registry/theme-colors.json index a896f25..d97e2c7 100644 --- a/public/registry/theme-colors.json +++ b/public/registry/theme-colors.json @@ -3,7 +3,7 @@ "title": "Colors", "category": "Theme", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ diff --git a/public/registry/theme-globals.json b/public/registry/theme-globals.json index 746c940..544c9a7 100644 --- a/public/registry/theme-globals.json +++ b/public/registry/theme-globals.json @@ -3,7 +3,7 @@ "title": "Globals", "category": "Theme", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ diff --git a/public/registry/theme-provider.json b/public/registry/theme-provider.json index c07fca4..e373ce3 100644 --- a/public/registry/theme-provider.json +++ b/public/registry/theme-provider.json @@ -3,12 +3,16 @@ "title": "ThemeProvider", "category": "Providers", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ { "path": "registry/theme-provider.tsx", + "content": "\"use client\";\n\nimport { createContext, useSyncExternalStore, useContext, useMemo, type ReactNode } from \"react\";\n\nconst QUERY = \"(prefers-color-scheme: dark)\";\n\n/** The system scheme from the prefers-color-scheme media query; \"light\" on the server so hydration matches. */\nfunction useSystemScheme(): \"light\" | \"dark\" {\n return useSyncExternalStore(\n (onChange) => {\n const media = window.matchMedia(QUERY);\n media.addEventListener(\"change\", onChange);\n return () => media.removeEventListener(\"change\", onChange);\n },\n () => (window.matchMedia(QUERY).matches ? \"dark\" : \"light\"),\n () => \"light\",\n );\n}\n\nexport interface ThemePalette {\n background: string;\n foreground: string;\n card: string;\n muted: string;\n mutedForeground: string;\n primary: string;\n primaryForeground: string;\n border: string;\n destructive: string;\n}\n\nexport interface ThemeColors {\n light: Partial;\n dark: Partial;\n}\n\nconst LIGHT: ThemePalette = {\n background: \"#ffffff\",\n foreground: \"#111827\",\n card: \"#f9fafb\",\n muted: \"#f3f4f6\",\n mutedForeground: \"#6b7280\",\n primary: \"#4f46e5\",\n primaryForeground: \"#ffffff\",\n border: \"#e5e7eb\",\n destructive: \"#dc2626\",\n};\n\nconst DARK: ThemePalette = {\n background: \"#0b0b0f\",\n foreground: \"#f9fafb\",\n card: \"#16161d\",\n muted: \"#1f1f29\",\n mutedForeground: \"#9ca3af\",\n primary: \"#818cf8\",\n primaryForeground: \"#0b0b0f\",\n border: \"#2a2a36\",\n destructive: \"#f87171\",\n};\n\nexport interface Theme {\n scheme: \"light\" | \"dark\";\n colors: ThemePalette;\n}\n\nconst ThemeContext = createContext(null);\n\nexport interface ThemeProviderProps {\n children: ReactNode;\n /** Which palette to use. Leave it out to follow the system; pass `useMode().scheme` to follow your own switch. */\n scheme?: \"light\" | \"dark\";\n /** Overrides for single colours in either palette. */\n colors?: Partial;\n}\n\n/**\n * Supplies one palette to everything below it. Components call `useTheme()` and read colours by role,\n * so switching between light and dark restyles the whole tree at once with no per-component logic.\n * Override individual colours with `colors`; anything you leave out keeps its default.\n */\nexport function ThemeProvider({ children, scheme, colors }: ThemeProviderProps) {\n const system = useSystemScheme();\n const active = scheme ?? system;\n\n const value = useMemo(\n () => ({\n scheme: active,\n colors: active === \"dark\" ? { ...DARK, ...colors?.dark } : { ...LIGHT, ...colors?.light },\n }),\n [active, colors],\n );\n return {children};\n}\n\n/** The active scheme and its colours. Throws when used outside a ThemeProvider. */\nexport function useTheme(): Theme {\n const value = useContext(ThemeContext);\n if (!value) throw new Error(\"useTheme must be used inside a ThemeProvider\");\n return value;\n}\n" + }, + { + "path": "registry/theme-provider.native.tsx", "content": "import { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport { useColorScheme } from \"react-native\";\n\nexport interface ThemePalette {\n background: string;\n foreground: string;\n card: string;\n muted: string;\n mutedForeground: string;\n primary: string;\n primaryForeground: string;\n border: string;\n destructive: string;\n}\n\nexport interface ThemeColors {\n light: Partial;\n dark: Partial;\n}\n\nconst LIGHT: ThemePalette = {\n background: \"#ffffff\",\n foreground: \"#111827\",\n card: \"#f9fafb\",\n muted: \"#f3f4f6\",\n mutedForeground: \"#6b7280\",\n primary: \"#4f46e5\",\n primaryForeground: \"#ffffff\",\n border: \"#e5e7eb\",\n destructive: \"#dc2626\",\n};\n\nconst DARK: ThemePalette = {\n background: \"#0b0b0f\",\n foreground: \"#f9fafb\",\n card: \"#16161d\",\n muted: \"#1f1f29\",\n mutedForeground: \"#9ca3af\",\n primary: \"#818cf8\",\n primaryForeground: \"#0b0b0f\",\n border: \"#2a2a36\",\n destructive: \"#f87171\",\n};\n\nexport interface Theme {\n scheme: \"light\" | \"dark\";\n colors: ThemePalette;\n}\n\nconst ThemeContext = createContext(null);\n\nexport interface ThemeProviderProps {\n children: ReactNode;\n /** Which palette to use. Leave it out to follow the system; pass `useMode().scheme` to follow your own switch. */\n scheme?: \"light\" | \"dark\";\n /** Overrides for single colours in either palette. */\n colors?: Partial;\n}\n\n/**\n * Supplies one palette to everything below it. Components call `useTheme()` and read colours by role,\n * so switching between light and dark restyles the whole tree at once with no per-component logic.\n * Override individual colours with `colors`; anything you leave out keeps its default.\n */\nexport function ThemeProvider({ children, scheme, colors }: ThemeProviderProps) {\n const system = useColorScheme() === \"dark\" ? \"dark\" : \"light\";\n const active = scheme ?? system;\n\n const value = useMemo(\n () => ({\n scheme: active,\n colors: active === \"dark\" ? { ...DARK, ...colors?.dark } : { ...LIGHT, ...colors?.light },\n }),\n [active, colors],\n );\n return {children};\n}\n\n/** The active scheme and its colours. Throws when used outside a ThemeProvider. */\nexport function useTheme(): Theme {\n const value = useContext(ThemeContext);\n if (!value) throw new Error(\"useTheme must be used inside a ThemeProvider\");\n return value;\n}\n" } ] diff --git a/public/registry/tick-box.json b/public/registry/tick-box.json index a4a1e51..603bd30 100644 --- a/public/registry/tick-box.json +++ b/public/registry/tick-box.json @@ -1,7 +1,7 @@ { "name": "tick-box", "title": "Tick Box", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/timeline-list.json b/public/registry/timeline-list.json index f92f8e2..41e25c7 100644 --- a/public/registry/timeline-list.json +++ b/public/registry/timeline-list.json @@ -1,7 +1,7 @@ { "name": "timeline-list", "title": "Timeline List", - "category": "React Native", + "category": "React Native · Data", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/tip-popover.json b/public/registry/tip-popover.json index bba14e0..12ccbda 100644 --- a/public/registry/tip-popover.json +++ b/public/registry/tip-popover.json @@ -1,7 +1,7 @@ { "name": "tip-popover", "title": "Tip Popover", - "category": "React Native", + "category": "React Native · Overlays", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/typing-dots.json b/public/registry/typing-dots.json index 60ede3a..92b641d 100644 --- a/public/registry/typing-dots.json +++ b/public/registry/typing-dots.json @@ -1,7 +1,7 @@ { "name": "typing-dots", "title": "Typing Dots", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/undo-snackbar.json b/public/registry/undo-snackbar.json index 5ef8e9e..6b1d221 100644 --- a/public/registry/undo-snackbar.json +++ b/public/registry/undo-snackbar.json @@ -1,7 +1,7 @@ { "name": "undo-snackbar", "title": "Undo Snackbar", - "category": "React Native", + "category": "React Native · Feedback", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/use-color-scheme.json b/public/registry/use-color-scheme.json index a8b0fa9..dfca8df 100644 --- a/public/registry/use-color-scheme.json +++ b/public/registry/use-color-scheme.json @@ -3,12 +3,16 @@ "title": "useColorScheme", "category": "Hooks", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ { "path": "registry/use-color-scheme.ts", + "content": "\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\nexport type Scheme = \"light\" | \"dark\";\n\nconst QUERY = \"(prefers-color-scheme: dark)\";\n\nfunction subscribe(onChange: () => void) {\n const media = window.matchMedia(QUERY);\n media.addEventListener(\"change\", onChange);\n return () => media.removeEventListener(\"change\", onChange);\n}\n\n/**\n * The system colour scheme, always \"light\" or \"dark\". It reads the prefers-color-scheme media query and\n * re-renders when the person switches appearance. On the server, and for the first render while\n * hydrating, it returns \"light\" so the markup matches.\n */\nexport function useColorScheme(): Scheme {\n return useSyncExternalStore(\n subscribe,\n () => (window.matchMedia(QUERY).matches ? \"dark\" : \"light\"),\n () => \"light\",\n );\n}\n" + }, + { + "path": "registry/use-color-scheme.native.ts", "content": "import { useColorScheme as useSystemScheme } from \"react-native\";\n\nexport type Scheme = \"light\" | \"dark\";\n\n/**\n * The system colour scheme, always \"light\" or \"dark\". React Native's own hook can return null before\n * the platform reports a value; this one falls back to light so styles never see a missing scheme.\n * It re-renders when the user switches appearance.\n */\nexport function useColorScheme(): Scheme {\n return useSystemScheme() === \"dark\" ? \"dark\" : \"light\";\n}\n" } ] diff --git a/public/registry/use-debounced-value.json b/public/registry/use-debounced-value.json index 16404dc..6b73542 100644 --- a/public/registry/use-debounced-value.json +++ b/public/registry/use-debounced-value.json @@ -3,13 +3,13 @@ "title": "useDebouncedValue", "category": "Hooks", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ { "path": "registry/use-debounced-value.ts", - "content": "import { useEffect, useState } from \"react\";\n\n/**\n * A copy of `value` that only updates after it has stopped changing for `delay` milliseconds. Use it\n * to wait out typing before searching: render with the live value, query with the debounced one. The\n * first render returns the value straight away.\n */\nexport function useDebouncedValue(value: T, delay = 300): T {\n const [debounced, setDebounced] = useState(value);\n\n useEffect(() => {\n const id = setTimeout(() => setDebounced(value), delay);\n return () => clearTimeout(id);\n }, [value, delay]);\n\n return debounced;\n}\n" + "content": "\"use client\";\n\nimport { useEffect, useState } from \"react\";\n\n/**\n * A copy of `value` that only updates after it has stopped changing for `delay` milliseconds. Use it\n * to wait out typing before searching: render with the live value, query with the debounced one. The\n * first render returns the value straight away.\n */\nexport function useDebouncedValue(value: T, delay = 300): T {\n const [debounced, setDebounced] = useState(value);\n\n useEffect(() => {\n const id = setTimeout(() => setDebounced(value), delay);\n return () => clearTimeout(id);\n }, [value, delay]);\n\n return debounced;\n}\n" } ] } \ No newline at end of file diff --git a/public/registry/use-haptics.json b/public/registry/use-haptics.json index d3be6b7..1af236e 100644 --- a/public/registry/use-haptics.json +++ b/public/registry/use-haptics.json @@ -3,12 +3,16 @@ "title": "useHaptics", "category": "Hooks", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ { "path": "registry/use-haptics.ts", + "content": "\"use client\";\n\nimport { useMemo } from \"react\";\n\nexport interface Haptics {\n /** A light tick, for a press or a selection. */\n tap: () => void;\n /** Two short pulses, for something that worked. */\n success: () => void;\n /** Two firmer pulses, for something that needs attention. */\n warning: () => void;\n /** Three pulses, for something that failed. */\n error: () => void;\n}\n\n/**\n * Touch feedback built on the browser's Vibration API, so it needs no extra package. Pass `enabled`\n * false, for example from a settings switch, and every call does nothing. Browsers that cannot vibrate,\n * which includes Safari and every desktop browser, ignore the calls without an error.\n */\nexport function useHaptics(enabled = true): Haptics {\n return useMemo(() => {\n const run = (pattern: number | number[]) => {\n if (enabled && typeof navigator !== \"undefined\") navigator.vibrate?.(pattern);\n };\n return {\n tap: () => run(10),\n success: () => run([0, 15, 60, 15]),\n warning: () => run([0, 30, 50, 30]),\n error: () => run([0, 50, 40, 50, 40, 50]),\n };\n }, [enabled]);\n}\n" + }, + { + "path": "registry/use-haptics.native.ts", "content": "import { useMemo } from \"react\";\nimport { Vibration } from \"react-native\";\n\nexport interface Haptics {\n /** A light tick, for a press or a selection. */\n tap: () => void;\n /** Two short pulses, for something that worked. */\n success: () => void;\n /** Two firmer pulses, for something that needs attention. */\n warning: () => void;\n /** Three pulses, for something that failed. */\n error: () => void;\n}\n\n/**\n * Touch feedback built on React Native's Vibration, so it needs no extra package. Pass `enabled`\n * false, for example from a settings switch, and every call does nothing. Android follows the\n * patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback\n * swap the bodies for expo-haptics.\n */\nexport function useHaptics(enabled = true): Haptics {\n return useMemo(() => {\n const run = (pattern: number | number[]) => {\n if (enabled) Vibration.vibrate(pattern);\n };\n return {\n tap: () => run(10),\n success: () => run([0, 15, 60, 15]),\n warning: () => run([0, 30, 50, 30]),\n error: () => run([0, 50, 40, 50, 40, 50]),\n };\n }, [enabled]);\n}\n" } ] diff --git a/public/registry/use-keyboard-height.json b/public/registry/use-keyboard-height.json index bb29c31..2be1f95 100644 --- a/public/registry/use-keyboard-height.json +++ b/public/registry/use-keyboard-height.json @@ -3,12 +3,16 @@ "title": "useKeyboardHeight", "category": "Hooks", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ { "path": "registry/use-keyboard-height.ts", + "content": "\"use client\";\n\nimport { useEffect, useState } from \"react\";\n\n/**\n * The height of the on-screen keyboard on a phone's browser, or 0 while it is hidden. It measures how\n * much of the layout viewport the visual viewport has lost, which is what the keyboard covers. It is\n * always 0 on desktop, and while the page is pinch-zoomed, because a zoom also shrinks the visual\n * viewport and would be mistaken for a keyboard.\n */\nexport function useKeyboardHeight(): number {\n const [height, setHeight] = useState(0);\n\n useEffect(() => {\n const viewport = window.visualViewport;\n if (!viewport) return;\n const update = () =>\n setHeight(\n viewport.scale > 1\n ? 0\n : Math.max(0, Math.round(window.innerHeight - viewport.height - viewport.offsetTop)),\n );\n update();\n viewport.addEventListener(\"resize\", update);\n viewport.addEventListener(\"scroll\", update);\n return () => {\n viewport.removeEventListener(\"resize\", update);\n viewport.removeEventListener(\"scroll\", update);\n };\n }, []);\n\n return height;\n}\n" + }, + { + "path": "registry/use-keyboard-height.native.ts", "content": "import { useEffect, useState } from \"react\";\nimport { Keyboard, Platform } from \"react-native\";\n\n/**\n * The height of the on-screen keyboard, or 0 while it is hidden. On iOS it updates as the keyboard\n * starts to move, so a view can slide up alongside it; on Android it updates once the keyboard has\n * finished appearing. Always 0 on the web, where there is no on-screen keyboard to measure.\n */\nexport function useKeyboardHeight(): number {\n const [height, setHeight] = useState(0);\n\n useEffect(() => {\n const ios = Platform.OS === \"ios\";\n const show = Keyboard.addListener(ios ? \"keyboardWillShow\" : \"keyboardDidShow\", (event) =>\n setHeight(event.endCoordinates.height),\n );\n const hide = Keyboard.addListener(ios ? \"keyboardWillHide\" : \"keyboardDidHide\", () =>\n setHeight(0),\n );\n return () => {\n show.remove();\n hide.remove();\n };\n }, []);\n\n return height;\n}\n" } ] diff --git a/public/registry/use-reduce-motion.json b/public/registry/use-reduce-motion.json index 69099ba..418cc69 100644 --- a/public/registry/use-reduce-motion.json +++ b/public/registry/use-reduce-motion.json @@ -3,12 +3,16 @@ "title": "useReduceMotion", "category": "Hooks", "type": "components:ui", - "platform": "native", + "platform": "both", "added": "2026-11-05", "dependencies": [], "files": [ { "path": "registry/use-reduce-motion.ts", + "content": "\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\nconst QUERY = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribe(onChange: () => void) {\n const media = window.matchMedia(QUERY);\n media.addEventListener(\"change\", onChange);\n return () => media.removeEventListener(\"change\", onChange);\n}\n\n/**\n * Whether the person has asked the system to reduce motion. It reads the prefers-reduced-motion media\n * query and follows later changes, so animated components can skip or shorten their motion. On the\n * server, and for the first render while hydrating, it returns false so the markup matches.\n */\nexport function useReduceMotion(): boolean {\n return useSyncExternalStore(\n subscribe,\n () => window.matchMedia(QUERY).matches,\n () => false,\n );\n}\n" + }, + { + "path": "registry/use-reduce-motion.native.ts", "content": "import { useEffect, useState } from \"react\";\nimport { AccessibilityInfo } from \"react-native\";\n\n/**\n * Whether the person has asked the system to reduce motion. It reads the setting once on mount and\n * follows later changes, so animated components can skip or shorten their motion. It starts as false\n * until the platform answers.\n */\nexport function useReduceMotion(): boolean {\n const [reduce, setReduce] = useState(false);\n\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const subscription = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => subscription.remove();\n }, []);\n\n return reduce;\n}\n" } ] diff --git a/public/registry/value-slider.json b/public/registry/value-slider.json index 8c3a35e..a51cf95 100644 --- a/public/registry/value-slider.json +++ b/public/registry/value-slider.json @@ -1,7 +1,7 @@ { "name": "value-slider", "title": "Value Slider", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/public/registry/wave-bars.json b/public/registry/wave-bars.json index d847307..7334cda 100644 --- a/public/registry/wave-bars.json +++ b/public/registry/wave-bars.json @@ -1,7 +1,7 @@ { "name": "wave-bars", "title": "Wave Bars", - "category": "React Native", + "category": "React Native · Progress", "type": "components:ui", "platform": "native", "added": "2026-11-03", diff --git a/public/registry/wheel-picker.json b/public/registry/wheel-picker.json index b04c8e0..f50bed4 100644 --- a/public/registry/wheel-picker.json +++ b/public/registry/wheel-picker.json @@ -1,7 +1,7 @@ { "name": "wheel-picker", "title": "Wheel Picker", - "category": "React Native", + "category": "React Native · Inputs", "type": "components:ui", "platform": "native", "added": "2026-11-02", diff --git a/scripts/build-registry.ts b/scripts/build-registry.ts index 0974dd3..40551e9 100644 --- a/scripts/build-registry.ts +++ b/scripts/build-registry.ts @@ -14,8 +14,11 @@ const failures: string[] = []; for (const item of registry) { try { - const content = fs.readFileSync(path.join(process.cwd(), "src", item.files[0]), "utf8"); - const payload = { ...item, files: [{ path: item.files[0], content }] }; + const files = item.files.map((file) => ({ + path: file, + content: fs.readFileSync(path.join(process.cwd(), "src", file), "utf8"), + })); + const payload = { ...item, files }; fs.writeFileSync( path.join(REGISTRY_PATH, `${item.name}.json`), diff --git a/src/app/components/layout.tsx b/src/app/components/layout.tsx index c60f453..55dff5a 100644 --- a/src/app/components/layout.tsx +++ b/src/app/components/layout.tsx @@ -16,8 +16,14 @@ import { type LucideIcon, Box, PanelsTopLeft, - Smartphone, Webhook, + TextCursorInput, + MousePointerClick, + Compass, + PanelBottom, + Bell, + Loader, + Table2, Layers, Palette, } from "lucide-react"; @@ -33,7 +39,13 @@ const CATEGORY_ICONS: Record = { Typography: Type, Sections: PanelsTopLeft, Components: LayoutTemplate, - "React Native": Smartphone, + "React Native · Inputs": TextCursorInput, + "React Native · Buttons": MousePointerClick, + "React Native · Navigation": Compass, + "React Native · Overlays": PanelBottom, + "React Native · Feedback": Bell, + "React Native · Progress": Loader, + "React Native · Data": Table2, Hooks: Webhook, Providers: Layers, Theme: Palette, diff --git a/src/components/component-preview-client.tsx b/src/components/component-preview-client.tsx index 290bfc2..2df8a59 100644 --- a/src/components/component-preview-client.tsx +++ b/src/components/component-preview-client.tsx @@ -9,23 +9,29 @@ import { cn } from "@/lib/utils"; import { ThemePicker } from "@/components/theme-picker"; import { CopyPromptButton } from "@/components/copy-prompt-button"; -interface ComponentPreviewClientProps { - name: string; +interface Variant { + label: string; preview: React.ReactNode; code: string; filePath: string; highlightedCode: React.ReactNode; } +interface ComponentPreviewClientProps extends Omit { + name: string; + /** Versions of the same item for different platforms, such as React and React Native. */ + variants?: Variant[]; +} + export const ComponentPreviewClient = ({ name, - preview, - code, - filePath, - highlightedCode, + variants, + ...single }: ComponentPreviewClientProps) => { const [activeTab, setActiveTab] = useState("preview"); const [key, setKey] = useState(0); + const [variant, setVariant] = useState(0); + const { preview, code, filePath, highlightedCode } = variants?.[variant] ?? single; const handleRestart = () => { setKey((prev) => prev + 1); @@ -53,6 +59,34 @@ export const ComponentPreviewClient = ({ ))}
+ {variants && ( +
+ {variants.map((item, i) => ( + + ))} +
+ )}
diff --git a/src/components/component-preview.tsx b/src/components/component-preview.tsx index 863fbc7..b3de9f0 100644 --- a/src/components/component-preview.tsx +++ b/src/components/component-preview.tsx @@ -20,8 +20,30 @@ export const ComponentPreview = async ({ name }: ComponentPreviewProps) => { const filePath = component.files[0] || `components/ui/${name}.tsx`; + // An item with separate React and React Native files gets a switch between the two. + const variants = + component.nativeFile && component.nativeContent + ? [ + { + label: "React", + preview: , + code: component.content, + filePath, + highlightedCode: , + }, + { + label: "React Native", + preview: , + code: component.nativeContent, + filePath: component.nativeFile, + highlightedCode: , + }, + ] + : undefined; + return ( } code={component.content} diff --git a/src/components/platform-icon.tsx b/src/components/platform-icon.tsx index 9477e63..3d013c8 100644 --- a/src/components/platform-icon.tsx +++ b/src/components/platform-icon.tsx @@ -1,9 +1,13 @@ import { Globe, Smartphone } from "lucide-react"; import { cn } from "@/lib/utils"; -export type ComponentPlatform = "web" | "native"; +export type ComponentPlatform = "web" | "native" | "both"; -const LABELS: Record = { web: "Web", native: "React Native" }; +const LABELS: Record = { + web: "Web", + native: "React Native", + both: "React and React Native", +}; /** A small icon telling web components (globe) from React Native ones (phone). */ export function PlatformIcon({ @@ -13,21 +17,41 @@ export function PlatformIcon({ platform: ComponentPlatform; className?: string; }) { - const Icon = platform === "native" ? Smartphone : Globe; + const icons = + platform === "both" ? [Globe, Smartphone] : [platform === "native" ? Smartphone : Globe]; return ( - - + + {icons.map((Icon, i) => ( + + ))} ); } /** Icon and name together, for the top of a component's page. */ export function PlatformBadge({ platform }: { platform: ComponentPlatform }) { - const Icon = platform === "native" ? Smartphone : Globe; + const icons = + platform === "both" ? [Globe, Smartphone] : [platform === "native" ? Smartphone : Globe]; + const text = { + web: "Web (React)", + native: "React Native (Expo)", + both: "React and React Native", + }[platform]; return ( - - {platform === "native" ? "React Native (Expo)" : "Web (React)"} + {icons.map((Icon, i) => ( + + ))} + {text} ); } diff --git a/src/components/registry-demo.tsx b/src/components/registry-demo.tsx index aebd54b..543d268 100644 --- a/src/components/registry-demo.tsx +++ b/src/components/registry-demo.tsx @@ -1,12 +1,12 @@ "use client"; -import { getDemo } from "@/registry/demos"; +import { getDemo, getWebDemo } from "@/registry/demos"; /** * Renders a component's demo by name. The lookup runs on the client so a server page references only * this component, and each demo stays in its own lazily loaded chunk instead of every page's bundle. */ -export function RegistryDemo({ name }: { name: string }) { - const Demo = getDemo(name); +export function RegistryDemo({ name, variant }: { name: string; variant?: "web" }) { + const Demo = variant === "web" ? getWebDemo(name) : getDemo(name); return Demo ? : null; } diff --git a/src/content/docs/mode-provider.mdx b/src/content/docs/mode-provider.mdx index 8d6c13c..7cb6c4f 100644 --- a/src/content/docs/mode-provider.mdx +++ b/src/content/docs/mode-provider.mdx @@ -3,7 +3,7 @@ title: ModeProvider description: A React Native provider that holds the light, dark or system choice and exposes it through a useMode hook. --- -Holds the light, dark or system choice for the whole app. Read it anywhere below with `useMode()`. "system" follows the device and updates when the device changes. The provider keeps the choice in memory only; save it from `onModeChange` and pass it back as `initialMode` to remember it. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +Holds the light, dark or system choice for the whole app. Read it anywhere below with `useMode()`. "system" follows the device and updates when the device changes. The provider keeps the choice in memory only; save it from `onModeChange` and pass it back as `initialMode` to remember it. Works in React and in React Native with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add mode-provider ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab, using the React or React Native switch for your project. 2. Create a file at `components/ui/mode-provider.tsx`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The CLI installs the React Native version in an Expo or React Native app and the React version everywhere else. In a project that targets both, keep the React file `mode-provider.tsx` and the React Native file `mode-provider.native.tsx` side by side and import `./mode-provider`; Metro picks the `.native` file on its own. ## Usage diff --git a/src/content/docs/theme-colors.mdx b/src/content/docs/theme-colors.mdx index 4ed10cf..3cd6c54 100644 --- a/src/content/docs/theme-colors.mdx +++ b/src/content/docs/theme-colors.mdx @@ -3,7 +3,7 @@ title: Colors description: Light and dark colour palettes for React Native, named by role, with a helper that adds transparency to any colour. --- -Every colour a screen needs, named by role rather than by shade, so light and dark can swap freely. `lightColors` and `darkColors` hold the same nine names, and `withAlpha` turns any #rrggbb colour into an rgba() string for overlays and pressed states. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +Every colour a screen needs, named by role rather than by shade, so light and dark can swap freely. `lightColors` and `darkColors` hold the same nine names, and `withAlpha` turns any #rrggbb colour into an rgba() string for overlays and pressed states. One file that works unchanged in React and in React Native, with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add theme-colors ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab. 2. Create a file at `components/ui/theme-colors.ts`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The same file serves React and React Native, so the CLI installs it unchanged in either. ## Usage diff --git a/src/content/docs/theme-globals.mdx b/src/content/docs/theme-globals.mdx index a9f65ef..870a0d0 100644 --- a/src/content/docs/theme-globals.mdx +++ b/src/content/docs/theme-globals.mdx @@ -3,7 +3,7 @@ title: Globals description: Shared React Native design tokens for spacing, corner radius, type sizes, font weights and shadows. --- -The numbers every screen repeats, in one place. Pick spacing, radius, type size and shadow from a scale instead of typing a value, and the whole app stays consistent when you change one. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +The numbers every screen repeats, in one place. Pick spacing, radius, type size and shadow from a scale instead of typing a value, and the whole app stays consistent when you change one. One file that works unchanged in React and in React Native, with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add theme-globals ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab. 2. Create a file at `components/ui/theme-globals.ts`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The same file serves React and React Native, so the CLI installs it unchanged in either. ## Usage diff --git a/src/content/docs/theme-provider.mdx b/src/content/docs/theme-provider.mdx index 1872198..d16cbb1 100644 --- a/src/content/docs/theme-provider.mdx +++ b/src/content/docs/theme-provider.mdx @@ -3,7 +3,7 @@ title: ThemeProvider description: A React Native provider that supplies one colour palette to the tree through a useTheme hook, with per-colour overrides. --- -Supplies one palette to everything below it. Components call `useTheme()` and read colours by role, so switching between light and dark restyles the whole tree at once with no per-component logic. Override individual colours with `colors`; anything you leave out keeps its default. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +Supplies one palette to everything below it. Components call `useTheme()` and read colours by role, so switching between light and dark restyles the whole tree at once with no per-component logic. Override individual colours with `colors`; anything you leave out keeps its default. Works in React and in React Native with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add theme-provider ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab, using the React or React Native switch for your project. 2. Create a file at `components/ui/theme-provider.tsx`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The CLI installs the React Native version in an Expo or React Native app and the React version everywhere else. In a project that targets both, keep the React file `theme-provider.tsx` and the React Native file `theme-provider.native.tsx` side by side and import `./theme-provider`; Metro picks the `.native` file on its own. ## Usage diff --git a/src/content/docs/use-color-scheme.mdx b/src/content/docs/use-color-scheme.mdx index 3a98607..e44d4e8 100644 --- a/src/content/docs/use-color-scheme.mdx +++ b/src/content/docs/use-color-scheme.mdx @@ -3,7 +3,7 @@ title: useColorScheme description: A React Native hook that returns the system colour scheme as light or dark, never null. --- -The system colour scheme, always "light" or "dark". React Native's own hook can return null before the platform reports a value; this one falls back to light so styles never see a missing scheme. It re-renders when the person switches appearance. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +The system colour scheme, always "light" or "dark". React Native's own hook can return null before the platform reports a value; this one falls back to light so styles never see a missing scheme. It re-renders when the person switches appearance. Works in React and in React Native with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add use-color-scheme ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab, using the React or React Native switch for your project. 2. Create a file at `components/ui/use-color-scheme.ts`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The CLI installs the React Native version in an Expo or React Native app and the React version everywhere else. In a project that targets both, keep the React file `use-color-scheme.ts` and the React Native file `use-color-scheme.native.ts` side by side and import `./use-color-scheme`; Metro picks the `.native` file on its own. ## Usage diff --git a/src/content/docs/use-debounced-value.mdx b/src/content/docs/use-debounced-value.mdx index 407dcca..189f12a 100644 --- a/src/content/docs/use-debounced-value.mdx +++ b/src/content/docs/use-debounced-value.mdx @@ -3,7 +3,7 @@ title: useDebouncedValue description: A React Native hook that returns a copy of a value which only updates after it stops changing. --- -A copy of `value` that only updates after it has stopped changing for `delay` milliseconds. Use it to wait out typing before searching: render with the live value, query with the debounced one. The first render returns the value straight away. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +A copy of `value` that only updates after it has stopped changing for `delay` milliseconds. Use it to wait out typing before searching: render with the live value, query with the debounced one. The first render returns the value straight away. One file that works unchanged in React and in React Native, with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add use-debounced-value ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab. 2. Create a file at `components/ui/use-debounced-value.ts`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The same file serves React and React Native, so the CLI installs it unchanged in either. ## Usage diff --git a/src/content/docs/use-haptics.mdx b/src/content/docs/use-haptics.mdx index f8490dc..7be6f01 100644 --- a/src/content/docs/use-haptics.mdx +++ b/src/content/docs/use-haptics.mdx @@ -3,7 +3,7 @@ title: useHaptics description: A React Native hook for touch feedback with tap, success, warning and error patterns that you can switch off. --- -Touch feedback built on React Native's Vibration, so it needs no extra package. Pass `enabled` false, for example from a settings switch, and every call does nothing. Android follows the patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback swap the bodies for expo-haptics. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +Touch feedback built on React Native's Vibration, so it needs no extra package. Pass `enabled` false, for example from a settings switch, and every call does nothing. Android follows the patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback swap the bodies for expo-haptics. Works in React and in React Native with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add use-haptics ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab, using the React or React Native switch for your project. 2. Create a file at `components/ui/use-haptics.ts`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The CLI installs the React Native version in an Expo or React Native app and the React version everywhere else. In a project that targets both, keep the React file `use-haptics.ts` and the React Native file `use-haptics.native.ts` side by side and import `./use-haptics`; Metro picks the `.native` file on its own. ## Usage diff --git a/src/content/docs/use-keyboard-height.mdx b/src/content/docs/use-keyboard-height.mdx index 4b4123d..ca2017f 100644 --- a/src/content/docs/use-keyboard-height.mdx +++ b/src/content/docs/use-keyboard-height.mdx @@ -3,7 +3,7 @@ title: useKeyboardHeight description: A React Native hook that returns the on-screen keyboard height, or 0 while it is hidden. --- -The height of the on-screen keyboard, or 0 while it is hidden. On iOS it updates as the keyboard starts to move, so a view can slide up alongside it; on Android it updates once the keyboard has finished appearing. It is always 0 on the web, where there is no on-screen keyboard to measure. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +The height of the on-screen keyboard, or 0 while it is hidden. On iOS it updates as the keyboard starts to move, so a view can slide up alongside it; on Android it updates once the keyboard has finished appearing. It is always 0 on the web, where there is no on-screen keyboard to measure. Works in React and in React Native with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add use-keyboard-height ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab, using the React or React Native switch for your project. 2. Create a file at `components/ui/use-keyboard-height.ts`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The CLI installs the React Native version in an Expo or React Native app and the React version everywhere else. In a project that targets both, keep the React file `use-keyboard-height.ts` and the React Native file `use-keyboard-height.native.ts` side by side and import `./use-keyboard-height`; Metro picks the `.native` file on its own. ## Usage diff --git a/src/content/docs/use-reduce-motion.mdx b/src/content/docs/use-reduce-motion.mdx index cc4d6ea..9987168 100644 --- a/src/content/docs/use-reduce-motion.mdx +++ b/src/content/docs/use-reduce-motion.mdx @@ -3,7 +3,7 @@ title: useReduceMotion description: A React Native hook that reports whether the system asks to reduce motion and follows later changes. --- -Whether the person has asked the system to reduce motion. It reads the setting once on mount and follows later changes, so animated components can skip or shorten their motion. It starts as false until the platform answers. Built for React Native and Expo with `react-native` only; this page previews it in the browser through react-native-web. +Whether the person has asked the system to reduce motion. It reads the setting once on mount and follows later changes, so animated components can skip or shorten their motion. It starts as false until the platform answers. Works in React and in React Native with no extra packages. @@ -17,11 +17,11 @@ npx @modus-ui/cli add use-reduce-motion ### Manual -1. Copy the code from the component tab. +1. Copy the code from the code tab, using the React or React Native switch for your project. 2. Create a file at `components/ui/use-reduce-motion.ts`. 3. Paste the code. -It needs no packages beyond `react-native`, which your Expo or React Native app already has. +The CLI installs the React Native version in an Expo or React Native app and the React version everywhere else. In a project that targets both, keep the React file `use-reduce-motion.ts` and the React Native file `use-reduce-motion.native.ts` side by side and import `./use-reduce-motion`; Metro picks the `.native` file on its own. ## Usage diff --git a/src/lib/agent-docs.ts b/src/lib/agent-docs.ts index 0724bc4..977e2b5 100644 --- a/src/lib/agent-docs.ts +++ b/src/lib/agent-docs.ts @@ -56,7 +56,12 @@ export function componentMarkdown(name: string): string | null { `> ${doc.description}`, `Install: \`${SITE.cli} ${name}\``, doc.body, - `## Source\n\n\`components/ui/${name}.tsx\`\n\n\`\`\`tsx\n${component.content.trimEnd()}\n\`\`\``, + component.nativeContent + ? [ + `## Source (React)\n\n\`${component.files[0]}\`\n\n\`\`\`tsx\n${component.content.trimEnd()}\n\`\`\``, + `## Source (React Native)\n\n\`${component.nativeFile}\`\n\n\`\`\`tsx\n${component.nativeContent.trimEnd()}\n\`\`\``, + ].join("\n\n") + : `## Source\n\n\`components/ui/${name}.tsx\`\n\n\`\`\`tsx\n${component.content.trimEnd()}\n\`\`\``, ].join("\n\n"); } diff --git a/src/lib/registry.ts b/src/lib/registry.ts index 405d4dd..a201948 100644 --- a/src/lib/registry.ts +++ b/src/lib/registry.ts @@ -14,20 +14,32 @@ export function isNew(item: RegistryItem) { return !!item.added && Date.now() - Date.parse(item.added) < NEW_FOR_MS; } -/** Whether a component is a web (React) or React Native one. Defaults to web. */ -export function platformOf(item: RegistryItem): "web" | "native" { +/** Whether a component is a web (React) one, a React Native one, or works in both. Defaults to web. */ +export function platformOf(item: RegistryItem): "web" | "native" | "both" { return item.platform ?? "web"; } +/** The React Native file of an item, when it has one that differs from its React file. */ +export const nativeFileOf = (item: RegistryItem) => + item.platform === "native" + ? item.files[0] + : item.files.find((file) => /\.native\.tsx?$/.test(file)); + export function getRegistryComponent(name: string) { - const item = registry.find((c) => c.name === name); + const item: RegistryItem | undefined = registry.find((c) => c.name === name); if (!item) return null; const filePath = path.join(process.cwd(), "src", item.files[0]); const content = fs.readFileSync(filePath, "utf8"); + const nativeFile = nativeFileOf(item); return { ...item, content, + nativeFile: item.platform === "both" ? nativeFile : undefined, + nativeContent: + item.platform === "both" && nativeFile + ? fs.readFileSync(path.join(process.cwd(), "src", nativeFile), "utf8") + : undefined, }; } diff --git a/src/registry/demos.ts b/src/registry/demos.ts index 694c969..993bd75 100644 --- a/src/registry/demos.ts +++ b/src/registry/demos.ts @@ -324,3 +324,18 @@ export const demos: Record = { export function getDemo(name: string): ComponentType | undefined { return Object.hasOwn(demos, name) ? demos[name as ComponentName] : undefined; } + +// The React version of a "both" item whose React and React Native files differ. Items that share one file +// are previewed by the React Native demo alone, which react-native-web draws in the browser too. +const webDemos: Partial> = { + "use-color-scheme": dynamic(() => import("./web-demos/use-color-scheme"), { ssr: false }), + "use-keyboard-height": dynamic(() => import("./web-demos/use-keyboard-height"), { ssr: false }), + "use-haptics": dynamic(() => import("./web-demos/use-haptics"), { ssr: false }), + "use-reduce-motion": dynamic(() => import("./web-demos/use-reduce-motion"), { ssr: false }), + "mode-provider": dynamic(() => import("./web-demos/mode-provider"), { ssr: false }), + "theme-provider": dynamic(() => import("./web-demos/theme-provider"), { ssr: false }), +}; + +export function getWebDemo(name: string): ComponentType | undefined { + return Object.hasOwn(webDemos, name) ? webDemos[name as ComponentName] : undefined; +} diff --git a/src/registry/index.ts b/src/registry/index.ts index f5a679a..def545b 100644 --- a/src/registry/index.ts +++ b/src/registry/index.ts @@ -12,7 +12,13 @@ export const CATEGORIES = [ "Typography", "Sections", "Components", - "React Native", + "React Native · Inputs", + "React Native · Buttons", + "React Native · Navigation", + "React Native · Overlays", + "React Native · Feedback", + "React Native · Progress", + "React Native · Data", "Hooks", "Providers", "Theme", @@ -50,9 +56,11 @@ export interface RegistryItem { /** * "native" components are React Native (Expo) files, previewed on the site through react-native-web. * They import only `react-native`, which the host app already has, so they list no dependencies. + * "both" items work in React and in React Native. Their first file is the React version; a second file + * ending in `.native.ts(x)` is the React Native version, and a single file works unchanged on both. * Defaults to "web". */ - platform?: "web" | "native"; + platform?: "web" | "native" | "both"; dependencies: readonly string[]; files: readonly string[]; /** Date first published (YYYY-MM-DD). Shows a New badge for 30 days after it. */ @@ -4140,7 +4148,7 @@ export const registry = [ { name: "swipe-actions", title: "Swipe Actions", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-10-30", @@ -4150,7 +4158,7 @@ export const registry = [ { name: "snap-sheet", title: "Snap Sheet", - category: "React Native", + category: "React Native · Overlays", type: "components:ui", platform: "native", added: "2026-10-30", @@ -4160,7 +4168,7 @@ export const registry = [ { name: "glide-segments", title: "Glide Segments", - category: "React Native", + category: "React Native · Navigation", type: "components:ui", platform: "native", added: "2026-10-30", @@ -4170,7 +4178,7 @@ export const registry = [ { name: "swipe-deck", title: "Swipe Deck", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-10-30", @@ -4180,7 +4188,7 @@ export const registry = [ { name: "fan-menu", title: "Fan Menu", - category: "React Native", + category: "React Native · Buttons", type: "components:ui", platform: "native", added: "2026-10-30", @@ -4190,7 +4198,7 @@ export const registry = [ { name: "pin-pad", title: "Pin Pad", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-10-30", @@ -4200,7 +4208,7 @@ export const registry = [ { name: "flick-toast", title: "Flick Toast", - category: "React Native", + category: "React Native · Feedback", type: "components:ui", platform: "native", added: "2026-11-01", @@ -4210,7 +4218,7 @@ export const registry = [ { name: "fold-panel", title: "Fold Panel", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-01", @@ -4220,7 +4228,7 @@ export const registry = [ { name: "snap-carousel", title: "Snap Carousel", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-01", @@ -4230,7 +4238,7 @@ export const registry = [ { name: "slide-switch", title: "Slide Switch", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-01", @@ -4240,7 +4248,7 @@ export const registry = [ { name: "shimmer-block", title: "Shimmer Block", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-01", @@ -4250,7 +4258,7 @@ export const registry = [ { name: "parallax-header", title: "Parallax Header", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-01", @@ -4260,7 +4268,7 @@ export const registry = [ { name: "bubble-tab-bar", title: "Bubble Tab Bar", - category: "React Native", + category: "React Native · Navigation", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4270,7 +4278,7 @@ export const registry = [ { name: "roll-number", title: "Roll Number", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4280,7 +4288,7 @@ export const registry = [ { name: "star-rating", title: "Star Rating", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4290,7 +4298,7 @@ export const registry = [ { name: "value-slider", title: "Value Slider", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4300,7 +4308,7 @@ export const registry = [ { name: "expand-search", title: "Expand Search", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4310,7 +4318,7 @@ export const registry = [ { name: "intro-pager", title: "Intro Pager", - category: "React Native", + category: "React Native · Navigation", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4320,7 +4328,7 @@ export const registry = [ { name: "drag-list", title: "Drag List", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4330,7 +4338,7 @@ export const registry = [ { name: "long-press-menu", title: "Long Press Menu", - category: "React Native", + category: "React Native · Overlays", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4340,7 +4348,7 @@ export const registry = [ { name: "slide-confirm", title: "Slide Confirm", - category: "React Native", + category: "React Native · Buttons", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4350,7 +4358,7 @@ export const registry = [ { name: "calendar-strip", title: "Calendar Strip", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4360,7 +4368,7 @@ export const registry = [ { name: "step-tracker", title: "Step Tracker", - category: "React Native", + category: "React Native · Navigation", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4370,7 +4378,7 @@ export const registry = [ { name: "chip-input", title: "Chip Input", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4380,7 +4388,7 @@ export const registry = [ { name: "typing-dots", title: "Typing Dots", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4390,7 +4398,7 @@ export const registry = [ { name: "marquee-ticker", title: "Marquee Ticker", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4400,7 +4408,7 @@ export const registry = [ { name: "choice-chips", title: "Choice Chips", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4410,7 +4418,7 @@ export const registry = [ { name: "hold-stepper", title: "Hold Stepper", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4420,7 +4428,7 @@ export const registry = [ { name: "action-tray", title: "Action Tray", - category: "React Native", + category: "React Native · Overlays", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4430,7 +4438,7 @@ export const registry = [ { name: "confirm-dialog", title: "Confirm Dialog", - category: "React Native", + category: "React Native · Overlays", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4440,7 +4448,7 @@ export const registry = [ { name: "code-boxes", title: "Code Boxes", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4450,7 +4458,7 @@ export const registry = [ { name: "hue-picker", title: "Hue Picker", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4460,7 +4468,7 @@ export const registry = [ { name: "tab-pager", title: "Tab Pager", - category: "React Native", + category: "React Native · Navigation", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4470,7 +4478,7 @@ export const registry = [ { name: "wheel-picker", title: "Wheel Picker", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4480,7 +4488,7 @@ export const registry = [ { name: "avatar-stack", title: "Avatar Stack", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4490,7 +4498,7 @@ export const registry = [ { name: "stripe-progress", title: "Stripe Progress", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4500,7 +4508,7 @@ export const registry = [ { name: "range-slider", title: "Range Slider", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4510,7 +4518,7 @@ export const registry = [ { name: "tick-box", title: "Tick Box", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4520,7 +4528,7 @@ export const registry = [ { name: "notice-banner", title: "Notice Banner", - category: "React Native", + category: "React Native · Feedback", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4530,7 +4538,7 @@ export const registry = [ { name: "side-drawer", title: "Side Drawer", - category: "React Native", + category: "React Native · Navigation", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4540,7 +4548,7 @@ export const registry = [ { name: "reaction-bar", title: "Reaction Bar", - category: "React Native", + category: "React Native · Buttons", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4550,7 +4558,7 @@ export const registry = [ { name: "suggest-input", title: "Suggest Input", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4560,7 +4568,7 @@ export const registry = [ { name: "expand-card", title: "Expand Card", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4570,7 +4578,7 @@ export const registry = [ { name: "ring-meter", title: "Ring Meter", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4580,7 +4588,7 @@ export const registry = [ { name: "count-badge", title: "Count Badge", - category: "React Native", + category: "React Native · Feedback", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4590,7 +4598,7 @@ export const registry = [ { name: "float-field", title: "Float Field", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4600,7 +4608,7 @@ export const registry = [ { name: "month-grid", title: "Month Grid", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-02", @@ -4610,7 +4618,7 @@ export const registry = [ { name: "chat-bubble", title: "Chat Bubble", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4620,7 +4628,7 @@ export const registry = [ { name: "live-dot", title: "Live Dot", - category: "React Native", + category: "React Native · Feedback", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4630,7 +4638,7 @@ export const registry = [ { name: "composer-bar", title: "Composer Bar", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4640,7 +4648,7 @@ export const registry = [ { name: "setting-list", title: "Setting List", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4650,7 +4658,7 @@ export const registry = [ { name: "pull-refresh", title: "Pull Refresh", - category: "React Native", + category: "React Native · Feedback", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4660,7 +4668,7 @@ export const registry = [ { name: "story-bars", title: "Story Bars", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4670,7 +4678,7 @@ export const registry = [ { name: "action-button", title: "Action Button", - category: "React Native", + category: "React Native · Buttons", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4680,7 +4688,7 @@ export const registry = [ { name: "spin-loader", title: "Spin Loader", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4690,7 +4698,7 @@ export const registry = [ { name: "radio-group", title: "Radio Group", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4700,7 +4708,7 @@ export const registry = [ { name: "mode-toggle", title: "Mode Toggle", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4710,7 +4718,7 @@ export const registry = [ { name: "tip-popover", title: "Tip Popover", - category: "React Native", + category: "React Native · Overlays", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4720,7 +4728,7 @@ export const registry = [ { name: "data-table", title: "Data Table", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4730,7 +4738,7 @@ export const registry = [ { name: "wave-bars", title: "Wave Bars", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4740,7 +4748,7 @@ export const registry = [ { name: "page-dots", title: "Page Dots", - category: "React Native", + category: "React Native · Navigation", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4750,7 +4758,7 @@ export const registry = [ { name: "password-meter", title: "Password Meter", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4760,7 +4768,7 @@ export const registry = [ { name: "timeline-list", title: "Timeline List", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4770,7 +4778,7 @@ export const registry = [ { name: "empty-state", title: "Empty State", - category: "React Native", + category: "React Native · Feedback", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4780,7 +4788,7 @@ export const registry = [ { name: "rating-histogram", title: "Rating Histogram", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4790,7 +4798,7 @@ export const registry = [ { name: "countdown-timer", title: "Countdown Timer", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4800,7 +4808,7 @@ export const registry = [ { name: "contact-index", title: "Contact Index", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4810,7 +4818,7 @@ export const registry = [ { name: "select-grid", title: "Select Grid", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4820,7 +4828,7 @@ export const registry = [ { name: "poll-bars", title: "Poll Bars", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4830,7 +4838,7 @@ export const registry = [ { name: "card-field", title: "Card Field", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4840,7 +4848,7 @@ export const registry = [ { name: "step-slider", title: "Step Slider", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4850,7 +4858,7 @@ export const registry = [ { name: "cart-quantity", title: "Cart Quantity", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4860,7 +4868,7 @@ export const registry = [ { name: "password-field", title: "Password Field", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4870,7 +4878,7 @@ export const registry = [ { name: "resend-button", title: "Resend Button", - category: "React Native", + category: "React Native · Buttons", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4880,7 +4888,7 @@ export const registry = [ { name: "gauge-meter", title: "Gauge Meter", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4890,7 +4898,7 @@ export const registry = [ { name: "undo-snackbar", title: "Undo Snackbar", - category: "React Native", + category: "React Native · Feedback", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4900,7 +4908,7 @@ export const registry = [ { name: "mood-picker", title: "Mood Picker", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4910,7 +4918,7 @@ export const registry = [ { name: "expandable-text", title: "Expandable Text", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4920,7 +4928,7 @@ export const registry = [ { name: "extended-fab", title: "Extended FAB", - category: "React Native", + category: "React Native · Buttons", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4930,7 +4938,7 @@ export const registry = [ { name: "swatch-picker", title: "Swatch Picker", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4940,7 +4948,7 @@ export const registry = [ { name: "like-button", title: "Like Button", - category: "React Native", + category: "React Native · Buttons", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4950,7 +4958,7 @@ export const registry = [ { name: "task-checklist", title: "Task Checklist", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4960,7 +4968,7 @@ export const registry = [ { name: "spark-bars", title: "Spark Bars", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4970,7 +4978,7 @@ export const registry = [ { name: "battery-meter", title: "Battery Meter", - category: "React Native", + category: "React Native · Progress", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4980,7 +4988,7 @@ export const registry = [ { name: "compare-slider", title: "Compare Slider", - category: "React Native", + category: "React Native · Data", type: "components:ui", platform: "native", added: "2026-11-03", @@ -4990,7 +4998,7 @@ export const registry = [ { name: "hold-confirm", title: "Hold Confirm", - category: "React Native", + category: "React Native · Buttons", type: "components:ui", platform: "native", added: "2026-11-03", @@ -5000,7 +5008,7 @@ export const registry = [ { name: "select-menu", title: "Select Menu", - category: "React Native", + category: "React Native · Inputs", type: "components:ui", platform: "native", added: "2026-11-03", @@ -5012,47 +5020,47 @@ export const registry = [ title: "useColorScheme", category: "Hooks", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], - files: ["registry/use-color-scheme.ts"], + files: ["registry/use-color-scheme.ts", "registry/use-color-scheme.native.ts"], }, { name: "use-keyboard-height", title: "useKeyboardHeight", category: "Hooks", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], - files: ["registry/use-keyboard-height.ts"], + files: ["registry/use-keyboard-height.ts", "registry/use-keyboard-height.native.ts"], }, { name: "use-haptics", title: "useHaptics", category: "Hooks", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], - files: ["registry/use-haptics.ts"], + files: ["registry/use-haptics.ts", "registry/use-haptics.native.ts"], }, { name: "use-reduce-motion", title: "useReduceMotion", category: "Hooks", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], - files: ["registry/use-reduce-motion.ts"], + files: ["registry/use-reduce-motion.ts", "registry/use-reduce-motion.native.ts"], }, { name: "use-debounced-value", title: "useDebouncedValue", category: "Hooks", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], files: ["registry/use-debounced-value.ts"], @@ -5062,27 +5070,27 @@ export const registry = [ title: "ModeProvider", category: "Providers", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], - files: ["registry/mode-provider.tsx"], + files: ["registry/mode-provider.tsx", "registry/mode-provider.native.tsx"], }, { name: "theme-provider", title: "ThemeProvider", category: "Providers", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], - files: ["registry/theme-provider.tsx"], + files: ["registry/theme-provider.tsx", "registry/theme-provider.native.tsx"], }, { name: "theme-colors", title: "Colors", category: "Theme", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], files: ["registry/theme-colors.ts"], @@ -5092,7 +5100,7 @@ export const registry = [ title: "Globals", category: "Theme", type: "components:ui", - platform: "native", + platform: "both", added: "2026-11-05", dependencies: [], files: ["registry/theme-globals.ts"], diff --git a/src/registry/mode-provider-demo.tsx b/src/registry/mode-provider-demo.tsx index 09bc2f1..3b2db96 100644 --- a/src/registry/mode-provider-demo.tsx +++ b/src/registry/mode-provider-demo.tsx @@ -1,7 +1,7 @@ "use client"; import { Pressable, Text, View } from "react-native"; -import { ModeProvider, useMode, type Mode } from "./mode-provider"; +import { ModeProvider, useMode, type Mode } from "./mode-provider.native"; import { NativeStage } from "./native-stage"; const MODES: Mode[] = ["light", "dark", "system"]; diff --git a/src/registry/mode-provider.native.tsx b/src/registry/mode-provider.native.tsx new file mode 100644 index 0000000..b311c2c --- /dev/null +++ b/src/registry/mode-provider.native.tsx @@ -0,0 +1,61 @@ +import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from "react"; +import { useColorScheme } from "react-native"; + +export type Mode = "light" | "dark" | "system"; + +export interface ModeValue { + /** What the person chose: light, dark, or follow the system. */ + mode: Mode; + /** The scheme actually in effect, with "system" resolved to light or dark. */ + scheme: "light" | "dark"; + setMode: (mode: Mode) => void; + /** Switches to the opposite of the scheme in effect. */ + toggle: () => void; +} + +const ModeContext = createContext(null); + +export interface ModeProviderProps { + children: ReactNode; + /** The mode to start in. */ + initialMode?: Mode; + /** Called whenever the mode changes, so you can save it. */ + onModeChange?: (mode: Mode) => void; +} + +/** + * Holds the light, dark or system choice for the whole app. Read it anywhere below with `useMode()`. + * "system" follows the device and updates when the device changes. The provider keeps the choice in + * memory only; save it from `onModeChange` and pass it back as `initialMode` to remember it. + */ +export function ModeProvider({ + children, + initialMode = "system", + onModeChange, +}: ModeProviderProps) { + const system = useColorScheme() === "dark" ? "dark" : "light"; + const [mode, setModeState] = useState(initialMode); + const scheme = mode === "system" ? system : mode; + + const setMode = useCallback( + (next: Mode) => { + setModeState(next); + onModeChange?.(next); + }, + [onModeChange], + ); + const toggle = useCallback( + () => setMode(scheme === "dark" ? "light" : "dark"), + [scheme, setMode], + ); + + const value = useMemo(() => ({ mode, scheme, setMode, toggle }), [mode, scheme, setMode, toggle]); + return {children}; +} + +/** The current mode and scheme. Throws when used outside a ModeProvider, so a missing one is caught early. */ +export function useMode(): ModeValue { + const value = useContext(ModeContext); + if (!value) throw new Error("useMode must be used inside a ModeProvider"); + return value; +} diff --git a/src/registry/mode-provider.tsx b/src/registry/mode-provider.tsx index b311c2c..8c4760e 100644 --- a/src/registry/mode-provider.tsx +++ b/src/registry/mode-provider.tsx @@ -1,5 +1,29 @@ -import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from "react"; -import { useColorScheme } from "react-native"; +"use client"; + +import { + createContext, + useCallback, + useSyncExternalStore, + useContext, + useMemo, + useState, + type ReactNode, +} from "react"; + +const QUERY = "(prefers-color-scheme: dark)"; + +/** The system scheme from the prefers-color-scheme media query; "light" on the server so hydration matches. */ +function useSystemScheme(): "light" | "dark" { + return useSyncExternalStore( + (onChange) => { + const media = window.matchMedia(QUERY); + media.addEventListener("change", onChange); + return () => media.removeEventListener("change", onChange); + }, + () => (window.matchMedia(QUERY).matches ? "dark" : "light"), + () => "light", + ); +} export type Mode = "light" | "dark" | "system"; @@ -33,7 +57,7 @@ export function ModeProvider({ initialMode = "system", onModeChange, }: ModeProviderProps) { - const system = useColorScheme() === "dark" ? "dark" : "light"; + const system = useSystemScheme(); const [mode, setModeState] = useState(initialMode); const scheme = mode === "system" ? system : mode; diff --git a/src/registry/theme-provider-demo.tsx b/src/registry/theme-provider-demo.tsx index 009cc85..b500817 100644 --- a/src/registry/theme-provider-demo.tsx +++ b/src/registry/theme-provider-demo.tsx @@ -1,8 +1,8 @@ "use client"; import { Pressable, Text, View } from "react-native"; -import { ThemeProvider, useTheme } from "./theme-provider"; -import { ModeProvider, useMode } from "./mode-provider"; +import { ThemeProvider, useTheme } from "./theme-provider.native"; +import { ModeProvider, useMode } from "./mode-provider.native"; import { NativeStage } from "./native-stage"; function Card() { diff --git a/src/registry/theme-provider.native.tsx b/src/registry/theme-provider.native.tsx new file mode 100644 index 0000000..68050b9 --- /dev/null +++ b/src/registry/theme-provider.native.tsx @@ -0,0 +1,84 @@ +import { createContext, useContext, useMemo, type ReactNode } from "react"; +import { useColorScheme } from "react-native"; + +export interface ThemePalette { + background: string; + foreground: string; + card: string; + muted: string; + mutedForeground: string; + primary: string; + primaryForeground: string; + border: string; + destructive: string; +} + +export interface ThemeColors { + light: Partial; + dark: Partial; +} + +const LIGHT: ThemePalette = { + background: "#ffffff", + foreground: "#111827", + card: "#f9fafb", + muted: "#f3f4f6", + mutedForeground: "#6b7280", + primary: "#4f46e5", + primaryForeground: "#ffffff", + border: "#e5e7eb", + destructive: "#dc2626", +}; + +const DARK: ThemePalette = { + background: "#0b0b0f", + foreground: "#f9fafb", + card: "#16161d", + muted: "#1f1f29", + mutedForeground: "#9ca3af", + primary: "#818cf8", + primaryForeground: "#0b0b0f", + border: "#2a2a36", + destructive: "#f87171", +}; + +export interface Theme { + scheme: "light" | "dark"; + colors: ThemePalette; +} + +const ThemeContext = createContext(null); + +export interface ThemeProviderProps { + children: ReactNode; + /** Which palette to use. Leave it out to follow the system; pass `useMode().scheme` to follow your own switch. */ + scheme?: "light" | "dark"; + /** Overrides for single colours in either palette. */ + colors?: Partial; +} + +/** + * Supplies one palette to everything below it. Components call `useTheme()` and read colours by role, + * so switching between light and dark restyles the whole tree at once with no per-component logic. + * Override individual colours with `colors`; anything you leave out keeps its default. + */ +export function ThemeProvider({ children, scheme, colors }: ThemeProviderProps) { + const system = useColorScheme() === "dark" ? "dark" : "light"; + const active = scheme ?? system; + + const value = useMemo( + () => ({ + scheme: active, + colors: active === "dark" ? { ...DARK, ...colors?.dark } : { ...LIGHT, ...colors?.light }, + }), + [active, colors], + ); + return {children}; +} + +/** The active scheme and its colours. Throws when used outside a ThemeProvider. */ +export function useTheme(): Theme { + const value = useContext(ThemeContext); + if (!value) throw new Error("useTheme must be used inside a ThemeProvider"); + return value; +} diff --git a/src/registry/theme-provider.tsx b/src/registry/theme-provider.tsx index 68050b9..83366ab 100644 --- a/src/registry/theme-provider.tsx +++ b/src/registry/theme-provider.tsx @@ -1,5 +1,21 @@ -import { createContext, useContext, useMemo, type ReactNode } from "react"; -import { useColorScheme } from "react-native"; +"use client"; + +import { createContext, useSyncExternalStore, useContext, useMemo, type ReactNode } from "react"; + +const QUERY = "(prefers-color-scheme: dark)"; + +/** The system scheme from the prefers-color-scheme media query; "light" on the server so hydration matches. */ +function useSystemScheme(): "light" | "dark" { + return useSyncExternalStore( + (onChange) => { + const media = window.matchMedia(QUERY); + media.addEventListener("change", onChange); + return () => media.removeEventListener("change", onChange); + }, + () => (window.matchMedia(QUERY).matches ? "dark" : "light"), + () => "light", + ); +} export interface ThemePalette { background: string; @@ -63,7 +79,7 @@ export interface ThemeProviderProps { * Override individual colours with `colors`; anything you leave out keeps its default. */ export function ThemeProvider({ children, scheme, colors }: ThemeProviderProps) { - const system = useColorScheme() === "dark" ? "dark" : "light"; + const system = useSystemScheme(); const active = scheme ?? system; const value = useMemo( diff --git a/src/registry/use-color-scheme-demo.tsx b/src/registry/use-color-scheme-demo.tsx index 06743e4..db02adc 100644 --- a/src/registry/use-color-scheme-demo.tsx +++ b/src/registry/use-color-scheme-demo.tsx @@ -1,7 +1,7 @@ "use client"; import { Text, View } from "react-native"; -import { useColorScheme } from "./use-color-scheme"; +import { useColorScheme } from "./use-color-scheme.native"; import { NativeStage } from "./native-stage"; function Readout() { diff --git a/src/registry/use-color-scheme.native.ts b/src/registry/use-color-scheme.native.ts new file mode 100644 index 0000000..60838d9 --- /dev/null +++ b/src/registry/use-color-scheme.native.ts @@ -0,0 +1,12 @@ +import { useColorScheme as useSystemScheme } from "react-native"; + +export type Scheme = "light" | "dark"; + +/** + * The system colour scheme, always "light" or "dark". React Native's own hook can return null before + * the platform reports a value; this one falls back to light so styles never see a missing scheme. + * It re-renders when the user switches appearance. + */ +export function useColorScheme(): Scheme { + return useSystemScheme() === "dark" ? "dark" : "light"; +} diff --git a/src/registry/use-color-scheme.ts b/src/registry/use-color-scheme.ts index 60838d9..cd8484a 100644 --- a/src/registry/use-color-scheme.ts +++ b/src/registry/use-color-scheme.ts @@ -1,12 +1,26 @@ -import { useColorScheme as useSystemScheme } from "react-native"; +"use client"; + +import { useSyncExternalStore } from "react"; export type Scheme = "light" | "dark"; +const QUERY = "(prefers-color-scheme: dark)"; + +function subscribe(onChange: () => void) { + const media = window.matchMedia(QUERY); + media.addEventListener("change", onChange); + return () => media.removeEventListener("change", onChange); +} + /** - * The system colour scheme, always "light" or "dark". React Native's own hook can return null before - * the platform reports a value; this one falls back to light so styles never see a missing scheme. - * It re-renders when the user switches appearance. + * The system colour scheme, always "light" or "dark". It reads the prefers-color-scheme media query and + * re-renders when the person switches appearance. On the server, and for the first render while + * hydrating, it returns "light" so the markup matches. */ export function useColorScheme(): Scheme { - return useSystemScheme() === "dark" ? "dark" : "light"; + return useSyncExternalStore( + subscribe, + () => (window.matchMedia(QUERY).matches ? "dark" : "light"), + () => "light", + ); } diff --git a/src/registry/use-debounced-value.ts b/src/registry/use-debounced-value.ts index 65d81b5..d9f5c82 100644 --- a/src/registry/use-debounced-value.ts +++ b/src/registry/use-debounced-value.ts @@ -1,3 +1,5 @@ +"use client"; + import { useEffect, useState } from "react"; /** diff --git a/src/registry/use-haptics-demo.tsx b/src/registry/use-haptics-demo.tsx index 8d60acb..e1d7800 100644 --- a/src/registry/use-haptics-demo.tsx +++ b/src/registry/use-haptics-demo.tsx @@ -2,7 +2,7 @@ import { useState } from "react"; import { Pressable, Text, View } from "react-native"; -import { useHaptics } from "./use-haptics"; +import { useHaptics } from "./use-haptics.native"; import { NativeStage } from "./native-stage"; export function UseHapticsDemo() { diff --git a/src/registry/use-haptics.native.ts b/src/registry/use-haptics.native.ts new file mode 100644 index 0000000..cca21c8 --- /dev/null +++ b/src/registry/use-haptics.native.ts @@ -0,0 +1,33 @@ +import { useMemo } from "react"; +import { Vibration } from "react-native"; + +export interface Haptics { + /** A light tick, for a press or a selection. */ + tap: () => void; + /** Two short pulses, for something that worked. */ + success: () => void; + /** Two firmer pulses, for something that needs attention. */ + warning: () => void; + /** Three pulses, for something that failed. */ + error: () => void; +} + +/** + * Touch feedback built on React Native's Vibration, so it needs no extra package. Pass `enabled` + * false, for example from a settings switch, and every call does nothing. Android follows the + * patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback + * swap the bodies for expo-haptics. + */ +export function useHaptics(enabled = true): Haptics { + return useMemo(() => { + const run = (pattern: number | number[]) => { + if (enabled) Vibration.vibrate(pattern); + }; + return { + tap: () => run(10), + success: () => run([0, 15, 60, 15]), + warning: () => run([0, 30, 50, 30]), + error: () => run([0, 50, 40, 50, 40, 50]), + }; + }, [enabled]); +} diff --git a/src/registry/use-haptics.ts b/src/registry/use-haptics.ts index cca21c8..bd168ae 100644 --- a/src/registry/use-haptics.ts +++ b/src/registry/use-haptics.ts @@ -1,5 +1,6 @@ +"use client"; + import { useMemo } from "react"; -import { Vibration } from "react-native"; export interface Haptics { /** A light tick, for a press or a selection. */ @@ -13,15 +14,14 @@ export interface Haptics { } /** - * Touch feedback built on React Native's Vibration, so it needs no extra package. Pass `enabled` - * false, for example from a settings switch, and every call does nothing. Android follows the - * patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback - * swap the bodies for expo-haptics. + * Touch feedback built on the browser's Vibration API, so it needs no extra package. Pass `enabled` + * false, for example from a settings switch, and every call does nothing. Browsers that cannot vibrate, + * which includes Safari and every desktop browser, ignore the calls without an error. */ export function useHaptics(enabled = true): Haptics { return useMemo(() => { const run = (pattern: number | number[]) => { - if (enabled) Vibration.vibrate(pattern); + if (enabled && typeof navigator !== "undefined") navigator.vibrate?.(pattern); }; return { tap: () => run(10), diff --git a/src/registry/use-keyboard-height-demo.tsx b/src/registry/use-keyboard-height-demo.tsx index 7f35cb1..23d1bb5 100644 --- a/src/registry/use-keyboard-height-demo.tsx +++ b/src/registry/use-keyboard-height-demo.tsx @@ -1,7 +1,7 @@ "use client"; import { Text, TextInput, View } from "react-native"; -import { useKeyboardHeight } from "./use-keyboard-height"; +import { useKeyboardHeight } from "./use-keyboard-height.native"; import { NativeStage } from "./native-stage"; export function UseKeyboardHeightDemo() { diff --git a/src/registry/use-keyboard-height.native.ts b/src/registry/use-keyboard-height.native.ts new file mode 100644 index 0000000..fb5600e --- /dev/null +++ b/src/registry/use-keyboard-height.native.ts @@ -0,0 +1,27 @@ +import { useEffect, useState } from "react"; +import { Keyboard, Platform } from "react-native"; + +/** + * The height of the on-screen keyboard, or 0 while it is hidden. On iOS it updates as the keyboard + * starts to move, so a view can slide up alongside it; on Android it updates once the keyboard has + * finished appearing. Always 0 on the web, where there is no on-screen keyboard to measure. + */ +export function useKeyboardHeight(): number { + const [height, setHeight] = useState(0); + + useEffect(() => { + const ios = Platform.OS === "ios"; + const show = Keyboard.addListener(ios ? "keyboardWillShow" : "keyboardDidShow", (event) => + setHeight(event.endCoordinates.height), + ); + const hide = Keyboard.addListener(ios ? "keyboardWillHide" : "keyboardDidHide", () => + setHeight(0), + ); + return () => { + show.remove(); + hide.remove(); + }; + }, []); + + return height; +} diff --git a/src/registry/use-keyboard-height.ts b/src/registry/use-keyboard-height.ts index fb5600e..f5527eb 100644 --- a/src/registry/use-keyboard-height.ts +++ b/src/registry/use-keyboard-height.ts @@ -1,25 +1,31 @@ +"use client"; + import { useEffect, useState } from "react"; -import { Keyboard, Platform } from "react-native"; /** - * The height of the on-screen keyboard, or 0 while it is hidden. On iOS it updates as the keyboard - * starts to move, so a view can slide up alongside it; on Android it updates once the keyboard has - * finished appearing. Always 0 on the web, where there is no on-screen keyboard to measure. + * The height of the on-screen keyboard on a phone's browser, or 0 while it is hidden. It measures how + * much of the layout viewport the visual viewport has lost, which is what the keyboard covers. It is + * always 0 on desktop, and while the page is pinch-zoomed, because a zoom also shrinks the visual + * viewport and would be mistaken for a keyboard. */ export function useKeyboardHeight(): number { const [height, setHeight] = useState(0); useEffect(() => { - const ios = Platform.OS === "ios"; - const show = Keyboard.addListener(ios ? "keyboardWillShow" : "keyboardDidShow", (event) => - setHeight(event.endCoordinates.height), - ); - const hide = Keyboard.addListener(ios ? "keyboardWillHide" : "keyboardDidHide", () => - setHeight(0), - ); + const viewport = window.visualViewport; + if (!viewport) return; + const update = () => + setHeight( + viewport.scale > 1 + ? 0 + : Math.max(0, Math.round(window.innerHeight - viewport.height - viewport.offsetTop)), + ); + update(); + viewport.addEventListener("resize", update); + viewport.addEventListener("scroll", update); return () => { - show.remove(); - hide.remove(); + viewport.removeEventListener("resize", update); + viewport.removeEventListener("scroll", update); }; }, []); diff --git a/src/registry/use-reduce-motion-demo.tsx b/src/registry/use-reduce-motion-demo.tsx index 82ab8a6..d584220 100644 --- a/src/registry/use-reduce-motion-demo.tsx +++ b/src/registry/use-reduce-motion-demo.tsx @@ -2,7 +2,7 @@ import { useEffect, useRef } from "react"; import { Animated, Easing, Text, View } from "react-native"; -import { useReduceMotion } from "./use-reduce-motion"; +import { useReduceMotion } from "./use-reduce-motion.native"; import { NativeStage } from "./native-stage"; export function UseReduceMotionDemo() { diff --git a/src/registry/use-reduce-motion.native.ts b/src/registry/use-reduce-motion.native.ts new file mode 100644 index 0000000..1c37293 --- /dev/null +++ b/src/registry/use-reduce-motion.native.ts @@ -0,0 +1,19 @@ +import { useEffect, useState } from "react"; +import { AccessibilityInfo } from "react-native"; + +/** + * Whether the person has asked the system to reduce motion. It reads the setting once on mount and + * follows later changes, so animated components can skip or shorten their motion. It starts as false + * until the platform answers. + */ +export function useReduceMotion(): boolean { + const [reduce, setReduce] = useState(false); + + useEffect(() => { + AccessibilityInfo.isReduceMotionEnabled().then(setReduce); + const subscription = AccessibilityInfo.addEventListener("reduceMotionChanged", setReduce); + return () => subscription.remove(); + }, []); + + return reduce; +} diff --git a/src/registry/use-reduce-motion.ts b/src/registry/use-reduce-motion.ts index 1c37293..5b69384 100644 --- a/src/registry/use-reduce-motion.ts +++ b/src/registry/use-reduce-motion.ts @@ -1,19 +1,24 @@ -import { useEffect, useState } from "react"; -import { AccessibilityInfo } from "react-native"; +"use client"; + +import { useSyncExternalStore } from "react"; + +const QUERY = "(prefers-reduced-motion: reduce)"; + +function subscribe(onChange: () => void) { + const media = window.matchMedia(QUERY); + media.addEventListener("change", onChange); + return () => media.removeEventListener("change", onChange); +} /** - * Whether the person has asked the system to reduce motion. It reads the setting once on mount and - * follows later changes, so animated components can skip or shorten their motion. It starts as false - * until the platform answers. + * Whether the person has asked the system to reduce motion. It reads the prefers-reduced-motion media + * query and follows later changes, so animated components can skip or shorten their motion. On the + * server, and for the first render while hydrating, it returns false so the markup matches. */ export function useReduceMotion(): boolean { - const [reduce, setReduce] = useState(false); - - useEffect(() => { - AccessibilityInfo.isReduceMotionEnabled().then(setReduce); - const subscription = AccessibilityInfo.addEventListener("reduceMotionChanged", setReduce); - return () => subscription.remove(); - }, []); - - return reduce; + return useSyncExternalStore( + subscribe, + () => window.matchMedia(QUERY).matches, + () => false, + ); } diff --git a/src/registry/web-demos/mode-provider.tsx b/src/registry/web-demos/mode-provider.tsx new file mode 100644 index 0000000..08db9c2 --- /dev/null +++ b/src/registry/web-demos/mode-provider.tsx @@ -0,0 +1,53 @@ +"use client"; + +import { ModeProvider, useMode, type Mode } from "../mode-provider"; + +const MODES: Mode[] = ["light", "dark", "system"]; + +function Panel() { + const { mode, scheme, setMode, toggle } = useMode(); + const dark = scheme === "dark"; + return ( +
+
+

useMode()

+

+ mode: {mode} · scheme: {scheme} +

+
+
+ {MODES.map((m) => ( + + ))} +
+ +
+ ); +} + +export default function ModeProviderWebDemo() { + return ( + + + + ); +} diff --git a/src/registry/web-demos/theme-provider.tsx b/src/registry/web-demos/theme-provider.tsx new file mode 100644 index 0000000..90bfe92 --- /dev/null +++ b/src/registry/web-demos/theme-provider.tsx @@ -0,0 +1,54 @@ +"use client"; + +import { ModeProvider, useMode } from "../mode-provider"; +import { ThemeProvider, useTheme } from "../theme-provider"; + +function Card() { + const { colors } = useTheme(); + const { toggle, scheme } = useMode(); + const next = scheme === "dark" ? "light" : "dark"; + return ( +
+
+

+ Themed card +

+

+ Every colour here comes from useTheme(), not from the card itself. +

+ +
+
+ ); +} + +function Themed() { + const { scheme } = useMode(); + return ( + + + + ); +} + +export default function ThemeProviderWebDemo() { + return ( + + + + ); +} diff --git a/src/registry/web-demos/use-color-scheme.tsx b/src/registry/web-demos/use-color-scheme.tsx new file mode 100644 index 0000000..d219401 --- /dev/null +++ b/src/registry/web-demos/use-color-scheme.tsx @@ -0,0 +1,22 @@ +"use client"; + +import { useColorScheme } from "../use-color-scheme"; + +export default function UseColorSchemeWebDemo() { + const scheme = useColorScheme(); + return ( +
+

useColorScheme() returned

+
+

+ {scheme} +

+
+

+ It follows your device. Change your system appearance and the card flips. +

+
+ ); +} diff --git a/src/registry/web-demos/use-haptics.tsx b/src/registry/web-demos/use-haptics.tsx new file mode 100644 index 0000000..32ac32d --- /dev/null +++ b/src/registry/web-demos/use-haptics.tsx @@ -0,0 +1,47 @@ +"use client"; + +import { useState } from "react"; +import { useHaptics } from "../use-haptics"; + +const KINDS = ["tap", "success", "warning", "error"] as const; + +export default function UseHapticsWebDemo() { + const [enabled, setEnabled] = useState(true); + const [last, setLast] = useState("Nothing yet"); + const haptics = useHaptics(enabled); + + return ( +
+

Haptics

+
+ {KINDS.map((kind) => ( + + ))} +
+ +

+ Last fired: {last}. You will feel it on an Android phone in Chrome. +

+
+ ); +} diff --git a/src/registry/web-demos/use-keyboard-height.tsx b/src/registry/web-demos/use-keyboard-height.tsx new file mode 100644 index 0000000..e06a47c --- /dev/null +++ b/src/registry/web-demos/use-keyboard-height.tsx @@ -0,0 +1,25 @@ +"use client"; + +import { useKeyboardHeight } from "../use-keyboard-height"; + +export default function UseKeyboardHeightWebDemo() { + const height = useKeyboardHeight(); + return ( +
+

useKeyboardHeight() returned

+

+ {height} +

+

+ On a phone browser this is the keyboard's height while it is open, so you can lift a + bar above it. It stays 0 on desktop. +

+ +
+ ); +} diff --git a/src/registry/web-demos/use-reduce-motion.tsx b/src/registry/web-demos/use-reduce-motion.tsx new file mode 100644 index 0000000..a4980ed --- /dev/null +++ b/src/registry/web-demos/use-reduce-motion.tsx @@ -0,0 +1,27 @@ +"use client"; + +import { useReduceMotion } from "../use-reduce-motion"; + +export default function UseReduceMotionWebDemo() { + const reduce = useReduceMotion(); + return ( +
+

useReduceMotion() returned

+

+ {String(reduce)} +

+
+ +
+ +

+ The dot slides back and forth, and stays put when your system asks to reduce motion. +

+
+ ); +} diff --git a/tests/component-colors.test.ts b/tests/component-colors.test.ts index 4a04c65..765a729 100644 --- a/tests/component-colors.test.ts +++ b/tests/component-colors.test.ts @@ -62,11 +62,10 @@ describe("component colours", () => { if (name in HEX_ALLOWED) return; // React Native has no CSS variables to read, so native components carry plain default colours; // the next test makes sure each one can be themed through its `colors` prop. - if ( - (registry as readonly RegistryItem[]).find((item) => item.name === name)?.platform === - "native" - ) - return; + const platform = (registry as readonly RegistryItem[]).find( + (item) => item.name === name, + )?.platform; + if (platform === "native" || platform === "both") return; const source = readFileSync(join(process.cwd(), "src", file), "utf8"); expect(source.match(HEX)?.[0]).toBeUndefined(); }, diff --git a/tests/platforms.test.ts b/tests/platforms.test.ts new file mode 100644 index 0000000..534e211 --- /dev/null +++ b/tests/platforms.test.ts @@ -0,0 +1,38 @@ +import fs from "node:fs"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; +import { registry, type RegistryItem } from "@/registry"; +import { nativeFileOf } from "@/lib/registry"; + +const SRC = path.join(process.cwd(), "src"); +const read = (file: string) => fs.readFileSync(path.join(SRC, file), "utf8"); +const both = (registry as readonly RegistryItem[]).filter((item) => item.platform === "both"); + +// An item that works in React and React Native ships its React file first and, when the two differ, +// a React Native file beside it ending in `.native`, which Metro picks by itself. +describe("items for both platforms", () => { + it.each(both)("$name lists a React file and at most one .native file", (item) => { + expect(item.files.length).toBeLessThanOrEqual(2); + expect(item.files[0]).not.toMatch(/\.native\.tsx?$/); + if (item.files[1]) expect(item.files[1]).toBe(item.files[0].replace(/\.(tsx?)$/, ".native.$1")); + }); + + it.each(both)("$name has no web-only code in its React Native file", (item) => { + const file = nativeFileOf(item); + if (!file) return; + const source = read(file); + expect(source).not.toMatch(/\b(window|document|navigator)\b\./); + expect(source).not.toMatch(/from\s+["'](react-dom|next\b|framer-motion|clsx|tailwind-merge)/); + }); + + it.each(both)("$name has no react-native import in its React file", (item) => { + expect(read(item.files[0])).not.toMatch(/from\s+["']react-native["']/); + }); + + it.each(both.filter((item) => item.files.length === 2))( + "$name has a React demo beside its React Native one", + (item) => { + expect(fs.existsSync(path.join(SRC, "registry/web-demos", `${item.name}.tsx`))).toBe(true); + }, + ); +}); diff --git a/tests/reduced-motion.test.ts b/tests/reduced-motion.test.ts index cfefea9..f6ebc88 100644 --- a/tests/reduced-motion.test.ts +++ b/tests/reduced-motion.test.ts @@ -19,7 +19,9 @@ describe("reduced motion", () => { (item) => { const source = read(item.files[0]); // useReducedMotion for JS-driven motion; Tailwind's motion-reduce: for CSS-only motion. - expect(source).toMatch(PATTERN[(item as RegistryItem).platform ?? "web"]); + expect(source).toMatch( + PATTERN[(item as RegistryItem).platform === "native" ? "native" : "web"], + ); }, );