Stagger
atroui/staggerFreeComponent
Stagger children on scroll with StaggerChild.
Install it
npx shadcn@latest add https://atroui.com/r/stagger.jsonSource
1"use client"23import * as React from "react"4import { motion, useReducedMotion } from "motion/react"5import type { HTMLMotionProps } from "motion/react"67type StaggerProps = HTMLMotionProps<"div"> & {8 delay?: number9 stagger?: number10 once?: boolean11 /** Docs: play on mount instead of waiting for scroll. */12 preview?: boolean13}1415export function Stagger({16 delay = 0,17 stagger = 0.08,18 once = true,19 preview = false,20 children,21 ...props22}: StaggerProps) {23 const reduce = useReducedMotion()2425 if (reduce) {26 return (27 <div {...(props as React.HTMLAttributes<HTMLDivElement>)}>28 {children as React.ReactNode}29 </div>30 )31 }3233 const transition = {34 delayChildren: delay,35 staggerChildren: stagger,36 }3738 return (39 <motion.div40 initial="hidden"41 {...(preview42 ? { animate: "show" as const }43 : {44 whileInView: "show" as const,45 viewport: { once, margin: "0px", amount: 0.15 },46 })}47 variants={{48 hidden: {},49 show: { transition },50 }}51 {...props}52 >53 {children}54 </motion.div>55 )56}5758type ChildProps = HTMLMotionProps<"div"> & { y?: number }5960export function StaggerChild({ y = 14, children, ...props }: ChildProps) {61 const reduce = useReducedMotion()6263 if (reduce) {64 return (65 <div {...(props as React.HTMLAttributes<HTMLDivElement>)}>66 {children as React.ReactNode}67 </div>68 )69 }7071 return (72 <motion.div73 variants={{74 hidden: { opacity: 0, y },75 show: {76 opacity: 1,77 y: 0,78 transition: { duration: 0.26, ease: [0.23, 1, 0.32, 1] },79 },80 }}81 {...props}82 >83 {children}84 </motion.div>85 )86}
What it pulls in
npm packages
Files it writes
More from atroui
All 81 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Breadcrumbsbreadcrumbs | atroui | Components | Free | 2 deps | |
| Buttonbutton | atroui | Components | Free | 2 deps | |
| Cardcard | atroui | Components | Free | no deps | |
| Fade Infade-in | atroui | Components | Free | 1 dep | |
| Form Selectform-select | atroui | Components | Free | 2 deps | |
| Founder Avatarfounder-avatar | atroui | Components | Free | 1 dep | |
| Logologo | atroui | Components | Free | no deps | |
| Mockup Framemockup-frame | atroui | Components | Free | no deps |
