Reveal
atroui/revealFreeBlock
IntersectionObserver reveal using .atro-reveal CSS.
Install it
npx shadcn@latest add https://atroui.com/r/reveal.jsonSource
1"use client"23import * as React from "react"45import { cn } from "@/lib/utils"67type RevealProps = {8 as?: React.ElementType9 delay?: number10 once?: boolean11 id?: string12 className?: string13 children: React.ReactNode14}1516/**17 * IntersectionObserver reveal. Pair with `.atro-reveal` / `.atro-reveal-in` CSS.18 */19export function Reveal({20 as,21 delay = 0,22 once = true,23 id,24 className,25 children,26}: RevealProps) {27 const Tag = (as ?? "div") as React.ElementType28 const ref = React.useRef<HTMLElement | null>(null)29 const [inView, setInView] = React.useState(false)3031 React.useEffect(() => {32 const node = ref.current33 if (!node) return34 if (typeof IntersectionObserver === "undefined") {35 setInView(true)36 return37 }38 const io = new IntersectionObserver(39 ([entry]) => {40 if (entry?.isIntersecting) {41 setInView(true)42 if (once) io.disconnect()43 } else if (!once) {44 setInView(false)45 }46 },47 { threshold: 0.12, rootMargin: "0px 0px -40px 0px" }48 )49 io.observe(node)50 return () => io.disconnect()51 }, [once])5253 return (54 <Tag55 id={id}56 ref={ref as React.Ref<HTMLElement>}57 className={cn("atro-reveal", inView && "atro-reveal-in", className)}58 style={delay ? { animationDelay: `${delay}ms` } : undefined}59 >60 {children}61 </Tag>62 )63}
What it pulls in
Other registry items
Files it writes
More from atroui
All 82 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Analytics Provideranalytics-provider | atroui | Blocks | Free | 1 dep | |
| AR Portfolioar-portfolio | atroui | Blocks | Free | 1 dep | |
| Before / Afterbefore-after-slider | atroui | Blocks | Free | no deps | |
| Calendly Embedcalendly-embed | atroui | Blocks | Free | 1 dep | |
| Changelogchangelog | atroui | Blocks | Free | no deps | |
| Command Menucommand-menu | atroui | Blocks | Free | 4 deps | |
| Contact Formcontact-form | atroui | Blocks | Free | 2 deps | |
| Contextual CTAcontextual-cta | atroui | Blocks | Free | 2 deps |
