Thumbnail carousels
Five carousels with a thumbnail strip: below, side, dots and thumbs, scaled and bordered. Clicking a thumbnail jumps to that slide while the main viewer cross-fades. 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-thumbnailsDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/carousel-thumbnails.tsx"use client"
import * as React from "react"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Thumbnails carousel family: 5 self-contained sliders (NO embla, NO radix). A
strip of small previews sits below (or beside) the main image; clicking a
thumbnail jumps to that slide. Each export is a complete carousel: it holds the
slide index internally, and the arrows + thumbnails change it. 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 thumbnail gets a primary frame, via alpha color-mix. Gated
on framer's useReducedMotion: under reduced motion the slide changes
instantly. */
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"
const arrowBtn =
"absolute top-1/2 z-20 inline-flex size-9 -translate-y-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 prev/next 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 }
}
/* Shared dot group: the active one widens and turns primary. */
function CarouselDots({
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 items-center justify-center", 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 h-2 rounded-full transition-colors",
active
? "w-6 bg-primary"
: "w-2 bg-[color-mix(in_oklab,var(--color-foreground)_25%,transparent)] hover:bg-[color-mix(in_oklab,var(--color-foreground)_45%,transparent)]"
)}
/>
</button>
)
})}
</div>
)
}
interface CarouselProps {
className?: string
size?: StyledSize
slides?: React.ReactNode[]
}
/* The main image: the slides cross-fade, with arrows over them. */
function MainViewer({
items,
index,
next,
prev,
size,
reduce,
}: {
items: React.ReactNode[]
index: number
next: () => void
prev: () => void
size: StyledSize
reduce: boolean | null
}) {
return (
<div className={cn("relative w-full flex-1 overflow-hidden rounded-xl border border-border", trackHeight[size])}>
<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 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={reduce ? { duration: 0 } : { duration: 0.35, ease: "easeInOut" }}
>
{items[index]}
</motion.div>
</AnimatePresence>
<button type="button" aria-label="Previous slide" onClick={prev} className={cn(arrowBtn, focusRing, "left-3")}>
<ChevronLeft />
</button>
<button type="button" aria-label="Next slide" onClick={next} className={cn(arrowBtn, focusRing, "right-3")}>
<ChevronRight />
</button>
</div>
)
}
/* The thumbnail strip settings. orientation: horizontal (below) or vertical
(beside), scaled: the active thumbnail grows, border: every thumbnail gets a
pronounced frame. */
interface ThumbConfig {
orientation: "row" | "col"
scaled: boolean
bordered: boolean
showDots: boolean
}
function ThumbStrip({
items,
index,
onSelect,
config,
reduce,
}: {
items: React.ReactNode[]
index: number
onSelect: (i: number) => void
config: ThumbConfig
reduce: boolean | null
}) {
const vertical = config.orientation === "col"
return (
<div
className={cn(
"flex gap-2",
vertical ? "h-full w-20 shrink-0 flex-col overflow-y-auto" : "w-full flex-row overflow-x-auto"
)}
>
{items.map((slide, i) => {
const active = i === index
return (
<motion.button
key={i}
type="button"
aria-label={`Go to slide ${i + 1}`}
aria-current={active}
onClick={() => onSelect(i)}
initial={false}
animate={config.scaled && !reduce ? { scale: active ? 1 : 0.88 } : { scale: 1 }}
transition={reduce ? { duration: 0 } : { type: "spring" as const, stiffness: 400, damping: 30 }}
className={cn(
"relative shrink-0 overflow-hidden rounded-md transition-colors",
vertical ? "h-14 w-full" : "h-12 w-16",
config.bordered ? "border-2" : "border",
active
? "border-primary"
: "border-border hover:border-[color-mix(in_oklab,var(--color-foreground)_35%,transparent)]",
focusRing
)}
>
<div aria-hidden="true" className="pointer-events-none h-full w-full">
{slide}
</div>
{active ? null : (
<span
aria-hidden="true"
className="absolute inset-0 bg-[color-mix(in_oklab,var(--color-background)_35%,transparent)]"
/>
)}
</motion.button>
)
})}
</div>
)
}
function Thumbnails({
className,
size = "md",
slides,
config,
}: CarouselProps & { config: ThumbConfig }) {
const reduce = useReducedMotion()
const items = resolveSlides(slides)
const { index, setIndex, next, prev } = useCarousel(items.length)
const viewer = (
<MainViewer items={items} index={index} next={next} prev={prev} size={size} reduce={reduce} />
)
const strip = (
<ThumbStrip items={items} index={index} onSelect={setIndex} config={config} reduce={reduce} />
)
return (
<div
data-slot="styled-carousel"
role="region"
aria-roledescription="carousel"
aria-label="Gallery"
className={cn("relative w-full", className)}
>
{config.orientation === "col" ? (
<div className={cn("flex gap-3", trackHeight[size])}>
{viewer}
{strip}
</div>
) : (
<>
{viewer}
<div className="mt-3">{strip}</div>
{config.showDots ? (
<CarouselDots count={items.length} index={index} onSelect={setIndex} className="mt-3" />
) : null}
</>
)}
</div>
)
}
/* Below: kucuk resim seridi ana goruntunun altinda. */
export function BelowCarousel(props: CarouselProps) {
return <Thumbnails {...props} config={{ orientation: "row", scaled: false, bordered: false, showDots: false }} />
}
/* Side: the thumbnail strip is a vertical column to the right of the main image. */
export function SideCarousel(props: CarouselProps) {
return <Thumbnails {...props} config={{ orientation: "col", scaled: false, bordered: false, showDots: false }} />
}
/* DotsThumbs: alt kucuk resimlere ek olarak nokta gostergesi. */
export function DotsThumbsCarousel(props: CarouselProps) {
return <Thumbnails {...props} config={{ orientation: "row", scaled: false, bordered: false, showDots: true }} />
}
/* Scaled: aktif kucuk resim buyur, digerleri kuculur. */
export function ScaledCarousel(props: CarouselProps) {
return <Thumbnails {...props} config={{ orientation: "row", scaled: true, bordered: false, showDots: false }} />
}
/* Bordered: her kucuk resim kalin cerceveli, aktif primary. */
export function BorderedCarousel(props: CarouselProps) {
return <Thumbnails {...props} config={{ orientation: "row", scaled: false, bordered: true, showDots: false }} />
}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.
Below
A thumbnail row sits under the main viewer; the active thumb takes a primary border.
import { BelowCarousel } from "@/components/ui/carousel-thumbnails"
<BelowCarousel />Side
The thumbnail strip is a vertical column to the right of the viewer.
import { SideCarousel } from "@/components/ui/carousel-thumbnails"
<SideCarousel />Dots + Thumbs
Thumbnails below plus a dot indicator.
import { DotsThumbsCarousel } from "@/components/ui/carousel-thumbnails"
<DotsThumbsCarousel />Scaled
The active thumbnail scales up while the others shrink.
import { ScaledCarousel } from "@/components/ui/carousel-thumbnails"
<ScaledCarousel />Bordered
Each thumbnail has a bold border; the active one turns primary.
import { BorderedCarousel } from "@/components/ui/carousel-thumbnails"
<BorderedCarousel />ai2 Thumbnail carousels: 5 styled variations on the token system
The ai2 Thumbnail carousels are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around carousels with a thumbnail strip where clicking a thumb jumps to that slide. 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 cross-fades the main viewer and springs the active thumbnail. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the main viewer changes instantly and the thumbnails do not scale.
What is in the ai2 Thumbnail carousels?
5 exports in one file: Below, Side, Dots and Thumbs, Scaled and Bordered. 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 cross-fades the main viewer and springs the active thumbnail.
- Reduced-motion aware: Under prefers-reduced-motion, the main viewer changes instantly and the thumbnails do not scale.
- 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 Thumbnail 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.