From 6aa05c2de0f04b3f0c5f7b85b3187f56c4cc7bd5 Mon Sep 17 00:00:00 2001 From: kasimkazmi Date: Sun, 1 Nov 2026 14:59:25 -0500 Subject: [PATCH 1/6] feat: Add six more native components and platform icons on every component Flick Toast, Fold Panel, Snap Carousel, Slide Switch, Shimmer Block and Parallax Header. The sidebar, the components index and each component page now show a phone icon for React Native components and a globe for web ones. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 18 +- public/registry/flick-toast.json | 15 + public/registry/fold-panel.json | 15 + public/registry/index.json | 50 +++- public/registry/parallax-header.json | 15 + public/registry/shimmer-block.json | 15 + public/registry/slide-switch.json | 15 + public/registry/snap-carousel.json | 15 + src/app/components/[slug]/page.tsx | 9 + src/app/components/layout.tsx | 9 +- src/app/components/page.tsx | 13 +- src/components/platform-icon.tsx | 33 +++ src/components/sidebar-nav.tsx | 4 +- src/content/docs/flick-toast.mdx | 67 +++++ src/content/docs/fold-panel.mdx | 61 ++++ src/content/docs/parallax-header.mdx | 55 ++++ src/content/docs/shimmer-block.mdx | 63 +++++ src/content/docs/slide-switch.mdx | 51 ++++ src/content/docs/snap-carousel.mdx | 65 +++++ src/lib/registry.ts | 5 + src/registry/demos.ts | 6 + src/registry/flick-toast-demo.tsx | 99 +++++++ src/registry/flick-toast.tsx | 382 ++++++++++++++++++++++++++ src/registry/fold-panel-demo.tsx | 92 +++++++ src/registry/fold-panel.tsx | 229 +++++++++++++++ src/registry/index.ts | 60 ++++ src/registry/parallax-header-demo.tsx | 88 ++++++ src/registry/parallax-header.tsx | 177 ++++++++++++ src/registry/shimmer-block-demo.tsx | 121 ++++++++ src/registry/shimmer-block.tsx | 169 ++++++++++++ src/registry/slide-switch-demo.tsx | 73 +++++ src/registry/slide-switch.tsx | 206 ++++++++++++++ src/registry/snap-carousel-demo.tsx | 59 ++++ src/registry/snap-carousel.tsx | 311 +++++++++++++++++++++ 34 files changed, 2650 insertions(+), 15 deletions(-) create mode 100644 public/registry/flick-toast.json create mode 100644 public/registry/fold-panel.json create mode 100644 public/registry/parallax-header.json create mode 100644 public/registry/shimmer-block.json create mode 100644 public/registry/slide-switch.json create mode 100644 public/registry/snap-carousel.json create mode 100644 src/components/platform-icon.tsx create mode 100644 src/content/docs/flick-toast.mdx create mode 100644 src/content/docs/fold-panel.mdx create mode 100644 src/content/docs/parallax-header.mdx create mode 100644 src/content/docs/shimmer-block.mdx create mode 100644 src/content/docs/slide-switch.mdx create mode 100644 src/content/docs/snap-carousel.mdx create mode 100644 src/registry/flick-toast-demo.tsx create mode 100644 src/registry/flick-toast.tsx create mode 100644 src/registry/fold-panel-demo.tsx create mode 100644 src/registry/fold-panel.tsx create mode 100644 src/registry/parallax-header-demo.tsx create mode 100644 src/registry/parallax-header.tsx create mode 100644 src/registry/shimmer-block-demo.tsx create mode 100644 src/registry/shimmer-block.tsx create mode 100644 src/registry/slide-switch-demo.tsx create mode 100644 src/registry/slide-switch.tsx create mode 100644 src/registry/snap-carousel-demo.tsx create mode 100644 src/registry/snap-carousel.tsx diff --git a/README.md b/README.md index 8289dce..ed43aa1 100644 --- a/README.md +++ b/README.md @@ -83,15 +83,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 | -| **Native** | Swipe Actions, Snap Sheet, Glide Segments, Swipe Deck, Fan Menu, Pin Pad | +| 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 | +| **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 | **Native** components are React Native (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/flick-toast.json b/public/registry/flick-toast.json new file mode 100644 index 0000000..1d41025 --- /dev/null +++ b/public/registry/flick-toast.json @@ -0,0 +1,15 @@ +{ + "name": "flick-toast", + "title": "Flick Toast", + "category": "Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-01", + "dependencies": [], + "files": [ + { + "path": "registry/flick-toast.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\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 MAX_VISIBLE = 3;\n// Each toast behind the front one sits this much smaller and further from the edge.\nconst DEPTH_SCALE = 0.05;\nconst DEPTH_SHIFT = 10;\n\ntype Tone = \"default\" | \"success\" | \"error\";\ntype Exit = \"left\" | \"right\" | \"edge\";\n\nexport interface FlickToastItem {\n id: string;\n title: string;\n description?: string;\n tone?: Tone;\n}\n\nexport interface FlickToastColors {\n surface: string;\n text: string;\n mutedText: string;\n border: string;\n accent: string;\n success: string;\n error: string;\n}\n\nconst DEFAULT_COLORS: FlickToastColors = {\n surface: \"#111827\",\n text: \"#ffffff\",\n mutedText: \"#d1d5db\",\n border: \"rgba(255, 255, 255, 0.12)\",\n accent: \"#818cf8\",\n success: \"#22c55e\",\n error: \"#ef4444\",\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 FlickToastProps {\n /** The toasts to show, oldest first. The host owns the list: remove a toast in `onDismiss`. */\n toasts: FlickToastItem[];\n /** Called once a toast has left, whether it timed out, was flicked away or dismissed by a screen reader. */\n onDismiss: (id: string) => void;\n /** Milliseconds the front toast stays before it leaves. 0 keeps toasts until they are dismissed. */\n duration?: number;\n /** Which edge the stack sits against. */\n position?: \"top\" | \"bottom\";\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A stack of toasts you flick away. The newest slides in at the front with the older ones scaled back\n * behind it, a thin line counts down the front toast's time (and waits while you hold it), and a\n * sideways or toward-the-edge flick sends it off. Draws inside its parent, which must fill the area\n * the toasts should float over. Each toast is a live region with a dismiss action for screen readers.\n */\nexport function FlickToast({\n toasts,\n onDismiss,\n duration = 4000,\n position = \"top\",\n colors,\n style,\n}: FlickToastProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n // Newest first, so a toast's index is its depth in the stack.\n const visible = toasts.slice(-MAX_VISIBLE).reverse();\n\n return (\n \n {/* The front toast is drawn last, so it sits above the rest. */}\n {[...visible].reverse().map((item) => (\n \n ))}\n \n );\n}\n\ninterface ToastCardProps {\n item: FlickToastItem;\n depth: number;\n position: \"top\" | \"bottom\";\n duration: number;\n colors: FlickToastColors;\n reduceMotion: boolean;\n onDismiss: (id: string) => void;\n}\n\nfunction ToastCard({\n item,\n depth,\n position,\n duration,\n colors,\n reduceMotion,\n onDismiss,\n}: ToastCardProps) {\n // -1 when the edge is up (top), 1 when it is down (bottom): the direction \"toward the edge\".\n const edge = position === \"top\" ? -1 : 1;\n const enter = useRef(new Animated.Value(reduceMotion ? 1 : 0)).current;\n const stack = useRef(new Animated.Value(depth)).current;\n const fade = useRef(new Animated.Value(1)).current;\n const x = useRef(new Animated.Value(0)).current;\n const y = useRef(new Animated.Value(0)).current;\n // 1 to 0 over `duration`. Driven from JS so its current level can be read when paused.\n const remaining = useRef(new Animated.Value(1)).current;\n const level = useRef(1);\n const size = useRef({ width: 360, height: 72 });\n const leaving = useRef(false);\n const holding = useRef(false);\n const isFront = depth === 0;\n const live = useRef({ duration, edge, reduceMotion, onDismiss, isFront });\n live.current = { duration, edge, reduceMotion, onDismiss, isFront };\n\n useEffect(() => {\n const id = remaining.addListener(({ value }) => (level.current = value));\n return () => remaining.removeListener(id);\n }, [remaining]);\n\n useEffect(() => {\n if (!live.current.reduceMotion) {\n Animated.spring(enter, {\n toValue: 1,\n stiffness: 300,\n damping: 24,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }\n }, [enter]);\n\n useEffect(() => {\n if (reduceMotion) {\n stack.setValue(depth);\n return;\n }\n Animated.spring(stack, {\n toValue: depth,\n stiffness: 320,\n damping: 26,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [depth, reduceMotion, stack]);\n\n const run = () => {\n const total = live.current.duration;\n if (total <= 0 || leaving.current || holding.current) return;\n Animated.timing(remaining, {\n toValue: 0,\n duration: total * level.current,\n easing: Easing.linear,\n useNativeDriver: false,\n }).start(({ finished }) => {\n if (finished) leave(\"edge\");\n });\n };\n\n const leave = (exit: Exit) => {\n if (leaving.current) return;\n leaving.current = true;\n remaining.stopAnimation();\n const { edge: toward, reduceMotion: reduce, onDismiss: done } = live.current;\n if (reduce) {\n done(item.id);\n return;\n }\n const { width, height } = size.current;\n const move =\n exit === \"edge\"\n ? Animated.timing(y, {\n toValue: toward * (height + 80),\n duration: 220,\n useNativeDriver: NATIVE_DRIVER,\n })\n : Animated.timing(x, {\n toValue: (exit === \"right\" ? 1 : -1) * (width + 60),\n duration: 220,\n useNativeDriver: NATIVE_DRIVER,\n });\n Animated.parallel([\n move,\n Animated.timing(fade, { toValue: 0, duration: 220, useNativeDriver: NATIVE_DRIVER }),\n ]).start(() => done(item.id));\n };\n\n // The countdown belongs to the front toast; one pushed behind keeps the time it has left.\n useEffect(() => {\n if (isFront) run();\n return () => remaining.stopAnimation();\n // run reads everything through refs, so it only needs to start when the toast reaches the front.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isFront, duration]);\n\n const springBack = () => {\n holding.current = false;\n if (live.current.reduceMotion) {\n x.setValue(0);\n y.setValue(0);\n } else {\n const back = (value: Animated.Value) =>\n Animated.spring(value, {\n toValue: 0,\n stiffness: 360,\n damping: 28,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n });\n Animated.parallel([back(x), back(y)]).start();\n }\n if (live.current.isFront) run();\n };\n\n const pan = useRef(\n PanResponder.create({\n onStartShouldSetPanResponder: () => true,\n onMoveShouldSetPanResponder: () => true,\n onPanResponderGrant: () => {\n // Holding a toast stops its clock.\n holding.current = true;\n remaining.stopAnimation();\n x.stopAnimation();\n y.stopAnimation();\n },\n onPanResponderMove: (_, g) => {\n x.setValue(g.dx);\n // Toward the edge it follows the finger; the other way it resists.\n y.setValue(g.dy * live.current.edge > 0 ? g.dy : g.dy / 5);\n },\n onPanResponderRelease: (_, g) => {\n const toward = g.dy * live.current.edge;\n const towardSpeed = g.vy * live.current.edge;\n const sideways = Math.abs(g.dx) > 90 || (Math.abs(g.vx) > 0.8 && g.dx * g.vx > 0);\n if (sideways) {\n holding.current = false;\n leave(g.dx > 0 ? \"right\" : \"left\");\n } else if (toward > 40 || towardSpeed > 0.7) {\n holding.current = false;\n leave(\"edge\");\n } else {\n springBack();\n }\n },\n onPanResponderTerminate: () => springBack(),\n }),\n ).current;\n\n const tone = item.tone ?? \"default\";\n const toneColor =\n tone === \"success\" ? colors.success : tone === \"error\" ? colors.error : colors.accent;\n\n const enterShift = enter.interpolate({ inputRange: [0, 1], outputRange: [edge * 28, 0] });\n const stackShift = stack.interpolate({\n inputRange: [0, 1, 2],\n outputRange: [0, -edge * DEPTH_SHIFT, -edge * DEPTH_SHIFT * 2],\n });\n const scale = stack.interpolate({\n inputRange: [0, 1, 2],\n outputRange: [1, 1 - DEPTH_SCALE, 1 - DEPTH_SCALE * 2],\n });\n const stackOpacity = stack.interpolate({ inputRange: [0, 1, 2], outputRange: [1, 0.85, 0.7] });\n const tilt = reduceMotion\n ? \"0deg\"\n : x.interpolate({ inputRange: [-300, 0, 300], outputRange: [\"-6deg\", \"0deg\", \"6deg\"] });\n\n return (\n leave(\"edge\")}\n onLayout={(event: LayoutChangeEvent) => (size.current = event.nativeEvent.layout)}\n pointerEvents={isFront ? \"auto\" : \"none\"}\n style={[\n styles.card,\n position === \"top\" ? styles.atTop : styles.atBottom,\n {\n backgroundColor: colors.surface,\n borderColor: colors.border,\n opacity: Animated.multiply(Animated.multiply(enter, stackOpacity), fade),\n transform: [\n { translateX: x },\n { translateY: Animated.add(Animated.add(enterShift, stackShift), y) },\n { rotate: tilt },\n { scale },\n ],\n },\n ]}\n >\n \n \n \n \n {item.title}\n \n {item.description ? (\n \n {item.description}\n \n ) : null}\n \n \n {duration > 0 ? (\n \n \n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 },\n // userSelect keeps a mouse drag on the web from selecting the text instead of moving the toast.\n card: {\n position: \"absolute\",\n left: 16,\n right: 16,\n borderRadius: 16,\n borderWidth: 1,\n overflow: \"hidden\",\n userSelect: \"none\",\n boxShadow: \"0 10px 28px rgba(0, 0, 0, 0.28)\",\n },\n atTop: { top: 16 },\n atBottom: { bottom: 16 },\n row: {\n flexDirection: \"row\",\n alignItems: \"flex-start\",\n gap: 12,\n paddingHorizontal: 16,\n paddingVertical: 14,\n },\n dot: { width: 8, height: 8, borderRadius: 4, marginTop: 6 },\n copy: { flex: 1, gap: 2 },\n title: { fontSize: 15, fontWeight: \"600\" },\n description: { fontSize: 13, lineHeight: 18 },\n track: { height: 3, width: \"100%\" },\n line: { height: 3, width: \"100%\", transformOrigin: \"left\", opacity: 0.9 },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/fold-panel.json b/public/registry/fold-panel.json new file mode 100644 index 0000000..ad2facf --- /dev/null +++ b/public/registry/fold-panel.json @@ -0,0 +1,15 @@ +{ + "name": "fold-panel", + "title": "Fold Panel", + "category": "Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-01", + "dependencies": [], + "files": [ + { + "path": "registry/fold-panel.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\";\n\nexport interface FoldPanelItem {\n id: string;\n title: string;\n content: ReactNode;\n}\n\nexport interface FoldPanelColors {\n surface: string;\n text: string;\n mutedText: string;\n border: string;\n}\n\nconst DEFAULT_COLORS: FoldPanelColors = {\n surface: \"#ffffff\",\n text: \"#111827\",\n mutedText: \"#6b7280\",\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 FoldPanelProps {\n items: FoldPanelItem[];\n /** Whether several panels can be open at once. When false, opening one closes the others. */\n multiple?: boolean;\n /** Ids of the panels that start open. */\n defaultOpen?: string[];\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * An accordion whose panels grow to exactly the height of their content, measured rather than\n * guessed, so any content works. The chevron turns as a panel opens, and every header is a button\n * that tells screen readers whether it is expanded. Closed panels are hidden from them.\n */\nexport function FoldPanel({\n items,\n multiple = false,\n defaultOpen = [],\n colors,\n style,\n}: FoldPanelProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [open, setOpen] = useState(defaultOpen);\n\n const toggle = (id: string) =>\n setOpen((current) =>\n current.includes(id)\n ? current.filter((value) => value !== id)\n : multiple\n ? [...current, id]\n : [id],\n );\n\n return (\n \n {items.map((item, index) => (\n toggle(item.id)}\n />\n ))}\n \n );\n}\n\ninterface FoldRowProps {\n item: FoldPanelItem;\n open: boolean;\n last: boolean;\n colors: FoldPanelColors;\n reduceMotion: boolean;\n onToggle: () => void;\n}\n\nfunction FoldRow({ item, open, last, colors, reduceMotion, onToggle }: FoldRowProps) {\n const [measured, setMeasured] = useState(0);\n // Height can't use the native driver, so it gets its own value; the turn and fade ride the native one.\n const height = useRef(new Animated.Value(0)).current;\n const turn = useRef(new Animated.Value(open ? 1 : 0)).current;\n const placed = useRef(false);\n\n useEffect(() => {\n const target = open ? measured : 0;\n // The first measurement sets the height outright, so a panel that starts open does not animate in.\n if (!placed.current) {\n if (measured === 0) return;\n placed.current = true;\n height.setValue(target);\n return;\n }\n if (reduceMotion) {\n height.setValue(target);\n return;\n }\n Animated.timing(height, {\n toValue: target,\n duration: 260,\n useNativeDriver: false,\n }).start();\n }, [open, measured, reduceMotion, height]);\n\n useEffect(() => {\n if (reduceMotion) {\n turn.setValue(open ? 1 : 0);\n return;\n }\n Animated.spring(turn, {\n toValue: open ? 1 : 0,\n stiffness: 300,\n damping: 26,\n mass: 1,\n useNativeDriver: NATIVE_DRIVER,\n }).start();\n }, [open, reduceMotion, turn]);\n\n return (\n \n [styles.header, pressed && styles.pressed]}\n >\n {item.title}\n \n \n \n setMeasured(event.nativeEvent.layout.height)}\n style={[styles.body, { opacity: turn }]}\n >\n {item.content}\n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { borderWidth: 1, borderRadius: 18, overflow: \"hidden\" },\n header: {\n minHeight: 56,\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n gap: 12,\n paddingHorizontal: 18,\n paddingVertical: 12,\n },\n pressed: { opacity: 0.7 },\n title: { flex: 1, fontSize: 16, fontWeight: \"600\" },\n chevron: {\n width: 9,\n height: 9,\n marginBottom: 3,\n borderRightWidth: 2,\n borderBottomWidth: 2,\n },\n clip: { overflow: \"hidden\" },\n // Absolute so the body lays out at its natural height, whatever height the clip is animating to.\n body: {\n position: \"absolute\",\n top: 0,\n left: 0,\n right: 0,\n paddingHorizontal: 18,\n paddingBottom: 18,\n },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/index.json b/public/registry/index.json index 5b949a0..ca5422b 100644 --- a/public/registry/index.json +++ b/public/registry/index.json @@ -1,7 +1,7 @@ { "name": "Modus UI", "homepage": "https://modusui.kasimkazmi.com", - "count": 217, + "count": 223, "categories": [ "Navigation", "Actions", @@ -2648,6 +2648,54 @@ "platform": "native", "description": "A React Native numeric keypad for PINs and passcodes, with popping dots, a shake on a wrong PIN and spoken progress.", "dependencies": [] + }, + { + "name": "flick-toast", + "title": "Flick Toast", + "category": "Native", + "platform": "native", + "description": "A React Native stack of toasts you flick away, with a countdown line that waits while you hold, older toasts scaled back, and screen reader dismiss.", + "dependencies": [] + }, + { + "name": "fold-panel", + "title": "Fold Panel", + "category": "Native", + "platform": "native", + "description": "A React Native accordion whose panels grow to the measured height of their content, with a turning chevron and screen reader state.", + "dependencies": [] + }, + { + "name": "snap-carousel", + "title": "Snap Carousel", + "category": "Native", + "platform": "native", + "description": "A React Native carousel that settles on one card at a time, with neighbors that shrink and fade and dots that stretch to follow.", + "dependencies": [] + }, + { + "name": "slide-switch", + "title": "Slide Switch", + "category": "Native", + "platform": "native", + "description": "A React Native switch whose thumb can be dragged as well as tapped, stretching while held and settling on the nearer side.", + "dependencies": [] + }, + { + "name": "shimmer-block", + "title": "Shimmer Block", + "category": "Native", + "platform": "native", + "description": "A React Native loading placeholder with a soft highlight that sweeps across it, stacked lines that shimmer together, and one spoken \"Loading\" for the whole block.", + "dependencies": [] + }, + { + "name": "parallax-header", + "title": "Parallax Header", + "category": "Native", + "platform": "native", + "description": "A React Native scroll view whose hero stretches on overscroll, drifts at half speed, and collapses into a compact title bar.", + "dependencies": [] } ], "renamed": { diff --git a/public/registry/parallax-header.json b/public/registry/parallax-header.json new file mode 100644 index 0000000..6d66e62 --- /dev/null +++ b/public/registry/parallax-header.json @@ -0,0 +1,15 @@ +{ + "name": "parallax-header", + "title": "Parallax Header", + "category": "Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-01", + "dependencies": [], + "files": [ + { + "path": "registry/parallax-header.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 LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\nexport interface ParallaxHeaderColors {\n background: string;\n bar: string;\n title: string;\n border: string;\n}\n\nconst DEFAULT_COLORS: ParallaxHeaderColors = {\n background: \"#ffffff\",\n bar: \"#ffffff\",\n title: \"#111827\",\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 ParallaxHeaderProps {\n /** The hero's content. It fills the hero, so give it a background or an image. */\n header: ReactNode;\n /** The scrolling content. */\n children: ReactNode;\n /** Height of the hero before any scrolling. */\n headerHeight?: number;\n /** Height of the bar the hero collapses into. */\n collapsedHeight?: number;\n /** Shown in the collapsed bar. */\n title?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A scroll view with a hero that stretches when pulled past the top, drifts at half speed as you\n * scroll, and ends as a compact bar whose title fades in. The content slides over the hero, so give\n * the hero a full-bleed background. With reduced motion the hero scrolls with the content and the\n * bar simply appears once it is covered.\n */\nexport function ParallaxHeader({\n header,\n children,\n headerHeight = 220,\n collapsedHeight = 56,\n title,\n colors,\n style,\n}: ParallaxHeaderProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const scrollY = useRef(new Animated.Value(0)).current;\n const [viewport, setViewport] = useState(0);\n\n // Scroll distance over which the hero collapses into the bar.\n const range = Math.max(1, headerHeight - collapsedHeight);\n\n const heroTranslate = reduceMotion\n ? scrollY.interpolate({ inputRange: [-1, 0, 1], outputRange: [0, 0, -1] })\n : scrollY.interpolate({\n inputRange: [-headerHeight, 0, headerHeight],\n // Pulled down, the hero is pushed half as far as it grows, which keeps its top edge fixed.\n outputRange: [headerHeight / 2, 0, -headerHeight * 0.5],\n });\n const heroScale = reduceMotion\n ? 1\n : scrollY.interpolate({\n inputRange: [-headerHeight, 0],\n outputRange: [2, 1],\n extrapolateRight: \"clamp\",\n });\n const barOpacity = reduceMotion\n ? scrollY.interpolate({\n inputRange: [range - 1, range],\n outputRange: [0, 1],\n extrapolate: \"clamp\",\n })\n : scrollY.interpolate({\n inputRange: [range * 0.55, range],\n outputRange: [0, 1],\n extrapolate: \"clamp\",\n });\n\n return (\n setViewport(event.nativeEvent.layout.height)}\n style={[styles.root, { backgroundColor: palette.background }, style]}\n >\n \n {header}\n \n \n \n {children}\n \n \n \n {title ? (\n \n {title}\n \n ) : null}\n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { flex: 1, overflow: \"hidden\" },\n hero: { position: \"absolute\", top: 0, left: 0, right: 0, overflow: \"hidden\" },\n scroll: { flex: 1, backgroundColor: \"transparent\" },\n // The content overlaps the hero's lower edge, so its rounded top corners read as a sheet.\n sheet: { borderTopLeftRadius: 24, borderTopRightRadius: 24, overflow: \"hidden\" },\n bar: {\n position: \"absolute\",\n top: 0,\n left: 0,\n right: 0,\n justifyContent: \"center\",\n paddingHorizontal: 20,\n borderBottomWidth: StyleSheet.hairlineWidth,\n },\n title: { fontSize: 17, fontWeight: \"700\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/shimmer-block.json b/public/registry/shimmer-block.json new file mode 100644 index 0000000..fb679b9 --- /dev/null +++ b/public/registry/shimmer-block.json @@ -0,0 +1,15 @@ +{ + "name": "shimmer-block", + "title": "Shimmer Block", + "category": "Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-01", + "dependencies": [], + "files": [ + { + "path": "registry/shimmer-block.tsx", + "content": "import { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Easing,\n Platform,\n StyleSheet,\n View,\n type DimensionValue,\n type LayoutChangeEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\nconst GAP = 10;\n\n// Opacity of each strip across the highlight band: a smooth bell, so the band has soft edges.\nconst STRIPS = 13;\nconst BELL = Array.from(\n { length: STRIPS },\n (_, i) => 0.75 * Math.sin((Math.PI * (i + 0.5)) / STRIPS) ** 2,\n);\n\nexport interface ShimmerBlockColors {\n base: string;\n highlight: string;\n}\n\nconst DEFAULT_COLORS: ShimmerBlockColors = {\n base: \"#e5e7eb\",\n highlight: \"#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 ShimmerBlockProps {\n /** Width of the block, or of the whole stack when `lines` is more than 1. */\n width?: DimensionValue;\n /** Height of each line. */\n height?: number;\n radius?: number;\n /** How many stacked lines to draw. The last of several is shorter, like the end of a paragraph. */\n lines?: number;\n /** Time for the highlight to cross the block, in milliseconds. */\n duration?: number;\n /** Hide the block from screen readers. Use it for blocks inside a parent that already announces \"Loading\". */\n decorative?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A loading placeholder with a soft highlight that sweeps across it. The lines of a stack start\n * together and take the same time, so they shimmer in step. Screen readers hear a single \"Loading\"\n * for the whole block, or\n * nothing when it is `decorative`; with reduced motion the block stays still.\n */\nexport function ShimmerBlock({\n width = \"100%\",\n height = 16,\n radius = 8,\n lines = 1,\n duration = 1400,\n decorative = false,\n colors,\n style,\n}: ShimmerBlockProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n\n const count = Math.max(1, Math.floor(lines));\n\n return (\n \n {Array.from({ length: count }, (_, i) => (\n 1 && i === count - 1 ? \"60%\" : \"100%\"}\n height={height}\n radius={radius}\n colors={palette}\n />\n ))}\n \n );\n}\n\nfunction Line({\n animated,\n duration,\n width,\n height,\n radius,\n colors,\n}: {\n animated: boolean;\n duration: number;\n width: DimensionValue;\n height: number;\n radius: number;\n colors: ShimmerBlockColors;\n}) {\n const [measured, setMeasured] = useState(0);\n const band = Math.max(96, measured * 0.5);\n // The band is moved by its own value, not an interpolation made during render, and its style is\n // memoized below: react-native-web detaches a value whose animated props are rebuilt, and that\n // stops the animation.\n const translateX = useRef(new Animated.Value(0)).current;\n\n const bandStyle = useMemo(\n () => [styles.band, { width: band, transform: [{ translateX }] }],\n [band, translateX],\n );\n\n useEffect(() => {\n if (!animated || measured === 0) return;\n translateX.setValue(-band);\n const loop = Animated.loop(\n Animated.timing(translateX, {\n toValue: measured,\n duration,\n easing: Easing.inOut(Easing.quad),\n useNativeDriver: NATIVE_DRIVER,\n }),\n );\n loop.start();\n return () => loop.stop();\n }, [animated, band, duration, measured, translateX]);\n\n return (\n setMeasured(event.nativeEvent.layout.width)}\n style={[styles.line, { width, height, borderRadius: radius, backgroundColor: colors.base }]}\n >\n {animated ? (\n \n {BELL.map((opacity, i) => (\n \n ))}\n \n ) : null}\n \n );\n}\n\nconst styles = StyleSheet.create({\n line: { overflow: \"hidden\" },\n band: { position: \"absolute\", top: 0, bottom: 0, left: 0, flexDirection: \"row\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/slide-switch.json b/public/registry/slide-switch.json new file mode 100644 index 0000000..550f493 --- /dev/null +++ b/public/registry/slide-switch.json @@ -0,0 +1,15 @@ +{ + "name": "slide-switch", + "title": "Slide Switch", + "category": "Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-01", + "dependencies": [], + "files": [ + { + "path": "registry/slide-switch.tsx", + "content": "import { useEffect, useRef, useState } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n PanResponder,\n Pressable,\n StyleSheet,\n View,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst PADDING = 3;\n\nexport interface SlideSwitchColors {\n off: string;\n on: string;\n thumb: string;\n}\n\nconst DEFAULT_COLORS: SlideSwitchColors = {\n off: \"#d1d5db\",\n on: \"#4f46e5\",\n thumb: \"#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 SlideSwitchProps {\n value: boolean;\n onValueChange: (value: boolean) => void;\n /** Dims the switch and ignores touches. */\n disabled?: boolean;\n /** Height of the track. The track is 1.8 times as wide. */\n size?: number;\n /** Spoken name of the switch. */\n label?: string;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A switch whose thumb can be dragged as well as tapped. It stretches while held, follows the\n * finger, and settles on whichever side it is nearer to (a flick decides it sooner). The track\n * cross-fades between the two colors, and screen readers get a standard switch with its state.\n */\nexport function SlideSwitch({\n value,\n onValueChange,\n disabled = false,\n size = 32,\n label,\n colors,\n style,\n}: SlideSwitchProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n\n const trackWidth = size * 1.8;\n const thumb = size - PADDING * 2;\n const stretch = thumb * 0.28;\n // Space the thumb can travel; less while it is stretched, so it never leaves the track.\n const travel = trackWidth - PADDING * 2 - thumb;\n\n // 0 is off, 1 is on, and anything between is mid-drag.\n const pos = useRef(new Animated.Value(value ? 1 : 0)).current;\n const grow = useRef(new Animated.Value(0)).current;\n const posNow = useRef(value ? 1 : 0);\n const pressed = useRef(false);\n const dragging = useRef(false);\n const dragStart = useRef(0);\n\n const live = useRef({ value, disabled, travel, reduceMotion, onValueChange });\n live.current = { value, disabled, travel, reduceMotion, onValueChange };\n\n useEffect(() => {\n const id = pos.addListener(({ value: next }) => (posNow.current = next));\n return () => pos.removeListener(id);\n }, [pos]);\n\n const animate = (node: Animated.Value, toValue: number) => {\n if (live.current.reduceMotion) {\n node.setValue(toValue);\n return;\n }\n // Width and colors are not supported by the native driver, so the switch runs on the JS thread.\n Animated.spring(node, {\n toValue,\n stiffness: 520,\n damping: 30,\n mass: 1,\n useNativeDriver: false,\n }).start();\n };\n\n const syncGrow = () => animate(grow, pressed.current || dragging.current ? 1 : 0);\n\n // Follow the value when the parent changes it (and settle after a drag the parent accepted).\n useEffect(() => {\n if (!dragging.current) animate(pos, value ? 1 : 0);\n // animate reads everything through refs.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [value, reduceMotion]);\n\n const pan = useRef(\n PanResponder.create({\n onMoveShouldSetPanResponder: (_, g) =>\n !live.current.disabled && Math.abs(g.dx) > 3 && Math.abs(g.dx) > Math.abs(g.dy),\n onPanResponderGrant: () => {\n dragging.current = true;\n dragStart.current = posNow.current;\n syncGrow();\n },\n onPanResponderMove: (_, g) => {\n pos.setValue(Math.max(0, Math.min(1, dragStart.current + g.dx / live.current.travel)));\n },\n onPanResponderRelease: (_, g) => {\n // A flick decides at once; a slow drag goes to the nearer side.\n const next = Math.abs(g.vx) > 0.3 ? g.vx > 0 : posNow.current > 0.5;\n // The click a mouse sends on release is not a tap, so keep dragging set a moment longer.\n setTimeout(() => (dragging.current = false), 80);\n animate(pos, next ? 1 : 0);\n syncGrow();\n if (next !== live.current.value) live.current.onValueChange(next);\n },\n onPanResponderTerminate: () => {\n setTimeout(() => (dragging.current = false), 80);\n animate(pos, live.current.value ? 1 : 0);\n syncGrow();\n },\n }),\n ).current;\n\n const thumbWidth = grow.interpolate({\n inputRange: [0, 1],\n outputRange: [thumb, thumb + stretch],\n });\n const room = grow.interpolate({ inputRange: [0, 1], outputRange: [travel, travel - stretch] });\n\n return (\n \n {\n if (!dragging.current) onValueChange(!value);\n }}\n onPressIn={() => {\n pressed.current = true;\n syncGrow();\n }}\n onPressOut={() => {\n pressed.current = false;\n syncGrow();\n }}\n style={[\n styles.track,\n { width: trackWidth, height: size, borderRadius: size / 2, backgroundColor: palette.off },\n ]}\n >\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 the thumb.\n root: { alignSelf: \"flex-start\", userSelect: \"none\" },\n track: { overflow: \"hidden\" },\n fill: { position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 },\n thumb: { position: \"absolute\", boxShadow: \"0 1px 3px rgba(0, 0, 0, 0.3)\" },\n});\n" + } + ] +} \ No newline at end of file diff --git a/public/registry/snap-carousel.json b/public/registry/snap-carousel.json new file mode 100644 index 0000000..4ab6a05 --- /dev/null +++ b/public/registry/snap-carousel.json @@ -0,0 +1,15 @@ +{ + "name": "snap-carousel", + "title": "Snap Carousel", + "category": "Native", + "type": "components:ui", + "platform": "native", + "added": "2026-11-01", + "dependencies": [], + "files": [ + { + "path": "registry/snap-carousel.tsx", + "content": "import { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport {\n AccessibilityInfo,\n Animated,\n Platform,\n PanResponder,\n Pressable,\n StyleSheet,\n View,\n type LayoutChangeEvent,\n type NativeScrollEvent,\n type NativeSyntheticEvent,\n type StyleProp,\n type ViewStyle,\n} from \"react-native\";\n\nconst NATIVE_DRIVER = Platform.OS !== \"web\";\n\n// The one method used from the scroll view's instance.\ntype Scroller = { scrollTo: (options: { x: number; animated?: boolean }) => void };\n// How small and faint the cards beside the centered one are drawn.\nconst SIDE_SCALE = 0.88;\nconst SIDE_OPACITY = 0.55;\nconst DOT = 8;\nconst DOT_ACTIVE = 22;\n\nexport interface SnapCarouselColors {\n dot: string;\n activeDot: string;\n}\n\nconst DEFAULT_COLORS: SnapCarouselColors = {\n dot: \"#d1d5db\",\n activeDot: \"#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 SnapCarouselProps {\n data: T[];\n /** Renders a card's content. The carousel sizes and animates the card itself. */\n renderItem: (item: T, index: number) => ReactNode;\n keyExtractor: (item: T, index: number) => string;\n /** Card width as a fraction of the carousel's width. */\n itemWidth?: number;\n /** Space between cards. */\n gap?: number;\n /** Called when a different card becomes the centered one. */\n onIndexChange?: (index: number) => void;\n /** Index of the card centered at first. */\n initialIndex?: number;\n /** Whether to draw the dots under the cards. */\n showDots?: boolean;\n colors?: Partial;\n style?: StyleProp;\n}\n\n/**\n * A horizontal carousel that settles on one card at a time. The centered card is full size and\n * opaque, its neighbors shrink and fade with the scroll position, and the dots below stretch to\n * follow. Tap a dot or a neighboring card to go there. The dots row doubles as an adjustable\n * control for screen readers, and on desktop the cards can be dragged with a mouse.\n */\nexport function SnapCarousel({\n data,\n renderItem,\n keyExtractor,\n itemWidth = 0.72,\n gap = 12,\n onIndexChange,\n initialIndex = 0,\n showDots = true,\n colors,\n style,\n}: SnapCarouselProps) {\n const palette = { ...DEFAULT_COLORS, ...colors };\n const reduceMotion = useReduceMotion();\n const [width, setWidth] = useState(0);\n const [index, setIndex] = useState(initialIndex);\n const scroll = useRef(null);\n const x = useRef(new Animated.Value(0)).current;\n const offset = useRef(0);\n const current = useRef(initialIndex);\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\n const card = width * itemWidth;\n const step = card + gap;\n const side = (width - card) / 2;\n const last = data.length - 1;\n\n const live = useRef({ step, last, reduceMotion, onIndexChange });\n live.current = { step, last, reduceMotion, onIndexChange };\n\n const goTo = (target: number, animated = !live.current.reduceMotion) => {\n const clamped = Math.max(0, Math.min(live.current.last, target));\n scroll.current?.scrollTo({ x: clamped * live.current.step, animated });\n };\n\n // Put the initial card in the middle once the width is known.\n useEffect(() => {\n if (step <= 0) return;\n const start = Math.max(0, Math.min(last, initialIndex)) * step;\n x.setValue(start);\n offset.current = start;\n scroll.current?.scrollTo({ x: start, animated: false });\n // Only the first measurement positions the carousel.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [step > 0]);\n\n const track = (event: NativeSyntheticEvent) => {\n const next = Math.max(\n 0,\n Math.min(\n live.current.last,\n Math.round(event.nativeEvent.contentOffset.x / live.current.step),\n ),\n );\n offset.current = event.nativeEvent.contentOffset.x;\n if (next !== current.current) {\n current.current = next;\n setIndex(next);\n live.current.onIndexChange?.(next);\n AccessibilityInfo.announceForAccessibility(`Item ${next + 1} of ${live.current.last + 1}`);\n }\n };\n\n // A mouse cannot drag a scroll view, so on desktop browsers the cards 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 },\n onPanResponderMove: (_, g) => {\n scroll.current?.scrollTo({ x: dragStart.current - g.dx, animated: false });\n },\n onPanResponderRelease: (_, g) => {\n setTimeout(() => (dragging.current = false), 80);\n // Carry a flick on to the next card, otherwise settle on the nearest one.\n const projected = offset.current - g.vx * 160;\n goTo(Math.round(projected / live.current.step));\n },\n onPanResponderTerminate: () => {\n setTimeout(() => (dragging.current = false), 80);\n goTo(Math.round(offset.current / live.current.step));\n },\n }),\n ).current;\n\n return (\n setWidth(event.nativeEvent.layout.width)}\n style={[styles.root, style]}\n >\n {width > 0 ? (\n \n \n {data.map((item, i) => {\n const range = [(i - 1) * step, i * step, (i + 1) * step];\n return (\n \n {\n if (!dragging.current) goTo(i);\n }}\n style={styles.card}\n >\n \n {renderItem(item, i)}\n \n \n \n );\n })}\n \n \n ) : null}\n \n goTo(index + (event.nativeEvent.actionName === \"increment\" ? 1 : -1))\n }\n style={showDots ? styles.dots : styles.noDots}\n >\n {showDots\n ? data.map((item, i) => (\n goTo(i)}\n />\n ))\n : null}\n \n \n );\n}\n\nfunction Dot({\n active,\n colors,\n reduceMotion,\n onPress,\n}: {\n active: boolean;\n colors: SnapCarouselColors;\n reduceMotion: boolean;\n onPress: () => void;\n}) {\n const size = useRef(new Animated.Value(active ? DOT_ACTIVE : DOT)).current;\n\n useEffect(() => {\n const target = active ? DOT_ACTIVE : DOT;\n if (reduceMotion) {\n size.setValue(target);\n return;\n }\n // Width is not supported by the native driver, so the dots run on the JS thread.\n Animated.spring(size, {\n toValue: target,\n stiffness: 360,\n damping: 24,\n mass: 1,\n useNativeDriver: false,\n }).start();\n }, [active, reduceMotion, size]);\n\n return (\n \n \n \n );\n}\n\nconst styles = StyleSheet.create({\n root: { width: \"100%\" },\n // userSelect keeps a mouse drag on the web from selecting the cards' text instead of moving them.\n drag: { width: \"100%\", userSelect: \"none\" },\n card: { flex: 1 },\n dots: {\n flexDirection: \"row\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: 6,\n paddingTop: 14,\n height: 30,\n },\n noDots: { height: 0 },\n dot: { height: DOT, borderRadius: DOT / 2 },\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 362ae81..a8e4454 100644 --- a/src/app/components/[slug]/page.tsx +++ b/src/app/components/[slug]/page.tsx @@ -6,6 +6,9 @@ import { notFound } from "next/navigation"; import { TableOfContents } from "@/components/table-of-contents"; import { FavoriteButton } from "@/components/favorite-button"; import { Comments } from "@/components/comments"; +import { PlatformBadge } from "@/components/platform-icon"; +import { registry } from "@/registry"; +import { platformOf } from "@/lib/registry"; interface PageProps { params: { @@ -36,6 +39,7 @@ export async function generateMetadata({ params }: PageProps): Promise export default async function DocPage({ params }: PageProps) { const doc = await getDocBySlug(params.slug); + const entry = registry.find((item) => item.name === params.slug); if (!doc) { notFound(); @@ -57,6 +61,11 @@ export default async function DocPage({ params }: PageProps) {

{doc.frontmatter.title}

+ {entry && ( +
+ +
+ )}

{doc.frontmatter.description}

diff --git a/src/app/components/layout.tsx b/src/app/components/layout.tsx index 9abc657..1882a14 100644 --- a/src/app/components/layout.tsx +++ b/src/app/components/layout.tsx @@ -19,7 +19,7 @@ import { Smartphone, } from "lucide-react"; import { CATEGORIES, registry, type Category } from "@/registry"; -import { isNew } from "@/lib/registry"; +import { isNew, platformOf } from "@/lib/registry"; const CATEGORY_ICONS: Record = { Navigation: PanelTop, @@ -39,7 +39,12 @@ const DOC_CATEGORIES: SidebarCategory[] = [ icon: React.createElement(CATEGORY_ICONS[category], { className: "h-3.5 w-3.5" }), items: registry .filter((item) => item.category === category) - .map((item) => ({ title: item.title, href: `/components/${item.name}`, isNew: isNew(item) })), + .map((item) => ({ + title: item.title, + href: `/components/${item.name}`, + isNew: isNew(item), + platform: platformOf(item), + })), })), { title: "Resources", diff --git a/src/app/components/page.tsx b/src/app/components/page.tsx index 20fc12d..c3da0a1 100644 --- a/src/app/components/page.tsx +++ b/src/app/components/page.tsx @@ -2,14 +2,22 @@ import React from "react"; import Link from "next/link"; import { MoveRight } from "lucide-react"; import { registry } from "@/registry"; -import { isNew } from "@/lib/registry"; +import { isNew, platformOf } from "@/lib/registry"; import { NewBadge } from "@/components/new-badge"; +import { PlatformIcon, type ComponentPlatform } from "@/components/platform-icon"; -const COMPONENT_LIST: { title: string; href: string; isNew?: boolean; disabled?: boolean }[] = [ +const COMPONENT_LIST: { + title: string; + href: string; + isNew?: boolean; + platform?: ComponentPlatform; + disabled?: boolean; +}[] = [ ...registry.map((item) => ({ title: item.title, href: `/components/${item.name}`, isNew: isNew(item), + platform: platformOf(item), })), { title: "Coming Soon", href: "/components/coming-soon", disabled: true }, ]; @@ -43,6 +51,7 @@ export default function ComponentsPage() { className="group flex items-center justify-between border-b border-border/40 py-2 transition-all duration-300 hover:border-foreground" > + {component.platform && } {component.title} {component.isNew && } diff --git a/src/components/platform-icon.tsx b/src/components/platform-icon.tsx new file mode 100644 index 0000000..9477e63 --- /dev/null +++ b/src/components/platform-icon.tsx @@ -0,0 +1,33 @@ +import { Globe, Smartphone } from "lucide-react"; +import { cn } from "@/lib/utils"; + +export type ComponentPlatform = "web" | "native"; + +const LABELS: Record = { web: "Web", native: "React Native" }; + +/** A small icon telling web components (globe) from React Native ones (phone). */ +export function PlatformIcon({ + platform, + className, +}: { + platform: ComponentPlatform; + className?: string; +}) { + const Icon = platform === "native" ? Smartphone : Globe; + return ( + + + + ); +} + +/** Icon and name together, for the top of a component's page. */ +export function PlatformBadge({ platform }: { platform: ComponentPlatform }) { + const Icon = platform === "native" ? Smartphone : Globe; + return ( + + + {platform === "native" ? "React Native (Expo)" : "Web (React)"} + + ); +} diff --git a/src/components/sidebar-nav.tsx b/src/components/sidebar-nav.tsx index 103260c..8631a4a 100644 --- a/src/components/sidebar-nav.tsx +++ b/src/components/sidebar-nav.tsx @@ -6,11 +6,12 @@ import { usePathname } from "next/navigation"; import { ChevronDown, Search } from "lucide-react"; import { cn } from "@/lib/utils"; import { NewBadge } from "@/components/new-badge"; +import { PlatformIcon, type ComponentPlatform } from "@/components/platform-icon"; export interface SidebarCategory { title: string; icon: React.ReactNode; - items: { title: string; href: string; isNew?: boolean }[]; + items: { title: string; href: string; isNew?: boolean; platform?: ComponentPlatform }[]; } export function SidebarNav({ categories }: { categories: SidebarCategory[] }) { @@ -122,6 +123,7 @@ export function SidebarNav({ categories }: { categories: SidebarCategory[] }) { : "text-muted-foreground hover:bg-secondary/60 hover:text-foreground", )} > + {item.platform && } {item.title} {item.isNew && } diff --git a/src/content/docs/flick-toast.mdx b/src/content/docs/flick-toast.mdx new file mode 100644 index 0000000..1a7882e --- /dev/null +++ b/src/content/docs/flick-toast.mdx @@ -0,0 +1,67 @@ +--- +title: Flick Toast +description: A React Native stack of toasts you flick away, with a countdown line that waits while you hold, older toasts scaled back, and screen reader dismiss. +--- + +A stack of toasts you flick away. The newest slides in at the front with the older ones scaled back behind it. A thin line counts down the front toast's time and waits while you hold it, and a sideways or toward-the-edge flick sends it off. The host owns the list: remove a toast in `onDismiss`. Each toast is a live region with a dismiss action for screen readers. 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 flick-toast +``` + +### Manual + +1. Copy the code from the component tab. +2. Create a file at `components/ui/flick-toast.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 { FlickToast, type FlickToastItem } from "@/components/ui/flick-toast"; + +export default function Example() { + const [toasts, setToasts] = useState([]); + + return ( + +