Skip to content

🧁 A cute, flexible stack component with smooth expand & collapse animations

Notifications You must be signed in to change notification settings

kurocodes/Stacklet

Repository files navigation

🧁 Stacklet

A tiny, playful stacking component with smooth expand & collapse animations ✨

Stacklet is a fun, reusable UI component for stacking elements that smoothly expand and collapse.
It’s designed to add a sense of depth, motion, and delight to your interface — without locking you into a specific use-case.

You can use Stacklet for:

  • notifications
  • cards
  • images
  • toasts
  • previews

…and pretty much anything you want to stack 🪄

🛠️ Technologies

  • React
  • Motion
  • TypeScript
  • Tailwind CSS

✨ Features

  • Smooth expand & collapse animations
  • Control which item stays on top (stackedFrom)
  • Control stack growth direction (direction)
  • Control how items pile up (align)
  • Vertical and horizontal stacks (auto layout handling)
  • Limit visible items when collapsed
  • Graceful handling of large item counts
  • Extra items fade in/out (no visual popping)
  • Works with any trigger (hover, click, state, etc.)
  • Content-agnostic — not tied to notifications
  • Lightweight & reusable

🧠 Process

This component didn’t start as Stacklet.

A while ago, I built a collapsible notification UI and later noticed similar stacked interactions floating around the internet.
That’s when a thought popped into my head:

“Why should this be just for notifications?”

So I decided to strip away all notification-specific logic and rebuild the idea as a generic stacking system —
something that could work for cards, images, toasts, or any custom element.

The goal wasn’t to build a finished UI component, but a small motion primitive focused purely on:

  • layout
  • depth
  • direction
  • animation

The result is Stacklet — flexible, composable, and assumption-free.

🧩 Props

Stacklet exposes a small set of focused props.
You don’t need all of them — just the ones you care about.

Required

  • open: boolean
    Controls whether the stack is expanded or collapsed.

Layout & Order

  • stackedFrom?: "start" | "end"
    Controls which item stays on top in the stack.
    "start" → first item is the hero
    "end" → last item is the hero

  • direction?: "up" | "down" | "left" | "right"
    Controls the axis and direction the stack expands in.

  • align?: "forward" | "backward"
    Controls how items pile relative to the hero item.
    Useful for creating mirrored or inverted stacks.

Spacing & Size

  • itemSize?: number
    Size of one item along the stack axis
    (height for vertical stacks, width for horizontal stacks).
    Recommended for stable layouts (no reflow).

  • expandedSpacing?: number (default: 8)
    Space between items when expanded.

  • collapsedSpacing?: number (default: 10)
    Offset between items when collapsed.

Visual Depth

  • scaleStep?: number (default: 0.04)
    How much each stacked item scales down.

  • opacityStep?: number (default: 0.08)
    How much each stacked item fades.

Large Lists & Extras

  • collapsedCount?: number
    Limits how many items participate in the stack when collapsed.

  • extraItemsDelay?: number (default: 0.01)
    Delay before extra (non-stacked) items fade in when expanded.

  • extraItemsDuration?: number (default: 0.15)
    Fade animation duration for extra items.

Extra items are intentionally not part of the stack animation.
They fade in and out subtly to keep the stack animation clean and satisfying.

🚀 Usage

Here’s a simple example:

<div className="w-[240px]">
  <Stacklet
    open={isHovered}
    stackedFrom="start"
    direction="up"
    align="forward"
    itemSize={64}
    collapsedCount={3}
  >
    {items.map((item) => (
      <Item key={item.id} item={item} />
    ))}
  </Stacklet>
</div>

You control when it opens.
Stacklet handles how it stacks and animates ✨

🧪 Running the Project

  1. clone the repo: git clone https://github.com/your-username/stacklet.git
  2. install dependencies: npm install
  3. start dev server: npm run dev

Then open your browser and enjoy the stack magic 🪄

👀 Preview

Stacklet.Notifications.mp4
Stacklet.Profiles.Stack.Preview.mp4

💖 Final Note

Stacklet is built with curiosity, experimentation, and a love for delightful UI interactions.

Feel free to fork it, break it, remix it, or use it in your own projects.
If you build something cool with it — I’d genuinely love to see it ✨

About

🧁 A cute, flexible stack component with smooth expand & collapse animations

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published