Components

AcknowledgementSlideshow

A hand-drawn slideshow for acknowledging people, with autoplay, arrows and dots.

Loved by developers

Auto-advancing acknowledgement cards.

“SketchUI was the first component library I saw and instantly decided to use for a project, and that became AskAMI. I loved its hand-drawn, artistic style, and the components were easy to customize and fit my design really well.”

D

dhruv

@atetoon

Controlled

“SketchUI was the first component library I saw and instantly decided to use for a project, and that became AskAMI. I loved its hand-drawn, artistic style, and the components were easy to customize and fit my design really well.”

D

dhruv

@atetoon

Active slide: 1 of 3

AcknowledgementSlideshow is a data-driven carousel for thank-you notes and testimonials. Each slide is a sketchy Card containing a quote doodle, the message, and an Avatar. It is the library version of the testimonial carousel used on the landing page, with autoplay, rough-drawn arrow buttons, and dot navigation.

Code

tsx
430 lines
"use client"

import "./style/AcknowledgementSlideshow.css"

import {
    useEffect,
    useRef,
    useState,
    type KeyboardEvent,
} from "react"
import rough from "roughjs"
import { cn } from "@/lib/utils"
import { Avatar } from "./Avatar"
import { Card } from "./Card"

type AcknowledgementAvatarVariant =
    | "gray"
    | "paper"
    | "yellow"
    | "purple"
    | "green"
    | "pink"
    | "blue"
    | "white"

export type AcknowledgementItem = {
    name: string
    role?: string
    message: string
    avatarSrc?: string
    avatarVariant?: AcknowledgementAvatarVariant
}

type AcknowledgementVariant =
    | "yellow"
    | "purple"
    | "green"
    | "pink"
    | "blue"
    | "gray"
    | "silver"
    | "red"
    | "orange"
    | "sky"
    | "paper"

type AcknowledgementBorderStyle = "rough" | "dashed" | "project-corner"

type RoughAcknowledgementOptions = {
    seed?: number
    stroke?: string
    strokeWidth?: number
    fill?: string
    fillStyle?: "solid" | "hachure" | "zigzag" | "cross-hatch" | "dots" | "dashed" | "zigzag-line"
    hachureGap?: number
    hachureAngle?: number
    roughness?: number
    bowing?: number
}

type AcknowledgementSlideshowProps = {
    items: AcknowledgementItem[]
    title?: string
    subtitle?: string

    activeIndex?: number
    defaultActiveIndex?: number
    onActiveIndexChange?: (index: number) => void

    autoPlay?: boolean
    interval?: number
    loop?: boolean

    showArrows?: boolean
    showDots?: boolean
    showQuoteIcon?: boolean

    variant?: AcknowledgementVariant
    borderStyle?: AcknowledgementBorderStyle
    width?: number | string
    height?: number

    roughOptions?: RoughAcknowledgementOptions

    className?: string
    cardClassName?: string
    slideClassName?: string
    arrowClassName?: string
    dotClassName?: string
    titleClassName?: string
    subtitleClassName?: string
}

type Direction = "next" | "prev"

function QuoteDoodle() {
    return (
        <svg
            viewBox="0 0 64 56"
            className="h-12 w-14 shrink-0 text-black/80"
            fill="none"
            aria-hidden="true"
        >
            <path
                d="M6 33 C6 18 15 9 29 8 L29 17 C20 18 15 23 14 30 L24 30 L24 45 L6 45 Z"
                stroke="currentColor"
                strokeWidth="2.4"
                strokeLinecap="round"
                strokeLinejoin="round"
            />
            <path
                d="M36 33 C36 18 45 9 59 8 L59 17 C50 18 45 23 44 30 L54 30 L54 45 L36 45 Z"
                stroke="currentColor"
                strokeWidth="2.4"
                strokeLinecap="round"
                strokeLinejoin="round"
            />
        </svg>
    )
}

function SketchArrowButton({
    direction,
    onClick,
    className,
}: {
    direction: Direction
    onClick: () => void
    className?: string
}) {
    const svgRef = useRef<SVGSVGElement | null>(null)

    useEffect(() => {
        const svg = svgRef.current
        if (!svg) return

        svg.replaceChildren()

        const rc = rough.svg(svg)
        const node = rc.circle(20, 20, 36, {
            seed: direction === "prev" ? 610 : 620,
            stroke: "#111",
            strokeWidth: 1.8,
            fill: "#fffbf2",
            fillStyle: "solid",
            roughness: 1.3,
            bowing: 0.8,
        })

        svg.appendChild(node)
    }, [direction])

    return (
        <button
            type="button"
            aria-label={
                direction === "prev"
                    ? "Previous acknowledgement"
                    : "Next acknowledgement"
            }
            onClick={onClick}
            className={cn(
                "relative grid size-10 shrink-0 place-items-center rounded-full outline-none",
                "transition-transform duration-150 hover:-translate-y-0.5 active:scale-95",
                "focus-visible:ring-2 focus-visible:ring-black focus-visible:ring-offset-2",
                className
            )}
        >
            <svg
                ref={svgRef}
                viewBox="0 0 40 40"
                className="pointer-events-none absolute inset-0 h-full w-full overflow-visible"
                aria-hidden="true"
            />
            <span className="relative z-10 font-family-hand text-lg font-black text-black">
                {direction === "prev" ? "←" : "→"}
            </span>
        </button>
    )
}

export function AcknowledgementSlideshow({
    items,
    title,
    subtitle,

    activeIndex,
    defaultActiveIndex = 0,
    onActiveIndexChange,

    autoPlay = true,
    interval = 4000,
    loop = true,

    showArrows = true,
    showDots = true,
    showQuoteIcon = true,

    variant = "paper",
    borderStyle = "rough",
    width = "100%",
    height = 280,

    roughOptions,

    className,
    cardClassName,
    slideClassName,
    arrowClassName,
    dotClassName,
    titleClassName,
    subtitleClassName,
}: AcknowledgementSlideshowProps) {
    const isControlled = activeIndex !== undefined

    const [internalIndex, setInternalIndex] = useState(defaultActiveIndex)
    const [direction, setDirection] = useState<Direction>("next")
    const [paused, setPaused] = useState(false)

    const count = items.length
    const requestedIndex = isControlled ? activeIndex : internalIndex
    const currentIndex =
        count === 0
            ? 0
            : ((requestedIndex % count) + count) % count
    const currentItem = items[currentIndex]

    useEffect(() => {
        if (!autoPlay || paused || count <= 1) return

        const timer = setTimeout(() => {
            setDirection("next")

            const nextIndex = loop
                ? (currentIndex + 1) % count
                : Math.min(count - 1, currentIndex + 1)

            if (!isControlled) {
                setInternalIndex(nextIndex)
            }

            onActiveIndexChange?.(nextIndex)
        }, interval)

        return () => clearTimeout(timer)
    }, [
        autoPlay,
        paused,
        count,
        interval,
        loop,
        currentIndex,
        isControlled,
        onActiveIndexChange,
    ])

    function goTo(index: number, nextDirection?: Direction) {
        if (count === 0) return

        const resolvedIndex = loop
            ? ((index % count) + count) % count
            : Math.min(count - 1, Math.max(0, index))

        setDirection(nextDirection ?? (resolvedIndex >= currentIndex ? "next" : "prev"))

        if (!isControlled) {
            setInternalIndex(resolvedIndex)
        }

        onActiveIndexChange?.(resolvedIndex)
    }

    function handleKeyDown(event: KeyboardEvent<HTMLDivElement>) {
        if (event.key === "ArrowRight") {
            event.preventDefault()
            goTo(currentIndex + 1, "next")
        }

        if (event.key === "ArrowLeft") {
            event.preventDefault()
            goTo(currentIndex - 1, "prev")
        }
    }

    return (
        <div
            role="region"
            aria-roledescription="carousel"
            aria-label={title ?? "Acknowledgements"}
            tabIndex={0}
            onKeyDown={handleKeyDown}
            onMouseEnter={() => setPaused(true)}
            onMouseLeave={() => setPaused(false)}
            onFocus={() => setPaused(true)}
            onBlur={() => setPaused(false)}
            className={cn(
                "relative w-full outline-none",
                "focus-visible:ring-2 focus-visible:ring-black",
                className
            )}
            style={{ width }}
        >
            {(title || subtitle) && (
                <div className="mb-6">
                    {title && (
                        <h2
                            className={cn(
                                "font-family-hand text-3xl font-black leading-tight",
                                titleClassName
                            )}
                        >
                            {title}
                        </h2>
                    )}
                    {subtitle && (
                        <p
                            className={cn(
                                "mt-2 font-family-gaegu text-lg text-black/70",
                                subtitleClassName
                            )}
                        >
                            {subtitle}
                        </p>
                    )}
                </div>
            )}

            <Card
                variant={variant}
                borderStyle={borderStyle}
                width="100%"
                height={height}
                className={cardClassName}
                contentClassName="h-full"
                roughOptions={roughOptions}
            >
                {!currentItem ? (
                    <div className="flex h-full items-center justify-center font-family-gaegu text-lg text-black/60">
                        No acknowledgements to show.
                    </div>
                ) : (
                    <div
                        key={`${currentIndex}-${direction}`}
                        role="group"
                        aria-roledescription="slide"
                        aria-label={`${currentIndex + 1} of ${count}`}
                        className={cn(
                            "relative flex h-full flex-col",
                            direction === "next"
                                ? "sketch-ack-slide-next"
                                : "sketch-ack-slide-prev",
                            slideClassName
                        )}
                    >
                        {showQuoteIcon && <QuoteDoodle />}

                        <p className="mt-2 flex-1 font-family-gaegu text-lg leading-relaxed text-black">
                            “{currentItem.message}”
                        </p>

                        <div className="mt-6 flex items-center gap-4">
                            <Avatar
                                name={currentItem.name}
                                src={currentItem.avatarSrc}
                                variant={currentItem.avatarVariant ?? "green"}
                                showInitials
                            />

                            <div className="min-w-0">
                                <p className="font-family-hand text-xl font-black">
                                    {currentItem.name}
                                </p>
                                {currentItem.role && (
                                    <p className="font-family-gaegu text-base text-black/60">
                                        {currentItem.role}
                                    </p>
                                )}
                            </div>
                        </div>
                    </div>
                )}
            </Card>

            {(showArrows || showDots) && count > 0 && (
                <div className="mt-6 flex items-center justify-center gap-6">
                    {showArrows && (
                        <SketchArrowButton
                            direction="prev"
                            onClick={() => goTo(currentIndex - 1, "prev")}
                            className={arrowClassName}
                        />
                    )}

                    {showDots && count > 1 && (
                        <div className="flex items-center gap-3">
                            {items.map((item, index) => (
                                <button
                                    key={`${item.name}-${index}`}
                                    type="button"
                                    aria-label={`Go to acknowledgement ${index + 1}`}
                                    aria-current={
                                        index === currentIndex ? "true" : undefined
                                    }
                                    onClick={() => goTo(index)}
                                    className={cn(
                                        "size-4 rounded-full border-2 border-black transition-all",
                                        "hover:scale-110 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black",
                                        index === currentIndex
                                            ? "bg-black"
                                            : "bg-white",
                                        dotClassName
                                    )}
                                />
                            ))}
                        </div>
                    )}

                    {showArrows && (
                        <SketchArrowButton
                            direction="next"
                            onClick={() => goTo(currentIndex + 1, "next")}
                            className={arrowClassName}
                        />
                    )}
                </div>
            )}
        </div>
    )
}

CSS

Create a style folder in ui and save this as AcknowledgementSlideshow.css, then import it at the top of the component.

css
39 lines
@keyframes sketch-ack-slide-next {
    from {
        opacity: 0;
        transform: translateX(40px) rotate(2deg);
    }

    to {
        opacity: 1;
        transform: translateX(0) rotate(0deg);
    }
}

@keyframes sketch-ack-slide-prev {
    from {
        opacity: 0;
        transform: translateX(-40px) rotate(-2deg);
    }

    to {
        opacity: 1;
        transform: translateX(0) rotate(0deg);
    }
}

.sketch-ack-slide-next {
    animation: sketch-ack-slide-next 500ms ease-out;
}

.sketch-ack-slide-prev {
    animation: sketch-ack-slide-prev 500ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .sketch-ack-slide-next,
    .sketch-ack-slide-prev {
        animation: none;
    }
}

Usage

tsx
import {
    AcknowledgementSlideshow,
    type AcknowledgementItem,
} from "@/components/ui/AcknowledgementSlideshow"

const items: AcknowledgementItem[] = [
    {
        name: "dhruv",
        role: "@atetoon",
        message: "SketchUI made our project feel hand-made and human.",
        avatarVariant: "green",
    },
    {
        name: "Sarah Chen",
        role: "Frontend Engineer",
        message: "Finally a UI library that feels creative without sacrificing usability.",
    },
]

export function Example() {
    return (
        <AcknowledgementSlideshow
            items={items}
            title="Loved by developers"
            subtitle="Kind words from the community."
            interval={5000}
        />
    )
}

Controlled index with autoplay off:

tsx
"use client"

import { useState } from "react"
import { AcknowledgementSlideshow } from "@/components/ui/AcknowledgementSlideshow"

export function ControlledExample() {
    const [activeIndex, setActiveIndex] = useState(0)

    return (
        <AcknowledgementSlideshow
            items={items}
            activeIndex={activeIndex}
            onActiveIndexChange={setActiveIndex}
            autoPlay={false}
            variant="yellow"
            borderStyle="dashed"
        />
    )
}

Props

PropTypeDefaultDescription
itemsAcknowledgementItem[]-Slides to show. Each item has name, optional role, message, avatarSrc, and avatarVariant.
titlestring-Optional heading above the card.
subtitlestring-Optional supporting text under the title.
activeIndexnumber-Controlled slide index.
defaultActiveIndexnumber0Initial slide index in uncontrolled mode.
onActiveIndexChange(index: number) => void-Called whenever the index changes.
autoPlaybooleantrueAdvances the slideshow automatically.
intervalnumber4000Milliseconds between automatic advances.
loopbooleantrueWraps around at the ends; when false, navigation clamps.
showArrowsbooleantrueShows the rough-drawn previous/next buttons.
showDotsbooleantrueShows dot navigation (hidden for a single slide).
showQuoteIconbooleantrueShows the hand-drawn quote doodle.
variantAcknowledgementVariant"paper"Card color theme.
borderStyle"rough" | "dashed" | "project-corner""rough"Card border treatment.
widthnumber | string"100%"Width of the whole slideshow.
heightnumber280Height of the slide card.
roughOptionsRoughAcknowledgementOptions-Custom RoughJS rendering configuration for the card.
classNamestring-Classes for the outer wrapper.
cardClassNamestring-Classes for the Card.
slideClassNamestring-Classes for the animated slide content.
arrowClassNamestring-Classes for both arrow buttons.
dotClassNamestring-Classes for each dot.
titleClassNamestring-Classes for the title.
subtitleClassNamestring-Classes for the subtitle.

Rough Options

The roughOptions prop customizes the card's hand-drawn appearance.

  • seed (number): Controls stroke randomness; set it for a stable sketch.
  • stroke (string): Stroke color.
  • strokeWidth (number): Stroke thickness.
  • fill (string): Fill color override.
  • fillStyle: "solid", "hachure", "zigzag", "cross-hatch", "dots", "dashed", "zigzag-line".
  • hachureGap (number): Gap between hachure strokes.
  • hachureAngle (number): Angle of hachure strokes.
  • roughness (number): Higher values look sketchier.
  • bowing (number): Bending effect of the stroke.
tsx
<AcknowledgementSlideshow
    items={items}
    variant="yellow"
    borderStyle="dashed"
    roughOptions={{
        fillStyle: "hachure",
        hachureGap: 4,
        roughness: 1.6,
    }}
/>

Variants

  • yellow
  • purple
  • green
  • pink
  • blue
  • gray
  • silver
  • red
  • orange
  • sky
  • paper

Border Styles

  • rough
  • dashed
  • project-corner

Accessibility

The root is a labelled region with aria-roledescription="carousel", and each slide is a group labelled "N of M". Arrow and dot buttons have descriptive aria-labels and the active dot uses aria-current. Autoplay pauses on hover and focus, ArrowLeft/ArrowRight navigate when the carousel has focus, and the slide animation is disabled under prefers-reduced-motion: reduce.