diff --git a/README.md b/README.md index 8be0d8d..3a61e7d 100644 --- a/README.md +++ b/README.md @@ -92,15 +92,15 @@ 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 | +| 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 | **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/action-button.json b/public/registry/action-button.json new file mode 100644 index 0000000..3d3e0c6 --- /dev/null +++ b/public/registry/action-button.json @@ -0,0 +1,15 @@ +{ + "name": "action-button", + "title": "Action Button", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/action-button.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport type ActionStatus = \"idle\" | \"loading\" | \"success\" | \"error\";\n\nexport interface ActionButtonColors {\n background: string;\n text: string;\n success: string;\n error: string;\n}\n\nconst DEFAULT_COLORS: ActionButtonColors = {\n background: \"#4f46e5\",\n text: \"#ffffff\",\n success: \"#16a34a\",\n error: \"#dc2626\",\n};\n\nconst INDEX: Record = { idle: 0, loading: 1, success: 2, error: 3 };\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ActionButtonProps {\n label: string;\n /** Called on press. If it returns a promise the button shows loading until it settles. */\n onPress: () => void | Promise;\n /** Sets the state yourself instead of following the promise. */\n status?: ActionStatus;\n variant?: \"solid\" | \"outline\" | \"ghost\";\n size?: \"md\" | \"lg\";\n /** Text announced and shown in the success state. */\n successLabel?: string;\n /** Text announced and shown in the error state. */\n errorLabel?: string;\n /** Milliseconds the success or error state stays before the button goes back to idle. */\n resetAfter?: number;\n disabled?: boolean;\n /** Stretches the button to the full width of its parent. */\n fullWidth?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A button that carries its own progress. Press it and, if the action returns a promise, the label\n * gives way to a spinner, then to a tick that pops in, or a cross and a shake if it fails, before it\n * settles back. The button never changes size, so nothing around it moves, and the outcome is read\n * out. Pressing while busy does nothing.\n */\nexport function ActionButton({\n label,\n onPress,\n status,\n variant = \"solid\",\n size = \"md\",\n successLabel = \"Done\",\n errorLabel = \"Failed\",\n resetAfter = 1600,\n disabled = false,\n fullWidth = false,\n colors,\n style,\n}: ActionButtonProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [inner, setInner] = useState(\"idle\");\n const current = status ?? inner;\n const m = useRef(new Animated.Value(INDEX[current])).current;\n const spin = useRef(new Animated.Value(0)).current;\n const press = useRef(new Animated.Value(1)).current;\n const shake = useRef(new Animated.Value(0)).current;\n const timers = useRef[]>([]);\n const mounted = useRef(true);\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n timers.current.forEach(clearTimeout);\n };\n }, []);\n\n useEffect(() => {\n if (reduceMotion) m.setValue(INDEX[current]);\n else\n Animated.timing(m, {\n toValue: INDEX[current],\n duration: 220,\n useNativeDriver: false,\n }).start();\n if (current === \"error\" && !reduceMotion) {\n Animated.sequence(\n [-7, 7, -5, 5, -2, 0].map((toValue) =>\n Animated.timing(shake, { toValue, duration: 50, useNativeDriver: NATIVE_DRIVER }),\n ),\n ).start();\n }\n }, [current, reduceMotion, m, shake]);\n\n useEffect(() => {\n if (current !== \"loading\" || reduceMotion) {\n spin.setValue(0);\n return;\n }\n const loop = Animated.loop(\n Animated.timing(spin, {\n toValue: 1,\n duration: 750,\n easing: Easing.linear,\n useNativeDriver: NATIVE_DRIVER,\n }),\n );\n loop.start();\n return () => loop.stop();\n }, [current, reduceMotion, spin]);\n\n const handlePress = () => {\n if (disabled || current !== \"idle\") return;\n const result = onPress();\n if (status !== undefined || !result || typeof (result as Promise).then !== \"function\")\n return;\n setInner(\"loading\");\n const finish = (next: ActionStatus) => {\n if (!mounted.current) return;\n setInner(next);\n timers.current.push(setTimeout(() => mounted.current && setInner(\"idle\"), resetAfter));\n };\n (result as Promise).then(\n () => finish(\"success\"),\n () => finish(\"error\"),\n );\n };\n\n const dip = (down: boolean) => {\n if (reduceMotion) return;\n Animated.spring(press, {\n toValue: down ? 0.97 : 1,\n stiffness: 500,\n damping: 26,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n const solid = variant === \"solid\";\n const ink = solid ? palette.text : palette.background;\n const idleFill = solid ? palette.background : \"transparent\";\n const fill = m.interpolate({\n inputRange: [0, 1, 2, 3],\n outputRange: [idleFill, idleFill, palette.success, palette.error],\n });\n const mark = (index: number) =>\n m.interpolate({\n inputRange: [index - 1, index, index + 1],\n outputRange: [0, 1, 0],\n extrapolate: \"clamp\",\n });\n const markInk = current === \"success\" || current === \"error\" ? palette.text : ink;\n const height = size === \"lg\" ? 56 : 48;\n const spoken =\n current === \"loading\"\n ? `${label}, working`\n : current === \"success\"\n ? successLabel\n : current === \"error\"\n ? errorLabel\n : label;\n\n return (\n dip(true)}\n onPressOut={() => dip(false)}\n style={[fullWidth ? styles.full : styles.auto, style]}\n >\n \n \n {label}\n \n \n \n \n \n \n \n \n ×\n \n \n \n {current === \"success\" ? successLabel : current === \"error\" ? errorLabel : \"\"}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n auto: { alignSelf: \"flex-start\" },\n full: { alignSelf: \"stretch\" },\n button: {\n paddingHorizontal: 24,\n alignItems: \"center\",\n justifyContent: \"center\",\n userSelect: \"none\",\n },\n label: { fontWeight: \"700\" },\n center: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n spinner: { width: 22, height: 22, borderRadius: 11, borderWidth: 3 },\n tick: {\n width: 9,\n height: 17,\n marginTop: -3,\n borderRightWidth: 3,\n borderBottomWidth: 3,\n transform: [{ rotate: \"45deg\" }],\n },\n cross: { fontSize: 30, lineHeight: 32, fontWeight: \"300\" },\n sr: { position: \"absolute\", width: 1, height: 1, opacity: 0 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/action-tray.json b/public/registry/action-tray.json new file mode 100644 index 0000000..ac8c95a --- /dev/null +++ b/public/registry/action-tray.json @@ -0,0 +1,15 @@ +{ + "name": "action-tray", + "title": "Action Tray", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/action-tray.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n// Space left under the tray when it is hidden, so its shadow never peeks out.\nconst HIDE_GAP = 24;\n// How far, or how fast, a drag must go to dismiss the tray.\nconst DISMISS_DISTANCE = 80;\nconst DISMISS_VELOCITY = 0.8;\n\nexport interface ActionTrayAction {\n label: string;\n onPress: () => void;\n /** Draws the action in the destructive color. */\n destructive?: boolean;\n disabled?: boolean;\n}\n\nexport interface ActionTrayColors {\n backdrop: string;\n surface: string;\n text: string;\n mutedText: string;\n destructive: string;\n divider: string;\n handle: string;\n}\n\nconst DEFAULT_COLORS: ActionTrayColors = {\n backdrop: \"rgba(0, 0, 0, 0.4)\",\n surface: \"#ffffff\",\n text: \"#111827\",\n mutedText: \"#6b7280\",\n destructive: \"#dc2626\",\n divider: \"#e5e7eb\",\n handle: \"#d1d5db\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ActionTrayProps {\n /** Whether the tray is showing. */\n open: boolean;\n /** Called when the tray should close: backdrop tap, Escape, a drag down, Cancel, or after an action. */\n onClose: () => void;\n title?: string;\n /** A line of smaller text under the title. */\n message?: string;\n actions: ActionTrayAction[];\n cancelLabel?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A bottom action list in the style of a native action sheet. It slides up from the bottom of its\n * parent over a dimmed backdrop, with the actions as one rounded group and Cancel as a separate\n * button. Tap the backdrop, press Escape, or drag the handle down to close it. It is drawn inside\n * its parent, so the parent must fill the area the tray should cover.\n */\nexport function ActionTray({\n open,\n onClose,\n title,\n message,\n actions,\n cancelLabel = \"Cancel\",\n colors,\n style,\n}: ActionTrayProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [height, setHeight] = useState(0);\n // Distance the tray is pushed down: 0 when open, `height + HIDE_GAP` when hidden.\n const y = useRef(new Animated.Value(0)).current;\n\n const live = useRef({ open, onClose, height, reduceMotion });\n live.current = { open, onClose, height, reduceMotion };\n\n const moveTo = (target: number) => {\n if (live.current.reduceMotion) {\n y.setValue(target);\n return;\n }\n Animated.spring(y, {\n toValue: target,\n stiffness: 360,\n damping: 34,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n useEffect(() => {\n if (height === 0) return;\n moveTo(open ? 0 : height + HIDE_GAP);\n // moveTo reads everything it needs through the ref.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, height]);\n\n // Escape closes the tray on the web.\n useEffect(() => {\n if (!open || Platform.OS !== \"web\") return;\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") live.current.onClose();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [open]);\n\n const pan = useRef(\n PanResponder.create({\n onStartShouldSetPanResponder: () => true,\n onPanResponderGrant: () => y.stopAnimation(),\n onPanResponderMove: (_, g) => y.setValue(Math.max(0, g.dy)),\n onPanResponderRelease: (_, g) => {\n if (g.dy > DISMISS_DISTANCE || g.vy > DISMISS_VELOCITY) {\n moveTo(live.current.height + HIDE_GAP);\n live.current.onClose();\n // If the parent ignores the request the tray is still open: bring it back.\n setTimeout(() => {\n if (live.current.open) moveTo(0);\n }, 80);\n } else {\n moveTo(0);\n }\n },\n onPanResponderTerminate: () => moveTo(0),\n }),\n ).current;\n\n const onLayout = (event: LayoutChangeEvent) => {\n const next = event.nativeEvent.layout.height;\n if (next === height) return;\n // Start hidden, so the first open slides in instead of appearing.\n if (height === 0) y.setValue(next + HIDE_GAP);\n setHeight(next);\n };\n\n const backdropOpacity = y.interpolate({\n inputRange: [0, (height || 1) + HIDE_GAP],\n outputRange: [1, 0],\n extrapolate: \"clamp\",\n });\n\n return (\n \n \n \n \n 0 ? 1 : 0, transform: [{ translateY: y }] }]}\n >\n \n \n \n {title ? (\n \n {title}\n \n ) : null}\n {message ? (\n {message}\n ) : null}\n \n {actions.map((action) => (\n {\n action.onPress();\n onClose();\n }}\n style={({ pressed }) => [\n styles.action,\n { borderTopColor: palette.divider },\n action.disabled && styles.disabled,\n pressed && styles.pressed,\n ]}\n >\n \n {action.label}\n \n \n ))}\n \n [\n styles.cancel,\n { backgroundColor: palette.surface },\n pressed && styles.pressed,\n ]}\n >\n {cancelLabel}\n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n justifyContent: \"flex-end\",\n },\n fill: { position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 },\n tray: { paddingHorizontal: 10, paddingBottom: 12, gap: 8 },\n group: { borderRadius: 16, overflow: \"hidden\" },\n // userSelect keeps a mouse drag on the web from selecting the title instead of moving the tray.\n header: {\n alignItems: \"center\",\n paddingTop: 8,\n paddingBottom: 12,\n paddingHorizontal: 16,\n gap: 4,\n userSelect: \"none\",\n },\n handle: { width: 36, height: 4, borderRadius: 2, marginBottom: 6 },\n title: { fontSize: 15, fontWeight: \"700\", textAlign: \"center\" },\n message: { fontSize: 13, textAlign: \"center\" },\n action: {\n minHeight: 54,\n alignItems: \"center\",\n justifyContent: \"center\",\n paddingHorizontal: 16,\n borderTopWidth: StyleSheet.hairlineWidth,\n },\n actionText: { fontSize: 17, fontWeight: \"500\" },\n cancel: {\n minHeight: 54,\n alignItems: \"center\",\n justifyContent: \"center\",\n borderRadius: 16,\n },\n cancelText: { fontSize: 17, fontWeight: \"700\" },\n disabled: { opacity: 0.4 },\n pressed: { opacity: 0.6 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/avatar-stack.json b/public/registry/avatar-stack.json new file mode 100644 index 0000000..a94aedc --- /dev/null +++ b/public/registry/avatar-stack.json @@ -0,0 +1,15 @@ +{ + "name": "avatar-stack", + "title": "Avatar Stack", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/avatar-stack.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Image,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\n// How far apart avatars sit when the stack is spread, in place of the overlap.\nconst SPREAD_GAP = 8;\nconst RING = 2;\n// Initials avatars take a stable color from this list, chosen by the person's name.\nconst PALETTE = [\n \"#6366f1\",\n \"#0ea5e9\",\n \"#14b8a6\",\n \"#22c55e\",\n \"#f59e0b\",\n \"#ef4444\",\n \"#ec4899\",\n \"#8b5cf6\",\n];\n\nexport interface AvatarPerson {\n id: string;\n name: string;\n /** A photo URL. Without one the avatar shows the person's initials. */\n image?: string;\n}\n\nexport interface AvatarStackColors {\n /** The ring around each avatar, normally the surface color, so overlaps read as separate. */\n ring: string;\n /** Initials. */\n text: string;\n /** Background of the \"+N\" avatar. */\n plus: string;\n}\n\nconst DEFAULT_COLORS: AvatarStackColors = {\n ring: \"#ffffff\",\n text: \"#ffffff\",\n plus: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nconst initialsOf = (name: string) =>\n name\n .split(/\\s+/)\n .filter(Boolean)\n .slice(0, 2)\n .map((word) => word[0].toUpperCase())\n .join(\"\");\n\nconst colorFor = (name: string) => {\n let sum = 0;\n for (const char of name) sum += char.charCodeAt(0);\n return PALETTE[sum % PALETTE.length];\n};\n\n/** \"Maya Chen, Leo Park and 3 others\": the first two names, then a count. */\nfunction describe(people: AvatarPerson[]) {\n const [first, second] = people;\n if (!first) return \"No people\";\n if (!second) return first.name;\n const rest = people.length - 2;\n if (rest === 0) return `${first.name} and ${second.name}`;\n return `${first.name}, ${second.name} and ${rest} ${rest === 1 ? \"other\" : \"others\"}`;\n}\n\nexport interface AvatarStackProps {\n people: AvatarPerson[];\n /** How many avatars show before the rest collapse into a \"+N\" avatar. */\n max?: number;\n /** Diameter of each avatar. */\n size?: number;\n /** How far each avatar covers the one before it, in pixels. */\n overlap?: number;\n /** Pressing the stack spreads the avatars apart and reveals the ones past `max`. */\n expandOnPress?: boolean;\n /** Called with the person whose avatar is pressed, once the stack is spread (or if it can't spread). */\n onPersonPress?: (person: AvatarPerson) => void;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * Overlapping avatars with a \"+N\" for the rest. Press the stack and the avatars spring apart one after\n * another, showing everyone; press again, or anywhere outside, and they fold back. The group reads out\n * as \"Maya Chen, Leo Park and 3 others\", and with reduced motion it spreads without animating.\n */\nexport function AvatarStack({\n people,\n max = 4,\n size = 40,\n overlap = 12,\n expandOnPress = true,\n onPersonPress,\n colors,\n style,\n}: AvatarStackProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n // `open` is the target; `showAll` stays true while the avatars fold back, then drops the extras.\n const [open, setOpen] = useState(false);\n const [showAll, setShowAll] = useState(false);\n // One 0 to 1 value per avatar, so they can spread one after another.\n const spreads = useRef(new Map());\n\n const hidden = Math.max(0, people.length - max);\n const shown = showAll ? people : people.slice(0, max);\n const showPlus = hidden > 0 && !showAll;\n\n const spreadFor = (key: string) => {\n let value = spreads.current.get(key);\n if (!value) {\n value = new Animated.Value(0);\n spreads.current.set(key, value);\n }\n return value;\n };\n\n useEffect(() => {\n const values = [...spreads.current.values()];\n const target = open ? 1 : 0;\n if (reduceMotion) {\n values.forEach((value) => value.setValue(target));\n if (!open) setShowAll(false);\n return;\n }\n // marginLeft is a layout property, so these springs cannot use the native driver.\n Animated.stagger(\n 45,\n values.map((value) =>\n Animated.spring(value, {\n toValue: target,\n stiffness: 260,\n damping: 18,\n mass: 1,\n useNativeDriver: false,\n }),\n ),\n ).start(({ finished }) => {\n if (finished && !open) setShowAll(false);\n });\n }, [open, showAll, reduceMotion]);\n\n const toggle = () => {\n if (open) {\n setOpen(false);\n return;\n }\n setShowAll(true);\n setOpen(true);\n };\n\n const pressPerson = (person: AvatarPerson) => {\n // A press first spreads a folded stack; once it is spread (or if it cannot spread) it picks the person.\n if (expandOnPress && !open) {\n toggle();\n return;\n }\n if (onPersonPress) onPersonPress(person);\n else if (expandOnPress) toggle();\n };\n\n const interactive = expandOnPress || !!onPersonPress;\n const hitSlop = Math.max(0, Math.ceil((44 - size) / 2));\n\n const avatarStyle = (key: string, index: number, extra: boolean) => {\n const spread = spreadFor(key);\n return {\n marginLeft:\n index === 0\n ? 0\n : spread.interpolate({ inputRange: [0, 1], outputRange: [-overlap, SPREAD_GAP] }),\n // Avatars past `max` fade and grow in as the stack spreads.\n ...(extra\n ? {\n opacity: spread.interpolate({ inputRange: [0, 0.4, 1], outputRange: [0, 1, 1] }),\n transform: [\n { scale: spread.interpolate({ inputRange: [0, 1], outputRange: [0.6, 1] }) },\n ],\n }\n : null),\n };\n };\n\n const ring = {\n width: size,\n height: size,\n borderRadius: size / 2,\n borderWidth: RING,\n borderColor: palette.ring,\n };\n\n return (\n \n {open ? (\n // Pressing anywhere outside folds the stack. Touches outside a parent's bounds are ignored on\n // Android, where the stack's own avatars and the toggle still work.\n setOpen(false)}\n style={styles.backdrop}\n />\n ) : null}\n \n {shown.map((person, index) => (\n = max)}>\n pressPerson(person)}\n style={[\n styles.avatar,\n ring,\n { backgroundColor: person.image ? palette.plus : colorFor(person.name) },\n ]}\n >\n {person.image ? (\n \n ) : (\n \n {initialsOf(person.name)}\n \n )}\n \n \n ))}\n {showPlus ? (\n \n \n \n +{hidden}\n \n \n \n ) : null}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { alignSelf: \"flex-start\" },\n backdrop: { position: \"absolute\", top: -4000, right: -4000, bottom: -4000, left: -4000 },\n // userSelect keeps a quick double press on the web from selecting the initials.\n row: { flexDirection: \"row\", alignItems: \"center\", userSelect: \"none\" },\n avatar: { alignItems: \"center\", justifyContent: \"center\", overflow: \"hidden\" },\n initials: { fontWeight: \"700\", letterSpacing: 0.3 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/battery-meter.json b/public/registry/battery-meter.json new file mode 100644 index 0000000..eaa0fd1 --- /dev/null +++ b/public/registry/battery-meter.json @@ -0,0 +1,15 @@ +{ + "name": "battery-meter", + "title": "Battery Meter", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/battery-meter.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface BatteryMeterColors {\n outline: string;\n low: string;\n ok: string;\n charging: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: BatteryMeterColors = {\n outline: \"#9ca3af\",\n low: \"#dc2626\",\n ok: \"#16a34a\",\n charging: \"#f59e0b\",\n text: \"#111827\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface BatteryMeterProps {\n /** Charge from 0 to 1. */\n level: number;\n /** Shows the charging colour and a bolt that pulses. */\n charging?: boolean;\n /** Width of the battery. */\n width?: number;\n /** Shows the percentage beside it. */\n showPercent?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A battery gauge. The fill slides to the charge level and turns red below 20 percent, amber while\n * charging, and green otherwise. While charging a bolt pulses over the cell. The level is read out\n * with whether it is charging.\n */\nexport function BatteryMeter({\n level,\n charging = false,\n width = 64,\n showPercent = true,\n colors,\n style,\n}: BatteryMeterProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const clamped = Math.max(0, Math.min(1, level));\n const percent = Math.round(clamped * 100);\n const fill = useRef(new Animated.Value(clamped)).current;\n const pulse = useRef(new Animated.Value(0)).current;\n const tint = charging ? palette.charging : clamped < 0.2 ? palette.low : palette.ok;\n const height = width * 0.5;\n\n useEffect(() => {\n if (reduceMotion) fill.setValue(clamped);\n else\n Animated.timing(fill, {\n toValue: clamped,\n duration: 400,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [clamped, reduceMotion, fill]);\n\n useEffect(() => {\n if (!charging || reduceMotion) {\n pulse.setValue(charging ? 1 : 0);\n return;\n }\n const loop = Animated.loop(\n Animated.sequence([\n Animated.timing(pulse, {\n toValue: 1,\n duration: 700,\n easing: Easing.inOut(Easing.sin),\n useNativeDriver: NATIVE_DRIVER,\n }),\n Animated.timing(pulse, {\n toValue: 0.3,\n duration: 700,\n easing: Easing.inOut(Easing.sin),\n useNativeDriver: NATIVE_DRIVER,\n }),\n ]),\n );\n loop.start();\n return () => loop.stop();\n }, [charging, reduceMotion, pulse]);\n\n return (\n \n \n \n \n \n ⚡\n \n \n \n \n {showPercent ? (\n {percent}%\n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"center\", gap: 10, alignSelf: \"flex-start\" },\n body: { flexDirection: \"row\", alignItems: \"center\" },\n shell: { borderWidth: 2, justifyContent: \"center\", overflow: \"hidden\" },\n cap: { width: 4, borderTopRightRadius: 2, borderBottomRightRadius: 2 },\n bolt: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n boltText: { color: \"#ffffff\" },\n percent: { fontSize: 15, fontWeight: \"700\", minWidth: 40 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/card-field.json b/public/registry/card-field.json new file mode 100644 index 0000000..664d7d9 --- /dev/null +++ b/public/registry/card-field.json @@ -0,0 +1,15 @@ +{ + "name": "card-field", + "title": "Card Field", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/card-field.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n StyleSheet,\n Text,\n TextInput,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface CardValue {\n number: string;\n expiry: string;\n cvc: string;\n}\n\nexport interface CardFieldColors {\n surface: string;\n border: string;\n text: string;\n placeholder: string;\n error: string;\n valid: string;\n}\n\nconst DEFAULT_COLORS: CardFieldColors = {\n surface: \"#ffffff\",\n border: \"#d1d5db\",\n text: \"#111827\",\n placeholder: \"#9ca3af\",\n error: \"#dc2626\",\n valid: \"#16a34a\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nconst digits = (text: string) => text.replace(/\\D/g, \"\");\n\nfunction brandOf(number: string) {\n if (/^3[47]/.test(number)) return \"Amex\";\n if (/^4/.test(number)) return \"Visa\";\n if (/^(5[1-5]|2[2-7])/.test(number)) return \"Mastercard\";\n if (/^6/.test(number)) return \"Discover\";\n return \"Card\";\n}\n\nfunction formatNumber(text: string) {\n const raw = digits(text);\n if (brandOf(raw) === \"Amex\") {\n const n = raw.slice(0, 15);\n return [n.slice(0, 4), n.slice(4, 10), n.slice(10)].filter(Boolean).join(\" \");\n }\n return (raw.slice(0, 16).match(/.{1,4}/g) ?? []).join(\" \");\n}\n\nfunction formatExpiry(text: string) {\n const raw = digits(text).slice(0, 4);\n return raw.length > 2 ? `${raw.slice(0, 2)}/${raw.slice(2)}` : raw;\n}\n\nfunction luhn(number: string) {\n let sum = 0;\n [...number].reverse().forEach((char, i) => {\n let d = Number(char);\n if (i % 2 === 1) d = d * 2 > 9 ? d * 2 - 9 : d * 2;\n sum += d;\n });\n return sum % 10 === 0;\n}\n\nexport interface CardFieldProps {\n value: CardValue;\n onChange: (value: CardValue) => void;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A card entry field. The number groups itself as you type, in fours or in the 4-6-5 pattern of an\n * Amex, the brand name appears from the first digits, the expiry adds its own slash, and a full\n * number that fails the Luhn check shakes and turns red. Each input has its own spoken name and the\n * numeric keyboard.\n */\nexport function CardField({ value, onChange, colors, style }: CardFieldProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const shake = useRef(new Animated.Value(0)).current;\n const raw = digits(value.number);\n const brand = brandOf(raw);\n const length = brand === \"Amex\" ? 15 : 16;\n const complete = raw.length === length;\n const valid = complete && luhn(raw);\n const bad = complete && !valid;\n const wasBad = useRef(false);\n\n useEffect(() => {\n if (bad && !wasBad.current && !reduceMotion) {\n Animated.sequence(\n [-6, 6, -4, 4, 0].map((toValue) =>\n Animated.timing(shake, { toValue, duration: 50, useNativeDriver: NATIVE_DRIVER }),\n ),\n ).start();\n }\n wasBad.current = bad;\n }, [bad, reduceMotion, shake]);\n\n const input = (props: React.ComponentProps) => (\n \n );\n\n return (\n \n \n {input({\n accessibilityLabel: \"Card number\",\n autoComplete: \"cc-number\",\n placeholder: \"1234 5678 9012 3456\",\n value: value.number,\n onChangeText: (text) => onChange({ ...value, number: formatNumber(text) }),\n style: [styles.input, styles.number, { color: palette.text }],\n })}\n \n {valid ? `${brand} ✓` : brand}\n \n \n \n {input({\n accessibilityLabel: \"Expiry date\",\n autoComplete: \"cc-exp\",\n placeholder: \"MM/YY\",\n value: value.expiry,\n onChangeText: (text) => onChange({ ...value, expiry: formatExpiry(text) }),\n style: [styles.input, styles.half, { color: palette.text }],\n })}\n {input({\n accessibilityLabel: \"Security code\",\n autoComplete: \"cc-csc\",\n placeholder: brand === \"Amex\" ? \"CVC (4)\" : \"CVC\",\n secureTextEntry: true,\n value: value.cvc,\n onChangeText: (text) =>\n onChange({ ...value, cvc: digits(text).slice(0, brand === \"Amex\" ? 4 : 3) }),\n style: [\n styles.input,\n styles.half,\n { color: palette.text, borderLeftColor: palette.border, borderLeftWidth: 1 },\n ],\n })}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { borderWidth: 1.5, borderRadius: 14, overflow: \"hidden\" },\n top: { flexDirection: \"row\", alignItems: \"center\", paddingRight: 14 },\n input: { height: 50, paddingHorizontal: 14, fontSize: 16 },\n number: { flex: 1 },\n half: { flex: 1 },\n brand: { fontSize: 13, fontWeight: \"700\" },\n bottom: { flexDirection: \"row\", borderTopWidth: 1 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/cart-quantity.json b/public/registry/cart-quantity.json new file mode 100644 index 0000000..62dd4c8 --- /dev/null +++ b/public/registry/cart-quantity.json @@ -0,0 +1,15 @@ +{ + "name": "cart-quantity", + "title": "Cart Quantity", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/cart-quantity.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface CartQuantityColors {\n surface: string;\n border: string;\n text: string;\n accent: string;\n remove: string;\n}\n\nconst DEFAULT_COLORS: CartQuantityColors = {\n surface: \"#ffffff\",\n border: \"#e5e7eb\",\n text: \"#111827\",\n accent: \"#4f46e5\",\n remove: \"#dc2626\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface CartQuantityProps {\n value: number;\n onChange: (value: number) => void;\n /** Called when minus is pressed at 1; the minus then shows a bin. Leave it out to stop at 1. */\n onRemove?: () => void;\n /** The most that can be ordered. */\n max?: number;\n /** Spoken name of the item. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A quantity picker for a cart line. At one, the minus becomes a bin so the same tap removes the item\n * instead of going to zero. The number pops when it changes and the plus dims at the limit. Each\n * button names the item it changes, and the new quantity is announced.\n */\nexport function CartQuantity({\n value,\n onChange,\n onRemove,\n max = 99,\n label = \"item\",\n colors,\n style,\n}: CartQuantityProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const pop = useRef(new Animated.Value(1)).current;\n const first = useRef(true);\n const removing = value <= 1 && !!onRemove;\n\n useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n if (reduceMotion) return;\n pop.setValue(1.3);\n Animated.spring(pop, {\n toValue: 1,\n stiffness: 400,\n damping: 16,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [value, reduceMotion, pop]);\n\n const decrease = () => (removing ? onRemove?.() : value > 1 && onChange(value - 1));\n const button = (\n text: string,\n name: string,\n onPress: () => void,\n disabled: boolean,\n tint: string,\n ) => (\n [styles.button, { opacity: disabled ? 0.35 : pressed ? 0.6 : 1 }]}\n >\n {text}\n \n );\n\n return (\n \n {removing\n ? button(\"🗑\", `Remove ${label}`, decrease, false, palette.remove)\n : button(\"−\", `Decrease ${label} quantity`, decrease, value <= 1, palette.accent)}\n \n {value}\n \n {button(\n \"+\",\n `Increase ${label} quantity`,\n () => onChange(Math.min(max, value + 1)),\n value >= max,\n palette.accent,\n )}\n \n );\n}\n\nconst styles = StyleSheet.create({\n root: {\n flexDirection: \"row\",\n alignItems: \"center\",\n alignSelf: \"flex-start\",\n borderWidth: 1,\n borderRadius: 14,\n },\n button: {\n width: 44,\n height: 44,\n alignItems: \"center\",\n justifyContent: \"center\",\n userSelect: \"none\",\n },\n glyph: { fontSize: 22, fontWeight: \"600\" },\n value: { minWidth: 32, textAlign: \"center\", fontSize: 17, fontWeight: \"700\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/chat-bubble.json b/public/registry/chat-bubble.json new file mode 100644 index 0000000..bf1e635 --- /dev/null +++ b/public/registry/chat-bubble.json @@ -0,0 +1,15 @@ +{ + "name": "chat-bubble", + "title": "Chat Bubble", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/chat-bubble.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport type ChatStatus = \"sending\" | \"sent\" | \"delivered\" | \"read\" | \"failed\";\n\nexport interface ChatBubbleColors {\n mine: string;\n theirs: string;\n mineText: string;\n theirsText: string;\n meta: string;\n read: string;\n failed: string;\n}\n\nconst DEFAULT_COLORS: ChatBubbleColors = {\n mine: \"#4f46e5\",\n theirs: \"#f3f4f6\",\n mineText: \"#ffffff\",\n theirsText: \"#111827\",\n meta: \"#9ca3af\",\n read: \"#38bdf8\",\n failed: \"#dc2626\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nconst STATUS_TEXT: Record = {\n sending: \"sending\",\n sent: \"sent\",\n delivered: \"delivered\",\n read: \"read\",\n failed: \"failed to send\",\n};\n\nexport interface ChatBubbleProps {\n /** The message text. */\n text?: string;\n /** Replaces the text, for an image or any other content. */\n children?: ReactNode;\n /** Whose message it is: your own sit on the right. */\n side?: \"me\" | \"them\";\n /** The sender's name, read out and shown above messages from others. */\n name?: string;\n /** The time shown under the message, for example \"9:41\". */\n time?: string;\n /** Delivery state of one of your own messages. */\n status?: ChatStatus;\n /** Draws the small tail. Turn it off for all but the last message of a run. */\n tail?: boolean;\n /** Called when a failed message is pressed. */\n onRetry?: () => void;\n /** Slides and scales the bubble in when it first appears. */\n animateIn?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A chat message bubble. It springs in from its own corner, shows delivery ticks that turn to read,\n * and a failed message becomes a retry button. A run of messages from one sender shares a single tail.\n * The sender, text, time and delivery state are read out as one sentence.\n */\nexport function ChatBubble({\n text,\n children,\n side = \"them\",\n name,\n time,\n status,\n tail = true,\n onRetry,\n animateIn = true,\n colors,\n style,\n}: ChatBubbleProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const mine = side === \"me\";\n const enter = useRef(new Animated.Value(animateIn ? 0 : 1)).current;\n\n useEffect(() => {\n if (!animateIn || reduceMotion) {\n enter.setValue(1);\n return;\n }\n Animated.spring(enter, {\n toValue: 1,\n stiffness: 360,\n damping: 24,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n // The entrance plays once, when the bubble mounts.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const failed = status === \"failed\";\n const bubbleColor = mine ? palette.mine : palette.theirs;\n const textColor = mine ? palette.mineText : palette.theirsText;\n const spoken = [\n mine ? \"You\" : (name ?? \"Them\"),\n text ?? \"attachment\",\n time,\n mine && status ? STATUS_TEXT[status] : undefined,\n ]\n .filter(Boolean)\n .join(\", \");\n\n const ticks =\n status === \"sending\"\n ? \"…\"\n : status === \"sent\"\n ? \"✓\"\n : status === \"delivered\" || status === \"read\"\n ? \"✓✓\"\n : \"\";\n\n const body = (\n \n {!mine && name ? {name} : null}\n {children ?? (\n {text}\n )}\n {time || ticks ? (\n \n {time ? (\n \n {time}\n \n ) : null}\n {mine && ticks ? (\n \n {ticks}\n \n ) : null}\n \n ) : null}\n \n );\n\n return (\n \n {failed && onRetry ? (\n \n ↻\n \n ) : null}\n {body}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"flex-end\", marginVertical: 2, paddingHorizontal: 12 },\n rowMine: { justifyContent: \"flex-end\", transformOrigin: \"right bottom\" },\n rowTheirs: { justifyContent: \"flex-start\", transformOrigin: \"left bottom\" },\n bubble: {\n maxWidth: \"78%\",\n paddingHorizontal: 12,\n paddingTop: 8,\n paddingBottom: 6,\n borderRadius: 18,\n },\n mineCorner: { borderBottomRightRadius: 5 },\n theirCorner: { borderBottomLeftRadius: 5 },\n noTail: { borderBottomRightRadius: 18, borderBottomLeftRadius: 18 },\n name: { fontSize: 12, fontWeight: \"700\", marginBottom: 2 },\n text: { fontSize: 16, lineHeight: 22 },\n meta: { flexDirection: \"row\", alignSelf: \"flex-end\", alignItems: \"center\", gap: 4, marginTop: 2 },\n time: { fontSize: 11 },\n ticks: { fontSize: 11, fontWeight: \"700\", letterSpacing: -1 },\n retry: { width: 44, height: 44, alignItems: \"center\", justifyContent: \"center\", marginRight: 2 },\n retryGlyph: { fontSize: 24, fontWeight: \"700\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/code-boxes.json b/public/registry/code-boxes.json new file mode 100644 index 0000000..91ac2d1 --- /dev/null +++ b/public/registry/code-boxes.json @@ -0,0 +1,15 @@ +{ + "name": "code-boxes", + "title": "Code Boxes", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/code-boxes.tsx", + "content": "import { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n StyleSheet,\n Text,\n TextInput,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst BOX_HEIGHT = 58;\n\nexport interface CodeBoxesColors {\n box: string;\n border: string;\n focusBorder: string;\n text: string;\n error: string;\n}\n\nconst DEFAULT_COLORS: CodeBoxesColors = {\n box: \"#ffffff\",\n border: \"#d1d5db\",\n focusBorder: \"#4f46e5\",\n text: \"#111827\",\n error: \"#dc2626\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface CodeBoxesProps {\n /** The code entered so far. */\n value: string;\n onChange: (next: string) => void;\n /** How many characters make the code. */\n length?: number;\n /** Called once when the last character arrives, with the full code. */\n onComplete?: (code: string) => void;\n /** Accept digits only and show a numeric keyboard. */\n numeric?: boolean;\n autoFocus?: boolean;\n /** Turns the boxes the error color and shakes them. */\n error?: boolean;\n disabled?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A one-time-code field drawn as separate boxes. One real, invisible input sits over them, so paste,\n * the keyboard and SMS autofill all work, and the boxes only show what it holds. The active box has\n * a ring and a blinking caret, each character pops in, and a wrong code shakes the row.\n */\nexport function CodeBoxes({\n value,\n onChange,\n length = 6,\n onComplete,\n numeric = true,\n autoFocus = false,\n error = false,\n disabled = false,\n colors,\n style,\n}: CodeBoxesProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [focused, setFocused] = useState(false);\n // Re-rendering with an unchanged value makes the input drop a character we refused (a letter in\n // numeric mode); bumping this is how we force that.\n const [, setRefresh] = useState(0);\n const blink = useRef(new Animated.Value(1)).current;\n const shake = useRef(new Animated.Value(0)).current;\n const completedFor = useRef(null);\n const wasError = useRef(false);\n\n const clean = (raw: string) =>\n (numeric ? raw.replace(/\\D/g, \"\") : raw.replace(/[^a-z0-9]/gi, \"\")).slice(0, length);\n\n const handleChangeText = (raw: string) => {\n const next = clean(raw);\n if (next !== value) onChange(next);\n else if (raw !== value) setRefresh((n) => n + 1);\n };\n\n // Report completion once per complete code, and again only after it has been edited.\n const onCompleteRef = useRef(onComplete);\n onCompleteRef.current = onComplete;\n useEffect(() => {\n if (value.length < length) {\n completedFor.current = null;\n return;\n }\n if (value.length === length && completedFor.current !== value) {\n completedFor.current = value;\n onCompleteRef.current?.(value);\n }\n }, [value, length]);\n\n // The caret blinks on its own value, so it keeps running while the active box moves.\n useEffect(() => {\n blink.setValue(1);\n if (!focused || reduceMotion || disabled) return;\n const loop = Animated.loop(\n Animated.sequence([\n Animated.timing(blink, { toValue: 0, duration: 500, useNativeDriver: NATIVE_DRIVER }),\n Animated.timing(blink, { toValue: 1, duration: 500, useNativeDriver: NATIVE_DRIVER }),\n ]),\n );\n loop.start();\n return () => loop.stop();\n }, [focused, reduceMotion, disabled, blink]);\n\n // Shake once each time the error turns on.\n useEffect(() => {\n if (error && !wasError.current && !reduceMotion) {\n Animated.sequence(\n [-10, 10, -7, 7, -3, 0].map((toValue) =>\n Animated.timing(shake, { toValue, duration: 55, useNativeDriver: NATIVE_DRIVER }),\n ),\n ).start();\n }\n wasError.current = error;\n }, [error, reduceMotion, shake]);\n\n const rowStyle = useMemo(() => ({ transform: [{ translateX: shake }] }), [shake]);\n const active = Math.min(value.length, length - 1);\n\n return (\n \n \n \n {Array.from({ length }, (_, index) => (\n \n ))}\n \n setFocused(true)}\n onBlur={() => setFocused(false)}\n editable={!disabled}\n autoFocus={autoFocus}\n keyboardType={numeric ? \"number-pad\" : \"default\"}\n inputMode={numeric ? \"numeric\" : \"text\"}\n textContentType=\"oneTimeCode\"\n autoComplete=\"sms-otp\"\n autoCapitalize=\"none\"\n autoCorrect={false}\n // react-native-web blurs a single-line field on Enter unless told not to.\n blurOnSubmit={false}\n caretHidden\n selectionColor=\"transparent\"\n accessibilityLabel=\"Verification code\"\n aria-label=\"Verification code\"\n aria-disabled={disabled}\n style={styles.input}\n />\n \n \n {`${value.length} of ${length} ${numeric ? \"digits\" : \"characters\"} entered`}\n \n \n );\n}\n\nfunction Box({\n char,\n isActive,\n showCaret,\n error,\n disabled,\n blink,\n reduceMotion,\n palette,\n}: {\n char: string;\n isActive: boolean;\n showCaret: boolean;\n error: boolean;\n disabled: boolean;\n blink: Animated.Value;\n reduceMotion: boolean;\n palette: CodeBoxesColors;\n}) {\n const scale = useRef(new Animated.Value(1)).current;\n const previous = useRef(char);\n\n // Pop when a character lands in an empty box.\n useEffect(() => {\n if (char && !previous.current && !reduceMotion) {\n scale.setValue(0.8);\n Animated.spring(scale, {\n toValue: 1,\n stiffness: 520,\n damping: 14,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }\n previous.current = char;\n }, [char, reduceMotion, scale]);\n\n const popStyle = useMemo(() => ({ transform: [{ scale }] }), [scale]);\n const caretStyle = useMemo(() => ({ opacity: blink }), [blink]);\n const borderColor = error ? palette.error : isActive ? palette.focusBorder : palette.border;\n\n return (\n \n {char}\n {/* Always mounted so its blink never restarts; only its visibility follows the active box. */}\n \n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n // userSelect keeps a mouse press on the web from selecting the digits.\n root: { alignSelf: \"stretch\", userSelect: \"none\" },\n wrap: { alignSelf: \"stretch\" },\n row: { flexDirection: \"row\", gap: 8 },\n box: {\n flex: 1,\n maxWidth: 56,\n height: BOX_HEIGHT,\n borderRadius: 12,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n char: { fontSize: 26, fontWeight: \"700\" },\n caretSlot: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n caret: { width: 2, height: 28, borderRadius: 1 },\n // Covers the boxes so a tap anywhere focuses it and paste lands in it, but shows nothing itself.\n input: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n opacity: 0,\n color: \"transparent\",\n },\n // Visually hidden, but still announced by screen readers.\n status: { position: \"absolute\", width: 1, height: 1, overflow: \"hidden\", opacity: 0 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/compare-slider.json b/public/registry/compare-slider.json new file mode 100644 index 0000000..eda0bf7 --- /dev/null +++ b/public/registry/compare-slider.json @@ -0,0 +1,15 @@ +{ + "name": "compare-slider", + "title": "Compare Slider", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/compare-slider.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst HANDLE = 40;\n\nexport interface CompareSliderColors {\n line: string;\n handle: string;\n arrows: string;\n}\n\nconst DEFAULT_COLORS: CompareSliderColors = {\n line: \"#ffffff\",\n handle: \"#ffffff\",\n arrows: \"#111827\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface CompareSliderProps {\n /** Shown on the left of the divider. */\n before: ReactNode;\n /** Shown on the right of the divider. */\n after: ReactNode;\n /** Where the divider starts, from 0 to 1. */\n initial?: number;\n height?: number;\n /** Spoken name of the slider. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A before and after comparison. Drag the handle, or touch anywhere, and the divider follows to reveal\n * more of one side or the other. It is an adjustable control for screen readers, which can step it by\n * ten percent, and the position is read out as a percentage.\n */\nexport function CompareSlider({\n before,\n after,\n initial = 0.5,\n height = 220,\n label = \"Comparison\",\n colors,\n style,\n}: CompareSliderProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [width, setWidth] = useState(0);\n const [percent, setPercent] = useState(Math.round(initial * 100));\n const pos = useRef(new Animated.Value(initial)).current;\n const at = useRef(initial);\n const start = useRef(initial);\n const live = useRef({ width, reduceMotion });\n live.current = { width, reduceMotion };\n\n const set = (next: number, animate = false) => {\n const clamped = Math.max(0, Math.min(1, next));\n at.current = clamped;\n setPercent(Math.round(clamped * 100));\n if (animate && !live.current.reduceMotion) {\n Animated.timing(pos, { toValue: clamped, duration: 180, useNativeDriver: false }).start();\n } else {\n pos.setValue(clamped);\n }\n };\n\n const responder = useRef(\n PanResponder.create({\n onStartShouldSetPanResponder: () => true,\n onPanResponderTerminationRequest: () => false,\n onPanResponderGrant: (event) => {\n const w = Math.max(1, live.current.width);\n set(event.nativeEvent.locationX / w);\n start.current = at.current;\n },\n onPanResponderMove: (_, g) => set(start.current + g.dx / Math.max(1, live.current.width)),\n }),\n ).current;\n\n const x = pos.interpolate({ inputRange: [0, 1], outputRange: [0, width] });\n\n return (\n setWidth(event.nativeEvent.layout.width)}\n accessible\n accessibilityRole=\"adjustable\"\n accessibilityLabel={label}\n aria-label={label}\n accessibilityValue={{ min: 0, max: 100, now: percent, text: `${percent} percent` }}\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={percent}\n accessibilityActions={[{ name: \"increment\" }, { name: \"decrement\" }]}\n onAccessibilityAction={(event) =>\n set(at.current + (event.nativeEvent.actionName === \"increment\" ? 0.1 : -0.1), true)\n }\n style={[styles.root, { height }, style]}\n >\n \n {after}\n \n \n {before}\n \n \n \n ◂▸\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { overflow: \"hidden\", borderRadius: 16, userSelect: \"none\" },\n layer: { position: \"absolute\", top: 0, bottom: 0, left: 0 },\n clip: { position: \"absolute\", top: 0, bottom: 0, left: 0, overflow: \"hidden\" },\n line: { position: \"absolute\", top: 0, bottom: 0, left: -1, width: 2 },\n handle: {\n position: \"absolute\",\n left: 0,\n width: HANDLE,\n height: HANDLE,\n borderRadius: HANDLE / 2,\n alignItems: \"center\",\n justifyContent: \"center\",\n boxShadow: \"0 2px 8px rgba(0, 0, 0, 0.35)\",\n },\n arrows: { fontSize: 14, fontWeight: \"800\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/composer-bar.json b/public/registry/composer-bar.json new file mode 100644 index 0000000..655ec71 --- /dev/null +++ b/public/registry/composer-bar.json @@ -0,0 +1,15 @@ +{ + "name": "composer-bar", + "title": "Composer Bar", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/composer-bar.tsx", + "content": "import { useEffect, useRef, useState, type ElementRef } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n TextInput,\n View,\n type StyleProp,\n type LayoutChangeEvent,\n type TextInputKeyPressEvent,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst LINE = 22;\nconst MIN_HEIGHT = 40;\n\nexport interface ComposerBarColors {\n background: string;\n field: string;\n border: string;\n text: string;\n placeholder: string;\n accent: string;\n accentText: string;\n icon: string;\n}\n\nconst DEFAULT_COLORS: ComposerBarColors = {\n background: \"#ffffff\",\n field: \"#f3f4f6\",\n border: \"#e5e7eb\",\n text: \"#111827\",\n placeholder: \"#9ca3af\",\n accent: \"#4f46e5\",\n accentText: \"#ffffff\",\n icon: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ComposerBarProps {\n value: string;\n onChangeText: (text: string) => void;\n /** Called with the trimmed text when the send button or Enter (on the web) is pressed. */\n onSend: (text: string) => void;\n placeholder?: string;\n /** How many lines the field grows to before it scrolls. */\n maxLines?: number;\n /** Shows a plus button on the left when given. */\n onAttach?: () => void;\n /** Shows a microphone in place of the send button while the field is empty, when given. */\n onRecord?: () => void;\n disabled?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A message composer. The field grows line by line up to a limit, and the button on the right turns\n * from a microphone into a send arrow as soon as there is text, with the two glyphs swapping on a\n * spring. On the web Enter sends and Shift+Enter starts a new line. It clears itself after sending.\n */\nexport function ComposerBar({\n value,\n onChangeText,\n onSend,\n placeholder = \"Message\",\n maxLines = 5,\n onAttach,\n onRecord,\n disabled = false,\n colors,\n style,\n}: ComposerBarProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const input = useRef>(null);\n const [height, setHeight] = useState(MIN_HEIGHT);\n const text = value.trim();\n const ready = text.length > 0;\n const mode = useRef(new Animated.Value(ready ? 1 : 0)).current;\n\n useEffect(() => {\n if (reduceMotion) {\n mode.setValue(ready ? 1 : 0);\n return;\n }\n Animated.spring(mode, {\n toValue: ready ? 1 : 0,\n stiffness: 420,\n damping: 24,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [ready, reduceMotion, mode]);\n\n const send = () => {\n if (!ready || disabled) return;\n onSend(text);\n onChangeText(\"\");\n setHeight(MIN_HEIGHT);\n input.current?.focus();\n };\n\n const onMirrorLayout = (event: LayoutChangeEvent) => {\n const next = event.nativeEvent.layout.height + 14;\n setHeight(Math.max(MIN_HEIGHT, Math.min(LINE * maxLines + 14, next)));\n };\n\n const onKeyPress = (event: TextInputKeyPressEvent) => {\n const native = event.nativeEvent as typeof event.nativeEvent & { shiftKey?: boolean };\n if (Platform.OS === \"web\" && native.key === \"Enter\" && !native.shiftKey) {\n (event as unknown as { preventDefault?: () => void }).preventDefault?.();\n send();\n }\n };\n\n const showAction = ready || !!onRecord;\n const micOpacity = mode.interpolate({ inputRange: [0, 1], outputRange: [1, 0] });\n const sendOpacity = mode;\n\n return (\n \n {onAttach ? (\n [styles.side, pressed && styles.dim]}\n >\n +\n \n ) : null}\n \n {/* A hidden copy of the text, wrapped like the field, whose height sets the field's. Measuring the\n field itself fails on the web: it reports a taller content size than it needs and never shrinks. */}\n \n {value.endsWith(\"\\n\") || value === \"\" ? `${value} ` : value}\n \n \n \n {showAction ? (\n [styles.side, pressed && styles.dim]}\n >\n \n \n ●\n \n \n ↑\n \n \n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n bar: {\n flexDirection: \"row\",\n alignItems: \"flex-end\",\n gap: 6,\n paddingHorizontal: 8,\n paddingVertical: 8,\n borderTopWidth: StyleSheet.hairlineWidth,\n },\n side: {\n width: 44,\n height: 44,\n alignItems: \"center\",\n justifyContent: \"center\",\n userSelect: \"none\",\n },\n plus: { fontSize: 30, lineHeight: 32, fontWeight: \"300\" },\n field: { flex: 1, borderRadius: 20, paddingHorizontal: 14, justifyContent: \"center\" },\n input: { fontSize: 16, lineHeight: LINE, paddingVertical: 7, outlineStyle: \"none\" } as object,\n action: {\n width: 36,\n height: 36,\n borderRadius: 18,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n glyph: { fontSize: 18, fontWeight: \"800\" },\n over: { position: \"absolute\" },\n mirror: { position: \"absolute\", left: 14, right: 14, top: 0, opacity: 0, paddingVertical: 0 },\n dim: { opacity: 0.6 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/confirm-dialog.json b/public/registry/confirm-dialog.json new file mode 100644 index 0000000..61ee2fb --- /dev/null +++ b/public/registry/confirm-dialog.json @@ -0,0 +1,15 @@ +{ + "name": "confirm-dialog", + "title": "Confirm Dialog", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/confirm-dialog.tsx", + "content": "import { useEffect, useRef, useState, type ElementRef } from \"react\";\nimport {\n AccessibilityInfo,\n ActivityIndicator,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n// Past this many characters a label no longer fits two side-by-side buttons.\nconst LONG_LABEL = 14;\n\nexport interface ConfirmDialogColors {\n surface: string;\n backdrop: string;\n title: string;\n message: string;\n border: string;\n cancelText: string;\n confirm: string;\n confirmText: string;\n destructive: string;\n}\n\nconst DEFAULT_COLORS: ConfirmDialogColors = {\n surface: \"#ffffff\",\n backdrop: \"rgba(0, 0, 0, 0.5)\",\n title: \"#111827\",\n message: \"#6b7280\",\n border: \"#e5e7eb\",\n cancelText: \"#111827\",\n confirm: \"#4f46e5\",\n confirmText: \"#ffffff\",\n destructive: \"#dc2626\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ConfirmDialogProps {\n open: boolean;\n onConfirm: () => void;\n onCancel: () => void;\n title: string;\n message?: string;\n confirmLabel?: string;\n cancelLabel?: string;\n /** Styles the confirm button as a warning, for actions that cannot be undone. */\n destructive?: boolean;\n /** Shows a spinner in the confirm button and disables the dialog while work is under way. */\n loading?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A centred alert dialog, drawn inside its parent so it works in a screen, a tab or a Modal alike.\n * It pops in on a spring over a dimmed backdrop. On the web focus starts on Cancel, so pressing Enter\n * can never confirm a destructive action by accident, and Escape cancels. While `loading` it cannot\n * be dismissed.\n */\nexport function ConfirmDialog({\n open,\n onConfirm,\n onCancel,\n title,\n message,\n confirmLabel = \"Confirm\",\n cancelLabel = \"Cancel\",\n destructive = false,\n loading = false,\n colors,\n style,\n}: ConfirmDialogProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const t = useRef(new Animated.Value(0)).current;\n const [mounted, setMounted] = useState(open);\n const cancelButton = useRef>(null);\n\n const live = useRef({ onCancel, loading });\n live.current = { onCancel, loading };\n\n useEffect(() => {\n if (open) setMounted(true);\n if (reduceMotion) {\n t.setValue(open ? 1 : 0);\n if (!open) setMounted(false);\n return;\n }\n Animated.spring(t, {\n toValue: open ? 1 : 0,\n stiffness: 360,\n damping: 28,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start(({ finished }) => {\n if (finished && !open) setMounted(false);\n });\n }, [open, reduceMotion, t]);\n\n // Web: start on Cancel and let Escape cancel.\n useEffect(() => {\n if (!open || !mounted || Platform.OS !== \"web\") return;\n const focus = setTimeout(\n () => (cancelButton.current as unknown as HTMLElement | null)?.focus?.(),\n 30,\n );\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\" && !live.current.loading) live.current.onCancel();\n };\n window.addEventListener(\"keydown\", onKey);\n return () => {\n clearTimeout(focus);\n window.removeEventListener(\"keydown\", onKey);\n };\n }, [open, mounted]);\n\n if (!mounted) return null;\n\n const stacked = confirmLabel.length > LONG_LABEL || cancelLabel.length > LONG_LABEL;\n const accent = destructive ? palette.destructive : palette.confirm;\n\n return (\n \n \n \n \n \n {title}\n {message ? (\n {message}\n ) : null}\n \n [\n styles.button,\n { borderColor: palette.border, borderWidth: 1 },\n stacked && styles.fullWidth,\n (pressed || loading) && styles.dim,\n ]}\n >\n {cancelLabel}\n \n [\n styles.button,\n { backgroundColor: accent },\n stacked && styles.fullWidth,\n pressed && styles.dim,\n ]}\n >\n {loading ? (\n \n ) : (\n \n {confirmLabel}\n \n )}\n \n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n alignItems: \"center\",\n justifyContent: \"center\",\n padding: 24,\n },\n fill: { position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 },\n card: {\n width: \"100%\",\n maxWidth: 320,\n borderRadius: 20,\n padding: 20,\n gap: 8,\n boxShadow: \"0 20px 50px rgba(0, 0, 0, 0.3)\",\n },\n title: { fontSize: 18, fontWeight: \"700\" },\n message: { fontSize: 15, lineHeight: 21 },\n buttons: { flexDirection: \"row\", gap: 10, marginTop: 14 },\n stacked: { flexDirection: \"column-reverse\" },\n button: {\n flex: 1,\n minHeight: 46,\n borderRadius: 12,\n alignItems: \"center\",\n justifyContent: \"center\",\n paddingHorizontal: 12,\n userSelect: \"none\",\n },\n fullWidth: { flex: 0, width: \"100%\" },\n buttonText: { fontSize: 15, fontWeight: \"600\" },\n dim: { opacity: 0.7 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/contact-index.json b/public/registry/contact-index.json new file mode 100644 index 0000000..0e8e0e8 --- /dev/null +++ b/public/registry/contact-index.json @@ -0,0 +1,15 @@ +{ + "name": "contact-index", + "title": "Contact Index", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/contact-index.tsx", + "content": "import { useEffect, useMemo, useRef, useState, type ElementRef } from \"react\";\nimport {\n AccessibilityInfo,\n PanResponder,\n Pressable,\n ScrollView,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst LETTER = 18;\n\nexport interface ContactItem {\n id: string;\n name: string;\n}\n\nexport interface ContactIndexColors {\n header: string;\n headerText: string;\n text: string;\n accent: string;\n border: string;\n}\n\nconst DEFAULT_COLORS: ContactIndexColors = {\n header: \"#f3f4f6\",\n headerText: \"#6b7280\",\n text: \"#111827\",\n accent: \"#4f46e5\",\n border: \"#e5e7eb\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ContactIndexProps {\n items: ContactItem[];\n onSelect?: (item: ContactItem) => void;\n colors?: Partial;\n /** Give it a height, for example flex: 1 or a number. */\n style?: StyleProp;\n}\n\n/**\n * An alphabetical list with a letter rail down the right edge, like a phone's contacts. Names are\n * grouped under letter headers. Tap or drag along the rail to jump to a letter and the list scrolls\n * there; the letter you are on is highlighted and its name is read out.\n */\nexport function ContactIndex({ items, onSelect, colors, style }: ContactIndexProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const list = useRef>(null);\n const tops = useRef>({});\n const [active, setActive] = useState(null);\n\n const groups = useMemo(() => {\n const map = new Map();\n [...items]\n .sort((a, b) => a.name.localeCompare(b.name))\n .forEach((item) => {\n const key = item.name.charAt(0).toUpperCase() || \"#\";\n map.set(key, [...(map.get(key) ?? []), item]);\n });\n return [...map.entries()];\n }, [items]);\n\n const live = useRef({ groups, reduceMotion });\n live.current = { groups, reduceMotion };\n\n const jump = (index: number) => {\n const { groups: all, reduceMotion: reduce } = live.current;\n const key = all[Math.max(0, Math.min(all.length - 1, index))]?.[0];\n if (!key) return;\n setActive(key);\n list.current?.scrollTo({ y: tops.current[key] ?? 0, animated: !reduce });\n AccessibilityInfo.announceForAccessibility(key);\n };\n\n const rail = useRef(\n PanResponder.create({\n onStartShouldSetPanResponder: () => true,\n onMoveShouldSetPanResponder: () => true,\n onPanResponderTerminationRequest: () => false,\n onPanResponderGrant: (event) => jump(Math.floor(event.nativeEvent.locationY / LETTER)),\n onPanResponderMove: (event) => jump(Math.floor(event.nativeEvent.locationY / LETTER)),\n }),\n ).current;\n\n return (\n \n \n {groups.map(([letter, people]) => (\n (tops.current[letter] = event.nativeEvent.layout.y)}\n >\n \n \n {letter}\n \n \n {people.map((person) => (\n onSelect?.(person)}\n style={[styles.row, { borderBottomColor: palette.border }]}\n >\n {person.name}\n \n ))}\n \n ))}\n \n \n {groups.map(([letter]) => (\n \n {letter}\n \n ))}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { flex: 1, flexDirection: \"row\" },\n header: { paddingHorizontal: 16, paddingVertical: 4 },\n headerText: { fontSize: 13, fontWeight: \"700\" },\n row: {\n minHeight: 48,\n paddingHorizontal: 16,\n justifyContent: \"center\",\n borderBottomWidth: StyleSheet.hairlineWidth,\n },\n name: { fontSize: 16 },\n rail: {\n width: 26,\n alignItems: \"center\",\n justifyContent: \"center\",\n paddingVertical: 8,\n userSelect: \"none\",\n },\n letter: { height: LETTER, fontSize: 11, fontWeight: \"700\", lineHeight: LETTER },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/count-badge.json b/public/registry/count-badge.json new file mode 100644 index 0000000..e11a3fe --- /dev/null +++ b/public/registry/count-badge.json @@ -0,0 +1,15 @@ +{ + "name": "count-badge", + "title": "Count Badge", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/count-badge.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface CountBadgeColors {\n badge: string;\n text: string;\n ring: string;\n}\n\nconst DEFAULT_COLORS: CountBadgeColors = {\n badge: \"#dc2626\",\n text: \"#ffffff\",\n ring: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface CountBadgeProps {\n /** The number to show. */\n count: number;\n /** Counts above this show as \"max+\", for example \"99+\". */\n max?: number;\n /** Shows a small dot instead of the number. */\n dot?: boolean;\n /** Hides the badge when the count is zero. */\n hideZero?: boolean;\n /** What is being counted, for example \"Notifications\". Read out with the number. */\n label?: string;\n /** The icon or avatar the badge sits on the corner of. */\n children?: ReactNode;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A count bubble that sits on the corner of an icon. It pops in when the count first appears, pulses\n * each time the number changes, and shrinks away when it returns to zero. Large counts read \"99+\",\n * and the label and number are read out together.\n */\nexport function CountBadge({\n count,\n max = 99,\n dot = false,\n hideZero = true,\n label = \"Notifications\",\n children,\n colors,\n style,\n}: CountBadgeProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const visible = !(hideZero && count <= 0);\n const show = useRef(new Animated.Value(visible ? 1 : 0)).current;\n const pulse = useRef(new Animated.Value(1)).current;\n const previous = useRef(count);\n\n useEffect(() => {\n if (reduceMotion) {\n show.setValue(visible ? 1 : 0);\n return;\n }\n Animated.spring(show, {\n toValue: visible ? 1 : 0,\n stiffness: 420,\n damping: 18,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [visible, reduceMotion, show]);\n\n // Each change in the number gives the badge a small bump.\n useEffect(() => {\n if (previous.current === count) return;\n previous.current = count;\n if (reduceMotion || !visible) return;\n pulse.setValue(1.35);\n Animated.spring(pulse, {\n toValue: 1,\n stiffness: 380,\n damping: 12,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [count, visible, reduceMotion, pulse]);\n\n const text = count > max ? `${max}+` : String(count);\n const spoken = `${label}, ${visible ? (count > max ? `more than ${max}` : count) : \"none\"}`;\n\n return (\n \n {children}\n \n {dot ? null : {text}}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n anchor: { alignSelf: \"flex-start\" },\n badge: {\n position: \"absolute\",\n top: -6,\n right: -8,\n minWidth: 20,\n height: 20,\n paddingHorizontal: 5,\n borderRadius: 10,\n borderWidth: 2,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n dot: {\n position: \"absolute\",\n top: -2,\n right: -2,\n width: 12,\n height: 12,\n borderRadius: 6,\n borderWidth: 2,\n },\n text: { fontSize: 11, fontWeight: \"800\", lineHeight: 14 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/countdown-timer.json b/public/registry/countdown-timer.json new file mode 100644 index 0000000..9aacc50 --- /dev/null +++ b/public/registry/countdown-timer.json @@ -0,0 +1,15 @@ +{ + "name": "countdown-timer", + "title": "Countdown Timer", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/countdown-timer.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface CountdownTimerColors {\n text: string;\n track: string;\n fill: string;\n done: string;\n}\n\nconst DEFAULT_COLORS: CountdownTimerColors = {\n text: \"#111827\",\n track: \"#e5e7eb\",\n fill: \"#4f46e5\",\n done: \"#16a34a\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nconst format = (ms: number) => {\n const total = Math.ceil(ms / 1000);\n return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, \"0\")}`;\n};\n\nexport interface CountdownTimerProps {\n /** How long to count down from, in seconds. Changing it restarts the timer. */\n seconds: number;\n /** Pauses the countdown when false. */\n running?: boolean;\n /** Called once when the time runs out. */\n onComplete?: () => void;\n /** Spoken name of the timer. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A minutes and seconds countdown with a bar that drains underneath. Pausing holds both the digits\n * and the bar and resuming carries on from there. When the time is up the digits turn to the done\n * colour and `onComplete` fires once. The remaining time is not announced every second; only\n * \"Time is up\" is, so a screen reader is not flooded.\n */\nexport function CountdownTimer({\n seconds,\n running = true,\n onComplete,\n label = \"Timer\",\n colors,\n style,\n}: CountdownTimerProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const total = seconds * 1000;\n const [remaining, setRemaining] = useState(total);\n const left = useRef(total);\n const bar = useRef(new Animated.Value(1)).current;\n const finished = useRef(false);\n const live = useRef({ onComplete });\n live.current = { onComplete };\n\n // A new duration starts over.\n useEffect(() => {\n left.current = total;\n finished.current = false;\n setRemaining(total);\n bar.setValue(1);\n }, [total, bar]);\n\n // The digits follow a wall clock, so they stay right when the tab is slow.\n useEffect(() => {\n if (!running || left.current <= 0) return;\n const end = Date.now() + left.current;\n const id = setInterval(() => {\n left.current = Math.max(0, end - Date.now());\n setRemaining(left.current);\n if (left.current === 0 && !finished.current) {\n finished.current = true;\n clearInterval(id);\n live.current.onComplete?.();\n }\n }, 200);\n return () => clearInterval(id);\n }, [running, total]);\n\n // The bar drains over the time that is left, or steps once a second with reduced motion.\n useEffect(() => {\n if (!running || left.current <= 0) return;\n if (reduceMotion) {\n bar.setValue(left.current / total);\n return;\n }\n const animation = Animated.timing(bar, {\n toValue: 0,\n duration: left.current,\n easing: Easing.linear,\n useNativeDriver: false,\n });\n animation.start();\n return () => animation.stop();\n }, [running, reduceMotion, total, bar]);\n\n useEffect(() => {\n if (reduceMotion) bar.setValue(remaining / total);\n }, [remaining, reduceMotion, total, bar]);\n\n const done = remaining <= 0;\n\n return (\n \n \n {format(remaining)}\n \n \n \n \n \n {done ? \"Time is up\" : \"\"}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { gap: 12, alignItems: \"stretch\" },\n digits: { fontSize: 56, fontWeight: \"800\", textAlign: \"center\", fontVariant: [\"tabular-nums\"] },\n track: { height: 8, borderRadius: 4, overflow: \"hidden\" },\n fill: { height: \"100%\", borderRadius: 4 },\n sr: { position: \"absolute\", width: 1, height: 1, opacity: 0 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/data-table.json b/public/registry/data-table.json new file mode 100644 index 0000000..bb34e30 --- /dev/null +++ b/public/registry/data-table.json @@ -0,0 +1,15 @@ +{ + "name": "data-table", + "title": "Data Table", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/data-table.tsx", + "content": "import { useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n ScrollView,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst DEFAULT_WIDTH = 120;\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\n// The arrow stays mounted and turns between ascending and descending.\nfunction SortArrow({ direction, color }: { direction: \"asc\" | \"desc\"; color: string }) {\n const reduceMotion = useReduceMotion();\n const turn = useRef(new Animated.Value(direction === \"asc\" ? 0 : 1)).current;\n useEffect(() => {\n const toValue = direction === \"asc\" ? 0 : 1;\n if (reduceMotion) turn.setValue(toValue);\n else Animated.timing(turn, { toValue, duration: 180, useNativeDriver: NATIVE_DRIVER }).start();\n }, [direction, reduceMotion, turn]);\n return (\n \n ↑\n \n );\n}\n\nexport interface DataTableColumn {\n key: keyof T & string;\n title: string;\n width?: number;\n align?: \"left\" | \"right\";\n sortable?: boolean;\n render?: (row: T) => ReactNode;\n}\n\nexport interface DataTableColors {\n header: string;\n headerText: string;\n text: string;\n border: string;\n stripe: string;\n background: string;\n}\n\nconst DEFAULT_COLORS: DataTableColors = {\n header: \"#f3f4f6\",\n headerText: \"#374151\",\n text: \"#111827\",\n border: \"#e5e7eb\",\n stripe: \"#f9fafb\",\n background: \"#ffffff\",\n};\n\nexport interface DataTableProps {\n columns: DataTableColumn[];\n rows: T[];\n /** Returns a unique key for a row. */\n rowKey: (row: T) => string;\n /** Column key and direction to sort by at first. */\n initialSort?: { key: string; direction: \"asc\" | \"desc\" };\n onRowPress?: (row: T) => void;\n /** Shades every other row. */\n striped?: boolean;\n /** Height of the rows area; the header stays above it while the rows scroll. */\n maxHeight?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A table that scrolls sideways when its columns are wider than the screen and keeps its header\n * visible while the rows scroll up and down. Tapping a sortable header sorts by it, then reverses,\n * and the arrow turns to match. Headers report their sort order to screen readers.\n */\nexport function DataTable({\n columns,\n rows,\n rowKey,\n initialSort,\n onRowPress,\n striped = true,\n maxHeight = 280,\n colors,\n style,\n}: DataTableProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const [sort, setSort] = useState(initialSort);\n\n const sorted = useMemo(() => {\n if (!sort) return rows;\n const key = sort.key as keyof T;\n const sign = sort.direction === \"asc\" ? 1 : -1;\n return [...rows].sort((a, b) => {\n const x = a[key];\n const y = b[key];\n if (typeof x === \"number\" && typeof y === \"number\") return (x - y) * sign;\n return String(x).localeCompare(String(y)) * sign;\n });\n }, [rows, sort]);\n\n const toggle = (key: string) =>\n setSort((now) =>\n now?.key === key\n ? { key, direction: now.direction === \"asc\" ? \"desc\" : \"asc\" }\n : { key, direction: \"asc\" },\n );\n\n const total = columns.reduce((sum, column) => sum + (column.width ?? DEFAULT_WIDTH), 0);\n\n return (\n \n \n \n \n {columns.map((column) => {\n const active = sort?.key === column.key;\n const direction = active ? sort.direction : undefined;\n const cell = (\n \n \n {column.title}\n \n {direction ? (\n \n ) : null}\n \n );\n const box = { width: column.width ?? DEFAULT_WIDTH };\n return column.sortable ? (\n toggle(column.key)}\n style={[styles.cell, box]}\n >\n {cell}\n \n ) : (\n \n {cell}\n \n );\n })}\n \n \n {sorted.map((row, index) => (\n onRowPress?.(row)}\n style={[\n styles.row,\n { borderTopColor: palette.border, borderTopWidth: StyleSheet.hairlineWidth },\n striped && index % 2 === 1 && { backgroundColor: palette.stripe },\n ]}\n >\n {columns.map((column) => (\n \n {column.render ? (\n column.render(row)\n ) : (\n \n {String(row[column.key])}\n \n )}\n \n ))}\n \n ))}\n \n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { borderWidth: 1, borderRadius: 14, overflow: \"hidden\" },\n row: { flexDirection: \"row\" },\n cell: { minHeight: 44, paddingHorizontal: 12, justifyContent: \"center\", userSelect: \"none\" },\n head: { flexDirection: \"row\", alignItems: \"center\", gap: 4 },\n headRight: { justifyContent: \"flex-end\" },\n headText: { fontSize: 13, fontWeight: \"700\" },\n text: { fontSize: 14 },\n right: { textAlign: \"right\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/empty-state.json b/public/registry/empty-state.json new file mode 100644 index 0000000..5e6b5a0 --- /dev/null +++ b/public/registry/empty-state.json @@ -0,0 +1,15 @@ +{ + "name": "empty-state", + "title": "Empty State", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/empty-state.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface EmptyStateColors {\n badge: string;\n title: string;\n message: string;\n button: string;\n buttonText: string;\n}\n\nconst DEFAULT_COLORS: EmptyStateColors = {\n badge: \"#eef2ff\",\n title: \"#111827\",\n message: \"#6b7280\",\n button: \"#4f46e5\",\n buttonText: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface EmptyStateProps {\n title: string;\n message?: string;\n /** A single glyph or emoji drawn in the badge. */\n icon?: string;\n /** Label of the button under the message; leave it out for no button. */\n actionLabel?: string;\n onAction?: () => void;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * What to show when a list has nothing in it yet. A badge with a glyph floats gently above a title,\n * a short message and an optional button, and the whole block rises into place when it appears.\n * With reduced motion it appears already in place and the badge stays still.\n */\nexport function EmptyState({\n title,\n message,\n icon = \"📭\",\n actionLabel,\n onAction,\n colors,\n style,\n}: EmptyStateProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const enter = useRef(new Animated.Value(0)).current;\n const bob = useRef(new Animated.Value(0)).current;\n\n useEffect(() => {\n if (reduceMotion) {\n enter.setValue(1);\n bob.setValue(0);\n return;\n }\n Animated.timing(enter, {\n toValue: 1,\n duration: 420,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n const loop = Animated.loop(\n Animated.sequence([\n Animated.timing(bob, {\n toValue: 1,\n duration: 1600,\n easing: Easing.inOut(Easing.sin),\n useNativeDriver: NATIVE_DRIVER,\n }),\n Animated.timing(bob, {\n toValue: 0,\n duration: 1600,\n easing: Easing.inOut(Easing.sin),\n useNativeDriver: NATIVE_DRIVER,\n }),\n ]),\n );\n loop.start();\n return () => loop.stop();\n }, [reduceMotion, enter, bob]);\n\n return (\n \n \n {icon}\n \n {title}\n {message ? {message} : null}\n {actionLabel && onAction ? (\n [\n styles.button,\n { backgroundColor: palette.button, opacity: pressed ? 0.8 : 1 },\n ]}\n >\n {actionLabel}\n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { alignItems: \"center\", gap: 8, paddingHorizontal: 24 },\n badge: {\n width: 88,\n height: 88,\n borderRadius: 44,\n alignItems: \"center\",\n justifyContent: \"center\",\n marginBottom: 8,\n },\n icon: { fontSize: 40 },\n title: { fontSize: 20, fontWeight: \"700\", textAlign: \"center\" },\n message: { fontSize: 15, lineHeight: 22, textAlign: \"center\", maxWidth: 280 },\n button: {\n marginTop: 12,\n minHeight: 46,\n paddingHorizontal: 24,\n borderRadius: 14,\n justifyContent: \"center\",\n userSelect: \"none\",\n },\n buttonText: { fontSize: 15, fontWeight: \"700\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/expand-card.json b/public/registry/expand-card.json new file mode 100644 index 0000000..d235409 --- /dev/null +++ b/public/registry/expand-card.json @@ -0,0 +1,15 @@ +{ + "name": "expand-card", + "title": "Expand Card", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/expand-card.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Pressable,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst PAD = 12;\n\nexport interface ExpandCardColors {\n surface: string;\n border: string;\n hero: string;\n title: string;\n subtitle: string;\n}\n\nconst DEFAULT_COLORS: ExpandCardColors = {\n surface: \"#ffffff\",\n border: \"#e5e7eb\",\n hero: \"#c7d2fe\",\n title: \"#111827\",\n subtitle: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ExpandCardProps {\n expanded: boolean;\n onExpandedChange: (expanded: boolean) => void;\n title: string;\n subtitle?: string;\n /** Drawn inside the picture box, which grows from a thumbnail to a banner. */\n hero?: ReactNode;\n /** The details revealed when the card is open. */\n children?: ReactNode;\n /** Height of the closed card. */\n collapsedHeight?: number;\n /** Height of the open card. */\n expandedHeight?: number;\n /** Height of the picture when the card is open. */\n heroHeight?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A card that grows from a compact row into a full detail view. The picture swells from a thumbnail\n * to a banner, the title slides under it, the details fade in, and the chevron turns over, all from\n * one value so the parts stay in step. Pressing the header toggles it; the details stay interactive.\n */\nexport function ExpandCard({\n expanded,\n onExpandedChange,\n title,\n subtitle,\n hero,\n children,\n collapsedHeight = 88,\n expandedHeight = 340,\n heroHeight = 160,\n colors,\n style,\n}: ExpandCardProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const t = useRef(new Animated.Value(expanded ? 1 : 0)).current;\n const [width, setWidth] = useState(0);\n\n useEffect(() => {\n if (reduceMotion) {\n t.setValue(expanded ? 1 : 0);\n return;\n }\n Animated.timing(t, {\n toValue: expanded ? 1 : 0,\n duration: 380,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [expanded, reduceMotion, t]);\n\n const thumb = collapsedHeight - PAD * 2;\n const mix = (from: number, to: number) =>\n t.interpolate({ inputRange: [0, 1], outputRange: [from, to] });\n const headerHeight = heroHeight + 70;\n const detailsTop = headerHeight + 4;\n\n return (\n setWidth(event.nativeEvent.layout.width)}\n style={[\n styles.card,\n {\n height: mix(collapsedHeight, expandedHeight),\n backgroundColor: palette.surface,\n borderColor: palette.border,\n },\n style,\n ]}\n >\n 0 ? mix(thumb, width) : thumb,\n height: mix(thumb, heroHeight),\n borderRadius: mix(12, 0),\n },\n ]}\n >\n {hero}\n \n \n \n {title}\n \n {subtitle ? (\n \n {subtitle}\n \n ) : null}\n \n \n ⌄\n \n \n {children}\n \n onExpandedChange(!expanded)}\n style={[styles.header, { height: expanded ? headerHeight : collapsedHeight }]}\n />\n \n );\n}\n\nconst styles = StyleSheet.create({\n card: { overflow: \"hidden\", borderRadius: 20, borderWidth: 1, userSelect: \"none\" },\n hero: {\n position: \"absolute\",\n overflow: \"hidden\",\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n titles: { position: \"absolute\", right: 44 },\n title: { fontSize: 17, fontWeight: \"700\" },\n subtitle: { fontSize: 13, marginTop: 2 },\n chevron: { position: \"absolute\", right: 16 },\n details: { position: \"absolute\", left: 20, right: 20, bottom: 0 },\n header: { position: \"absolute\", top: 0, left: 0, right: 0 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/expandable-text.json b/public/registry/expandable-text.json new file mode 100644 index 0000000..275c2e3 --- /dev/null +++ b/public/registry/expandable-text.json @@ -0,0 +1,15 @@ +{ + "name": "expandable-text", + "title": "Expandable Text", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/expandable-text.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Pressable,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface ExpandableTextColors {\n text: string;\n link: string;\n}\n\nconst DEFAULT_COLORS: ExpandableTextColors = {\n text: \"#374151\",\n link: \"#4f46e5\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ExpandableTextProps {\n text: string;\n /** How many lines show before it is cut off. */\n lines?: number;\n /** Height of one line. */\n lineHeight?: number;\n moreLabel?: string;\n lessLabel?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A paragraph that shows a few lines and a Read more link. Pressing the link grows the box to the\n * full text, and it shrinks back on Show less; the link only appears when the text is long enough to\n * be cut. The link reports whether it is expanded.\n */\nexport function ExpandableText({\n text,\n lines = 3,\n lineHeight = 22,\n moreLabel = \"Read more\",\n lessLabel = \"Show less\",\n colors,\n style,\n}: ExpandableTextProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [expanded, setExpanded] = useState(false);\n const [full, setFull] = useState(0);\n const collapsed = lines * lineHeight;\n const height = useRef(new Animated.Value(collapsed)).current;\n const long = full > collapsed + 1;\n\n useEffect(() => {\n if (full === 0) return;\n const toValue = expanded && long ? full : collapsed;\n if (reduceMotion) height.setValue(toValue);\n else\n Animated.timing(height, {\n toValue,\n duration: 260,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [expanded, full, long, collapsed, reduceMotion, height]);\n\n return (\n \n \n setFull(event.nativeEvent.layout.height)}\n style={[styles.text, { color: palette.text, lineHeight }]}\n >\n {text}\n \n \n {long ? (\n setExpanded(!expanded)}\n hitSlop={8}\n style={styles.link}\n >\n \n {expanded ? lessLabel : moreLabel}\n \n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n text: { fontSize: 15 },\n link: { alignSelf: \"flex-start\", minHeight: 40, justifyContent: \"center\", userSelect: \"none\" },\n linkText: { fontSize: 15, fontWeight: \"700\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/extended-fab.json b/public/registry/extended-fab.json new file mode 100644 index 0000000..d0981dc --- /dev/null +++ b/public/registry/extended-fab.json @@ -0,0 +1,15 @@ +{ + "name": "extended-fab", + "title": "Extended FAB", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/extended-fab.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Pressable,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst SIZE = 56;\n\nexport interface ExtendedFabColors {\n background: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: ExtendedFabColors = {\n background: \"#4f46e5\",\n text: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ExtendedFabProps {\n label: string;\n onPress: () => void;\n /** A glyph drawn before the label. */\n icon?: string;\n /** Shrinks the button to just its icon, for example while a list is scrolling down. */\n collapsed?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A floating action button with a label. While `collapsed` is false it shows icon and label; when it\n * turns true the label slides away and the button shrinks to a circle, the way the compose button\n * folds up as a list scrolls. The label stays in the accessibility tree either way.\n */\nexport function ExtendedFab({\n label,\n onPress,\n icon = \"+\",\n collapsed = false,\n colors,\n style,\n}: ExtendedFabProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [labelWidth, setLabelWidth] = useState(0);\n const t = useRef(new Animated.Value(collapsed ? 0 : 1)).current;\n\n useEffect(() => {\n const toValue = collapsed ? 0 : 1;\n if (reduceMotion) t.setValue(toValue);\n else\n Animated.timing(t, {\n toValue,\n duration: 240,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [collapsed, reduceMotion, t]);\n\n return (\n \n \n {icon}\n \n \n setLabelWidth(Math.ceil(event.nativeEvent.layout.width))\n }\n style={[styles.label, { color: palette.text }]}\n >\n {label}\n \n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n hit: { alignSelf: \"flex-start\", userSelect: \"none\" },\n fab: {\n height: SIZE,\n borderRadius: SIZE / 2,\n flexDirection: \"row\",\n alignItems: \"center\",\n overflow: \"hidden\",\n boxShadow: \"0 6px 16px rgba(0, 0, 0, 0.25)\",\n },\n icon: { width: SIZE, textAlign: \"center\", fontSize: 26, fontWeight: \"500\" },\n label: { fontSize: 15, fontWeight: \"700\", marginLeft: -4 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/float-field.json b/public/registry/float-field.json new file mode 100644 index 0000000..64fed9e --- /dev/null +++ b/public/registry/float-field.json @@ -0,0 +1,15 @@ +{ + "name": "float-field", + "title": "Float Field", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/float-field.tsx", + "content": "import { useEffect, useRef, useState, type ElementRef } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n TextInput,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst HEIGHT = 60;\n\nexport interface FloatFieldColors {\n background: string;\n border: string;\n focusBorder: string;\n label: string;\n text: string;\n error: string;\n helper: string;\n}\n\nconst DEFAULT_COLORS: FloatFieldColors = {\n background: \"#ffffff\",\n border: \"#d1d5db\",\n focusBorder: \"#4f46e5\",\n label: \"#6b7280\",\n text: \"#111827\",\n error: \"#dc2626\",\n helper: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface FloatFieldProps {\n value: string;\n onChangeText: (text: string) => void;\n /** The field's name. It sits inside the field, then floats up when there is text or focus. */\n label: string;\n /** A hint under the field. */\n helper?: string;\n /** Replaces the hint, turns the border red and shakes the field when it first appears. */\n error?: string;\n /** Hides the text, with a Show and Hide button. */\n secureTextEntry?: boolean;\n /** Shows a clear button while the field has text. */\n clearable?: boolean;\n disabled?: boolean;\n keyboardType?: \"default\" | \"email-address\" | \"numeric\" | \"phone-pad\" | \"url\";\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A text field whose label starts inside the box and floats up to the top as you focus or type. The\n * border blends to the focus colour, a new error shakes the field and turns it red, and the message\n * is announced. It can hide its text with a Show button, and clears with one tap.\n */\nexport function FloatField({\n value,\n onChangeText,\n label,\n helper,\n error,\n secureTextEntry = false,\n clearable = true,\n disabled = false,\n keyboardType = \"default\",\n colors,\n style,\n}: FloatFieldProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const input = useRef>(null);\n const [focused, setFocused] = useState(false);\n const [revealed, setRevealed] = useState(false);\n const floated = focused || value.length > 0;\n const float = useRef(new Animated.Value(floated ? 1 : 0)).current;\n const glow = useRef(new Animated.Value(focused ? 1 : 0)).current;\n const shake = useRef(new Animated.Value(0)).current;\n const hadError = useRef(false);\n\n useEffect(() => {\n if (reduceMotion) {\n float.setValue(floated ? 1 : 0);\n return;\n }\n Animated.timing(float, {\n toValue: floated ? 1 : 0,\n duration: 160,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [floated, reduceMotion, float]);\n\n useEffect(() => {\n if (reduceMotion) {\n glow.setValue(focused ? 1 : 0);\n return;\n }\n Animated.timing(glow, {\n toValue: focused ? 1 : 0,\n duration: 160,\n useNativeDriver: false,\n }).start();\n }, [focused, reduceMotion, glow]);\n\n // A shake when an error first appears, not every time it is re-rendered.\n useEffect(() => {\n const has = !!error;\n if (has && !hadError.current && !reduceMotion) {\n Animated.sequence(\n [-8, 8, -6, 6, -3, 0].map((toValue) =>\n Animated.timing(shake, { toValue, duration: 50, useNativeDriver: NATIVE_DRIVER }),\n ),\n ).start();\n }\n hadError.current = has;\n }, [error, reduceMotion, shake]);\n\n const borderColor = error\n ? palette.error\n : glow.interpolate({ inputRange: [0, 1], outputRange: [palette.border, palette.focusBorder] });\n const labelColor = error ? palette.error : focused ? palette.focusBorder : palette.label;\n const message = error ?? helper;\n const clear = () => {\n onChangeText(\"\");\n input.current?.focus();\n };\n\n return (\n \n \n \n {label}\n \n setFocused(true)}\n onBlur={() => setFocused(false)}\n editable={!disabled}\n secureTextEntry={secureTextEntry && !revealed}\n keyboardType={keyboardType}\n autoCapitalize=\"none\"\n autoCorrect={false}\n accessibilityLabel={label}\n aria-label={label}\n aria-invalid={!!error}\n aria-disabled={disabled}\n accessibilityHint={message}\n selectionColor={palette.focusBorder}\n style={[styles.input, { color: palette.text }]}\n />\n {clearable && value.length > 0 && !secureTextEntry ? (\n \n ×\n \n ) : null}\n {secureTextEntry && value.length > 0 ? (\n setRevealed((shown) => !shown)}\n style={styles.action}\n >\n \n {revealed ? \"Hide\" : \"Show\"}\n \n \n ) : null}\n \n {message ? (\n \n {message}\n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n box: { height: HEIGHT, borderRadius: 12, justifyContent: \"center\", paddingHorizontal: 14 },\n label: {\n position: \"absolute\",\n left: 14,\n top: 18,\n fontSize: 16,\n transformOrigin: \"left center\",\n },\n input: {\n fontSize: 16,\n paddingTop: 20,\n paddingBottom: 4,\n paddingRight: 44,\n height: HEIGHT - 4,\n outlineStyle: \"none\",\n } as object,\n action: {\n position: \"absolute\",\n right: 12,\n top: 0,\n bottom: 0,\n minWidth: 32,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n clear: { fontSize: 24, lineHeight: 26 },\n toggle: { fontSize: 13, fontWeight: \"700\" },\n message: { marginTop: 6, marginHorizontal: 4, fontSize: 13, lineHeight: 18 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/gauge-meter.json b/public/registry/gauge-meter.json new file mode 100644 index 0000000..baf3b89 --- /dev/null +++ b/public/registry/gauge-meter.json @@ -0,0 +1,15 @@ +{ + "name": "gauge-meter", + "title": "Gauge Meter", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/gauge-meter.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface GaugeMeterColors {\n track: string;\n fill: string;\n text: string;\n caption: string;\n}\n\nconst DEFAULT_COLORS: GaugeMeterColors = {\n track: \"#e5e7eb\",\n fill: \"#4f46e5\",\n text: \"#111827\",\n caption: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface GaugeMeterProps {\n /** Progress from 0 to 1. */\n value: number;\n /** Width of the gauge; its height is half of this. */\n size?: number;\n /** Width of the arc. */\n thickness?: number;\n /** Text under the number. */\n caption?: string;\n /** Spoken name of the gauge. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A half-circle gauge. The arc sweeps round from the left to the value on a spring, with the\n * percentage in the middle and an optional caption below it. The arc is built from clipped, rotated\n * Views, so it needs no SVG package. Reads out as a progress bar.\n */\nexport function GaugeMeter({\n value,\n size = 220,\n thickness = 18,\n caption,\n label = \"Gauge\",\n colors,\n style,\n}: GaugeMeterProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const clamped = Math.max(0, Math.min(1, value));\n const sweep = useRef(new Animated.Value(clamped)).current;\n const percent = Math.round(clamped * 100);\n\n useEffect(() => {\n if (reduceMotion) {\n sweep.setValue(clamped);\n return;\n }\n Animated.spring(sweep, {\n toValue: clamped,\n stiffness: 120,\n damping: 18,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [clamped, reduceMotion, sweep]);\n\n const ring = {\n position: \"absolute\" as const,\n top: 0,\n left: 0,\n width: size,\n height: size,\n borderRadius: size / 2,\n borderWidth: thickness,\n };\n\n return (\n \n \n \n \n \n \n \n {percent}%\n \n {caption ? (\n {caption}\n ) : null}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n center: { position: \"absolute\", bottom: 0, alignItems: \"center\" },\n number: { fontWeight: \"800\", lineHeight: 44 },\n caption: { fontSize: 13 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/hold-confirm.json b/public/registry/hold-confirm.json new file mode 100644 index 0000000..2ca7b8e --- /dev/null +++ b/public/registry/hold-confirm.json @@ -0,0 +1,15 @@ +{ + "name": "hold-confirm", + "title": "Hold Confirm", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/hold-confirm.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface HoldConfirmColors {\n background: string;\n fill: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: HoldConfirmColors = {\n background: \"#fee2e2\",\n fill: \"#dc2626\",\n text: \"#7f1d1d\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface HoldConfirmProps {\n label: string;\n /** Called once when the button has been held long enough, or activated by a screen reader or Enter. */\n onComplete: () => void;\n /** How long to hold, in milliseconds. */\n duration?: number;\n /** Text shown after it completes. */\n doneLabel?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A button for actions that should not happen by accident, such as deleting an account. A colour fills\n * the button while it is held and the action runs when it is full; letting go early drains it back and\n * nothing happens. Because holding is hard for some people, a screen reader's activate action and the\n * Enter key on the web run the action straight away.\n */\nexport function HoldConfirm({\n label,\n onComplete,\n duration = 1200,\n doneLabel = \"Done\",\n colors,\n style,\n}: HoldConfirmProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const fill = useRef(new Animated.Value(0)).current;\n const [done, setDone] = useState(false);\n const live = useRef({ onComplete, reduceMotion, duration });\n live.current = { onComplete, reduceMotion, duration };\n const timer = useRef | null>(null);\n\n useEffect(\n () => () => {\n if (timer.current) clearTimeout(timer.current);\n },\n [],\n );\n\n const finish = () => {\n setDone(true);\n live.current.onComplete();\n timer.current = setTimeout(() => {\n setDone(false);\n fill.setValue(0);\n }, 1400);\n };\n\n const press = () => {\n if (done) return;\n fill.stopAnimation();\n if (live.current.reduceMotion) {\n // Without motion the hold is a plain timer, and the fill jumps to full when it ends.\n timer.current = setTimeout(() => {\n fill.setValue(1);\n finish();\n }, live.current.duration);\n return;\n }\n Animated.timing(fill, {\n toValue: 1,\n duration: live.current.duration,\n easing: Easing.linear,\n useNativeDriver: false,\n }).start(({ finished }) => {\n if (finished) finish();\n });\n };\n\n const release = () => {\n if (done) return;\n if (timer.current) clearTimeout(timer.current);\n fill.stopAnimation();\n if (live.current.reduceMotion) fill.setValue(0);\n else Animated.timing(fill, { toValue: 0, duration: 250, useNativeDriver: false }).start();\n };\n\n const keys = {\n onKeyDown: (event: { key: string }) => {\n if (event.key === \"Enter\" && !done) finish();\n },\n } as object;\n\n return (\n !done && finish()}\n onPressIn={press}\n onPressOut={release}\n {...keys}\n style={[styles.root, { backgroundColor: palette.background }, style]}\n >\n \n \n {done ? doneLabel : label}\n {done ? null : Hold}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: {\n minHeight: 56,\n borderRadius: 16,\n overflow: \"hidden\",\n justifyContent: \"center\",\n userSelect: \"none\",\n },\n fill: { position: \"absolute\", top: 0, bottom: 0, left: 0, opacity: 0.85 },\n center: {\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: 10,\n paddingHorizontal: 20,\n },\n text: { fontSize: 16, fontWeight: \"800\" },\n hint: { fontSize: 12, fontWeight: \"700\", opacity: 0.6 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/hue-picker.json b/public/registry/hue-picker.json new file mode 100644 index 0000000..82177f6 --- /dev/null +++ b/public/registry/hue-picker.json @@ -0,0 +1,15 @@ +{ + "name": "hue-picker", + "title": "Hue Picker", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/hue-picker.tsx", + "content": "import { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst THUMB = 28;\nconst TRACK_INSET = 5;\nconst HUE_SEGMENTS = 72;\nconst LIGHT_SEGMENTS = 24;\nconst STEP = 5;\n// Hue 360 is the same colour as 0, so the far end of the strip stops just short of it and the thumb\n// never jumps back to the start.\nconst MAX_HUE = 359.99;\nconst FALLBACK = \"#4f46e5\";\n\nexport interface HuePickerColors {\n ring: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: HuePickerColors = {\n ring: \"#111827\",\n text: \"#111827\",\n};\n\nconst DEFAULT_SWATCHES = [\n \"#ef4444\",\n \"#f97316\",\n \"#eab308\",\n \"#22c55e\",\n \"#14b8a6\",\n \"#3b82f6\",\n \"#8b5cf6\",\n \"#ec4899\",\n];\n\nconst HUE_COLORS = Array.from(\n { length: HUE_SEGMENTS },\n (_, i) => `hsl(${(i + 0.5) * (360 / HUE_SEGMENTS)}, 100%, 50%)`,\n);\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\ninterface Hsl {\n /** Degrees, 0 to 360. */\n h: number;\n /** Percent. */\n s: number;\n /** Percent. */\n l: number;\n}\n\n/** \"#abc\" or \"#aabbcc\", any case, to \"#aabbcc\"; null when it is not a hex colour. */\nfunction normalizeHex(input: string): string | null {\n const match = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(input.trim());\n if (!match) return null;\n const digits = match[1].toLowerCase();\n const full = digits.length === 3 ? digits.replace(/./g, (c) => c + c) : digits;\n return `#${full}`;\n}\n\nfunction hexToHsl(hex: string): Hsl {\n const r = parseInt(hex.slice(1, 3), 16) / 255;\n const g = parseInt(hex.slice(3, 5), 16) / 255;\n const b = parseInt(hex.slice(5, 7), 16) / 255;\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const d = max - min;\n const l = (max + min) / 2;\n const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));\n let h = 0;\n if (d !== 0) {\n if (max === r) h = ((g - b) / d) % 6;\n else if (max === g) h = (b - r) / d + 2;\n else h = (r - g) / d + 4;\n }\n return { h: (h * 60 + 360) % 360, s: s * 100, l: l * 100 };\n}\n\nfunction hslToHex({ h, s, l }: Hsl): string {\n const sat = s / 100;\n const light = l / 100;\n const chroma = (1 - Math.abs(2 * light - 1)) * sat;\n const sector = (((h % 360) + 360) % 360) / 60;\n const x = chroma * (1 - Math.abs((sector % 2) - 1));\n const [r, g, b] =\n sector < 1\n ? [chroma, x, 0]\n : sector < 2\n ? [x, chroma, 0]\n : sector < 3\n ? [0, chroma, x]\n : sector < 4\n ? [0, x, chroma]\n : sector < 5\n ? [x, 0, chroma]\n : [chroma, 0, x];\n const m = light - chroma / 2;\n const byte = (v: number) =>\n Math.max(0, Math.min(255, Math.round((v + m) * 255)))\n .toString(16)\n .padStart(2, \"0\");\n return `#${byte(r)}${byte(g)}${byte(b)}`;\n}\n\nexport interface HuePickerProps {\n /** The colour as a hex string such as \"#4f46e5\". Expected to echo `onChange`. */\n value: string;\n /** Called with a lowercase \"#rrggbb\" string as the colour changes. */\n onChange: (hex: string) => void;\n /** Colours offered as one-tap swatches. */\n swatches?: string[];\n /** Show the hex text next to the preview. */\n showValue?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A colour picker built from plain Views: a hue strip, a lightness strip for the chosen hue, and\n * swatches. Hue, saturation and lightness are kept as numbers while you drag and only turned into\n * hex on the way out, so the hex never drifts and the hue survives passing through black or white.\n */\nexport function HuePicker({\n value,\n onChange,\n swatches = DEFAULT_SWATCHES,\n showValue = true,\n colors,\n style,\n}: HuePickerProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const initial = normalizeHex(value) ?? FALLBACK;\n const [hsl, setHsl] = useState(() => hexToHsl(initial));\n const [width, setWidth] = useState(0);\n const emitted = useRef(initial);\n const dragging = useRef<\"hue\" | \"light\" | null>(null);\n const placed = useRef(false);\n const start = useRef(0);\n const hueX = useRef(new Animated.Value(0)).current;\n const lightX = useRef(new Animated.Value(0)).current;\n const hueGrow = useRef(new Animated.Value(0)).current;\n const lightGrow = useRef(new Animated.Value(0)).current;\n\n const span = Math.max(0, width - THUMB);\n const hex = hslToHex(hsl);\n\n // The responders are created once, so they read the latest values from here.\n const live = useRef({ hsl, onChange, span, reduceMotion });\n live.current = { hsl: live.current.hsl, onChange, span, reduceMotion };\n\n // Adopt a colour the parent changed, but not the one we just reported.\n useEffect(() => {\n const next = normalizeHex(value);\n if (next && next !== emitted.current) {\n emitted.current = next;\n const parsed = hexToHsl(next);\n live.current.hsl = parsed;\n setHsl(parsed);\n }\n }, [value]);\n\n const apply = (next: Hsl) => {\n live.current.hsl = next;\n setHsl(next);\n const nextHex = hslToHex(next);\n if (nextHex !== emitted.current) {\n emitted.current = nextHex;\n live.current.onChange(nextHex);\n }\n };\n\n const spring = (node: Animated.Value, toValue: number) => {\n if (live.current.reduceMotion) {\n node.setValue(toValue);\n return;\n }\n Animated.spring(node, {\n toValue,\n stiffness: 420,\n damping: 28,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n // Put the thumbs where the colour says. Dragging moves them directly, so skip it then.\n useEffect(() => {\n if (span <= 0 || dragging.current) return;\n const targets: [Animated.Value, number][] = [\n [hueX, (hsl.h / 360) * span],\n [lightX, (hsl.l / 100) * span],\n ];\n for (const [node, px] of targets) {\n if (!placed.current) node.setValue(px);\n else spring(node, px);\n }\n placed.current = true;\n // spring reads from refs; the dependencies below are what should re-run it.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [hsl.h, hsl.l, span, reduceMotion]);\n\n const move = (kind: \"hue\" | \"light\", x: number) => {\n const room = live.current.span;\n if (room <= 0) return;\n const ratio = Math.max(0, Math.min(1, (x - THUMB / 2) / room));\n if (kind === \"hue\") {\n hueX.setValue(ratio * room);\n apply({ ...live.current.hsl, h: Math.min(MAX_HUE, ratio * 360) });\n } else {\n lightX.setValue(ratio * room);\n apply({ ...live.current.hsl, l: ratio * 100 });\n }\n };\n\n const makePan = (kind: \"hue\" | \"light\") => {\n const grow = kind === \"hue\" ? hueGrow : lightGrow;\n const finish = () => {\n if (dragging.current !== kind) return;\n dragging.current = null;\n spring(grow, 0);\n };\n return PanResponder.create({\n onStartShouldSetPanResponder: () => true,\n onPanResponderTerminationRequest: () => false,\n onPanResponderGrant: (event) => {\n dragging.current = kind;\n start.current = event.nativeEvent.locationX;\n spring(grow, 1);\n // Touching the strip puts the thumb under the finger.\n move(kind, start.current);\n },\n onPanResponderMove: (_, g) => move(kind, start.current + g.dx),\n onPanResponderRelease: finish,\n onPanResponderTerminate: finish,\n });\n };\n const huePan = useRef(makePan(\"hue\")).current;\n const lightPan = useRef(makePan(\"light\")).current;\n\n const nudge = (kind: \"hue\" | \"light\", direction: 1 | -1) => {\n const current = live.current.hsl;\n if (kind === \"hue\") {\n apply({ ...current, h: Math.max(0, Math.min(MAX_HUE, current.h + direction * STEP)) });\n } else {\n apply({ ...current, l: Math.max(0, Math.min(100, current.l + direction * STEP)) });\n }\n };\n\n const choose = (swatch: string) => {\n const normal = normalizeHex(swatch);\n if (!normal) return;\n const parsed = hexToHsl(normal);\n live.current.hsl = parsed;\n setHsl(parsed);\n if (normal !== emitted.current) {\n emitted.current = normal;\n live.current.onChange(normal);\n }\n };\n\n // The lightness strip runs dark to light in the chosen hue and saturation.\n const hueKey = Math.round(hsl.h);\n const satKey = Math.round(hsl.s);\n const lightColors = useMemo(\n () =>\n Array.from(\n { length: LIGHT_SEGMENTS },\n (_, i) => `hsl(${hueKey}, ${satKey}%, ${(i / (LIGHT_SEGMENTS - 1)) * 100}%)`,\n ),\n [hueKey, satKey],\n );\n\n return (\n setWidth(event.nativeEvent.layout.width)}\n style={[styles.root, style]}\n >\n \n \n {showValue ? {hex} : null}\n \n nudge(\"hue\", direction)}\n />\n nudge(\"light\", direction)}\n />\n \n {swatches.map((swatch, index) => (\n choose(swatch)}\n />\n ))}\n \n \n );\n}\n\nfunction Strip({\n label,\n segments,\n x,\n grow,\n thumbColor,\n panHandlers,\n now,\n max,\n text,\n onNudge,\n}: {\n label: string;\n segments: string[];\n x: Animated.Value;\n grow: Animated.Value;\n thumbColor: string;\n panHandlers: object;\n now: number;\n max: number;\n text: string;\n onNudge: (direction: 1 | -1) => void;\n}) {\n // Built once so react-native-web never restarts a running spring when this re-renders.\n const thumbStyle = useMemo(\n () => ({\n transform: [\n { translateX: x },\n { scale: grow.interpolate({ inputRange: [0, 1], outputRange: [1, 1.18] }) },\n ],\n }),\n [x, grow],\n );\n\n return (\n \n onNudge(event.nativeEvent.actionName === \"increment\" ? 1 : -1)\n }\n style={styles.strip}\n >\n \n {segments.map((color, index) => (\n \n ))}\n \n \n \n );\n}\n\nfunction Swatch({\n hex,\n selected,\n ring,\n reduceMotion,\n onPress,\n}: {\n hex: string;\n selected: boolean;\n ring: string;\n reduceMotion: boolean;\n onPress: () => void;\n}) {\n const shown = useRef(new Animated.Value(selected ? 1 : 0)).current;\n\n useEffect(() => {\n if (reduceMotion) {\n shown.setValue(selected ? 1 : 0);\n return;\n }\n Animated.spring(shown, {\n toValue: selected ? 1 : 0,\n stiffness: 420,\n damping: 24,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [selected, reduceMotion, shown]);\n\n const ringStyle = useMemo(\n () => ({\n opacity: shown,\n transform: [{ scale: shown.interpolate({ inputRange: [0, 1], outputRange: [0.75, 1] }) }],\n }),\n [shown],\n );\n\n return (\n \n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n // userSelect keeps a mouse drag on the web from selecting text instead of moving a thumb.\n root: { alignSelf: \"stretch\", gap: 16, userSelect: \"none\" },\n preview: { flexDirection: \"row\", alignItems: \"center\", gap: 12 },\n chip: {\n width: 48,\n height: 48,\n borderRadius: 14,\n borderWidth: 1,\n borderColor: \"rgba(0, 0, 0, 0.12)\",\n },\n hex: { fontSize: 18, fontWeight: \"700\", letterSpacing: 0.5 },\n strip: { height: THUMB, justifyContent: \"center\" },\n clip: {\n position: \"absolute\",\n top: TRACK_INSET,\n bottom: TRACK_INSET,\n left: 0,\n right: 0,\n flexDirection: \"row\",\n borderRadius: 10,\n overflow: \"hidden\",\n },\n segment: { flex: 1 },\n thumb: {\n position: \"absolute\",\n left: 0,\n top: 0,\n width: THUMB,\n height: THUMB,\n borderRadius: THUMB / 2,\n borderWidth: 3,\n borderColor: \"#ffffff\",\n boxShadow: \"0 1px 5px rgba(0, 0, 0, 0.35)\",\n },\n swatches: { flexDirection: \"row\", flexWrap: \"wrap\", gap: 10 },\n swatchHit: { width: 34, height: 34, alignItems: \"center\", justifyContent: \"center\" },\n swatch: { width: 26, height: 26, borderRadius: 13 },\n swatchRing: {\n position: \"absolute\",\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n borderRadius: 17,\n borderWidth: 2.5,\n },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/index.json b/public/registry/index.json index c79ecf0..4751b12 100644 --- a/public/registry/index.json +++ b/public/registry/index.json @@ -1,7 +1,7 @@ { "name": "Modus UI", "homepage": "https://modusui.kasimkazmi.com", - "count": 239, + "count": 298, "categories": [ "Navigation", "Actions", @@ -2824,6 +2824,478 @@ "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": [] + }, + { + "name": "action-tray", + "title": "Action Tray", + "category": "React Native", + "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": [] + }, + { + "name": "confirm-dialog", + "title": "Confirm Dialog", + "category": "React Native", + "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": [] + }, + { + "name": "code-boxes", + "title": "Code Boxes", + "category": "React Native", + "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": [] + }, + { + "name": "hue-picker", + "title": "Hue Picker", + "category": "React Native", + "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": [] + }, + { + "name": "tab-pager", + "title": "Tab Pager", + "category": "React Native", + "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": [] + }, + { + "name": "wheel-picker", + "title": "Wheel Picker", + "category": "React Native", + "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": [] + }, + { + "name": "avatar-stack", + "title": "Avatar Stack", + "category": "React Native", + "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": [] + }, + { + "name": "stripe-progress", + "title": "Stripe Progress", + "category": "React Native", + "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": [] + }, + { + "name": "range-slider", + "title": "Range Slider", + "category": "React Native", + "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": [] + }, + { + "name": "tick-box", + "title": "Tick Box", + "category": "React Native", + "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": [] + }, + { + "name": "notice-banner", + "title": "Notice Banner", + "category": "React Native", + "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": [] + }, + { + "name": "side-drawer", + "title": "Side Drawer", + "category": "React Native", + "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": [] + }, + { + "name": "reaction-bar", + "title": "Reaction Bar", + "category": "React Native", + "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": [] + }, + { + "name": "suggest-input", + "title": "Suggest Input", + "category": "React Native", + "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": [] + }, + { + "name": "expand-card", + "title": "Expand Card", + "category": "React Native", + "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": [] + }, + { + "name": "ring-meter", + "title": "Ring Meter", + "category": "React Native", + "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": [] + }, + { + "name": "count-badge", + "title": "Count Badge", + "category": "React Native", + "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": [] + }, + { + "name": "float-field", + "title": "Float Field", + "category": "React Native", + "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": [] + }, + { + "name": "month-grid", + "title": "Month Grid", + "category": "React Native", + "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": [] + }, + { + "name": "chat-bubble", + "title": "Chat Bubble", + "category": "React Native", + "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": [] + }, + { + "name": "live-dot", + "title": "Live Dot", + "category": "React Native", + "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": [] + }, + { + "name": "composer-bar", + "title": "Composer Bar", + "category": "React Native", + "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": [] + }, + { + "name": "setting-list", + "title": "Setting List", + "category": "React Native", + "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": [] + }, + { + "name": "pull-refresh", + "title": "Pull Refresh", + "category": "React Native", + "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": [] + }, + { + "name": "story-bars", + "title": "Story Bars", + "category": "React Native", + "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": [] + }, + { + "name": "action-button", + "title": "Action Button", + "category": "React Native", + "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": [] + }, + { + "name": "spin-loader", + "title": "Spin Loader", + "category": "React Native", + "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": [] + }, + { + "name": "radio-group", + "title": "Radio Group", + "category": "React Native", + "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": [] + }, + { + "name": "mode-toggle", + "title": "Mode Toggle", + "category": "React Native", + "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": [] + }, + { + "name": "tip-popover", + "title": "Tip Popover", + "category": "React Native", + "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": [] + }, + { + "name": "data-table", + "title": "Data Table", + "category": "React Native", + "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": [] + }, + { + "name": "wave-bars", + "title": "Wave Bars", + "category": "React Native", + "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": [] + }, + { + "name": "page-dots", + "title": "Page Dots", + "category": "React Native", + "platform": "native", + "description": "React Native pager dots where the current page stretches into a pill and every dot can be tapped to jump.", + "dependencies": [] + }, + { + "name": "password-meter", + "title": "Password Meter", + "category": "React Native", + "platform": "native", + "description": "A React Native strength meter whose four bars fill and change colour as a password gets stronger.", + "dependencies": [] + }, + { + "name": "timeline-list", + "title": "Timeline List", + "category": "React Native", + "platform": "native", + "description": "A React Native vertical timeline with completed, current and upcoming steps and a pulsing dot on the step in progress.", + "dependencies": [] + }, + { + "name": "empty-state", + "title": "Empty State", + "category": "React Native", + "platform": "native", + "description": "A React Native empty list placeholder with a floating badge, a message and an optional action button.", + "dependencies": [] + }, + { + "name": "rating-histogram", + "title": "Rating Histogram", + "category": "React Native", + "platform": "native", + "description": "A React Native review breakdown with one animated bar per star level and the average beside them.", + "dependencies": [] + }, + { + "name": "countdown-timer", + "title": "Countdown Timer", + "category": "React Native", + "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": [] + }, + { + "name": "contact-index", + "title": "Contact Index", + "category": "React Native", + "platform": "native", + "description": "A React Native alphabetical list with a draggable letter rail that jumps between sections like a phone's contacts.", + "dependencies": [] + }, + { + "name": "select-grid", + "title": "Select Grid", + "category": "React Native", + "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": [] + }, + { + "name": "poll-bars", + "title": "Poll Bars", + "category": "React Native", + "platform": "native", + "description": "A React Native poll whose options turn into animated result bars with percentages once a vote is cast.", + "dependencies": [] + }, + { + "name": "card-field", + "title": "Card Field", + "category": "React Native", + "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": [] + }, + { + "name": "step-slider", + "title": "Step Slider", + "category": "React Native", + "platform": "native", + "description": "A React Native slider with fixed stops whose thumb follows the finger and springs onto the nearest label.", + "dependencies": [] + }, + { + "name": "cart-quantity", + "title": "Cart Quantity", + "category": "React Native", + "platform": "native", + "description": "A React Native quantity picker whose minus turns into a bin at one so the same tap removes the item.", + "dependencies": [] + }, + { + "name": "password-field", + "title": "Password Field", + "category": "React Native", + "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": [] + }, + { + "name": "resend-button", + "title": "Resend Button", + "category": "React Native", + "platform": "native", + "description": "A React Native resend code link that waits out a countdown, pulses when ready and starts over after each press.", + "dependencies": [] + }, + { + "name": "gauge-meter", + "title": "Gauge Meter", + "category": "React Native", + "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": [] + }, + { + "name": "undo-snackbar", + "title": "Undo Snackbar", + "category": "React Native", + "platform": "native", + "description": "A React Native snackbar with an Undo button that slides up, shows a draining timer line and closes itself.", + "dependencies": [] + }, + { + "name": "mood-picker", + "title": "Mood Picker", + "category": "React Native", + "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": [] + }, + { + "name": "expandable-text", + "title": "Expandable Text", + "category": "React Native", + "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": [] + }, + { + "name": "extended-fab", + "title": "Extended FAB", + "category": "React Native", + "platform": "native", + "description": "A React Native floating action button with a label that slides away to leave a circle when collapsed.", + "dependencies": [] + }, + { + "name": "swatch-picker", + "title": "Swatch Picker", + "category": "React Native", + "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": [] + }, + { + "name": "like-button", + "title": "Like Button", + "category": "React Native", + "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": [] + }, + { + "name": "task-checklist", + "title": "Task Checklist", + "category": "React Native", + "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": [] + }, + { + "name": "spark-bars", + "title": "Spark Bars", + "category": "React Native", + "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": [] + }, + { + "name": "battery-meter", + "title": "Battery Meter", + "category": "React Native", + "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": [] + }, + { + "name": "compare-slider", + "title": "Compare Slider", + "category": "React Native", + "platform": "native", + "description": "A React Native before and after slider where dragging a handle reveals more of one side, steppable by screen readers.", + "dependencies": [] + }, + { + "name": "hold-confirm", + "title": "Hold Confirm", + "category": "React Native", + "platform": "native", + "description": "A React Native press and hold button for risky actions that fills while held and drains back if released early.", + "dependencies": [] + }, + { + "name": "select-menu", + "title": "Select Menu", + "category": "React Native", + "platform": "native", + "description": "A React Native dropdown that opens in place, pushing content down instead of floating, with a turning chevron.", + "dependencies": [] } ], "renamed": { diff --git a/public/registry/like-button.json b/public/registry/like-button.json new file mode 100644 index 0000000..e470db3 --- /dev/null +++ b/public/registry/like-button.json @@ -0,0 +1,15 @@ +{ + "name": "like-button", + "title": "Like Button", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/like-button.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst SPARKS = 8;\n\nexport interface LikeButtonColors {\n liked: string;\n idle: string;\n count: string;\n}\n\nconst DEFAULT_COLORS: LikeButtonColors = {\n liked: \"#ef4444\",\n idle: \"#9ca3af\",\n count: \"#374151\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface LikeButtonProps {\n liked: boolean;\n onChange: (liked: boolean) => void;\n /** Shows a number beside the heart. */\n count?: number;\n /** Size of the heart. */\n size?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A heart button. Liking pops the heart past full size and settles it back while a ring of sparks\n * flies outward and fades; unliking just shrinks it quietly. The button reports whether it is pressed\n * and the count is part of its spoken name. With reduced motion the colour changes and nothing else.\n */\nexport function LikeButton({ liked, onChange, count, size = 28, colors, style }: LikeButtonProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const pop = useRef(new Animated.Value(1)).current;\n const burst = useRef(new Animated.Value(0)).current;\n const first = useRef(true);\n\n useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n if (reduceMotion) return;\n if (liked) {\n pop.setValue(0.6);\n Animated.spring(pop, {\n toValue: 1,\n stiffness: 300,\n damping: 9,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n burst.setValue(0);\n Animated.timing(burst, {\n toValue: 1,\n duration: 480,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n } else {\n pop.setValue(0.8);\n Animated.spring(pop, {\n toValue: 1,\n stiffness: 400,\n damping: 20,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }\n }, [liked, reduceMotion, pop, burst]);\n\n const spark = size * 0.14;\n const reach = size * 0.95;\n\n return (\n onChange(!liked)}\n hitSlop={8}\n style={[styles.root, style]}\n >\n \n {Array.from({ length: SPARKS }, (_, i) => {\n const angle = (i / SPARKS) * Math.PI * 2;\n return (\n \n );\n })}\n \n {liked ? \"♥\" : \"♡\"}\n \n \n {count !== undefined ? (\n {count}\n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n root: {\n flexDirection: \"row\",\n alignItems: \"center\",\n gap: 4,\n alignSelf: \"flex-start\",\n userSelect: \"none\",\n },\n count: { fontSize: 15, fontWeight: \"700\", minWidth: 20 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/live-dot.json b/public/registry/live-dot.json new file mode 100644 index 0000000..60bb7e2 --- /dev/null +++ b/public/registry/live-dot.json @@ -0,0 +1,15 @@ +{ + "name": "live-dot", + "title": "Live Dot", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/live-dot.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport type LiveStatus = \"live\" | \"online\" | \"away\" | \"busy\" | \"offline\";\n\nexport interface LiveDotColors {\n live: string;\n online: string;\n away: string;\n busy: string;\n offline: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: LiveDotColors = {\n live: \"#ef4444\",\n online: \"#22c55e\",\n away: \"#f59e0b\",\n busy: \"#dc2626\",\n offline: \"#9ca3af\",\n text: \"#111827\",\n};\n\nconst WORDS: Record = {\n live: \"Live\",\n online: \"Online\",\n away: \"Away\",\n busy: \"Busy\",\n offline: \"Offline\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface LiveDotProps {\n status: LiveStatus;\n /** Diameter of the dot. */\n size?: number;\n /** Sends a soft ring outward from the dot while it is live or online. */\n pulse?: boolean;\n /** Shows the status word beside the dot. */\n showLabel?: boolean;\n /** Replaces the status word, for example \"Recording\". */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A presence or broadcast indicator. A live or online dot sends a soft ring outward on a loop, and\n * the colour change between statuses blends. Away, busy and offline stay still. The status is read\n * out, so it never relies on colour alone.\n */\nexport function LiveDot({\n status,\n size = 10,\n pulse = true,\n showLabel = false,\n label,\n colors,\n style,\n}: LiveDotProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const ring = useRef(new Animated.Value(0)).current;\n const active = pulse && !reduceMotion && (status === \"live\" || status === \"online\");\n const word = label ?? WORDS[status];\n\n useEffect(() => {\n if (!active) {\n ring.setValue(0);\n return;\n }\n const loop = Animated.loop(\n Animated.timing(ring, {\n toValue: 1,\n duration: status === \"live\" ? 1100 : 1900,\n easing: Easing.out(Easing.quad),\n useNativeDriver: NATIVE_DRIVER,\n }),\n );\n loop.start();\n return () => loop.stop();\n }, [active, status, ring]);\n\n const color = palette[status];\n const spread = size * 2.6;\n\n return (\n \n \n \n \n \n {showLabel ? (\n \n {status === \"live\" ? word.toUpperCase() : word}\n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"center\", gap: 6 },\n ring: { position: \"absolute\", top: 0, left: 0 },\n label: { fontSize: 13, fontWeight: \"700\", letterSpacing: 0.3 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/mode-toggle.json b/public/registry/mode-toggle.json new file mode 100644 index 0000000..8eab5a8 --- /dev/null +++ b/public/registry/mode-toggle.json @@ -0,0 +1,15 @@ +{ + "name": "mode-toggle", + "title": "Mode Toggle", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/mode-toggle.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Pressable,\n StyleSheet,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport type Mode = \"light\" | \"dark\";\n\nexport interface ModeToggleColors {\n dayTrack: string;\n nightTrack: string;\n sun: string;\n moon: string;\n star: string;\n}\n\nconst DEFAULT_COLORS: ModeToggleColors = {\n dayTrack: \"#7dd3fc\",\n nightTrack: \"#1e1b4b\",\n sun: \"#facc15\",\n moon: \"#e5e7eb\",\n star: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ModeToggleProps {\n mode: Mode;\n onChange: (mode: Mode) => void;\n size?: \"md\" | \"lg\";\n /** Spoken name of the switch. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A light and dark switch. The sun slides across the sky, its glow turns into a moon as a shadow\n * crosses it, the day sky deepens to night and stars fade in. It reads as a switch that is on when\n * the mode is dark. With reduced motion it jumps between the two states.\n */\nexport function ModeToggle({\n mode,\n onChange,\n size = \"md\",\n label = \"Dark mode\",\n colors,\n style,\n}: ModeToggleProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const dark = mode === \"dark\";\n const m = useRef(new Animated.Value(dark ? 1 : 0)).current;\n\n useEffect(() => {\n if (reduceMotion) {\n m.setValue(dark ? 1 : 0);\n return;\n }\n // Colours cannot run on the native driver, so the whole toggle is driven from JS.\n Animated.timing(m, {\n toValue: dark ? 1 : 0,\n duration: 380,\n easing: Easing.inOut(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [dark, reduceMotion, m]);\n\n const height = size === \"lg\" ? 44 : 36;\n const width = height * 2;\n const pad = 4;\n const thumb = height - pad * 2;\n\n const track = m.interpolate({\n inputRange: [0, 1],\n outputRange: [palette.dayTrack, palette.nightTrack],\n });\n const body = m.interpolate({ inputRange: [0, 1], outputRange: [palette.sun, palette.moon] });\n const x = m.interpolate({ inputRange: [0, 1], outputRange: [pad, width - thumb - pad] });\n const shadowX = m.interpolate({ inputRange: [0, 1], outputRange: [thumb, thumb * 0.35] });\n const stars = m.interpolate({ inputRange: [0, 0.6, 1], outputRange: [0, 0, 1] });\n\n const star = (left: number, top: number, s: number) => (\n \n );\n\n return (\n onChange(dark ? \"light\" : \"dark\")}\n style={[styles.hit, style]}\n >\n \n {star(height * 0.3, height * 0.28, 3)}\n {star(height * 0.55, height * 0.6, 2)}\n {star(height * 0.8, height * 0.22, 2)}\n \n \n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n hit: { alignSelf: \"flex-start\", userSelect: \"none\" },\n track: { justifyContent: \"center\", overflow: \"hidden\" },\n thumb: { position: \"absolute\", top: 4, overflow: \"hidden\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/month-grid.json b/public/registry/month-grid.json new file mode 100644 index 0000000..fb5248f --- /dev/null +++ b/public/registry/month-grid.json @@ -0,0 +1,15 @@ +{ + "name": "month-grid", + "title": "Month Grid", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/month-grid.tsx", + "content": "import { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst ROW = 44;\nconst ROWS = 6;\n\nexport interface MonthGridColors {\n text: string;\n mutedText: string;\n pill: string;\n pillText: string;\n today: string;\n dot: string;\n}\n\nconst DEFAULT_COLORS: MonthGridColors = {\n text: \"#111827\",\n mutedText: \"#9ca3af\",\n pill: \"#4f46e5\",\n pillText: \"#ffffff\",\n today: \"#4f46e5\",\n dot: \"#f59e0b\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nconst pad = (n: number) => String(n).padStart(2, \"0\");\n/** YYYY-MM-DD for a local date. Dates here are local, never UTC, so a day cannot shift. */\nconst toISO = (date: Date) =>\n `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\nconst toMonth = (date: Date) => `${date.getFullYear()}-${pad(date.getMonth() + 1)}`;\n/** The first day of a YYYY-MM month, as a local date. */\nconst firstOf = (month: string) => {\n const [year, m] = month.split(\"-\").map(Number);\n return new Date(year, m - 1, 1);\n};\nconst addMonths = (month: string, delta: number) => {\n const first = firstOf(month);\n return toMonth(new Date(first.getFullYear(), first.getMonth() + delta, 1));\n};\n\nexport interface MonthGridProps {\n /** The month shown, as YYYY-MM. */\n month: string;\n onMonthChange: (month: string) => void;\n /** The selected day, as YYYY-MM-DD, or null for none. */\n selected: string | null;\n onSelect: (date: string) => void;\n /** Days (YYYY-MM-DD) that show a small dot, for example days with events. */\n marked?: string[];\n /** The first column: 1 for Monday, 0 for Sunday. */\n weekStart?: 0 | 1;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A month calendar. A pill glides to the selected day, the grid slides in from the side when the\n * month changes, and a horizontal swipe changes the month too. Days outside the month are faded but\n * still selectable. Dates are local YYYY-MM-DD strings, so nothing shifts a day across time zones.\n */\nexport function MonthGrid({\n month,\n onMonthChange,\n selected,\n onSelect,\n marked,\n weekStart = 1,\n colors,\n style,\n}: MonthGridProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [width, setWidth] = useState(0);\n const pill = useRef(new Animated.ValueXY()).current;\n const pillOn = useRef(new Animated.Value(0)).current;\n const slide = useRef(new Animated.Value(0)).current;\n const fade = useRef(new Animated.Value(1)).current;\n const previousMonth = useRef(month);\n const placed = useRef(false);\n // True during a swipe and for a moment after it: the click that follows a mouse drag is not a tap.\n const dragging = useRef(false);\n\n const live = useRef({ month, onMonthChange });\n live.current = { month, onMonthChange };\n\n const todayISO = useMemo(() => toISO(new Date()), []);\n const markedSet = useMemo(() => new Set(marked), [marked]);\n const title = useMemo(\n () =>\n new Intl.DateTimeFormat(undefined, { month: \"long\", year: \"numeric\" }).format(firstOf(month)),\n [month],\n );\n const weekdays = useMemo(() => {\n const format = new Intl.DateTimeFormat(undefined, { weekday: \"narrow\" });\n const spoken = new Intl.DateTimeFormat(undefined, { weekday: \"long\" });\n // 2023-01-01 was a Sunday.\n return Array.from({ length: 7 }, (_, i) => {\n const date = new Date(2023, 0, 1 + ((i + weekStart) % 7));\n return { short: format.format(date), long: spoken.format(date) };\n });\n }, [weekStart]);\n const spokenDay = useMemo(\n () =>\n new Intl.DateTimeFormat(undefined, {\n weekday: \"long\",\n day: \"numeric\",\n month: \"long\",\n year: \"numeric\",\n }),\n [],\n );\n\n const cells = useMemo(() => {\n const first = firstOf(month);\n const lead = (first.getDay() - weekStart + 7) % 7;\n return Array.from({ length: ROWS * 7 }, (_, i) => {\n const date = new Date(first.getFullYear(), first.getMonth(), 1 - lead + i);\n return { iso: toISO(date), date, inMonth: toMonth(date) === month };\n });\n }, [month, weekStart]);\n\n const cell = width / 7;\n const selectedIndex = selected ? cells.findIndex((c) => c.iso === selected) : -1;\n\n // The pill glides to the selected day, or fades out when it is not on this page.\n useEffect(() => {\n if (cell <= 0) return;\n const to = { x: (selectedIndex % 7) * cell, y: Math.floor(selectedIndex / 7) * ROW };\n if (selectedIndex < 0) {\n Animated.timing(pillOn, {\n toValue: 0,\n duration: 120,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n return;\n }\n if (!placed.current || reduceMotion) {\n placed.current = true;\n pill.setValue(to);\n pillOn.setValue(1);\n return;\n }\n Animated.parallel([\n Animated.spring(pill, {\n toValue: to,\n stiffness: 420,\n damping: 30,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }),\n Animated.timing(pillOn, { toValue: 1, duration: 120, useNativeDriver: NATIVE_DRIVER }),\n ]).start();\n }, [selectedIndex, cell, reduceMotion, pill, pillOn]);\n\n // The grid slides in from the side the new month lies on.\n useEffect(() => {\n if (previousMonth.current === month) return;\n const direction = month > previousMonth.current ? 1 : -1;\n previousMonth.current = month;\n if (reduceMotion) return;\n slide.setValue(direction * 28);\n fade.setValue(0);\n Animated.parallel([\n Animated.spring(slide, {\n toValue: 0,\n stiffness: 320,\n damping: 28,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }),\n Animated.timing(fade, { toValue: 1, duration: 180, useNativeDriver: NATIVE_DRIVER }),\n ]).start();\n }, [month, reduceMotion, slide, fade]);\n\n const swipe = useRef(\n PanResponder.create({\n onMoveShouldSetPanResponder: (_, g) =>\n Math.abs(g.dx) > 12 && Math.abs(g.dx) > Math.abs(g.dy) * 1.5,\n onPanResponderGrant: () => {\n dragging.current = true;\n },\n onPanResponderRelease: (_, g) => {\n setTimeout(() => (dragging.current = false), 80);\n if (Math.abs(g.dx) < 50 && Math.abs(g.vx) < 0.5) return;\n live.current.onMonthChange(addMonths(live.current.month, g.dx < 0 ? 1 : -1));\n },\n onPanResponderTerminate: () => setTimeout(() => (dragging.current = false), 80),\n }),\n ).current;\n\n const nav = (label: string, glyph: string, delta: number) => (\n onMonthChange(addMonths(month, delta))}\n style={({ pressed }) => [styles.nav, pressed && styles.dim]}\n >\n {glyph}\n \n );\n\n return (\n \n \n {nav(\"Previous month\", \"‹\", -1)}\n \n {title}\n \n {nav(\"Next month\", \"›\", 1)}\n \n \n {weekdays.map((day, i) => (\n \n {day.short}\n \n ))}\n \n setWidth(event.nativeEvent.layout.width)}\n style={styles.gridWrap}\n >\n \n {cell > 0 ? (\n \n \n \n ) : null}\n \n {cells.map(({ iso, date, inMonth }) => {\n const isSelected = iso === selected;\n const isToday = iso === todayISO;\n const hasEvents = markedSet.has(iso);\n return (\n {\n if (dragging.current) return;\n if (!inMonth) onMonthChange(toMonth(date));\n onSelect(iso);\n }}\n style={[styles.cell, { width: `${100 / 7}%` }]}\n >\n \n \n {date.getDate()}\n \n \n \n \n );\n })}\n \n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n header: {\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n marginBottom: 8,\n },\n nav: {\n width: 44,\n height: 44,\n alignItems: \"center\",\n justifyContent: \"center\",\n userSelect: \"none\",\n },\n navGlyph: { fontSize: 28, lineHeight: 30, fontWeight: \"600\" },\n dim: { opacity: 0.5 },\n title: { fontSize: 17, fontWeight: \"800\" },\n week: { flexDirection: \"row\", marginBottom: 4 },\n weekday: { flex: 1, textAlign: \"center\", fontSize: 12, fontWeight: \"700\" },\n gridWrap: { overflow: \"hidden\", userSelect: \"none\" },\n cells: { flexDirection: \"row\", flexWrap: \"wrap\" },\n cell: { height: ROW, alignItems: \"center\", justifyContent: \"center\" },\n day: {\n width: 34,\n height: 34,\n borderRadius: 17,\n alignItems: \"center\",\n justifyContent: \"center\",\n borderColor: \"transparent\",\n borderWidth: 1.5,\n },\n dayText: { fontSize: 15 },\n dot: { position: \"absolute\", bottom: 3, width: 4, height: 4, borderRadius: 2 },\n pill: { position: \"absolute\", top: 0, left: 0, alignItems: \"center\", justifyContent: \"center\" },\n pillInner: { width: 34, height: 34, borderRadius: 17 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/mood-picker.json b/public/registry/mood-picker.json new file mode 100644 index 0000000..a1c48e6 --- /dev/null +++ b/public/registry/mood-picker.json @@ -0,0 +1,15 @@ +{ + "name": "mood-picker", + "title": "Mood Picker", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/mood-picker.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface MoodPickerColors {\n accent: string;\n surface: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: MoodPickerColors = {\n accent: \"#eef2ff\",\n surface: \"#f3f4f6\",\n text: \"#374151\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface MoodPickerProps {\n /** The chosen index, or null for none. */\n value: number | null;\n onChange: (index: number) => void;\n /** One glyph per level, worst first. */\n icons?: string[];\n /** One spoken name per level, matching icons. */\n labels?: string[];\n colors?: Partial;\n style?: StyleProp;\n}\n\nconst ICONS = [\"😡\", \"🙁\", \"😐\", \"🙂\", \"😍\"];\nconst LABELS = [\"Awful\", \"Bad\", \"Okay\", \"Good\", \"Great\"];\n\nfunction Face({\n icon,\n label,\n selected,\n dimmed,\n palette,\n reduceMotion,\n onPress,\n index,\n count,\n}: {\n icon: string;\n label: string;\n selected: boolean;\n dimmed: boolean;\n palette: MoodPickerColors;\n reduceMotion: boolean;\n onPress: () => void;\n index: number;\n count: number;\n}) {\n const grow = useRef(new Animated.Value(selected ? 1 : 0)).current;\n useEffect(() => {\n if (reduceMotion) grow.setValue(selected ? 1 : 0);\n else\n Animated.spring(grow, {\n toValue: selected ? 1 : 0,\n stiffness: 420,\n damping: 15,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [selected, reduceMotion, grow]);\n\n return (\n \n \n {icon}\n \n \n {label}\n \n \n );\n}\n\n/**\n * A row of faces for rating how something felt, from awful to great. The chosen face swells with a\n * bounce and its name appears beneath it while the others dim. The faces form a radio group, so a\n * screen reader reads each name and which one is chosen.\n */\nexport function MoodPicker({\n value,\n onChange,\n icons = ICONS,\n labels = LABELS,\n colors,\n style,\n}: MoodPickerProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n\n return (\n \n {icons.map((icon, i) => (\n onChange(i)}\n />\n ))}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", justifyContent: \"space-between\" },\n face: { alignItems: \"center\", gap: 8, userSelect: \"none\" },\n bubble: {\n width: 52,\n height: 52,\n borderRadius: 26,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n icon: { fontSize: 28 },\n label: { fontSize: 12, fontWeight: \"700\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/notice-banner.json b/public/registry/notice-banner.json new file mode 100644 index 0000000..9bce04e --- /dev/null +++ b/public/registry/notice-banner.json @@ -0,0 +1,15 @@ +{ + "name": "notice-banner", + "title": "Notice Banner", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/notice-banner.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst SWIPE_AWAY = 90;\n\nexport type NoticeTone = \"info\" | \"success\" | \"warning\" | \"error\";\n\nexport interface NoticeBannerColors {\n info: string;\n success: string;\n warning: string;\n error: string;\n surface: string;\n title: string;\n message: string;\n}\n\nconst DEFAULT_COLORS: NoticeBannerColors = {\n info: \"#2563eb\",\n success: \"#16a34a\",\n warning: \"#d97706\",\n error: \"#dc2626\",\n surface: \"#ffffff\",\n title: \"#111827\",\n message: \"#4b5563\",\n};\n\nconst GLYPH: Record = { info: \"i\", success: \"✓\", warning: \"!\", error: \"×\" };\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface NoticeBannerProps {\n title: string;\n message?: string;\n tone?: NoticeTone;\n /** Shows or hides the banner. It slides in and collapses out, so the content below follows smoothly. */\n visible?: boolean;\n /** When given, the banner shows a close button and can be swiped away. */\n onDismiss?: () => void;\n /** A button under the message, for example \"Undo\" or \"View\". */\n action?: { label: string; onPress: () => void };\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * An inline alert in one of four tones. It slides in and collapses its height on the way out, so the\n * content below follows smoothly, and with `onDismiss` it can be closed with a button or swiped\n * sideways. Errors and warnings are announced at once; the other tones wait politely.\n */\nexport function NoticeBanner({\n title,\n message,\n tone = \"info\",\n visible = true,\n onDismiss,\n action,\n colors,\n style,\n}: NoticeBannerProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [shown, setShown] = useState(visible);\n const [mounted, setMounted] = useState(visible);\n const [height, setHeight] = useState(0);\n const t = useRef(new Animated.Value(visible ? 1 : 0)).current;\n const x = useRef(new Animated.Value(0)).current;\n // True during a drag and for a moment after it: the click a mouse sends on release is not a tap.\n const dragging = useRef(false);\n\n const live = useRef({ onDismiss, reduceMotion });\n live.current = { onDismiss, reduceMotion };\n\n // Follow the `visible` prop.\n useEffect(() => setShown(visible), [visible]);\n\n useEffect(() => {\n if (shown) setMounted(true);\n x.setValue(0);\n if (reduceMotion) {\n t.setValue(shown ? 1 : 0);\n if (!shown) setMounted(false);\n return;\n }\n Animated.timing(t, {\n toValue: shown ? 1 : 0,\n duration: 260,\n useNativeDriver: false,\n }).start(({ finished }) => {\n if (finished && !shown) setMounted(false);\n });\n }, [shown, reduceMotion, t, x]);\n\n const dismiss = () => {\n setShown(false);\n live.current.onDismiss?.();\n };\n\n const pan = useRef(\n PanResponder.create({\n onMoveShouldSetPanResponder: (_, g) =>\n !!live.current.onDismiss && Math.abs(g.dx) > 8 && Math.abs(g.dx) > Math.abs(g.dy),\n onPanResponderGrant: () => {\n dragging.current = true;\n },\n onPanResponderMove: (_, g) => x.setValue(g.dx),\n onPanResponderRelease: (_, g) => {\n setTimeout(() => (dragging.current = false), 80);\n if (Math.abs(g.dx) > SWIPE_AWAY || Math.abs(g.vx) > 0.8) {\n dismiss();\n return;\n }\n if (live.current.reduceMotion) x.setValue(0);\n else\n Animated.spring(x, {\n toValue: 0,\n stiffness: 360,\n damping: 28,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n },\n onPanResponderTerminate: () => {\n setTimeout(() => (dragging.current = false), 80);\n x.setValue(0);\n },\n }),\n ).current;\n\n if (!mounted) return null;\n\n const accent = palette[tone];\n const urgent = tone === \"error\" || tone === \"warning\";\n\n return (\n 0 ? t.interpolate({ inputRange: [0, 1], outputRange: [0, height] }) : undefined,\n opacity: t,\n overflow: \"hidden\",\n }}\n >\n setHeight(event.nativeEvent.layout.height)}>\n \n \n {GLYPH[tone]}\n \n \n {title}\n {message ? (\n {message}\n ) : null}\n {action ? (\n {\n if (!dragging.current) action.onPress();\n }}\n style={({ pressed }) => [styles.action, pressed && styles.dim]}\n >\n {action.label}\n \n ) : null}\n \n {onDismiss ? (\n {\n if (!dragging.current) dismiss();\n }}\n style={({ pressed }) => [styles.close, pressed && styles.dim]}\n >\n ×\n \n ) : null}\n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n card: {\n flexDirection: \"row\",\n alignItems: \"flex-start\",\n gap: 12,\n padding: 14,\n borderRadius: 14,\n borderWidth: 1,\n borderLeftWidth: 4,\n userSelect: \"none\",\n },\n glyph: {\n width: 24,\n height: 24,\n borderRadius: 12,\n alignItems: \"center\",\n justifyContent: \"center\",\n marginTop: 1,\n },\n glyphText: { color: \"#ffffff\", fontSize: 14, fontWeight: \"800\", lineHeight: 18 },\n body: { flex: 1, gap: 2 },\n title: { fontSize: 15, fontWeight: \"700\", lineHeight: 22 },\n message: { fontSize: 14, lineHeight: 20 },\n action: { alignSelf: \"flex-start\", minHeight: 32, justifyContent: \"center\", marginTop: 4 },\n actionText: { fontSize: 14, fontWeight: \"700\" },\n close: { width: 28, height: 28, alignItems: \"center\", justifyContent: \"center\" },\n closeText: { fontSize: 22, lineHeight: 24 },\n dim: { opacity: 0.6 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/page-dots.json b/public/registry/page-dots.json new file mode 100644 index 0000000..79eac0f --- /dev/null +++ b/public/registry/page-dots.json @@ -0,0 +1,15 @@ +{ + "name": "page-dots", + "title": "Page Dots", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/page-dots.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Pressable,\n StyleSheet,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface PageDotsColors {\n active: string;\n inactive: string;\n}\n\nconst DEFAULT_COLORS: PageDotsColors = {\n active: \"#4f46e5\",\n inactive: \"#d1d5db\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface PageDotsProps {\n /** How many pages there are. */\n count: number;\n /** The page showing now, from 0. */\n index: number;\n /** Makes each dot tappable and calls this with the page it stands for. */\n onIndexChange?: (index: number) => void;\n /** Diameter of a dot. */\n dotSize?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\ninterface DotProps {\n active: boolean;\n size: number;\n page: number;\n count: number;\n palette: PageDotsColors;\n reduceMotion: boolean;\n onPress?: () => void;\n}\n\nfunction Dot({ active, size, page, count, palette, reduceMotion, onPress }: DotProps) {\n const grow = useRef(new Animated.Value(active ? 1 : 0)).current;\n\n useEffect(() => {\n if (reduceMotion) grow.setValue(active ? 1 : 0);\n else\n Animated.timing(grow, {\n toValue: active ? 1 : 0,\n duration: 220,\n useNativeDriver: false,\n }).start();\n }, [active, reduceMotion, grow]);\n\n return (\n \n \n \n );\n}\n\n/**\n * The row of dots under a pager. The current page's dot stretches into a pill and takes the accent\n * colour while the others shrink back to circles. Give it `onIndexChange` and the dots become buttons.\n */\nexport function PageDots({\n count,\n index,\n onIndexChange,\n dotSize = 8,\n colors,\n style,\n}: PageDotsProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n\n return (\n \n {Array.from({ length: count }, (_, i) => (\n onIndexChange(i) : undefined}\n />\n ))}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"center\", alignSelf: \"center\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/password-field.json b/public/registry/password-field.json new file mode 100644 index 0000000..27a45b1 --- /dev/null +++ b/public/registry/password-field.json @@ -0,0 +1,15 @@ +{ + "name": "password-field", + "title": "Password Field", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/password-field.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Pressable,\n StyleSheet,\n Text,\n TextInput,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface PasswordFieldColors {\n surface: string;\n border: string;\n focus: string;\n text: string;\n placeholder: string;\n toggle: string;\n}\n\nconst DEFAULT_COLORS: PasswordFieldColors = {\n surface: \"#ffffff\",\n border: \"#d1d5db\",\n focus: \"#4f46e5\",\n text: \"#111827\",\n placeholder: \"#9ca3af\",\n toggle: \"#4f46e5\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface PasswordFieldProps {\n value: string;\n onChangeText: (text: string) => void;\n placeholder?: string;\n /** Spoken name of the field. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A password input with a Show and Hide button at its end. The border eases to the accent colour\n * while the field has focus. The button says what it will do, and its pressed state is exposed, so a\n * screen reader hears \"Show password\" and then \"Hide password\".\n */\nexport function PasswordField({\n value,\n onChangeText,\n placeholder = \"Password\",\n label = \"Password\",\n colors,\n style,\n}: PasswordFieldProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [shown, setShown] = useState(false);\n const focus = useRef(new Animated.Value(0)).current;\n\n const setFocus = (on: boolean) => {\n if (reduceMotion) focus.setValue(on ? 1 : 0);\n else\n Animated.timing(focus, {\n toValue: on ? 1 : 0,\n duration: 160,\n useNativeDriver: false,\n }).start();\n };\n\n return (\n \n setFocus(true)}\n onBlur={() => setFocus(false)}\n style={[styles.input, { color: palette.text }]}\n />\n setShown(!shown)}\n hitSlop={8}\n style={styles.toggle}\n >\n \n {shown ? \"Hide\" : \"Show\"}\n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { flexDirection: \"row\", alignItems: \"center\", borderWidth: 2, borderRadius: 14 },\n input: { flex: 1, minWidth: 0, height: 50, paddingHorizontal: 14, fontSize: 16 },\n toggle: { paddingHorizontal: 14, height: 50, justifyContent: \"center\", userSelect: \"none\" },\n toggleText: { fontSize: 14, fontWeight: \"700\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/password-meter.json b/public/registry/password-meter.json new file mode 100644 index 0000000..1b4c1b3 --- /dev/null +++ b/public/registry/password-meter.json @@ -0,0 +1,15 @@ +{ + "name": "password-meter", + "title": "Password Meter", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/password-meter.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface PasswordMeterColors {\n track: string;\n weak: string;\n fair: string;\n good: string;\n strong: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: PasswordMeterColors = {\n track: \"#e5e7eb\",\n weak: \"#dc2626\",\n fair: \"#f59e0b\",\n good: \"#84cc16\",\n strong: \"#16a34a\",\n text: \"#374151\",\n};\n\nconst NAMES = [\"Too short\", \"Weak\", \"Fair\", \"Good\", \"Strong\"];\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\n/** Scores a password from 0 to 4 on its length and the kinds of characters it mixes. */\nexport function scorePassword(value: string) {\n if (value.length < 6) return 0;\n const kinds = [/[a-z]/, /[A-Z]/, /\\d/, /[^A-Za-z0-9]/].filter((re) => re.test(value)).length;\n const length = value.length >= 12 ? 2 : value.length >= 8 ? 1 : 0;\n return Math.max(1, Math.min(4, Math.floor((kinds + length) / 1.5)));\n}\n\nexport interface PasswordMeterProps {\n /** The password to rate. */\n value: string;\n /** Shows the strength as a word beside the bars. */\n showLabel?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\nfunction Segment({\n lit,\n color,\n track,\n reduceMotion,\n}: {\n lit: boolean;\n color: string;\n track: string;\n reduceMotion: boolean;\n}) {\n const fill = useRef(new Animated.Value(lit ? 1 : 0)).current;\n useEffect(() => {\n if (reduceMotion) fill.setValue(lit ? 1 : 0);\n else\n Animated.timing(fill, {\n toValue: lit ? 1 : 0,\n duration: 200,\n useNativeDriver: false,\n }).start();\n }, [lit, reduceMotion, fill]);\n return (\n \n \n \n );\n}\n\n/**\n * Four bars that fill and change colour as a password gets stronger, with the verdict beside them.\n * The rating looks at length and how many kinds of character are mixed. It is a hint, not a guarantee,\n * and the verdict is read out whenever it changes.\n */\nexport function PasswordMeter({ value, showLabel = true, colors, style }: PasswordMeterProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const score = value ? scorePassword(value) : 0;\n const tint = [palette.weak, palette.weak, palette.fair, palette.good, palette.strong][score];\n const name = value ? NAMES[score] : \"Enter a password\";\n\n return (\n \n \n {[1, 2, 3, 4].map((n) => (\n \n ))}\n \n {showLabel ? (\n \n {name}\n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"center\", gap: 12 },\n bars: { flex: 1, flexDirection: \"row\", gap: 4 },\n segment: { flex: 1, height: 6, borderRadius: 3, overflow: \"hidden\" },\n fill: { height: \"100%\" },\n label: { minWidth: 72, fontSize: 13, fontWeight: \"700\", textAlign: \"right\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/poll-bars.json b/public/registry/poll-bars.json new file mode 100644 index 0000000..db5e7fe --- /dev/null +++ b/public/registry/poll-bars.json @@ -0,0 +1,15 @@ +{ + "name": "poll-bars", + "title": "Poll Bars", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/poll-bars.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface PollOption {\n id: string;\n label: string;\n votes: number;\n}\n\nexport interface PollBarsColors {\n bar: string;\n chosenBar: string;\n surface: string;\n border: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: PollBarsColors = {\n bar: \"#e0e7ff\",\n chosenBar: \"#a5b4fc\",\n surface: \"#ffffff\",\n border: \"#e5e7eb\",\n text: \"#111827\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface PollBarsProps {\n options: PollOption[];\n /** The id the person voted for; once set, results show. */\n selected?: string;\n onVote: (id: string) => void;\n colors?: Partial;\n style?: StyleProp;\n}\n\nfunction Row({\n option,\n share,\n chosen,\n voted,\n palette,\n reduceMotion,\n onVote,\n}: {\n option: PollOption;\n share: number;\n chosen: boolean;\n voted: boolean;\n palette: PollBarsColors;\n reduceMotion: boolean;\n onVote: () => void;\n}) {\n const fill = useRef(new Animated.Value(0)).current;\n useEffect(() => {\n const toValue = voted ? share : 0;\n if (reduceMotion) fill.setValue(toValue);\n else\n Animated.timing(fill, {\n toValue,\n duration: 550,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [voted, share, reduceMotion, fill]);\n\n return (\n \n \n \n {option.label}\n {chosen ? \" ✓\" : \"\"}\n \n {voted ? (\n {Math.round(share * 100)}%\n ) : null}\n \n );\n}\n\n/**\n * A poll. Before anyone has voted each option is a button. After a vote the options turn into bars\n * that grow to each one's share of the votes, with percentages, and the chosen option is marked.\n * Results are read out for each option, along with which one is yours.\n */\nexport function PollBars({ options, selected, onVote, colors, style }: PollBarsProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const voted = selected !== undefined;\n const total = options.reduce((sum, option) => sum + option.votes, 0);\n\n return (\n \n {options.map((option) => (\n onVote(option.id)}\n />\n ))}\n \n {voted ? `${total} votes` : \"\"}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { gap: 8 },\n row: {\n minHeight: 52,\n borderRadius: 14,\n borderWidth: 2,\n overflow: \"hidden\",\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n paddingHorizontal: 16,\n userSelect: \"none\",\n },\n fill: { position: \"absolute\", top: 0, bottom: 0, left: 0 },\n label: { fontSize: 16, fontWeight: \"600\" },\n percent: { fontSize: 15, fontWeight: \"700\" },\n total: { fontSize: 13, textAlign: \"right\", opacity: 0.7, minHeight: 18 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/pull-refresh.json b/public/registry/pull-refresh.json new file mode 100644 index 0000000..b76a5d0 --- /dev/null +++ b/public/registry/pull-refresh.json @@ -0,0 +1,15 @@ +{ + "name": "pull-refresh", + "title": "Pull Refresh", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/pull-refresh.tsx", + "content": "import { useEffect, useRef, useState, type ElementRef, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n PanResponder,\n Platform,\n ScrollView,\n StyleSheet,\n Text,\n View,\n type NativeScrollEvent,\n type NativeSyntheticEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst INDICATOR = 40;\n\nexport interface PullRefreshColors {\n indicator: string;\n arrow: string;\n background: string;\n}\n\nconst DEFAULT_COLORS: PullRefreshColors = {\n indicator: \"#4f46e5\",\n arrow: \"#6b7280\",\n background: \"transparent\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface PullRefreshProps {\n /** Whether a refresh is under way. Set it true in `onRefresh` and false when the work is done. */\n refreshing: boolean;\n /** Called when the list is pulled past the threshold and let go. */\n onRefresh: () => void;\n /** The scrolling content. */\n children: ReactNode;\n /** How far, in pixels, the content must be pulled to trigger a refresh. */\n threshold?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A scrolling list you refresh by pulling it down from the top. The content follows your finger\n * with growing resistance, an arrow turns over as you reach the threshold, and on release a spinner\n * holds the content open until you set `refreshing` back to false. It works with a mouse drag on the\n * web, and screen readers get a Refresh action instead.\n */\nexport function PullRefresh({\n refreshing,\n onRefresh,\n children,\n threshold = 72,\n colors,\n style,\n}: PullRefreshProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const pull = useRef(new Animated.Value(0)).current;\n const spin = useRef(new Animated.Value(0)).current;\n const atTop = useRef(true);\n const dragging = useRef(false);\n const hold = INDICATOR + 12;\n\n const live = useRef({ refreshing, onRefresh, threshold, reduceMotion });\n live.current = { refreshing, onRefresh, threshold, reduceMotion };\n\n const settleTo = (toValue: number) => {\n if (live.current.reduceMotion) {\n pull.setValue(toValue);\n return;\n }\n Animated.spring(pull, {\n toValue,\n stiffness: 300,\n damping: 28,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n // Hold the content open while refreshing, and close it when the work is done.\n useEffect(() => {\n if (dragging.current) return;\n settleTo(refreshing ? hold : 0);\n // settleTo reads everything through refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [refreshing, reduceMotion]);\n\n useEffect(() => {\n if (!refreshing || reduceMotion) {\n spin.setValue(0);\n return;\n }\n const loop = Animated.loop(\n Animated.timing(spin, {\n toValue: 1,\n duration: 800,\n easing: Easing.linear,\n useNativeDriver: NATIVE_DRIVER,\n }),\n );\n loop.start();\n return () => loop.stop();\n }, [refreshing, reduceMotion, spin]);\n\n const responder = useRef(\n PanResponder.create({\n onMoveShouldSetPanResponder: (_, g) =>\n atTop.current && !live.current.refreshing && g.dy > 6 && Math.abs(g.dy) > Math.abs(g.dx),\n onPanResponderGrant: () => {\n dragging.current = true;\n pull.stopAnimation();\n },\n // Growing resistance: the content moves less and less the further it is pulled.\n onPanResponderMove: (_, g) => {\n const limit = live.current.threshold * 1.8;\n pull.setValue(limit * (1 - Math.exp(-Math.max(0, g.dy) / (limit * 1.2))));\n },\n onPanResponderRelease: () => {\n dragging.current = false;\n pull.stopAnimation((value) => {\n if (value >= live.current.threshold * 0.8) {\n live.current.onRefresh();\n settleTo(hold);\n } else {\n settleTo(0);\n }\n });\n },\n onPanResponderTerminate: () => {\n dragging.current = false;\n settleTo(live.current.refreshing ? hold : 0);\n },\n }),\n ).current;\n\n const onScroll = (event: NativeSyntheticEvent) => {\n atTop.current = event.nativeEvent.contentOffset.y <= 0;\n };\n\n const progress = pull.interpolate({\n inputRange: [0, threshold * 0.8],\n outputRange: [0, 1],\n extrapolate: \"clamp\",\n });\n const scroller = useRef>(null);\n\n return (\n {\n if (event.nativeEvent.actionName === \"refresh\" && !refreshing) onRefresh();\n }}\n style={[styles.root, { backgroundColor: palette.background }, style]}\n >\n \n {refreshing ? (\n \n ) : (\n \n ↓\n \n )}\n \n \n \n {children}\n \n \n {refreshing ? (\n \n Refreshing\n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { flex: 1, overflow: \"hidden\", userSelect: \"none\" },\n indicator: {\n position: \"absolute\",\n top: 0,\n left: 0,\n right: 0,\n height: INDICATOR,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n spinner: {\n width: 26,\n height: 26,\n borderRadius: 13,\n borderWidth: 3,\n borderColor: \"rgba(128,128,128,0.25)\",\n },\n arrow: { fontSize: 22, fontWeight: \"800\" },\n content: { flex: 1 },\n sr: { position: \"absolute\", width: 1, height: 1, opacity: 0 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/radio-group.json b/public/registry/radio-group.json new file mode 100644 index 0000000..4887e16 --- /dev/null +++ b/public/registry/radio-group.json @@ -0,0 +1,15 @@ +{ + "name": "radio-group", + "title": "Radio Group", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/radio-group.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface RadioOption {\n value: string;\n label: string;\n description?: string;\n disabled?: boolean;\n}\n\nexport interface RadioGroupColors {\n accent: string;\n border: string;\n surface: string;\n selectedSurface: string;\n label: string;\n description: string;\n}\n\nconst DEFAULT_COLORS: RadioGroupColors = {\n accent: \"#4f46e5\",\n border: \"#d1d5db\",\n surface: \"#ffffff\",\n selectedSurface: \"#eef2ff\",\n label: \"#111827\",\n description: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface RadioGroupProps {\n options: RadioOption[];\n /** The selected option's value. */\n value: string;\n onChange: (value: string) => void;\n /** Spoken name of the group. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\ninterface RowProps {\n option: RadioOption;\n selected: boolean;\n index: number;\n count: number;\n palette: RadioGroupColors;\n reduceMotion: boolean;\n onSelect: () => void;\n}\n\nfunction Row({ option, selected, index, count, palette, reduceMotion, onSelect }: RowProps) {\n // Every dot stays mounted with its own value, so the spring is never cut short by an unmount.\n const dot = useRef(new Animated.Value(selected ? 1 : 0)).current;\n\n useEffect(() => {\n if (reduceMotion) {\n dot.setValue(selected ? 1 : 0);\n return;\n }\n Animated.spring(dot, {\n toValue: selected ? 1 : 0,\n stiffness: 420,\n damping: 20,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [selected, reduceMotion, dot]);\n\n return (\n \n \n \n \n \n {option.label}\n {option.description ? (\n \n {option.description}\n \n ) : null}\n \n \n );\n}\n\n/**\n * A group of mutually exclusive choices drawn as cards. The selected card takes the accent colour\n * and its dot springs in. Only the selected radio is a tab stop, and on the web the arrow keys move\n * the selection, skipping disabled options and wrapping at the ends, as a native radio group does.\n */\nexport function RadioGroup({\n options,\n value,\n onChange,\n label = \"Options\",\n colors,\n style,\n}: RadioGroupProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n\n const move = (direction: 1 | -1) => {\n const enabled = options.filter((option) => !option.disabled);\n if (enabled.length === 0) return;\n const at = enabled.findIndex((option) => option.value === value);\n const next = enabled[(at + direction + enabled.length) % enabled.length];\n onChange(next.value);\n };\n\n const onKeyDown = (event: { key: string; preventDefault: () => void }) => {\n if (event.key === \"ArrowDown\" || event.key === \"ArrowRight\") {\n event.preventDefault();\n move(1);\n } else if (event.key === \"ArrowUp\" || event.key === \"ArrowLeft\") {\n event.preventDefault();\n move(-1);\n }\n };\n\n const webKeys = { onKeyDown } as object;\n\n return (\n \n {options.map((option, index) => (\n onChange(option.value)}\n />\n ))}\n \n );\n}\n\nconst styles = StyleSheet.create({\n group: { gap: 10 },\n row: {\n flexDirection: \"row\",\n alignItems: \"center\",\n gap: 14,\n minHeight: 56,\n paddingVertical: 12,\n paddingHorizontal: 16,\n borderRadius: 16,\n borderWidth: 2,\n userSelect: \"none\",\n },\n ring: {\n width: 24,\n height: 24,\n borderRadius: 12,\n borderWidth: 2,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n dot: { width: 12, height: 12, borderRadius: 6 },\n text: { flex: 1, gap: 2 },\n title: { fontSize: 16, fontWeight: \"600\" },\n description: { fontSize: 13, lineHeight: 18 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/range-slider.json b/public/registry/range-slider.json new file mode 100644 index 0000000..b533cb4 --- /dev/null +++ b/public/registry/range-slider.json @@ -0,0 +1,15 @@ +{ + "name": "range-slider", + "title": "Range Slider", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/range-slider.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Platform,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst THUMB = 28;\n\nexport interface RangeSliderColors {\n track: string;\n fill: string;\n thumb: string;\n bubble: string;\n bubbleText: string;\n}\n\nconst DEFAULT_COLORS: RangeSliderColors = {\n track: \"#e5e7eb\",\n fill: \"#4f46e5\",\n thumb: \"#ffffff\",\n bubble: \"#111827\",\n bubbleText: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface RangeSliderProps {\n /** The selected range as [low, high]. */\n value: [number, number];\n onValueChange: (value: [number, number]) => void;\n /** Called once when a drag ends. */\n onSlidingComplete?: (value: [number, number]) => void;\n min?: number;\n max?: number;\n step?: number;\n /** The least the two thumbs may be apart. */\n minGap?: number;\n /** Floats the thumb's value above it while it is held. */\n showBubbles?: boolean;\n disabled?: boolean;\n /** Spoken name of the range; the thumbs add \"minimum\" and \"maximum\". */\n label?: string;\n /** Turns a value into the text shown in the bubble and read out. */\n format?: (value: number) => string;\n colors?: Partial;\n style?: StyleProp;\n}\n\ntype Which = 0 | 1;\n\n/**\n * A slider with two thumbs for choosing a range, such as a price band. Each thumb drags on its own and\n * can never cross the other, values snap to `step`, and tapping the track moves the nearest thumb.\n * Both thumbs are adjustable controls for screen readers.\n */\nexport function RangeSlider({\n value,\n onValueChange,\n onSlidingComplete,\n min = 0,\n max = 100,\n step = 1,\n minGap = 0,\n showBubbles = true,\n disabled = false,\n label = \"Range\",\n format = String,\n colors,\n style,\n}: RangeSliderProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [width, setWidth] = useState(0);\n const [active, setActive] = useState(null);\n const [top, setTop] = useState(1);\n const grow = useRef([new Animated.Value(0), new Animated.Value(0)]).current;\n const startValue = useRef(0);\n\n const live = useRef({\n value,\n min,\n max,\n step,\n minGap,\n width,\n disabled,\n onValueChange,\n onSlidingComplete,\n });\n live.current = {\n value,\n min,\n max,\n step,\n minGap,\n width,\n disabled,\n onValueChange,\n onSlidingComplete,\n };\n\n const travel = Math.max(1, width - THUMB);\n const toX = (v: number) => ((v - min) / (max - min)) * travel;\n const lowX = toX(value[0]);\n const highX = toX(value[1]);\n\n const snap = (raw: number) => {\n const { min: lo, max: hi, step: s } = live.current;\n const snapped = Math.round((raw - lo) / s) * s + lo;\n return Math.max(lo, Math.min(hi, Number(snapped.toFixed(6))));\n };\n\n const setThumb = (which: Which, raw: number) => {\n const { value: current, minGap: gap, min: lo, max: hi } = live.current;\n const next: [number, number] = [current[0], current[1]];\n const snapped = snap(raw);\n next[which] =\n which === 0 ? Math.min(snapped, current[1] - gap) : Math.max(snapped, current[0] + gap);\n next[which] = Math.max(lo, Math.min(hi, next[which]));\n if (next[0] !== current[0] || next[1] !== current[1]) live.current.onValueChange(next);\n };\n\n const press = (which: Which, down: boolean) => {\n setActive(down ? which : null);\n if (down) setTop(which);\n if (reduceMotion) return;\n Animated.spring(grow[which], {\n toValue: down ? 1 : 0,\n stiffness: 420,\n damping: 24,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n const makeResponder = (which: Which) =>\n PanResponder.create({\n onStartShouldSetPanResponder: () => !live.current.disabled,\n onMoveShouldSetPanResponder: () => !live.current.disabled,\n onPanResponderTerminationRequest: () => false,\n onPanResponderGrant: () => {\n startValue.current = live.current.value[which];\n press(which, true);\n },\n onPanResponderMove: (_, g) => {\n const { min: lo, max: hi, width: w } = live.current;\n const perPixel = (hi - lo) / Math.max(1, w - THUMB);\n setThumb(which, startValue.current + g.dx * perPixel);\n },\n onPanResponderRelease: () => {\n press(which, false);\n live.current.onSlidingComplete?.(live.current.value);\n },\n onPanResponderTerminate: () => press(which, false),\n });\n // Responders are created once per thumb and read everything through `live`.\n const responders = useRef([makeResponder(0), makeResponder(1)]).current;\n\n // Touching the bare track moves whichever thumb is closer to it, and the drag carries on from there.\n const trackWhich = useRef(0);\n const trackResponder = useRef(\n PanResponder.create({\n onStartShouldSetPanResponder: () => !live.current.disabled,\n onPanResponderTerminationRequest: () => false,\n onPanResponderGrant: (event) => {\n const { value: current, min: lo, max: hi, width: w } = live.current;\n const x = event.nativeEvent.locationX;\n const raw = lo + ((x - THUMB / 2) / Math.max(1, w - THUMB)) * (hi - lo);\n if (!Number.isFinite(raw)) return;\n const which: Which = Math.abs(raw - current[0]) <= Math.abs(raw - current[1]) ? 0 : 1;\n trackWhich.current = which;\n setThumb(which, raw);\n startValue.current = snap(raw);\n press(which, true);\n },\n onPanResponderMove: (_, g) => {\n const { min: lo, max: hi, width: w } = live.current;\n setThumb(\n trackWhich.current,\n startValue.current + g.dx * ((hi - lo) / Math.max(1, w - THUMB)),\n );\n },\n onPanResponderRelease: () => {\n press(trackWhich.current, false);\n live.current.onSlidingComplete?.(live.current.value);\n },\n onPanResponderTerminate: () => press(trackWhich.current, false),\n }),\n ).current;\n\n const adjust = (which: Which, direction: 1 | -1) =>\n setThumb(which, value[which] + direction * step);\n\n const thumb = (which: Which) => {\n const x = which === 0 ? lowX : highX;\n const name = which === 0 ? \"minimum\" : \"maximum\";\n const text = format(value[which]);\n const scale = grow[which].interpolate({ inputRange: [0, 1], outputRange: [1, 1.18] });\n return (\n \n adjust(which, event.nativeEvent.actionName === \"increment\" ? 1 : -1)\n }\n style={[\n styles.thumb,\n {\n left: x,\n zIndex: top === which ? 2 : 1,\n backgroundColor: palette.thumb,\n transform: [{ scale }],\n },\n ]}\n >\n {showBubbles && active === which ? (\n \n \n {text}\n \n \n ) : null}\n \n );\n };\n\n return (\n setWidth(event.nativeEvent.layout.width)}\n style={[styles.root, disabled && styles.disabled, style]}\n >\n \n \n \n \n {width > 0 ? [thumb(0), thumb(1)] : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { height: 44, justifyContent: \"center\", userSelect: \"none\" },\n hit: { height: 44, justifyContent: \"center\" },\n track: { height: 6, borderRadius: 3 },\n fill: { position: \"absolute\", top: 19, height: 6, borderRadius: 3 },\n thumb: {\n position: \"absolute\",\n top: (44 - THUMB) / 2,\n width: THUMB,\n height: THUMB,\n borderRadius: THUMB / 2,\n boxShadow: \"0 2px 6px rgba(0, 0, 0, 0.3)\",\n },\n // Wider than the thumb and centred on it, so the bubble sits right above whatever its width is.\n bubbleWrap: {\n position: \"absolute\",\n bottom: THUMB + 6,\n left: -40,\n width: THUMB + 80,\n alignItems: \"center\",\n },\n bubble: {\n minWidth: 36,\n paddingHorizontal: 8,\n paddingVertical: 4,\n borderRadius: 8,\n alignItems: \"center\",\n },\n bubbleText: { fontSize: 12, fontWeight: \"700\" },\n disabled: { opacity: 0.4 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/rating-histogram.json b/public/registry/rating-histogram.json new file mode 100644 index 0000000..30c4a3a --- /dev/null +++ b/public/registry/rating-histogram.json @@ -0,0 +1,15 @@ +{ + "name": "rating-histogram", + "title": "Rating Histogram", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/rating-histogram.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface RatingHistogramColors {\n bar: string;\n track: string;\n text: string;\n average: string;\n}\n\nconst DEFAULT_COLORS: RatingHistogramColors = {\n bar: \"#f59e0b\",\n track: \"#e5e7eb\",\n text: \"#6b7280\",\n average: \"#111827\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface RatingHistogramProps {\n /** How many ratings each star level got, from one star up to five. */\n counts: [number, number, number, number, number];\n /** Shows the average and the total beside the bars. */\n showAverage?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\nfunction Row({\n stars,\n share,\n count,\n palette,\n reduceMotion,\n}: {\n stars: number;\n share: number;\n count: number;\n palette: RatingHistogramColors;\n reduceMotion: boolean;\n}) {\n const fill = useRef(new Animated.Value(share)).current;\n useEffect(() => {\n if (reduceMotion) fill.setValue(share);\n else\n Animated.timing(fill, {\n toValue: share,\n duration: 500,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [share, reduceMotion, fill]);\n return (\n 1 ? \"s\" : \"\"}: ${count} rating${count === 1 ? \"\" : \"s\"}`}\n style={styles.row}\n >\n {stars}★\n \n \n \n {count}\n \n );\n}\n\n/**\n * The breakdown of ratings you see on a product page: one bar per star level that grows to its share\n * of all ratings, with the average beside them. Bars animate to new counts, and each row reads out\n * as \"4 stars: 12 ratings\".\n */\nexport function RatingHistogram({\n counts,\n showAverage = true,\n colors,\n style,\n}: RatingHistogramProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const total = counts.reduce((sum, n) => sum + n, 0);\n const average = total ? counts.reduce((sum, n, i) => sum + n * (i + 1), 0) / total : 0;\n\n return (\n \n {showAverage ? (\n \n {average.toFixed(1)}\n {total} ratings\n \n ) : null}\n \n {[5, 4, 3, 2, 1].map((stars) => (\n \n ))}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { flexDirection: \"row\", alignItems: \"center\", gap: 20 },\n summary: { alignItems: \"center\", gap: 2 },\n average: { fontSize: 44, fontWeight: \"800\" },\n total: { fontSize: 12 },\n bars: { flex: 1, gap: 6 },\n row: { flexDirection: \"row\", alignItems: \"center\", gap: 8 },\n star: { width: 28, fontSize: 13 },\n track: { flex: 1, height: 8, borderRadius: 4, overflow: \"hidden\" },\n fill: { height: \"100%\", borderRadius: 4 },\n count: { width: 32, fontSize: 13, textAlign: \"right\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/reaction-bar.json b/public/registry/reaction-bar.json new file mode 100644 index 0000000..953fa1a --- /dev/null +++ b/public/registry/reaction-bar.json @@ -0,0 +1,15 @@ +{ + "name": "reaction-bar", + "title": "Reaction Bar", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/reaction-bar.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface Reaction {\n id: string;\n emoji: string;\n /** Spoken name, for example \"Love\". */\n label: string;\n}\n\nexport interface ReactionBarColors {\n pill: string;\n selectedPill: string;\n border: string;\n selectedBorder: string;\n text: string;\n count: string;\n}\n\nconst DEFAULT_COLORS: ReactionBarColors = {\n pill: \"#f3f4f6\",\n selectedPill: \"#e0e7ff\",\n border: \"transparent\",\n selectedBorder: \"#4f46e5\",\n text: \"#111827\",\n count: \"#4b5563\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ReactionBarProps {\n reactions: Reaction[];\n /** How many other people chose each reaction, by id. Your own choice is added on top. */\n counts: Record;\n /** The reaction you chose, or null. */\n value: string | null;\n /** Called with the reaction you chose, or null when you take yours back. */\n onChange: (next: string | null) => void;\n /** Hides the count on reactions nobody chose. */\n hideZero?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A row of emoji reactions. Choosing one pops and wobbles its emoji, tints the pill and rolls the\n * count to its new number; pressing your choice again takes it back. You can hold one reaction at a\n * time. Each pill reads out as \"Love, 9, selected\" and mirrors its state for screen readers.\n */\nexport function ReactionBar({\n reactions,\n counts,\n value,\n onChange,\n hideZero = true,\n colors,\n style,\n}: ReactionBarProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n return (\n \n {reactions.map((reaction) => {\n const mine = value === reaction.id;\n return (\n onChange(mine ? null : reaction.id)}\n />\n );\n })}\n \n );\n}\n\ninterface PillProps {\n reaction: Reaction;\n count: number;\n selected: boolean;\n hideZero: boolean;\n palette: ReactionBarColors;\n onPress: () => void;\n}\n\nfunction Pill({ reaction, count, selected, hideZero, palette, onPress }: PillProps) {\n const reduceMotion = useReduceMotion();\n const tint = useRef(new Animated.Value(selected ? 1 : 0)).current;\n const pop = useRef(new Animated.Value(0)).current;\n const roll = useRef(new Animated.Value(0)).current;\n const press = useRef(new Animated.Value(1)).current;\n const previous = useRef({ count, selected });\n\n useEffect(() => {\n const was = previous.current;\n previous.current = { count, selected };\n if (reduceMotion) {\n tint.setValue(selected ? 1 : 0);\n return;\n }\n Animated.timing(tint, {\n toValue: selected ? 1 : 0,\n duration: 180,\n useNativeDriver: false,\n }).start();\n if (selected && !was.selected) {\n pop.setValue(0);\n Animated.timing(pop, {\n toValue: 1,\n duration: 480,\n easing: Easing.out(Easing.quad),\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }\n if (count !== was.count) {\n // The new number slides in from the direction it moved.\n roll.setValue(count > was.count ? 1 : -1);\n Animated.timing(roll, {\n toValue: 0,\n duration: 220,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }\n }, [count, selected, reduceMotion, tint, pop, roll]);\n\n const dip = (down: boolean) => {\n if (reduceMotion) return;\n Animated.spring(press, {\n toValue: down ? 0.94 : 1,\n stiffness: 500,\n damping: 24,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n const showCount = !(hideZero && count === 0);\n\n return (\n dip(true)}\n onPressOut={() => dip(false)}\n >\n \n \n {reaction.emoji}\n \n {showCount ? (\n \n \n {count}\n \n \n ) : null}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", flexWrap: \"wrap\", gap: 8 },\n pill: {\n minHeight: 40,\n paddingHorizontal: 12,\n borderRadius: 20,\n borderWidth: 1.5,\n flexDirection: \"row\",\n alignItems: \"center\",\n gap: 6,\n userSelect: \"none\",\n },\n emoji: { fontSize: 18 },\n countClip: { overflow: \"hidden\", minWidth: 10 },\n count: { fontSize: 14, fontWeight: \"700\", fontVariant: [\"tabular-nums\"] },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/resend-button.json b/public/registry/resend-button.json new file mode 100644 index 0000000..c88e539 --- /dev/null +++ b/public/registry/resend-button.json @@ -0,0 +1,15 @@ +{ + "name": "resend-button", + "title": "Resend Button", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/resend-button.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface ResendButtonColors {\n accent: string;\n disabled: string;\n}\n\nconst DEFAULT_COLORS: ResendButtonColors = {\n accent: \"#4f46e5\",\n disabled: \"#9ca3af\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface ResendButtonProps {\n /** Called when the button is pressed after the wait; the wait then starts over. */\n onResend: () => void;\n /** How long to wait before it can be pressed, in seconds. */\n seconds?: number;\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * The \"Resend code\" link under a verification form. It starts out waiting, showing the seconds left,\n * and becomes pressable when the wait is over, pulsing once to say so. Pressing it calls\n * `onResend` and starts the wait again. The time is not announced each second; only \"You can resend\n * now\" is.\n */\nexport function ResendButton({\n onResend,\n seconds = 30,\n label = \"Resend code\",\n colors,\n style,\n}: ResendButtonProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [left, setLeft] = useState(seconds);\n const pulse = useRef(new Animated.Value(1)).current;\n const ready = left <= 0;\n\n useEffect(() => {\n if (ready) return;\n const id = setInterval(() => setLeft((s) => Math.max(0, s - 1)), 1000);\n return () => clearInterval(id);\n }, [ready]);\n\n useEffect(() => {\n if (!ready || reduceMotion) return;\n Animated.sequence([\n Animated.timing(pulse, { toValue: 1.12, duration: 160, useNativeDriver: NATIVE_DRIVER }),\n Animated.spring(pulse, {\n toValue: 1,\n stiffness: 400,\n damping: 14,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }),\n ]).start();\n }, [ready, reduceMotion, pulse]);\n\n const text = ready\n ? label\n : `${label} in ${Math.floor(left / 60)}:${String(left % 60).padStart(2, \"0\")}`;\n\n return (\n {\n onResend();\n setLeft(seconds);\n }}\n hitSlop={8}\n style={[styles.root, style]}\n >\n \n {text}\n \n \n {ready ? \"You can resend now\" : \"\"}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { alignSelf: \"center\", minHeight: 44, justifyContent: \"center\", userSelect: \"none\" },\n text: { fontSize: 15, fontWeight: \"700\", fontVariant: [\"tabular-nums\"] },\n sr: { position: \"absolute\", width: 1, height: 1, opacity: 0 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/ring-meter.json b/public/registry/ring-meter.json new file mode 100644 index 0000000..bb9de86 --- /dev/null +++ b/public/registry/ring-meter.json @@ -0,0 +1,15 @@ +{ + "name": "ring-meter", + "title": "Ring Meter", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/ring-meter.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface RingMeterColors {\n track: string;\n fill: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: RingMeterColors = {\n track: \"#e5e7eb\",\n fill: \"#4f46e5\",\n text: \"#111827\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface RingMeterProps {\n /** Progress from 0 to 1. */\n value: number;\n /** Diameter of the ring. */\n size?: number;\n /** Width of the ring's stroke. */\n thickness?: number;\n /** Shows the percentage in the middle when there are no children. */\n showValue?: boolean;\n /** Animates the ring to each new value. */\n animated?: boolean;\n /** Spoken name of the meter. */\n label?: string;\n /** Replaces the percentage in the middle. */\n children?: ReactNode;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A circular progress ring built from plain views, with no SVG package. Two half rings, each a\n * bordered circle clipped to one side, are turned by the same value: the right half sweeps first,\n * then the left takes over, so the arc grows smoothly all the way round.\n */\nexport function RingMeter({\n value,\n size = 120,\n thickness = 10,\n showValue = true,\n animated = true,\n label = \"Progress\",\n children,\n colors,\n style,\n}: RingMeterProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const clamped = Math.max(0, Math.min(1, value));\n const percent = Math.round(clamped * 100);\n const p = useRef(new Animated.Value(clamped)).current;\n\n useEffect(() => {\n if (!animated || reduceMotion) {\n p.setValue(clamped);\n return;\n }\n Animated.timing(p, {\n toValue: clamped,\n duration: 700,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [clamped, animated, reduceMotion, p]);\n\n // A circle whose top and right borders are coloured shows a half ring. Turned by -135 degrees it\n // lies in the left half and is clipped away; turned by +45 it fills the right half exactly.\n const right = p.interpolate({\n inputRange: [0, 0.5, 1],\n outputRange: [\"-135deg\", \"45deg\", \"45deg\"],\n });\n const left = p.interpolate({\n inputRange: [0, 0.5, 1],\n outputRange: [\"45deg\", \"45deg\", \"225deg\"],\n });\n\n const half = size / 2;\n const arc = {\n position: \"absolute\" as const,\n top: 0,\n width: size,\n height: size,\n borderRadius: half,\n borderWidth: thickness,\n borderColor: \"transparent\",\n borderTopColor: palette.fill,\n borderRightColor: palette.fill,\n };\n\n return (\n \n \n \n \n \n \n \n \n \n {children ??\n (showValue ? (\n \n {percent}%\n \n ) : null)}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n clip: { position: \"absolute\", top: 0, overflow: \"hidden\" },\n center: {\n position: \"absolute\",\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n value: { fontWeight: \"800\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/select-grid.json b/public/registry/select-grid.json new file mode 100644 index 0000000..1070672 --- /dev/null +++ b/public/registry/select-grid.json @@ -0,0 +1,15 @@ +{ + "name": "select-grid", + "title": "Select Grid", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/select-grid.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface SelectOption {\n id: string;\n label: string;\n /** A glyph or emoji drawn above the label. */\n icon?: string;\n}\n\nexport interface SelectGridColors {\n accent: string;\n border: string;\n surface: string;\n selectedSurface: string;\n label: string;\n checkText: string;\n}\n\nconst DEFAULT_COLORS: SelectGridColors = {\n accent: \"#4f46e5\",\n border: \"#e5e7eb\",\n surface: \"#ffffff\",\n selectedSurface: \"#eef2ff\",\n label: \"#111827\",\n checkText: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface SelectGridProps {\n options: SelectOption[];\n /** The ids of the selected options. */\n value: string[];\n onChange: (value: string[]) => void;\n /** Cards per row. */\n columns?: number;\n /** The most cards that can be selected; further taps are ignored until one is cleared. */\n max?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\ninterface CardProps {\n option: SelectOption;\n selected: boolean;\n blocked: boolean;\n palette: SelectGridColors;\n reduceMotion: boolean;\n onPress: () => void;\n}\n\nfunction Card({ option, selected, blocked, palette, reduceMotion, onPress }: CardProps) {\n const check = useRef(new Animated.Value(selected ? 1 : 0)).current;\n const press = useRef(new Animated.Value(1)).current;\n\n useEffect(() => {\n if (reduceMotion) check.setValue(selected ? 1 : 0);\n else\n Animated.spring(check, {\n toValue: selected ? 1 : 0,\n stiffness: 480,\n damping: 22,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [selected, reduceMotion, check]);\n\n const dip = (down: boolean) => {\n if (reduceMotion) return;\n Animated.spring(press, {\n toValue: down ? 0.96 : 1,\n stiffness: 500,\n damping: 26,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n return (\n dip(true)}\n onPressOut={() => dip(false)}\n style={styles.cell}\n >\n \n {option.icon ? {option.icon} : null}\n {option.label}\n \n ✓\n \n \n \n );\n}\n\n/**\n * A grid of cards where any number can be picked, such as interests during onboarding. A picked card\n * takes the accent border and a tick springs into its corner. Set `max` and the remaining cards dim\n * once the limit is reached. Every card is a checkbox for screen readers.\n */\nexport function SelectGrid({\n options,\n value,\n onChange,\n columns = 2,\n max,\n colors,\n style,\n}: SelectGridProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const full = max !== undefined && value.length >= max;\n\n const toggle = (id: string) => {\n if (value.includes(id)) onChange(value.filter((v) => v !== id));\n else if (!full) onChange([...value, id]);\n };\n\n return (\n \n {options.map((option) => {\n const selected = value.includes(option.id);\n return (\n \n toggle(option.id)}\n />\n \n );\n })}\n \n );\n}\n\nconst styles = StyleSheet.create({\n grid: { flexDirection: \"row\", flexWrap: \"wrap\", margin: -5 },\n cell: { padding: 5, userSelect: \"none\" },\n card: {\n minHeight: 88,\n borderRadius: 16,\n borderWidth: 2,\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: 6,\n padding: 12,\n },\n icon: { fontSize: 28 },\n label: { fontSize: 15, fontWeight: \"600\" },\n badge: {\n position: \"absolute\",\n top: 8,\n right: 8,\n width: 20,\n height: 20,\n borderRadius: 10,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n tick: { fontSize: 12, fontWeight: \"800\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/select-menu.json b/public/registry/select-menu.json new file mode 100644 index 0000000..80181c7 --- /dev/null +++ b/public/registry/select-menu.json @@ -0,0 +1,15 @@ +{ + "name": "select-menu", + "title": "Select Menu", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/select-menu.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst ROW = 48;\n\nexport interface SelectOption {\n value: string;\n label: string;\n}\n\nexport interface SelectMenuColors {\n surface: string;\n border: string;\n text: string;\n placeholder: string;\n selected: string;\n accent: string;\n}\n\nconst DEFAULT_COLORS: SelectMenuColors = {\n surface: \"#ffffff\",\n border: \"#d1d5db\",\n text: \"#111827\",\n placeholder: \"#9ca3af\",\n selected: \"#eef2ff\",\n accent: \"#4f46e5\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface SelectMenuProps {\n options: SelectOption[];\n /** The chosen option's value, or an empty string for none. */\n value: string;\n onChange: (value: string) => void;\n placeholder?: string;\n /** Spoken name of the menu. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A dropdown that opens in place, pushing the content below it down instead of floating over it, which\n * keeps it inside a scrolling screen. The chevron turns and the list grows open; choosing an option or\n * pressing Escape on the web closes it. The trigger reports whether it is expanded.\n */\nexport function SelectMenu({\n options,\n value,\n onChange,\n placeholder = \"Select an option\",\n label = \"Select\",\n colors,\n style,\n}: SelectMenuProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [open, setOpen] = useState(false);\n const t = useRef(new Animated.Value(0)).current;\n const chosen = options.find((option) => option.value === value);\n const live = useRef({ setOpen });\n live.current = { setOpen };\n\n useEffect(() => {\n if (reduceMotion) {\n t.setValue(open ? 1 : 0);\n return;\n }\n Animated.timing(t, {\n toValue: open ? 1 : 0,\n duration: 220,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [open, reduceMotion, t]);\n\n useEffect(() => {\n if (!open || Platform.OS !== \"web\") return;\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") live.current.setOpen(false);\n };\n window.addEventListener(\"keydown\", onKey);\n return () => window.removeEventListener(\"keydown\", onKey);\n }, [open]);\n\n return (\n \n setOpen(!open)}\n style={styles.trigger}\n >\n \n {chosen ? chosen.label : placeholder}\n \n \n ⌄\n \n \n \n {options.map((option) => {\n const selected = option.value === value;\n return (\n {\n onChange(option.value);\n setOpen(false);\n }}\n style={[\n styles.option,\n {\n backgroundColor: selected ? palette.selected : \"transparent\",\n borderTopColor: palette.border,\n },\n ]}\n >\n \n {option.label}\n \n {selected ? (\n ✓\n ) : null}\n \n );\n })}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { borderWidth: 2, borderRadius: 14, overflow: \"hidden\" },\n trigger: {\n minHeight: ROW,\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n paddingHorizontal: 14,\n userSelect: \"none\",\n },\n value: { fontSize: 16 },\n chevron: { fontSize: 22, fontWeight: \"700\" },\n option: {\n height: ROW,\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n paddingHorizontal: 14,\n borderTopWidth: StyleSheet.hairlineWidth,\n userSelect: \"none\",\n },\n optionText: { fontSize: 16 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/setting-list.json b/public/registry/setting-list.json new file mode 100644 index 0000000..125c828 --- /dev/null +++ b/public/registry/setting-list.json @@ -0,0 +1,15 @@ +{ + "name": "setting-list", + "title": "Setting List", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/setting-list.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst TRACK_W = 46;\nconst TRACK_H = 28;\nconst THUMB = 22;\n\nexport interface SettingItem {\n id: string;\n label: string;\n /** A glyph or small view shown in a tile at the start of the row. */\n icon?: ReactNode;\n /** A smaller line under the label. */\n description?: string;\n /** \"link\" shows a chevron, \"value\" shows `value`, \"toggle\" a switch, and \"info\" is not pressable. */\n kind?: \"link\" | \"value\" | \"toggle\" | \"info\";\n value?: string;\n checked?: boolean;\n onPress?: () => void;\n onToggle?: (next: boolean) => void;\n destructive?: boolean;\n disabled?: boolean;\n}\n\nexport interface SettingListColors {\n surface: string;\n border: string;\n text: string;\n muted: string;\n accent: string;\n destructive: string;\n tile: string;\n track: string;\n}\n\nconst DEFAULT_COLORS: SettingListColors = {\n surface: \"#ffffff\",\n border: \"#e5e7eb\",\n text: \"#111827\",\n muted: \"#6b7280\",\n accent: \"#4f46e5\",\n destructive: \"#dc2626\",\n tile: \"#f3f4f6\",\n track: \"#d1d5db\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nfunction Switch({\n on,\n accent,\n track,\n reduceMotion,\n}: {\n on: boolean;\n accent: string;\n track: string;\n reduceMotion: boolean;\n}) {\n const t = useRef(new Animated.Value(on ? 1 : 0)).current;\n useEffect(() => {\n if (reduceMotion) {\n t.setValue(on ? 1 : 0);\n return;\n }\n Animated.spring(t, {\n toValue: on ? 1 : 0,\n stiffness: 420,\n damping: 26,\n mass: 1,\n useNativeDriver: false,\n }).start();\n }, [on, reduceMotion, t]);\n return (\n \n \n \n );\n}\n\nexport interface SettingListProps {\n items: SettingItem[];\n /** A small heading above the group. */\n header?: string;\n /** Explanatory text under the group. */\n footer?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A grouped settings list in the style of a phone's own settings screen: rounded rows split by\n * hairlines, with an icon tile, a label and a description, and a chevron, a value or a switch on the\n * right. Switches are real switches to screen readers, and a pressed row highlights.\n */\nexport function SettingList({ items, header, footer, colors, style }: SettingListProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n\n return (\n \n {header ? (\n {header.toUpperCase()}\n ) : null}\n \n {items.map((item, i) => {\n const kind = item.kind ?? \"link\";\n const toggle = kind === \"toggle\";\n const pressable = kind !== \"info\" && !item.disabled;\n const color = item.destructive ? palette.destructive : palette.text;\n const spoken = [item.label, item.description, kind === \"value\" ? item.value : undefined]\n .filter(Boolean)\n .join(\", \");\n return (\n (toggle ? item.onToggle?.(!item.checked) : item.onPress?.())}\n style={({ pressed }) => [\n styles.row,\n i > 0 && {\n borderTopWidth: StyleSheet.hairlineWidth,\n borderTopColor: palette.border,\n },\n pressed && { backgroundColor: palette.tile },\n item.disabled && styles.disabled,\n ]}\n >\n {item.icon ? (\n {item.icon}\n ) : null}\n \n {item.label}\n {item.description ? (\n \n {item.description}\n \n ) : null}\n \n {toggle ? (\n \n ) : (\n \n {item.value && (kind === \"value\" || kind === \"link\" || kind === \"info\") ? (\n {item.value}\n ) : null}\n {kind === \"link\" ? (\n ›\n ) : null}\n \n )}\n \n );\n })}\n \n {footer ? {footer} : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n header: { fontSize: 12, fontWeight: \"700\", letterSpacing: 0.6, marginBottom: 6, marginLeft: 14 },\n group: { borderRadius: 14, borderWidth: StyleSheet.hairlineWidth, overflow: \"hidden\" },\n row: {\n minHeight: 54,\n flexDirection: \"row\",\n alignItems: \"center\",\n gap: 12,\n paddingHorizontal: 14,\n paddingVertical: 8,\n userSelect: \"none\",\n },\n tile: { width: 32, height: 32, borderRadius: 8, alignItems: \"center\", justifyContent: \"center\" },\n text: { flex: 1, gap: 1 },\n label: { fontSize: 16, fontWeight: \"500\" },\n description: { fontSize: 13 },\n end: { flexDirection: \"row\", alignItems: \"center\", gap: 6 },\n value: { fontSize: 15 },\n chevron: { fontSize: 24, lineHeight: 26 },\n footer: { fontSize: 13, lineHeight: 18, marginTop: 6, marginHorizontal: 14 },\n disabled: { opacity: 0.45 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/side-drawer.json b/public/registry/side-drawer.json new file mode 100644 index 0000000..4a60ccb --- /dev/null +++ b/public/registry/side-drawer.json @@ -0,0 +1,15 @@ +{ + "name": "side-drawer", + "title": "Side Drawer", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/side-drawer.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Platform,\n Pressable,\n StyleSheet,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n// Width of the strip along the edge that a swipe can start from.\nconst EDGE = 22;\n\nexport interface SideDrawerColors {\n surface: string;\n backdrop: string;\n border: string;\n}\n\nconst DEFAULT_COLORS: SideDrawerColors = {\n surface: \"#ffffff\",\n backdrop: \"rgba(0, 0, 0, 0.45)\",\n border: \"#e5e7eb\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface SideDrawerProps {\n open: boolean;\n /** Called when the drawer is closed by a backdrop tap, a drag or Escape on the web. */\n onClose: () => void;\n /** Called when a swipe from the screen edge pulls it open. Without it the edge swipe is off. */\n onOpen?: () => void;\n /** Which edge the drawer comes from. */\n side?: \"left\" | \"right\";\n /** Width of the panel. */\n width?: number;\n /** Spoken name of the drawer. */\n label?: string;\n children: ReactNode;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A panel that slides in from the left or right edge of its parent. Drag it toward its edge to close\n * it, tap the backdrop, or press Escape on the web. Give it `onOpen` and a swipe that starts at the\n * screen edge pulls it open, following your finger. Draw it inside the screen it belongs to, so the\n * parent must fill that screen.\n */\nexport function SideDrawer({\n open,\n onClose,\n onOpen,\n side = \"left\",\n width = 280,\n label = \"Menu\",\n children,\n colors,\n style,\n}: SideDrawerProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n // 0 is closed, 1 is open, and a drag sets it anywhere between.\n const p = useRef(new Animated.Value(open ? 1 : 0)).current;\n const current = useRef(open ? 1 : 0);\n const sign = side === \"left\" ? -1 : 1;\n\n const live = useRef({ open, onClose, onOpen, width, reduceMotion, sign });\n live.current = { open, onClose, onOpen, width, reduceMotion, sign };\n\n const animateTo = (target: 0 | 1, velocity = 0) => {\n current.current = target;\n if (live.current.reduceMotion) {\n p.setValue(target);\n return;\n }\n Animated.spring(p, {\n toValue: target,\n velocity,\n stiffness: 320,\n damping: 32,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n useEffect(() => {\n animateTo(open ? 1 : 0);\n // animateTo reads everything through refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, reduceMotion]);\n\n // Escape closes it on the web.\n useEffect(() => {\n if (!open || Platform.OS !== \"web\") return;\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") live.current.onClose();\n };\n window.addEventListener(\"keydown\", onKey);\n return () => window.removeEventListener(\"keydown\", onKey);\n }, [open]);\n\n const settle = (progress: number, vx: number, wasOpen: boolean) => {\n const { sign: dir, width: w } = live.current;\n // Velocity toward the open direction (positive) or away from it (negative), in progress per ms.\n const along = (vx * -dir) / w;\n const target: 0 | 1 = along > 0.0015 ? 1 : along < -0.0015 ? 0 : progress > 0.5 ? 1 : 0;\n animateTo(target, along * 1000);\n if (target === 1 && !wasOpen) live.current.onOpen?.();\n if (target === 0 && wasOpen) live.current.onClose();\n };\n\n // Drag the open panel toward its edge to close it.\n const closeDrag = useRef(\n PanResponder.create({\n onMoveShouldSetPanResponder: (_, g) =>\n live.current.open && Math.abs(g.dx) > 6 && Math.abs(g.dx) > Math.abs(g.dy),\n onPanResponderGrant: () => p.stopAnimation(),\n onPanResponderMove: (_, g) => {\n const { sign: dir, width: w } = live.current;\n p.setValue(Math.max(0, Math.min(1, 1 + (g.dx * dir) / w)));\n },\n onPanResponderRelease: (_, g) => {\n const { sign: dir, width: w } = live.current;\n settle(Math.max(0, Math.min(1, 1 + (g.dx * dir) / w)), g.vx, true);\n },\n onPanResponderTerminate: () => animateTo(live.current.open ? 1 : 0),\n }),\n ).current;\n\n // A swipe from the screen edge pulls the closed panel open.\n const edgeDrag = useRef(\n PanResponder.create({\n onStartShouldSetPanResponder: () => !live.current.open && !!live.current.onOpen,\n onMoveShouldSetPanResponder: (_, g) =>\n !live.current.open &&\n !!live.current.onOpen &&\n Math.abs(g.dx) > 4 &&\n Math.abs(g.dx) > Math.abs(g.dy),\n onPanResponderGrant: () => p.stopAnimation(),\n onPanResponderMove: (_, g) => {\n const { sign: dir, width: w } = live.current;\n p.setValue(Math.max(0, Math.min(1, (g.dx * -dir) / w)));\n },\n onPanResponderRelease: (_, g) => {\n const { sign: dir, width: w } = live.current;\n settle(Math.max(0, Math.min(1, (g.dx * -dir) / w)), g.vx, false);\n },\n onPanResponderTerminate: () => animateTo(0),\n }),\n ).current;\n\n const translateX = p.interpolate({ inputRange: [0, 1], outputRange: [sign * width, 0] });\n\n return (\n \n \n \n \n {!open && onOpen ? (\n \n ) : null}\n \n {children}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0, overflow: \"hidden\" },\n fill: { position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 },\n edge: { position: \"absolute\", top: 0, bottom: 0, width: EDGE },\n panel: {\n position: \"absolute\",\n top: 0,\n bottom: 0,\n userSelect: \"none\",\n boxShadow: \"0 0 40px rgba(0, 0, 0, 0.25)\",\n },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/spark-bars.json b/public/registry/spark-bars.json new file mode 100644 index 0000000..ece4694 --- /dev/null +++ b/public/registry/spark-bars.json @@ -0,0 +1,15 @@ +{ + "name": "spark-bars", + "title": "Spark Bars", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/spark-bars.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n StyleSheet,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface SparkBarsColors {\n bar: string;\n active: string;\n}\n\nconst DEFAULT_COLORS: SparkBarsColors = {\n bar: \"#c7d2fe\",\n active: \"#4f46e5\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface SparkBarsProps {\n /** One value per bar; the tallest sets the scale. */\n values: number[];\n /** Height of the tallest bar. */\n height?: number;\n /** Space between bars. */\n gap?: number;\n /** Index of the bar drawn in the active colour; defaults to the last. */\n highlight?: number;\n /** Spoken name of the chart. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\nfunction Bar({\n share,\n height,\n color,\n index,\n reduceMotion,\n}: {\n share: number;\n height: number;\n color: string;\n index: number;\n reduceMotion: boolean;\n}) {\n const grow = useRef(new Animated.Value(0)).current;\n useEffect(() => {\n if (reduceMotion) {\n grow.setValue(share);\n return;\n }\n Animated.timing(grow, {\n toValue: share,\n duration: 420,\n delay: index * 40,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [share, index, reduceMotion, grow]);\n return (\n \n );\n}\n\n/**\n * A tiny bar chart for showing a trend inside a card. The bars grow up from the baseline one after\n * another, resize when the values change, and the active bar takes the accent colour. It reads out as\n * an image with every value listed, since the bars carry no labels.\n */\nexport function SparkBars({\n values,\n height = 48,\n gap = 4,\n highlight,\n label = \"Chart\",\n colors,\n style,\n}: SparkBarsProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const top = Math.max(...values, 1);\n const active = highlight ?? values.length - 1;\n\n return (\n \n {values.map((value, i) => (\n \n ))}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"flex-end\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/spin-loader.json b/public/registry/spin-loader.json new file mode 100644 index 0000000..a63d54d --- /dev/null +++ b/public/registry/spin-loader.json @@ -0,0 +1,15 @@ +{ + "name": "spin-loader", + "title": "Spin Loader", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/spin-loader.tsx", + "content": "import { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n StyleSheet,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport type SpinVariant = \"ring\" | \"dots\" | \"bars\" | \"pulse\";\n\nexport interface SpinLoaderColors {\n color: string;\n track: string;\n}\n\nconst DEFAULT_COLORS: SpinLoaderColors = {\n color: \"#4f46e5\",\n track: \"rgba(128, 128, 128, 0.25)\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface SpinLoaderProps {\n /** Which style of spinner to draw. */\n variant?: SpinVariant;\n /** Height and width of the spinner. */\n size?: number;\n /** Milliseconds for one full cycle. */\n duration?: number;\n /** Spoken name of the spinner. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * Four loading spinners in one component: a turning ring, three bouncing dots, a row of rising bars,\n * and a pulse that spreads outward. They share one loop, mount their views once so the animation\n * never restarts, and stand still when motion is reduced. Each reads out as a busy progress bar.\n */\nexport function SpinLoader({\n variant = \"ring\",\n size = 32,\n duration = 900,\n label = \"Loading\",\n colors,\n style,\n}: SpinLoaderProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const t = useRef(new Animated.Value(0)).current;\n\n useEffect(() => {\n if (reduceMotion) {\n t.setValue(0);\n return;\n }\n const loop = Animated.loop(\n Animated.timing(t, {\n toValue: 1,\n duration,\n easing: variant === \"ring\" ? Easing.linear : Easing.inOut(Easing.quad),\n useNativeDriver: NATIVE_DRIVER,\n }),\n );\n loop.start();\n return () => loop.stop();\n }, [reduceMotion, duration, variant, t]);\n\n // Offsets that stagger the dots and bars across the cycle.\n const phase = useMemo(() => (i: number) => i * 0.14, []);\n\n const body = (() => {\n if (variant === \"ring\") {\n return (\n \n );\n }\n if (variant === \"dots\") {\n const dot = size / 4;\n return (\n \n {[0, 1, 2].map((i) => (\n \n ))}\n \n );\n }\n if (variant === \"bars\") {\n const bar = size / 7;\n return (\n \n {[0, 1, 2, 3].map((i) => (\n \n ))}\n \n );\n }\n return (\n \n \n \n \n );\n })();\n\n return (\n \n {body}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"flex-end\", justifyContent: \"center\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/step-slider.json b/public/registry/step-slider.json new file mode 100644 index 0000000..5e60743 --- /dev/null +++ b/public/registry/step-slider.json @@ -0,0 +1,15 @@ +{ + "name": "step-slider", + "title": "Step Slider", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/step-slider.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Platform,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst THUMB = 28;\n\nexport interface StepSliderColors {\n track: string;\n fill: string;\n thumb: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: StepSliderColors = {\n track: \"#e5e7eb\",\n fill: \"#4f46e5\",\n thumb: \"#ffffff\",\n text: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface StepSliderProps {\n /** The label under each stop. */\n steps: string[];\n /** The index of the chosen stop. */\n value: number;\n onChange: (index: number) => void;\n /** Spoken name of the slider. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A slider with a fixed set of stops, such as a text size or a delivery speed. The thumb follows the\n * finger and settles on the nearest stop with a spring; tapping the track jumps to the stop under it.\n * It is an adjustable control for screen readers and reads out the label of the chosen stop.\n */\nexport function StepSlider({\n steps,\n value,\n onChange,\n label = \"Step\",\n colors,\n style,\n}: StepSliderProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [width, setWidth] = useState(0);\n const x = useRef(new Animated.Value(0)).current;\n const dragging = useRef(false);\n const last = steps.length - 1;\n const travel = Math.max(1, width - THUMB);\n\n const live = useRef({ travel, last, value, onChange, reduceMotion });\n live.current = { travel, last, value, onChange, reduceMotion };\n\n const settle = (index: number) => {\n const target = (index / Math.max(1, live.current.last)) * live.current.travel;\n if (live.current.reduceMotion) x.setValue(target);\n else\n Animated.spring(x, {\n toValue: target,\n stiffness: 420,\n damping: 30,\n mass: 1,\n useNativeDriver: false,\n }).start();\n };\n\n useEffect(() => {\n if (!dragging.current && width > 0) settle(value);\n // settle reads everything through refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [value, width, reduceMotion]);\n\n const indexAt = (px: number) => {\n const { travel: t, last: l } = live.current;\n return Math.max(0, Math.min(l, Math.round(((px - THUMB / 2) / t) * l)));\n };\n\n const start = useRef(0);\n const responder = useRef(\n PanResponder.create({\n onStartShouldSetPanResponder: () => true,\n onPanResponderTerminationRequest: () => false,\n onPanResponderGrant: (event) => {\n dragging.current = true;\n const px = Math.max(\n 0,\n Math.min(live.current.travel, event.nativeEvent.locationX - THUMB / 2),\n );\n start.current = px;\n x.stopAnimation();\n x.setValue(px);\n const next = indexAt(event.nativeEvent.locationX);\n if (next !== live.current.value) live.current.onChange(next);\n },\n onPanResponderMove: (_, g) => {\n const px = Math.max(0, Math.min(live.current.travel, start.current + g.dx));\n x.setValue(px);\n const next = indexAt(px + THUMB / 2);\n if (next !== live.current.value) live.current.onChange(next);\n },\n onPanResponderRelease: () => {\n dragging.current = false;\n settle(live.current.value);\n },\n onPanResponderTerminate: () => {\n dragging.current = false;\n settle(live.current.value);\n },\n }),\n ).current;\n\n const move = (direction: 1 | -1) => onChange(Math.max(0, Math.min(last, value + direction)));\n\n return (\n \n setWidth(event.nativeEvent.layout.width)}\n accessible\n accessibilityRole=\"adjustable\"\n accessibilityLabel={label}\n aria-label={label}\n accessibilityValue={{ min: 0, max: last, now: value, text: steps[value] }}\n aria-valuemin={0}\n aria-valuemax={last}\n aria-valuenow={value}\n aria-valuetext={steps[value]}\n accessibilityActions={[{ name: \"increment\" }, { name: \"decrement\" }]}\n onAccessibilityAction={(event) =>\n move(event.nativeEvent.actionName === \"increment\" ? 1 : -1)\n }\n style={styles.hit}\n >\n \n \n {steps.map((step, i) => (\n \n ))}\n \n \n \n {steps.map((step, i) => (\n \n {step}\n \n ))}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n hit: { height: 44, justifyContent: \"center\", userSelect: \"none\" },\n track: { height: 6, borderRadius: 3 },\n fill: { position: \"absolute\", left: 0, top: 19, height: 6, borderRadius: 3 },\n tick: { position: \"absolute\", top: 19, width: 6, height: 6, borderRadius: 3 },\n thumb: {\n position: \"absolute\",\n left: 0,\n top: 8,\n width: THUMB,\n height: THUMB,\n borderRadius: THUMB / 2,\n boxShadow: \"0 2px 6px rgba(0, 0, 0, 0.3)\",\n },\n labels: { flexDirection: \"row\", justifyContent: \"space-between\" },\n label: { fontSize: 12 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/story-bars.json b/public/registry/story-bars.json new file mode 100644 index 0000000..55a5e64 --- /dev/null +++ b/public/registry/story-bars.json @@ -0,0 +1,15 @@ +{ + "name": "story-bars", + "title": "Story Bars", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/story-bars.tsx", + "content": "import { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n StyleSheet,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface StoryBarsColors {\n track: string;\n fill: string;\n}\n\nconst DEFAULT_COLORS: StoryBarsColors = {\n track: \"rgba(255, 255, 255, 0.35)\",\n fill: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface StoryBarsProps {\n /** How many stories there are. */\n count: number;\n /** The story showing now, from 0. */\n index: number;\n /** Called when the current story's time is up and the next one should show. */\n onIndexChange: (index: number) => void;\n /** Called when the last story's time is up. */\n onComplete?: () => void;\n /** How long each story shows, in milliseconds. */\n duration?: number;\n /** Holds the bar where it is, for example while a finger is down. */\n paused?: boolean;\n /** Height of each bar. */\n height?: number;\n /** Space between the bars. */\n gap?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * The row of progress bars at the top of a story viewer. Finished stories are full, the current one\n * fills over `duration` and then asks for the next, and the rest are empty. Pausing holds the fill in\n * place and resuming carries on from there. The position is read out as \"Story 2 of 5\".\n */\nexport function StoryBars({\n count,\n index,\n onIndexChange,\n onComplete,\n duration = 5000,\n paused = false,\n height = 3,\n gap = 4,\n colors,\n style,\n}: StoryBarsProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n // One value per bar, and every bar stays mounted: an animated value stops itself when the view it\n // drives unmounts, so moving the fill to a different element between stories would freeze it.\n const bars = useMemo(\n () => Array.from({ length: count }, (_, i) => new Animated.Value(i < index ? 1 : 0)),\n // The starting fills only matter on mount; the effect below keeps them right from then on.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [count],\n );\n const value = useRef(0);\n const lastIndex = useRef(index);\n\n const live = useRef({ count, index, onIndexChange, onComplete, duration, reduceMotion });\n live.current = { count, index, onIndexChange, onComplete, duration, reduceMotion };\n\n useEffect(() => {\n // Finished stories are full and later ones empty; a new story starts from nothing, while a pause\n // and resume of the same story carries on from where it stopped.\n bars.forEach((bar, i) => {\n if (i < index) bar.setValue(1);\n else if (i > index) bar.setValue(0);\n });\n const current = bars[index];\n if (!current) return;\n if (lastIndex.current !== index) {\n lastIndex.current = index;\n current.setValue(0);\n }\n value.current = (current as unknown as { __getValue: () => number }).__getValue();\n const id = current.addListener(({ value: v }) => (value.current = v));\n if (paused) return () => current.removeListener(id);\n const remaining = Math.max(0, 1 - value.current) * live.current.duration;\n const animation = Animated.timing(current, {\n toValue: 1,\n duration: remaining,\n // With reduced motion the bar moves in ten steps instead of sliding.\n easing: live.current.reduceMotion ? (t: number) => Math.floor(t * 10) / 10 : Easing.linear,\n useNativeDriver: false,\n });\n animation.start(({ finished }) => {\n if (!finished) return;\n const { index: now, count: total } = live.current;\n if (now < total - 1) live.current.onIndexChange(now + 1);\n else live.current.onComplete?.();\n });\n return () => {\n animation.stop();\n current.removeListener(id);\n };\n }, [index, paused, bars, reduceMotion]);\n\n const label = `Story ${index + 1} of ${count}`;\n\n return (\n \n {bars.map((bar, i) => (\n \n \n \n ))}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\" },\n track: { flex: 1, overflow: \"hidden\" },\n fill: { height: \"100%\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/stripe-progress.json b/public/registry/stripe-progress.json new file mode 100644 index 0000000..3c9f3fa --- /dev/null +++ b/public/registry/stripe-progress.json @@ -0,0 +1,15 @@ +{ + "name": "stripe-progress", + "title": "Stripe Progress", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/stripe-progress.tsx", + "content": "import { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n// The indeterminate segment is this fraction of the track.\nconst SEGMENT = 0.4;\n// Horizontal distance between two stripes.\nconst MIN_PERIOD = 16;\n\nexport interface StripeProgressColors {\n track: string;\n fill: string;\n stripe: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: StripeProgressColors = {\n track: \"#e5e7eb\",\n fill: \"#4f46e5\",\n stripe: \"rgba(255, 255, 255, 0.3)\",\n text: \"#374151\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface StripeProgressProps {\n /** Progress from 0 to 1. Leave it out for an indeterminate bar. */\n value?: number;\n /** Height of the bar. */\n height?: number;\n /** Draws diagonal stripes on the fill. */\n striped?: boolean;\n /** Lets the stripes drift while the bar is determinate. */\n animated?: boolean;\n /** Spoken name of the bar. */\n label?: string;\n /** Shows the percentage next to the bar. */\n showPercent?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A progress bar whose fill grows with a spring and whose diagonal stripes drift along it. Leave\n * `value` out and a segment travels across the track instead. Stripes are plain rotated views, so it\n * needs no gradient or SVG package. With reduced motion nothing drifts or travels, but the fill still\n * follows the value.\n */\nexport function StripeProgress({\n value,\n height = 10,\n striped = true,\n animated = true,\n label = \"Progress\",\n showPercent = false,\n colors,\n style,\n}: StripeProgressProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [width, setWidth] = useState(0);\n const indeterminate = value === undefined;\n const clamped = Math.max(0, Math.min(1, value ?? 0));\n const percent = Math.round(clamped * 100);\n\n const fill = useRef(new Animated.Value(clamped)).current;\n const drift = useRef(new Animated.Value(0)).current;\n const travel = useRef(new Animated.Value(0)).current;\n\n const period = Math.max(MIN_PERIOD, height * 2);\n const stripeCount = width > 0 ? Math.ceil(width / period) + 3 : 0;\n const moving = !reduceMotion;\n\n // The fill follows the value.\n useEffect(() => {\n if (indeterminate) return;\n if (reduceMotion) {\n fill.setValue(clamped);\n return;\n }\n Animated.timing(fill, {\n toValue: clamped,\n duration: 450,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [clamped, indeterminate, reduceMotion, fill]);\n\n // Both loops start once the width is known, on views that are mounted from the start.\n useEffect(() => {\n if (width <= 0 || !moving) return;\n const loops: Animated.CompositeAnimation[] = [];\n if (striped && animated && !indeterminate) {\n drift.setValue(0);\n loops.push(\n Animated.loop(\n Animated.timing(drift, {\n toValue: period,\n duration: 900,\n easing: Easing.linear,\n useNativeDriver: NATIVE_DRIVER,\n }),\n ),\n );\n }\n if (indeterminate) {\n travel.setValue(0);\n loops.push(\n Animated.loop(\n Animated.timing(travel, {\n toValue: 1,\n duration: 1300,\n easing: Easing.inOut(Easing.quad),\n useNativeDriver: NATIVE_DRIVER,\n }),\n ),\n );\n }\n loops.forEach((loop) => loop.start());\n return () => loops.forEach((loop) => loop.stop());\n }, [width, moving, striped, animated, indeterminate, period, drift, travel]);\n\n const fillWidth = useMemo(\n () => fill.interpolate({ inputRange: [0, 1], outputRange: [0, width], extrapolate: \"clamp\" }),\n [fill, width],\n );\n const segmentWidth = width * SEGMENT;\n const segmentX = useMemo(\n () => travel.interpolate({ inputRange: [0, 1], outputRange: [-segmentWidth, width] }),\n [travel, width, segmentWidth],\n );\n const stripeList = useMemo(() => Array.from({ length: stripeCount }, (_, i) => i), [stripeCount]);\n\n return (\n \n setWidth(event.nativeEvent.layout.width)}\n style={[styles.track, { height, borderRadius: height / 2, backgroundColor: palette.track }]}\n >\n \n {striped ? (\n \n {stripeList.map((i) => (\n \n ))}\n \n ) : null}\n \n \n \n {showPercent ? (\n \n {indeterminate ? \"\" : `${percent}%`}\n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"center\", gap: 10 },\n track: { flex: 1, overflow: \"hidden\" },\n fill: { position: \"absolute\", top: 0, bottom: 0, left: 0, overflow: \"hidden\" },\n stripes: { position: \"absolute\", top: 0, bottom: 0 },\n segment: { position: \"absolute\", top: 0, bottom: 0, left: 0 },\n percent: { minWidth: 40, textAlign: \"right\", fontSize: 13, fontWeight: \"600\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/suggest-input.json b/public/registry/suggest-input.json new file mode 100644 index 0000000..cd58910 --- /dev/null +++ b/public/registry/suggest-input.json @@ -0,0 +1,15 @@ +{ + "name": "suggest-input", + "title": "Suggest Input", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/suggest-input.tsx", + "content": "import { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n TextInput,\n View,\n type StyleProp,\n type TextInputKeyPressEvent,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst FIELD_HEIGHT = 48;\nconst ROW_HEIGHT = 44;\n// On the web the field loses focus before a tap on a suggestion lands, so closing waits a moment.\nconst BLUR_DELAY = 160;\n\nexport interface SuggestInputColors {\n field: string;\n border: string;\n focusBorder: string;\n text: string;\n placeholder: string;\n panel: string;\n highlight: string;\n activeRow: string;\n}\n\nconst DEFAULT_COLORS: SuggestInputColors = {\n field: \"#ffffff\",\n border: \"#d1d5db\",\n focusBorder: \"#4f46e5\",\n text: \"#111827\",\n placeholder: \"#9ca3af\",\n panel: \"#ffffff\",\n highlight: \"#4f46e5\",\n activeRow: \"#eef2ff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface SuggestInputProps {\n value: string;\n onChangeText: (text: string) => void;\n /** Everything that can be suggested. The list under the field is these, narrowed by what is typed. */\n suggestions: string[];\n /** Called with the suggestion that was chosen. */\n onSelect: (suggestion: string) => void;\n placeholder?: string;\n /** How many characters must be typed before suggestions show. */\n minChars?: number;\n /** The most suggestions shown at once. */\n maxSuggestions?: number;\n /** Shown when nothing matches. */\n emptyText?: string;\n /** Spoken name of the field. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A text field with a list of suggestions that narrows as you type. Matches that start with the text\n * come first and the part that matched is bold. On the web the arrow keys move through the list, Enter\n * chooses and Escape closes it; on a phone you tap. It is a combobox to screen readers.\n */\nexport function SuggestInput({\n value,\n onChangeText,\n suggestions,\n onSelect,\n placeholder = \"Search\",\n minChars = 1,\n maxSuggestions = 5,\n emptyText = \"No matches\",\n label = \"Search\",\n colors,\n style,\n}: SuggestInputProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const id = useId();\n const [focused, setFocused] = useState(false);\n const [dismissed, setDismissed] = useState(false);\n const [active, setActive] = useState(-1);\n const t = useRef(new Animated.Value(0)).current;\n const blurTimer = useRef | null>(null);\n\n const query = value.trim().toLowerCase();\n const matches = useMemo(() => {\n if (query.length < minChars) return [];\n const found = suggestions.filter((item) => item.toLowerCase().includes(query));\n // Suggestions that start with the text come before those that only contain it.\n found.sort(\n (a, b) =>\n Number(b.toLowerCase().startsWith(query)) - Number(a.toLowerCase().startsWith(query)),\n );\n return found.slice(0, maxSuggestions);\n }, [suggestions, query, minChars, maxSuggestions]);\n\n const open = focused && !dismissed && query.length >= minChars;\n const rows = matches.length > 0 ? matches.length : 1;\n\n useEffect(() => {\n if (reduceMotion) {\n t.setValue(open ? 1 : 0);\n return;\n }\n Animated.timing(t, {\n toValue: open ? 1 : 0,\n duration: 140,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [open, reduceMotion, t]);\n\n useEffect(\n () => () => {\n if (blurTimer.current) clearTimeout(blurTimer.current);\n },\n [],\n );\n\n const choose = (item: string) => {\n onSelect(item);\n setDismissed(true);\n setActive(-1);\n };\n\n const onKeyPress = (event: TextInputKeyPressEvent) => {\n const key = event.nativeEvent.key;\n if (key === \"ArrowDown\" || key === \"ArrowUp\") {\n if (!open && matches.length > 0) setDismissed(false);\n if (matches.length === 0) return;\n const step = key === \"ArrowDown\" ? 1 : -1;\n setActive((current) => (current + step + matches.length) % matches.length);\n } else if (key === \"Enter\" && open && active >= 0 && matches[active]) {\n choose(matches[active]);\n } else if (key === \"Escape\") {\n setDismissed(true);\n setActive(-1);\n }\n };\n\n const optionId = (i: number) => `${id}-option-${i}`;\n\n return (\n \n {\n onChangeText(text);\n setDismissed(false);\n setActive(-1);\n }}\n onKeyPress={onKeyPress}\n onFocus={() => {\n if (blurTimer.current) clearTimeout(blurTimer.current);\n setFocused(true);\n }}\n onBlur={() => {\n blurTimer.current = setTimeout(() => setFocused(false), BLUR_DELAY);\n }}\n // react-native-web only reads blurOnSubmit; without it a single-line field blurs on Enter.\n blurOnSubmit={false}\n placeholder={placeholder}\n placeholderTextColor={palette.placeholder}\n autoCapitalize=\"none\"\n autoCorrect={false}\n returnKeyType=\"search\"\n accessibilityLabel={label}\n aria-label={label}\n role=\"combobox\"\n aria-expanded={open}\n aria-autocomplete=\"list\"\n aria-controls={`${id}-list`}\n aria-activedescendant={open && active >= 0 ? optionId(active) : undefined}\n selectionColor={palette.focusBorder}\n style={[\n styles.input,\n {\n backgroundColor: palette.field,\n color: palette.text,\n borderColor: focused ? palette.focusBorder : palette.border,\n },\n ]}\n />\n \n {matches.length === 0 ? (\n \n {emptyText}\n \n ) : (\n matches.map((item, i) => {\n const at = item.toLowerCase().indexOf(query);\n return (\n choose(item)}\n style={[styles.row, i === active && { backgroundColor: palette.activeRow }]}\n >\n \n {item.slice(0, at)}\n \n {item.slice(at, at + query.length)}\n \n {item.slice(at + query.length)}\n \n \n );\n })\n )}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { height: FIELD_HEIGHT, zIndex: 10 },\n input: {\n height: FIELD_HEIGHT,\n borderRadius: 14,\n borderWidth: 1.5,\n paddingHorizontal: 16,\n fontSize: 16,\n },\n panel: {\n position: \"absolute\",\n top: FIELD_HEIGHT + 6,\n left: 0,\n right: 0,\n borderRadius: 14,\n borderWidth: 1,\n overflow: \"hidden\",\n boxShadow: \"0 12px 30px rgba(0, 0, 0, 0.18)\",\n },\n row: { height: ROW_HEIGHT, justifyContent: \"center\", paddingHorizontal: 16 },\n text: { fontSize: 16 },\n match: { fontWeight: \"800\" },\n empty: { fontSize: 15 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/swatch-picker.json b/public/registry/swatch-picker.json new file mode 100644 index 0000000..89d5048 --- /dev/null +++ b/public/registry/swatch-picker.json @@ -0,0 +1,15 @@ +{ + "name": "swatch-picker", + "title": "Swatch Picker", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/swatch-picker.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface Swatch {\n /** A CSS colour such as \"#ef4444\". */\n value: string;\n /** Spoken name, such as \"Red\". */\n label: string;\n}\n\nexport interface SwatchPickerColors {\n ring: string;\n check: string;\n}\n\nconst DEFAULT_COLORS: SwatchPickerColors = {\n ring: \"#111827\",\n check: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface SwatchPickerProps {\n options: Swatch[];\n /** The chosen swatch's colour value. */\n value: string;\n onChange: (value: string) => void;\n /** Diameter of a swatch. */\n size?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\nfunction Dot({\n swatch,\n selected,\n size,\n palette,\n reduceMotion,\n onPress,\n index,\n count,\n}: {\n swatch: Swatch;\n selected: boolean;\n size: number;\n palette: SwatchPickerColors;\n reduceMotion: boolean;\n onPress: () => void;\n index: number;\n count: number;\n}) {\n const pick = useRef(new Animated.Value(selected ? 1 : 0)).current;\n useEffect(() => {\n if (reduceMotion) pick.setValue(selected ? 1 : 0);\n else\n Animated.spring(pick, {\n toValue: selected ? 1 : 0,\n stiffness: 420,\n damping: 18,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [selected, reduceMotion, pick]);\n\n const outer = size + 12;\n return (\n \n \n \n \n ✓\n \n \n \n );\n}\n\n/**\n * A row of colour circles to choose from, such as a theme or a label colour. The chosen one gets a ring\n * that springs out around it and a tick inside. The circles are a radio group and each is read out by\n * the name you give it, not by its hex code.\n */\nexport function SwatchPicker({\n options,\n value,\n onChange,\n size = 36,\n colors,\n style,\n}: SwatchPickerProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n\n return (\n \n {options.map((swatch, i) => (\n onChange(swatch.value)}\n />\n ))}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", flexWrap: \"wrap\", gap: 2, userSelect: \"none\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/tab-pager.json b/public/registry/tab-pager.json new file mode 100644 index 0000000..d1c7bc6 --- /dev/null +++ b/public/registry/tab-pager.json @@ -0,0 +1,15 @@ +{ + "name": "tab-pager", + "title": "Tab Pager", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/tab-pager.tsx", + "content": "import { useEffect, useRef, useState, type ElementRef, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Platform,\n Pressable,\n ScrollView,\n StyleSheet,\n View,\n type LayoutChangeEvent,\n type NativeScrollEvent,\n type NativeSyntheticEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface TabPagerTab {\n id: string;\n label: string;\n}\n\nexport interface TabPagerColors {\n text: string;\n activeText: string;\n indicator: string;\n border: string;\n background: string;\n}\n\nconst DEFAULT_COLORS: TabPagerColors = {\n text: \"#6b7280\",\n activeText: \"#111827\",\n indicator: \"#4f46e5\",\n border: \"#e5e7eb\",\n background: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface TabPagerProps {\n tabs: TabPagerTab[];\n /** Renders the content of one page. */\n renderPage: (tab: TabPagerTab, index: number) => ReactNode;\n /** The id of the selected tab. */\n value: string;\n onChange: (id: string) => void;\n colors?: Partial;\n style?: StyleProp;\n}\n\ninterface Box {\n x: number;\n width: number;\n}\n\n/**\n * Swipeable pages under a row of tabs. The underline follows your finger between the two tabs it is\n * travelling across, growing or shrinking to each label's width, and the labels blend from muted to\n * active as their page arrives. Tapping a tab scrolls to its page. On desktop browsers the pages can\n * also be dragged with a mouse.\n */\nexport function TabPager({ tabs, renderPage, value, onChange, colors, style }: TabPagerProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [width, setWidth] = useState(0);\n const [boxes, setBoxes] = useState([]);\n // Paging snaps the scroll back on the web, so it is switched off while a mouse drags the pages.\n const [snapping, setSnapping] = useState(true);\n const pages = useRef>(null);\n const header = useRef>(null);\n const scrollX = useRef(new Animated.Value(0)).current;\n const offset = useRef(0);\n const current = useRef(\n Math.max(\n 0,\n tabs.findIndex((tab) => tab.id === value),\n ),\n );\n // True during a mouse drag and for a moment after it: the click a mouse sends on release is not a tap.\n const dragging = useRef(false);\n const dragStart = useRef(0);\n const headerWidth = useRef(0);\n\n const index = Math.max(\n 0,\n tabs.findIndex((tab) => tab.id === value),\n );\n const last = tabs.length - 1;\n\n const live = useRef({ width, last, reduceMotion, onChange, tabs, boxes });\n live.current = { width, last, reduceMotion, onChange, tabs, boxes };\n\n const goTo = (target: number, animated = !live.current.reduceMotion) => {\n const clamped = Math.max(0, Math.min(live.current.last, target));\n pages.current?.scrollTo({ x: clamped * live.current.width, animated });\n };\n\n // Keep the selected tab's page in view when `value` changes from outside.\n useEffect(() => {\n if (width <= 0 || index === current.current) return;\n current.current = index;\n goTo(index);\n // goTo reads everything through refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [index, width]);\n\n // Put the first page in place once the width is known.\n useEffect(() => {\n if (width <= 0) return;\n scrollX.setValue(index * width);\n pages.current?.scrollTo({ x: index * width, animated: false });\n // Only the first measurement positions the pages.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [width > 0]);\n\n // Slide the header so the selected label stays visible when there are many tabs.\n useEffect(() => {\n const box = boxes[index];\n if (!box || headerWidth.current <= 0) return;\n header.current?.scrollTo({\n x: Math.max(0, box.x - (headerWidth.current - box.width) / 2),\n animated: !reduceMotion,\n });\n }, [index, boxes, reduceMotion]);\n\n const settle = (x: number) => {\n offset.current = x;\n const next = Math.max(0, Math.min(live.current.last, Math.round(x / live.current.width)));\n if (next !== current.current) {\n current.current = next;\n live.current.onChange(live.current.tabs[next].id);\n AccessibilityInfo.announceForAccessibility(\n `${live.current.tabs[next].label}, tab ${next + 1} of ${live.current.last + 1}`,\n );\n }\n };\n\n const onScroll = (event: NativeSyntheticEvent) => {\n offset.current = event.nativeEvent.contentOffset.x;\n };\n\n // A mouse cannot drag a scroll view, so on desktop browsers the pages are dragged by hand.\n const mouseDrag = useRef(\n PanResponder.create({\n onMoveShouldSetPanResponder: (_, g) =>\n Platform.OS === \"web\" &&\n typeof window !== \"undefined\" &&\n window.matchMedia(\"(pointer: fine)\").matches &&\n Math.abs(g.dx) > 6 &&\n Math.abs(g.dx) > Math.abs(g.dy),\n onPanResponderGrant: () => {\n dragging.current = true;\n dragStart.current = offset.current;\n setSnapping(false);\n },\n onPanResponderMove: (_, g) => {\n pages.current?.scrollTo({ x: dragStart.current - g.dx, animated: false });\n },\n onPanResponderRelease: (_, g) => {\n setTimeout(() => (dragging.current = false), 80);\n setSnapping(true);\n // Carry a flick on to the next page, otherwise settle on the nearest one.\n const target = Math.round((offset.current - g.vx * 160) / live.current.width);\n const clamped = Math.max(0, Math.min(live.current.last, target));\n goTo(clamped);\n settle(clamped * live.current.width);\n },\n onPanResponderTerminate: () => {\n setTimeout(() => (dragging.current = false), 80);\n setSnapping(true);\n goTo(Math.round(offset.current / live.current.width));\n },\n }),\n ).current;\n\n const ready = width > 0 && boxes.length === tabs.length && tabs.length > 1;\n const inputRange = tabs.map((_, i) => i * width);\n\n const indicatorX = ready\n ? scrollX.interpolate({\n inputRange,\n outputRange: boxes.map((box) => box.x),\n extrapolate: \"clamp\",\n })\n : 0;\n const indicatorWidth = ready\n ? scrollX.interpolate({\n inputRange,\n outputRange: boxes.map((box) => box.width),\n extrapolate: \"clamp\",\n })\n : (boxes[0]?.width ?? 0);\n\n return (\n \n \n {\n headerWidth.current = event.nativeEvent.layout.width;\n }}\n accessibilityRole=\"tablist\"\n contentContainerStyle={styles.header}\n >\n {tabs.map((tab, i) => {\n const selected = i === index;\n const color = ready\n ? scrollX.interpolate({\n inputRange: [(i - 1) * width, i * width, (i + 1) * width],\n outputRange: [palette.text, palette.activeText, palette.text],\n extrapolate: \"clamp\",\n })\n : selected\n ? palette.activeText\n : palette.text;\n return (\n {\n const { x, width: w } = event.nativeEvent.layout;\n setBoxes((all) => {\n const next = [...all];\n next[i] = { x, width: w };\n return next;\n });\n }}\n onPress={() => {\n if (dragging.current) return;\n goTo(i);\n settle(i * live.current.width);\n }}\n style={styles.tab}\n >\n \n {tab.label}\n \n \n );\n })}\n {boxes.length > 0 ? (\n \n ) : null}\n \n \n setWidth(event.nativeEvent.layout.width)}\n style={styles.body}\n >\n {width > 0 ? (\n \n settle(event.nativeEvent.contentOffset.x)}\n onScrollEndDrag={(event) => {\n // Without momentum (a slow drag that stops on a page) the momentum event never fires.\n if (!live.current.reduceMotion) return;\n settle(event.nativeEvent.contentOffset.x);\n }}\n >\n {tabs.map((tab, i) => (\n \n {renderPage(tab, i)}\n \n ))}\n \n \n ) : null}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { flex: 1 },\n headerWrap: { borderBottomWidth: StyleSheet.hairlineWidth },\n header: { paddingHorizontal: 8, position: \"relative\" },\n tab: { minHeight: 48, paddingHorizontal: 14, justifyContent: \"center\", userSelect: \"none\" },\n label: { fontSize: 15, fontWeight: \"600\" },\n indicator: { position: \"absolute\", left: 0, bottom: 0, height: 3, borderRadius: 2 },\n body: { flex: 1 },\n // userSelect keeps a mouse drag on the web from selecting the page's text instead of moving the pages.\n drag: { flex: 1, userSelect: \"none\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/task-checklist.json b/public/registry/task-checklist.json new file mode 100644 index 0000000..c9167cc --- /dev/null +++ b/public/registry/task-checklist.json @@ -0,0 +1,15 @@ +{ + "name": "task-checklist", + "title": "Task Checklist", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/task-checklist.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nexport interface ChecklistItem {\n id: string;\n label: string;\n}\n\nexport interface TaskChecklistColors {\n accent: string;\n text: string;\n done: string;\n track: string;\n border: string;\n}\n\nconst DEFAULT_COLORS: TaskChecklistColors = {\n accent: \"#4f46e5\",\n text: \"#111827\",\n done: \"#9ca3af\",\n track: \"#e5e7eb\",\n border: \"#d1d5db\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface TaskChecklistProps {\n items: ChecklistItem[];\n /** The ids of the finished tasks. */\n value: string[];\n onChange: (value: string[]) => void;\n colors?: Partial;\n style?: StyleProp;\n}\n\nfunction Row({\n item,\n done,\n palette,\n reduceMotion,\n onToggle,\n}: {\n item: ChecklistItem;\n done: boolean;\n palette: TaskChecklistColors;\n reduceMotion: boolean;\n onToggle: () => void;\n}) {\n const t = useRef(new Animated.Value(done ? 1 : 0)).current;\n useEffect(() => {\n if (reduceMotion) t.setValue(done ? 1 : 0);\n else\n Animated.timing(t, {\n toValue: done ? 1 : 0,\n duration: 260,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [done, reduceMotion, t]);\n\n return (\n \n \n ✓\n \n \n \n {item.label}\n \n \n \n \n );\n}\n\n/**\n * A to-do list with a progress bar above it. Ticking a task fills its box, greys its text and draws a\n * line through it from left to right, and the bar grows to the share of tasks finished. Each task is\n * a checkbox, and the progress is read out as \"2 of 4 done\".\n */\nexport function TaskChecklist({ items, value, onChange, colors, style }: TaskChecklistProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const share = items.length\n ? value.filter((id) => items.some((item) => item.id === id)).length / items.length\n : 0;\n const bar = useRef(new Animated.Value(share)).current;\n const finished = Math.round(share * items.length);\n\n useEffect(() => {\n if (reduceMotion) bar.setValue(share);\n else\n Animated.timing(bar, {\n toValue: share,\n duration: 320,\n easing: Easing.out(Easing.cubic),\n useNativeDriver: false,\n }).start();\n }, [share, reduceMotion, bar]);\n\n const toggle = (id: string) =>\n onChange(value.includes(id) ? value.filter((v) => v !== id) : [...value, id]);\n\n return (\n \n \n \n \n \n \n {finished}/{items.length}\n \n \n {items.map((item) => (\n toggle(item.id)}\n />\n ))}\n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { gap: 4 },\n progress: { flexDirection: \"row\", alignItems: \"center\", gap: 12, marginBottom: 8 },\n track: { flex: 1, height: 8, borderRadius: 4, overflow: \"hidden\" },\n fill: { height: \"100%\", borderRadius: 4 },\n count: { fontSize: 13, fontWeight: \"700\", minWidth: 28, textAlign: \"right\" },\n row: { flexDirection: \"row\", alignItems: \"center\", gap: 12, minHeight: 48, userSelect: \"none\" },\n box: {\n width: 24,\n height: 24,\n borderRadius: 8,\n borderWidth: 2,\n alignItems: \"center\",\n justifyContent: \"center\",\n },\n tick: { color: \"#ffffff\", fontSize: 14, fontWeight: \"800\" },\n labelBox: { flexShrink: 1, justifyContent: \"center\" },\n label: { fontSize: 16 },\n strike: { position: \"absolute\", left: 0, top: \"52%\", height: 2 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/tick-box.json b/public/registry/tick-box.json new file mode 100644 index 0000000..a4a1e51 --- /dev/null +++ b/public/registry/tick-box.json @@ -0,0 +1,15 @@ +{ + "name": "tick-box", + "title": "Tick Box", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/tick-box.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface TickBoxColors {\n border: string;\n fill: string;\n tick: string;\n text: string;\n description: string;\n}\n\nconst DEFAULT_COLORS: TickBoxColors = {\n border: \"#9ca3af\",\n fill: \"#4f46e5\",\n tick: \"#ffffff\",\n text: \"#111827\",\n description: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface TickBoxProps {\n /** Checked, unchecked, or \"mixed\" for a parent whose children are partly checked. */\n checked: boolean | \"mixed\";\n /** Called with the new state when pressed. A \"mixed\" box becomes checked. */\n onChange: (next: boolean) => void;\n /** Text beside the box. Pressing it toggles the box too. */\n label?: string;\n /** A second, smaller line under the label. */\n description?: string;\n /** Side of the box. */\n size?: number;\n /** Draws a circle instead of a rounded square. */\n round?: boolean;\n disabled?: boolean;\n /** Extra content shown after the label. */\n children?: ReactNode;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A checkbox whose fill pops in on a spring and whose tick grows out of its corner. It also has the\n * \"mixed\" state for a select-all box over partly checked children. The whole row is the touch target,\n * with the state read out as checked, unchecked or mixed.\n */\nexport function TickBox({\n checked,\n onChange,\n label,\n description,\n size = 24,\n round = false,\n disabled = false,\n children,\n colors,\n style,\n}: TickBoxProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const on = checked === true;\n const mixed = checked === \"mixed\";\n const fill = useRef(new Animated.Value(on || mixed ? 1 : 0)).current;\n const tick = useRef(new Animated.Value(on ? 1 : 0)).current;\n const bar = useRef(new Animated.Value(mixed ? 1 : 0)).current;\n const press = useRef(new Animated.Value(1)).current;\n\n useEffect(() => {\n const to = (value: Animated.Value, toValue: number, stiffness = 380) =>\n reduceMotion\n ? value.setValue(toValue)\n : Animated.spring(value, {\n toValue,\n stiffness,\n damping: 22,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n to(fill, on || mixed ? 1 : 0);\n to(tick, on ? 1 : 0, 300);\n to(bar, mixed ? 1 : 0, 300);\n }, [on, mixed, reduceMotion, fill, tick, bar]);\n\n const dip = (down: boolean) => {\n if (reduceMotion) return;\n Animated.spring(press, {\n toValue: down ? 0.92 : 1,\n stiffness: 500,\n damping: 24,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n };\n\n const radius = round ? size / 2 : size * 0.26;\n const stem = size * 0.5;\n const foot = size * 0.26;\n\n return (\n onChange(!on)}\n onPressIn={() => dip(true)}\n onPressOut={() => dip(false)}\n style={[styles.row, disabled && styles.disabled, style]}\n >\n \n \n \n \n \n {label || description || children ? (\n \n {label ? {label} : null}\n {description ? (\n {description}\n ) : null}\n {children}\n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: {\n flexDirection: \"row\",\n alignItems: \"flex-start\",\n gap: 12,\n minHeight: 44,\n paddingVertical: 8,\n userSelect: \"none\",\n },\n text: { flex: 1, gap: 2 },\n label: { fontSize: 16, fontWeight: \"600\", lineHeight: 24 },\n description: { fontSize: 13, lineHeight: 18 },\n disabled: { opacity: 0.45 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/timeline-list.json b/public/registry/timeline-list.json new file mode 100644 index 0000000..f92f8e2 --- /dev/null +++ b/public/registry/timeline-list.json @@ -0,0 +1,15 @@ +{ + "name": "timeline-list", + "title": "Timeline List", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/timeline-list.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst DOT = 16;\n\nexport interface TimelineItem {\n id: string;\n title: string;\n description?: string;\n /** Shown beside the title, such as a time or date. */\n time?: string;\n status: \"done\" | \"current\" | \"upcoming\";\n}\n\nexport interface TimelineListColors {\n line: string;\n done: string;\n current: string;\n upcoming: string;\n title: string;\n description: string;\n}\n\nconst DEFAULT_COLORS: TimelineListColors = {\n line: \"#e5e7eb\",\n done: \"#16a34a\",\n current: \"#4f46e5\",\n upcoming: \"#d1d5db\",\n title: \"#111827\",\n description: \"#6b7280\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface TimelineListProps {\n items: TimelineItem[];\n colors?: Partial;\n style?: StyleProp;\n}\n\nfunction Pulse({ color, reduceMotion }: { color: string; reduceMotion: boolean }) {\n const t = useRef(new Animated.Value(0)).current;\n useEffect(() => {\n if (reduceMotion) {\n t.setValue(0);\n return;\n }\n const loop = Animated.loop(\n Animated.timing(t, {\n toValue: 1,\n duration: 1400,\n easing: Easing.out(Easing.quad),\n useNativeDriver: NATIVE_DRIVER,\n }),\n );\n loop.start();\n return () => loop.stop();\n }, [reduceMotion, t]);\n return (\n \n );\n}\n\n/**\n * A vertical list of events joined by a line. Finished steps are green, the current step has a dot\n * that pulses outward, and later steps are muted. Each row reads out its status, so the progress does\n * not depend on colour alone. With reduced motion the pulse stands still.\n */\nexport function TimelineList({ items, colors, style }: TimelineListProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const status = { done: \"Completed\", current: \"In progress\", upcoming: \"Upcoming\" };\n\n return (\n \n {items.map((item, index) => {\n const tint = palette[item.status];\n const last = index === items.length - 1;\n return (\n \n \n \n {item.status === \"current\" ? (\n \n ) : null}\n \n \n {last ? null : (\n \n )}\n \n \n \n \n {item.title}\n \n {item.time ? (\n {item.time}\n ) : null}\n \n {item.description ? (\n \n {item.description}\n \n ) : null}\n \n \n );\n })}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", gap: 14 },\n rail: { width: DOT, alignItems: \"center\" },\n dotBox: { width: DOT, height: DOT, marginTop: 3, alignItems: \"center\", justifyContent: \"center\" },\n dot: { width: DOT, height: DOT, borderRadius: DOT / 2 },\n line: { flex: 1, width: 2, marginVertical: 4 },\n body: { flex: 1, gap: 2, paddingBottom: 22 },\n lastBody: { paddingBottom: 0 },\n head: { flexDirection: \"row\", justifyContent: \"space-between\", gap: 8 },\n title: { flex: 1, fontSize: 16, fontWeight: \"600\" },\n time: { fontSize: 13 },\n description: { fontSize: 14, lineHeight: 20 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/tip-popover.json b/public/registry/tip-popover.json new file mode 100644 index 0000000..bba14e0 --- /dev/null +++ b/public/registry/tip-popover.json @@ -0,0 +1,15 @@ +{ + "name": "tip-popover", + "title": "Tip Popover", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/tip-popover.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst WIDTH = 220;\nconst GAP = 10;\n\nexport interface TipPopoverColors {\n background: string;\n text: string;\n}\n\nconst DEFAULT_COLORS: TipPopoverColors = {\n background: \"#111827\",\n text: \"#ffffff\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface TipPopoverProps {\n open: boolean;\n onClose: () => void;\n /** The tip's text. */\n content: string;\n /** The element the tip points at. */\n children: ReactNode;\n /** Which side of the trigger the tip opens on. */\n placement?: \"top\" | \"bottom\";\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A small tip that points at its trigger. It is drawn inside its parent rather than in a Modal, so it\n * stays within a screen, and it springs out from the arrow. Tapping anywhere else closes it, and on\n * the web so does Escape. The tip is announced when it opens.\n */\nexport function TipPopover({\n open,\n onClose,\n content,\n children,\n placement = \"top\",\n colors,\n style,\n}: TipPopoverProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const t = useRef(new Animated.Value(0)).current;\n const [mounted, setMounted] = useState(open);\n const [triggerWidth, setTriggerWidth] = useState(0);\n const top = placement === \"top\";\n\n const live = useRef({ onClose });\n live.current = { onClose };\n\n useEffect(() => {\n if (open) setMounted(true);\n if (reduceMotion) {\n t.setValue(open ? 1 : 0);\n if (!open) setMounted(false);\n return;\n }\n Animated.spring(t, {\n toValue: open ? 1 : 0,\n stiffness: 380,\n damping: 26,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start(({ finished }) => {\n if (finished && !open) setMounted(false);\n });\n }, [open, reduceMotion, t]);\n\n useEffect(() => {\n if (open) AccessibilityInfo.announceForAccessibility(content);\n }, [open, content]);\n\n useEffect(() => {\n if (!open || Platform.OS !== \"web\") return;\n const onKey = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") live.current.onClose();\n };\n window.addEventListener(\"keydown\", onKey);\n return () => window.removeEventListener(\"keydown\", onKey);\n }, [open]);\n\n return (\n \n setTriggerWidth(event.nativeEvent.layout.width)}\n >\n {children}\n \n {mounted ? (\n <>\n {open ? : null}\n \n {!top ? (\n \n ) : null}\n \n {content}\n \n {top ? (\n \n ) : null}\n \n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { alignSelf: \"flex-start\", position: \"relative\" },\n // Large enough to catch a tap anywhere on the screen around the trigger.\n backdrop: { position: \"absolute\", top: -2000, left: -2000, width: 4400, height: 4400 },\n holder: { position: \"absolute\", width: WIDTH, alignItems: \"center\", zIndex: 10 },\n bubble: { paddingVertical: 10, paddingHorizontal: 14, borderRadius: 12 },\n text: { fontSize: 14, lineHeight: 20, textAlign: \"center\" },\n arrow: { width: 12, height: 12, transform: [{ rotate: \"45deg\" }] },\n arrowBottom: { marginTop: -6 },\n arrowTop: { marginBottom: -6 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/undo-snackbar.json b/public/registry/undo-snackbar.json new file mode 100644 index 0000000..5ef8e9e --- /dev/null +++ b/public/registry/undo-snackbar.json @@ -0,0 +1,15 @@ +{ + "name": "undo-snackbar", + "title": "Undo Snackbar", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/undo-snackbar.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n Pressable,\n StyleSheet,\n Text,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface UndoSnackbarColors {\n background: string;\n text: string;\n action: string;\n timer: string;\n}\n\nconst DEFAULT_COLORS: UndoSnackbarColors = {\n background: \"#111827\",\n text: \"#ffffff\",\n action: \"#a5b4fc\",\n timer: \"rgba(255, 255, 255, 0.35)\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface UndoSnackbarProps {\n open: boolean;\n /** Called when the time runs out or the action is pressed. */\n onClose: () => void;\n message: string;\n actionLabel?: string;\n /** Called when the action is pressed, before the snackbar closes. */\n onAction?: () => void;\n /** How long it stays, in milliseconds. */\n duration?: number;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * The bar that appears after a delete with an Undo button. It slides up from the bottom of its parent,\n * a thin line along its edge shows how long is left, and it closes itself when that runs out. The\n * message is announced when it opens, and the action is an ordinary button.\n */\nexport function UndoSnackbar({\n open,\n onClose,\n message,\n actionLabel = \"Undo\",\n onAction,\n duration = 5000,\n colors,\n style,\n}: UndoSnackbarProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const t = useRef(new Animated.Value(0)).current;\n const timer = useRef(new Animated.Value(1)).current;\n const [mounted, setMounted] = useState(open);\n const live = useRef({ onClose });\n live.current = { onClose };\n\n useEffect(() => {\n if (open) setMounted(true);\n if (reduceMotion) {\n t.setValue(open ? 1 : 0);\n if (!open) setMounted(false);\n return;\n }\n Animated.spring(t, {\n toValue: open ? 1 : 0,\n stiffness: 380,\n damping: 30,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start(({ finished }) => {\n if (finished && !open) setMounted(false);\n });\n }, [open, reduceMotion, t]);\n\n useEffect(() => {\n if (!open) return;\n AccessibilityInfo.announceForAccessibility(message);\n timer.setValue(1);\n const drain = Animated.timing(timer, {\n toValue: 0,\n duration,\n easing: Easing.linear,\n useNativeDriver: false,\n });\n if (!reduceMotion) drain.start();\n const id = setTimeout(() => live.current.onClose(), duration);\n return () => {\n drain.stop();\n clearTimeout(id);\n };\n }, [open, message, duration, reduceMotion, timer]);\n\n if (!mounted) return null;\n\n return (\n \n \n {message}\n {\n onAction?.();\n onClose();\n }}\n hitSlop={8}\n style={styles.action}\n >\n {actionLabel}\n \n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: {\n position: \"absolute\",\n left: 16,\n right: 16,\n bottom: 16,\n borderRadius: 14,\n overflow: \"hidden\",\n boxShadow: \"0 8px 24px rgba(0, 0, 0, 0.25)\",\n },\n row: { flexDirection: \"row\", alignItems: \"center\", gap: 12, paddingLeft: 16, minHeight: 52 },\n message: { flex: 1, fontSize: 15 },\n action: { minHeight: 52, paddingHorizontal: 16, justifyContent: \"center\", userSelect: \"none\" },\n actionText: { fontSize: 15, fontWeight: \"800\" },\n timer: { height: 3 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/wave-bars.json b/public/registry/wave-bars.json new file mode 100644 index 0000000..d847307 --- /dev/null +++ b/public/registry/wave-bars.json @@ -0,0 +1,15 @@ +{ + "name": "wave-bars", + "title": "Wave Bars", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-03", + "dependencies": [], + "files": [ + { + "path": "registry/wave-bars.tsx", + "content": "import { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n StyleSheet,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface WaveBarsColors {\n bar: string;\n played: string;\n}\n\nconst DEFAULT_COLORS: WaveBarsColors = {\n bar: \"#c7d2fe\",\n played: \"#4f46e5\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface WaveBarsProps {\n /** Makes the bars dance. */\n playing?: boolean;\n /** How many bars to draw. */\n count?: number;\n /** Height of the tallest bar. */\n height?: number;\n /** Colours the bars up to this fraction, from 0 to 1, as already played. */\n progress?: number;\n /** Spoken name of the waveform. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n// A fixed, repeatable shape so the bars look like a recording rather than noise.\nconst shape = (i: number) => 0.35 + 0.65 * Math.abs(Math.sin(i * 1.7) * Math.cos(i * 0.6));\n\n/**\n * A row of bars drawn like an audio waveform. At rest they keep their recorded shape. While\n * `playing` each bar swells and settles out of step with its neighbours, and `progress` tints the\n * bars already played. With reduced motion the bars hold still.\n */\nexport function WaveBars({\n playing = false,\n count = 24,\n height = 40,\n progress = 0,\n label = \"Waveform\",\n colors,\n style,\n}: WaveBarsProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const t = useRef(new Animated.Value(0)).current;\n const items = useMemo(() => Array.from({ length: count }, (_, i) => i), [count]);\n\n useEffect(() => {\n if (!playing || reduceMotion) {\n t.setValue(0);\n return;\n }\n const loop = Animated.loop(\n Animated.timing(t, {\n toValue: 1,\n duration: 900,\n easing: Easing.linear,\n useNativeDriver: NATIVE_DRIVER,\n }),\n );\n loop.start();\n return () => loop.stop();\n }, [playing, reduceMotion, t]);\n\n return (\n \n {items.map((i) => {\n const base = shape(i);\n const start = (i % 6) / 6;\n const scale = t.interpolate({\n inputRange: [0, start, Math.min(1, start + 0.3), 1],\n outputRange: [1, 1, 0.45, 1],\n extrapolate: \"clamp\",\n });\n return (\n \n );\n })}\n \n );\n}\n\nconst styles = StyleSheet.create({\n row: { flexDirection: \"row\", alignItems: \"center\", gap: 3 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/wheel-picker.json b/public/registry/wheel-picker.json new file mode 100644 index 0000000..b04c8e0 --- /dev/null +++ b/public/registry/wheel-picker.json @@ -0,0 +1,15 @@ +{ + "name": "wheel-picker", + "title": "Wheel Picker", + "category": "React Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-02", + "dependencies": [], + "files": [ + { + "path": "registry/wheel-picker.tsx", + "content": "import { useEffect, useMemo, useRef, useState, type ElementRef } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n Pressable,\n ScrollView,\n StyleSheet,\n View,\n type NativeScrollEvent,\n type NativeSyntheticEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n// How long the scroll must be still before a mouse wheel counts as settled.\nconst SETTLE_MS = 140;\n\nexport interface WheelPickerOption {\n value: string;\n label: string;\n}\n\nexport interface WheelPickerColors {\n text: string;\n selectedText: string;\n highlight: string;\n}\n\nconst DEFAULT_COLORS: WheelPickerColors = {\n text: \"#6b7280\",\n selectedText: \"#111827\",\n highlight: \"#f3f4f6\",\n};\n\nfunction useReduceMotion() {\n const [reduce, setReduce] = useState(false);\n useEffect(() => {\n AccessibilityInfo.isReduceMotionEnabled().then(setReduce);\n const sub = AccessibilityInfo.addEventListener(\"reduceMotionChanged\", setReduce);\n return () => sub.remove();\n }, []);\n return reduce;\n}\n\nexport interface WheelPickerProps {\n options: WheelPickerOption[];\n /** The selected option's `value`. */\n value: string;\n /** Called once the wheel settles on a different option, not on every frame of the scroll. */\n onChange: (value: string) => void;\n /** Height of one row. */\n itemHeight?: number;\n /** How many rows are visible. Use an odd number so one row sits in the middle. */\n visibleCount?: number;\n /** Spoken name of the wheel, for example \"Hour\". */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * An iOS-style scrolling wheel. Rows snap to the middle, shrink and fade with their distance from it,\n * and `onChange` fires when the wheel comes to rest, including when a mouse wheel stops. A tap on a\n * row brings it to the middle, and screen readers can step through the options.\n */\nexport function WheelPicker({\n options,\n value,\n onChange,\n itemHeight = 40,\n visibleCount = 5,\n label = \"Picker\",\n colors,\n style,\n}: WheelPickerProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const scroll = useRef>(null);\n const y = useRef(new Animated.Value(0)).current;\n const offset = useRef(0);\n const timer = useRef | null>(null);\n\n const index = Math.max(\n 0,\n options.findIndex((option) => option.value === value),\n );\n // The option the wheel last settled on, so a settle that changes nothing stays quiet.\n const settled = useRef(index);\n const rows = Math.max(1, visibleCount);\n const pad = Math.floor(rows / 2) * itemHeight;\n\n const live = useRef({ options, itemHeight, reduceMotion, onChange });\n live.current = { options, itemHeight, reduceMotion, onChange };\n\n const scrollToIndex = (target: number, animated = !live.current.reduceMotion) => {\n scroll.current?.scrollTo({ y: target * live.current.itemHeight, animated });\n };\n\n const settle = () => {\n const { options: list, itemHeight: h } = live.current;\n const next = Math.max(0, Math.min(list.length - 1, Math.round(offset.current / h)));\n // On the web a wheel can stop between rows, so finish the snap by hand.\n if (Math.abs(offset.current - next * h) > 1) scrollToIndex(next);\n if (next !== settled.current) {\n settled.current = next;\n live.current.onChange(list[next].value);\n }\n };\n\n const queueSettle = () => {\n if (timer.current) clearTimeout(timer.current);\n timer.current = setTimeout(settle, SETTLE_MS);\n };\n\n useEffect(\n () => () => {\n if (timer.current) clearTimeout(timer.current);\n },\n [],\n );\n\n // Start on the selected row, and follow `value` when it changes from outside.\n useEffect(() => {\n if (index === settled.current && Math.abs(offset.current - index * itemHeight) < 2) return;\n settled.current = index;\n scrollToIndex(index, offset.current !== 0);\n // scrollToIndex reads everything through refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [index, itemHeight]);\n\n const onScroll = (event: NativeSyntheticEvent) => {\n offset.current = event.nativeEvent.contentOffset.y;\n queueSettle();\n };\n\n const step = (direction: 1 | -1) => {\n const next = Math.max(0, Math.min(options.length - 1, index + direction));\n if (next === index) return;\n settled.current = next;\n scrollToIndex(next);\n onChange(options[next].value);\n };\n\n const rowStyles = useMemo(\n () =>\n options.map((_, i) => {\n const at = (n: number) => (i + n) * itemHeight;\n const range = [at(-2), at(-1), at(0), at(1), at(2)];\n return {\n opacity: y.interpolate({\n inputRange: range,\n outputRange: [0.25, 0.5, 1, 0.5, 0.25],\n extrapolate: \"clamp\",\n }),\n scale: reduceMotion\n ? 1\n : y.interpolate({\n inputRange: range,\n outputRange: [0.8, 0.9, 1, 0.9, 0.8],\n extrapolate: \"clamp\",\n }),\n // The selected colour fades in over the plain one as a row nears the middle.\n selected: y.interpolate({\n inputRange: [at(-1), at(0), at(1)],\n outputRange: [0, 1, 0],\n extrapolate: \"clamp\",\n }),\n };\n }),\n [options, itemHeight, y, reduceMotion],\n );\n\n return (\n step(event.nativeEvent.actionName === \"increment\" ? 1 : -1)}\n style={[styles.root, { height: itemHeight * rows }, style]}\n >\n \n \n {options.map((option, i) => (\n {\n scrollToIndex(i);\n offset.current = i * itemHeight;\n queueSettle();\n }}\n style={{ height: itemHeight, justifyContent: \"center\", alignItems: \"center\" }}\n >\n \n \n {option.label}\n \n \n {option.label}\n \n \n \n ))}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { overflow: \"hidden\", userSelect: \"none\" },\n band: { position: \"absolute\", left: 0, right: 0, borderRadius: 10 },\n label: { fontSize: 20, fontWeight: \"600\", textAlign: \"center\" },\n over: { position: \"absolute\", left: 0, right: 0, top: 0 },\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 a8e4454..f6a7a8f 100644 --- a/src/app/components/[slug]/page.tsx +++ b/src/app/components/[slug]/page.tsx @@ -28,9 +28,20 @@ export async function generateMetadata({ params }: PageProps): Promise if (!doc) return {}; const { title, description } = doc.frontmatter; const url = `/components/${params.slug}`; + const entry = registry.find((item) => item.name === params.slug); + const native = entry ? platformOf(entry) === "native" : false; + const keywords = [ + title, + ...(native + ? [`${title} React Native`, "React Native component", "Expo component"] + : [`${title} React`, "React component"]), + ...(entry ? [entry.category] : []), + ...SITE.keywords.slice(0, 4), + ]; return { title, description, + keywords, alternates: { canonical: url }, openGraph: { type: "article", siteName: SITE.name, title, description, url }, twitter: { card: "summary_large_image", title, description }, diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 808b138..160817a 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -58,6 +58,7 @@ export const metadata: Metadata = { metadataBase: new URL(SITE.url), title: { default: SITE.name, template: `%s · ${SITE.name}` }, description: SITE.description, + keywords: [...SITE.keywords], openGraph: { type: "website", siteName: SITE.name, diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts index 01f483f..2e8a501 100644 --- a/src/app/sitemap.ts +++ b/src/app/sitemap.ts @@ -1,13 +1,25 @@ import type { MetadataRoute } from "next"; -import { registry } from "@/registry"; +import { registry as all, type RegistryItem } from "@/registry"; import { SITE } from "@/lib/site"; +const registry: readonly RegistryItem[] = all; + export default function sitemap(): MetadataRoute.Sitemap { - const paths = [ - "/", - "/components", - ...registry.map((item) => `/components/${item.name}`), - "/blog", + const added = registry.flatMap((item) => (item.added ? [item.added] : [])); + const newest = added.sort().at(-1); + const top = [ + { path: "/", lastModified: newest, priority: 1 }, + { path: "/components", lastModified: newest, priority: 0.9 }, + { path: "/blog", lastModified: undefined, priority: 0.5 }, ]; - return paths.map((path) => ({ url: new URL(path, SITE.url).toString() })); + const components = registry.map((item) => ({ + path: `/components/${item.name}`, + lastModified: item.added, + priority: 0.7, + })); + return [...top, ...components].map(({ path, lastModified, priority }) => ({ + url: new URL(path, SITE.url).toString(), + ...(lastModified ? { lastModified } : {}), + priority, + })); } diff --git a/src/content/docs/action-button.mdx b/src/content/docs/action-button.mdx new file mode 100644 index 0000000..70ceed0 --- /dev/null +++ b/src/content/docs/action-button.mdx @@ -0,0 +1,58 @@ +--- +title: Action Button +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. +--- + +A button that carries its own progress. Press it and, if the action returns a promise, the label gives way to a spinner, then to a tick that pops in, or a cross and a shake if it fails, before it settles back to idle. The button never changes size, so nothing around it moves, the outcome is read out to screen readers, and pressing while it is busy does nothing. 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 action-button +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/action-button.tsx`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { ActionButton } from "@/components/ui/action-button"; + +export default function Example() { + return ( + { + await fetch("/api/save", { method: "POST" }); + }} + /> + ); +} +``` + +## Props + +| Prop | Type | Default | Description | +| :------------- | :-------------------------------------------- | :--------- | :---------------------------------------------------------------------------------- | +| `label` | `string` | - | The button's text. | +| `onPress` | `() => void \| Promise` | - | Called on press. If it returns a promise the button shows loading until it settles. | +| `status` | `"idle" \| "loading" \| "success" \| "error"` | - | Sets the state yourself instead of following the promise. | +| `variant` | `"solid" \| "outline" \| "ghost"` | `"solid"` | How the button is drawn. | +| `size` | `"md" \| "lg"` | `"md"` | Height of the button. | +| `successLabel` | `string` | `"Done"` | Text announced in the success state. | +| `errorLabel` | `string` | `"Failed"` | Text announced in the error state. | +| `resetAfter` | `number` | `1600` | Milliseconds the success or error state stays before going back to idle. | +| `disabled` | `boolean` | `false` | Dims the button and ignores presses. | +| `fullWidth` | `boolean` | `false` | Stretches the button to the full width of its parent. | +| `colors` | `Partial` | - | Overrides `background`, `text`, `success` and `error`. | +| `style` | `StyleProp` | - | Style for the button's outer wrapper. | diff --git a/src/content/docs/action-tray.mdx b/src/content/docs/action-tray.mdx new file mode 100644 index 0000000..2e1248a --- /dev/null +++ b/src/content/docs/action-tray.mdx @@ -0,0 +1,66 @@ +--- +title: Action Tray +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. +--- + +A bottom action list in the style of a native action sheet. It slides up from the bottom of its parent over a dimmed backdrop, with the actions as one rounded group and Cancel as a separate button. Tap the backdrop, press Escape on the web, or drag the handle down to close it. It is drawn inside its parent, so it works in a screen, a tab or a `Modal` alike, and on the web it stays inside whatever frame holds 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 action-tray +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/action-tray.tsx`. +3. Paste the code. + +It needs no packages beyond `react-native`, which your Expo or React Native app already has. + +## Usage + +```tsx +import { useState } from "react"; +import { Button, View } from "react-native"; +import { ActionTray } from "@/components/ui/action-tray"; + +export default function Example() { + const [open, setOpen] = useState(false); + + return ( + +