Layered Stack
componentry/layered-stackFreeComponent
Component for layered-stack
Live preview
live · rendered by the registry
Rendered by componentry on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://componentry.dev/r/layered-stack.jsonSource
1"use client";23import { ComponentProps, useCallback, useEffect, useRef } from "react";4import gsap from "gsap";5import { cn } from "@/lib/utils";67export type LayeredStackProps = ComponentProps<"div">;89export const LayeredStack = ({ children, className, ...props }: LayeredStackProps) => {10 const containerRef = useRef<HTMLDivElement>(null);11 const isStacked = useRef(true);1213 const stackCards = useCallback((animate = true) => {14 const container = containerRef.current;15 if (!container) return;1617 isStacked.current = true;18 const cards = Array.from(container.children) as HTMLElement[];1920 // First clear all transforms so offsetLeft/offsetTop reflect true grid positions21 cards.forEach((card) => {22 gsap.killTweensOf(card);23 });2425 if (!animate) {26 // Instant reposition: clear transforms, recalculate, set immediately27 cards.forEach((card) => gsap.set(card, { x: 0, y: 0, rotate: 0 }));28 // Wait a frame so the browser recalculates layout29 requestAnimationFrame(() => {30 const container = containerRef.current;31 if (!container || !isStacked.current) return;32 const cards = Array.from(container.children) as HTMLElement[];33 cards.forEach((card, i) => {34 const offsetX = container.clientWidth / 2 - card.offsetWidth / 2 - card.offsetLeft;35 const offsetY = container.clientHeight / 2 - card.offsetHeight / 2 - card.offsetTop;36 gsap.set(card, {37 x: offsetX,38 y: offsetY,39 rotate: gsap.utils.random(-10, 10),40 zIndex: 100 - i,41 });42 });43 });44 return;45 }4647 // Animated: first clear, then after layout recalc, animate to center48 cards.forEach((card) => gsap.set(card, { x: 0, y: 0, rotate: 0 }));49 requestAnimationFrame(() => {50 const container = containerRef.current;51 if (!container || !isStacked.current) return;52 const cards = Array.from(container.children) as HTMLElement[];53 cards.forEach((card, i) => {54 const offsetX = container.clientWidth / 2 - card.offsetWidth / 2 - card.offsetLeft;55 const offsetY = container.clientHeight / 2 - card.offsetHeight / 2 - card.offsetTop;56 gsap.to(card, {57// … truncated
More from componentry
All 59 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradientanimated-gradient | componentry | Components | Free | no deps | |
| ASCII Effectascii-effect | componentry | Components | Free | no deps | |
| Aurora Flowaurora-flow | componentry | Components | Free | no deps | |
| auth-modalauth-modal | componentry | Components | Free | no deps | |
| border-beamborder-beam | componentry | Components | Free | no deps | |
| circuit-boardcircuit-board | componentry | Components | Free | no deps | |
| closing-plasmaclosing-plasma | componentry | Components | Free | no deps | |
| collection-surfercollection-surfer | componentry | Components | Free | no deps |
