Vertical carousels
Five vertical carousels: slide, fade, cards, dots and stack. Each moves on the Y axis with up and down arrows (or a vertical dot column). Self-contained (no embla), token-driven and sized.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/carousel-verticalDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/carousel-vertical.tsx"use client"
import * as React from "react"
import { ChevronDown, ChevronUp } from "lucide-react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Vertical carousel family: 5 self-contained vertical sliders (NO embla, NO
radix). The slides move along the y axis; the up/down arrows change the index.
Each export is a complete carousel: it holds the slide index internally.
Deterministic (index-based, no Date.now or Math.random). The root carries
data-slot="styled-carousel" and role="region". Color comes ONLY from semantic
tokens; the active dot is primary, via alpha color-mix. Gated on framer's
useReducedMotion: under reduced motion the slide changes instantly and there is
no vertical transform. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const trackHeight: Record<StyledSize, string> = {
sm: "h-40",
md: "h-56",
lg: "h-72",
xl: "h-96",
}
const focusRing =
"outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50"
/* Dikey ok butonu: yatay olarak ortalanir, ust/alt kenara yerlesir. */
const arrowBtnV =
"absolute left-1/2 z-20 inline-flex size-9 -translate-x-1/2 items-center justify-center rounded-full border border-border bg-[color-mix(in_oklab,var(--color-background)_72%,transparent)] text-foreground shadow-sm transition-colors supports-[backdrop-filter]:backdrop-blur hover:bg-background [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
/* Token-surfaced, numbered placeholder panels - for prop-less rendering. */
const panelTones = ["bg-surface-2", "bg-surface-3", "bg-muted", "bg-accent"]
function defaultSlides(count = 4): React.ReactNode[] {
return Array.from({ length: count }, (_, i) => (
<div
key={i}
className={cn(
"flex h-full w-full items-center justify-center",
panelTones[i % panelTones.length]
)}
>
<span className="text-4xl font-semibold tabular-nums text-foreground">{i + 1}</span>
</div>
))
}
function resolveSlides(slides?: React.ReactNode[]): React.ReactNode[] {
return slides && slides.length > 0 ? slides : defaultSlides()
}
/* Ortak index state: sonsuz sarma (wrap) ile up/down ve dogrudan jump. */
function useCarousel(count: number) {
const [index, setIndex] = React.useState(0)
const total = Math.max(count, 1)
const wrap = React.useCallback((i: number) => ((i % total) + total) % total, [total])
const go = React.useCallback((i: number) => setIndex(wrap(i)), [wrap])
const next = React.useCallback(() => setIndex((p) => wrap(p + 1)), [wrap])
const prev = React.useCallback(() => setIndex((p) => wrap(p - 1)), [wrap])
return { index: Math.min(index, total - 1), setIndex: go, next, prev }
}
/* Vertical dot group: stacked along the right edge; the active one extends and turns primary. */
function CarouselDotsV({
count,
index,
onSelect,
className,
}: {
count: number
index: number
onSelect: (i: number) => void
className?: string
}) {
const reduce = useReducedMotion()
return (
<div
role="tablist"
aria-label="Choose slide to display"
className={cn("flex flex-col items-center justify-center gap-2", className)}
>
{Array.from({ length: count }, (_, i) => {
const active = i === index
return (
<button
key={i}
type="button"
role="tab"
aria-selected={active}
aria-label={`Go to slide ${i + 1}`}
onClick={() => onSelect(i)}
className={cn(
"relative inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full",
focusRing
)}
>
<motion.span
aria-hidden="true"
layout={!reduce}
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 500, damping: 34 }}
className={cn(
"block w-2 rounded-full transition-colors",
active
? "h-6 bg-primary"
: "h-2 bg-[color-mix(in_oklab,var(--color-foreground)_25%,transparent)] hover:bg-[color-mix(in_oklab,var(--color-foreground)_45%,transparent)]"
)}
/>
</button>
)
})}
</div>
)
}
/* Ust/alt ok cifti - dikey navigasyon. */
function ArrowsV({ next, prev }: { next: () => void; prev: () => void }) {
return (
<>
<button type="button" aria-label="Previous slide" onClick={prev} className={cn(arrowBtnV, focusRing, "top-3")}>
<ChevronUp />
</button>
<button type="button" aria-label="Next slide" onClick={next} className={cn(arrowBtnV, focusRing, "bottom-3")}>
<ChevronDown />
</button>
</>
)
}
interface CarouselProps {
className?: string
size?: StyledSize
slides?: React.ReactNode[]
}
/* Slide: slide'lar dikey kayar (translateY), ust/alt oklar. */
export function SlideCarousel({ className, size = "md", slides }: CarouselProps) {
const reduce = useReducedMotion()
const items = resolveSlides(slides)
const { index, next, prev } = useCarousel(items.length)
return (
<div
data-slot="styled-carousel"
role="region"
aria-roledescription="carousel"
aria-label="Gallery"
className={cn("relative w-full overflow-hidden rounded-xl border border-border", trackHeight[size], className)}
>
<motion.div
className="flex h-full w-full flex-col"
animate={{ y: `-${index * 100}%` }}
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 320, damping: 34 }}
>
{items.map((slide, i) => (
<div
key={i}
role="group"
aria-roledescription="slide"
aria-label={`${i + 1} of ${items.length}`}
aria-hidden={i !== index}
className="h-full w-full shrink-0 basis-full overflow-hidden"
>
{slide}
</div>
))}
</motion.div>
<ArrowsV next={next} prev={prev} />
</div>
)
}
/* Fade: the slides cross-fade, with top/bottom arrows. */
export function FadeCarousel({ className, size = "md", slides }: CarouselProps) {
const reduce = useReducedMotion()
const items = resolveSlides(slides)
const { index, next, prev } = useCarousel(items.length)
return (
<div
data-slot="styled-carousel"
role="region"
aria-roledescription="carousel"
aria-label="Gallery"
className={cn("relative w-full overflow-hidden rounded-xl border border-border", trackHeight[size], className)}
>
<AnimatePresence initial={false} mode="sync">
<motion.div
key={index}
role="group"
aria-roledescription="slide"
aria-label={`${index + 1} of ${items.length}`}
className="absolute inset-0 h-full w-full"
initial={reduce ? false : { opacity: 0, y: "8%" }}
animate={{ opacity: 1, y: "0%" }}
exit={reduce ? { opacity: 0 } : { opacity: 0, y: "-8%" }}
transition={reduce ? { duration: 0 } : { duration: 0.4, ease: "easeInOut" }}
>
{items[index]}
</motion.div>
</AnimatePresence>
<ArrowsV next={next} prev={prev} />
</div>
)
}
/* Cards: ust/alttaki komsu kartlarin ucu gorunur, orta kart one cikar (buyur +
tam opak). Dikey istif, ust/alt oklar. */
export function CardsCarousel({ className, size = "md", slides }: CarouselProps) {
const reduce = useReducedMotion()
const items = resolveSlides(slides)
const { index, setIndex, next, prev } = useCarousel(items.length)
return (
<div
data-slot="styled-carousel"
role="region"
aria-roledescription="carousel"
aria-label="Gallery"
className={cn("relative w-full overflow-hidden rounded-xl", trackHeight[size], className)}
>
<motion.div
className="flex h-full w-full flex-col items-center"
animate={{ y: `calc(${-index * 70}% + 15%)` }}
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 300, damping: 32 }}
>
{items.map((slide, i) => {
const active = i === index
return (
<motion.div
key={i}
role="group"
aria-roledescription="slide"
aria-label={`${i + 1} of ${items.length}`}
aria-hidden={!active}
className="w-full shrink-0 basis-[70%] py-2"
animate={{ scale: active ? 1 : 0.86, opacity: active ? 1 : 0.5 }}
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 300, damping: 32 }}
>
<button
type="button"
tabIndex={active ? -1 : 0}
aria-label={`Go to slide ${i + 1}`}
onClick={() => setIndex(i)}
className={cn("block h-full w-full overflow-hidden rounded-xl border border-border", focusRing)}
>
{slide}
</button>
</motion.div>
)
})}
</motion.div>
<ArrowsV next={next} prev={prev} />
</div>
)
}
/* Dots: minimal, vertical dots only (no arrows); tapping a dot jumps to that slide.
The dots overlap the right edge of the image. */
export function DotsCarousel({ className, size = "md", slides }: CarouselProps) {
const reduce = useReducedMotion()
const items = resolveSlides(slides)
const { index, setIndex } = useCarousel(items.length)
return (
<div
data-slot="styled-carousel"
role="region"
aria-roledescription="carousel"
aria-label="Gallery"
className={cn("relative w-full overflow-hidden rounded-xl border border-border", trackHeight[size], className)}
>
<AnimatePresence initial={false} mode="sync">
<motion.div
key={index}
role="group"
aria-roledescription="slide"
aria-label={`${index + 1} of ${items.length}`}
className="absolute inset-0 h-full w-full"
initial={reduce ? false : { opacity: 0, y: "8%" }}
animate={{ opacity: 1, y: "0%" }}
exit={reduce ? { opacity: 0 } : { opacity: 0, y: "-8%" }}
transition={reduce ? { duration: 0 } : { duration: 0.35, ease: "easeInOut" }}
>
{items[index]}
</motion.div>
</AnimatePresence>
<div className="absolute inset-y-0 right-3 z-10 flex items-center">
<CarouselDotsV count={items.length} index={index} onSelect={setIndex} />
</div>
</div>
)
}
/* Stack: komsu slide'lar merkezin arkasina dikey istiflenir (y kaymasi + kuculme +
solma); ust/alt oklar. */
export function StackCarousel({ className, size = "md", slides }: CarouselProps) {
const reduce = useReducedMotion()
const items = resolveSlides(slides)
const { index, setIndex, next, prev } = useCarousel(items.length)
return (
<div
data-slot="styled-carousel"
role="region"
aria-roledescription="carousel"
aria-label="Gallery"
className={cn("relative w-full overflow-hidden rounded-xl", trackHeight[size], className)}
>
<div className="relative h-full w-full">
{items.map((slide, i) => {
const offset = i - index
const abs = Math.abs(offset)
const active = offset === 0
const target = reduce
? { y: "0%", scale: 1, opacity: active ? 1 : 0 }
: {
y: `${offset * 14}%`,
scale: Math.max(0.82, 1 - abs * 0.08),
opacity: abs > 2 ? 0 : 1,
}
return (
<motion.div
key={i}
role="group"
aria-roledescription="slide"
aria-label={`${i + 1} of ${items.length}`}
aria-hidden={!active}
className="absolute inset-x-4 top-1/2 h-[70%] -translate-y-1/2 overflow-hidden rounded-xl border border-border shadow-sm"
style={{ zIndex: 100 - abs }}
initial={false}
animate={target}
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 260, damping: 30 }}
>
<button
type="button"
tabIndex={active ? -1 : 0}
aria-label={`Go to slide ${i + 1}`}
onClick={() => setIndex(i)}
className={cn("block h-full w-full", focusRing)}
>
{slide}
</button>
</motion.div>
)
})}
</div>
<ArrowsV next={next} prev={prev} />
</div>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Slide
Slides move vertically with up and down arrows.
import { SlideCarousel } from "@/components/ui/carousel-vertical"
<SlideCarousel />Fade
Slides cross-fade with a small vertical drift.
import { FadeCarousel } from "@/components/ui/carousel-vertical"
<FadeCarousel />Cards
The center card scales up while neighbors peek above and below.
import { CardsCarousel } from "@/components/ui/carousel-vertical"
<CardsCarousel />Dots
Minimal, a vertical dot column on the right, no arrows.
import { DotsCarousel } from "@/components/ui/carousel-vertical"
<DotsCarousel />Stack
Neighbors stack behind the center vertically with recession and fade.
import { StackCarousel } from "@/components/ui/carousel-vertical"
<StackCarousel />ai2 Vertical carousels: 5 styled variations on the token system
The ai2 Vertical carousels are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around vertical carousels where slides move on the Y axis with up and down arrows. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion springs the vertical slide, scale and fade on change. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, slides change instantly with no vertical movement or fading.
What is in the ai2 Vertical carousels?
5 exports in one file: Slide, Fade, Cards, Dots and Stack. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion springs the vertical slide, scale and fade on change.
- Reduced-motion aware: Under prefers-reduced-motion, slides change instantly with no vertical movement or fading.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Vertical carousels sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.