Book Shelf

A row of books standing spine-out on a shelf. Click a book and it swings open to the right until its front cover faces you. Click it again (or press Esc, or click outside) and it swings back. The books on its right slide over to make room. Only transforms are animated (x, rotateY) for maximum performance.

Installation

  1. 1

    Install the component:

    npx shadcn@latest add https://ui.amines.fun/registry/book-shelf.json
  2. 2

    Usage:

    jsx

    app/page.jsx

    const books = [  { id: "atomic-habits", title: "Atomic Habits", author: "James Clear", color: "#2d2a7b", textColor: "#d8b86a", thickness: 38, height: 258 },  { id: "48-laws", title: "The 48 Laws of Power", author: "Robert Greene", color: "#111111", textColor: "#e0a03a", thickness: 34, height: 278 },];<BookShelf books={books} />

Props

PropTypeDefaultDescriptionRequired
booksArray[]Array of book objects with id, title, author, spine, cover, color, textColor, height, thickness, coverWidth.No
activeIdstring | numberundefinedOpen book's id. Pass it to control the component; use null for 'all closed'.No
defaultActiveIdstring | numbernullInitially open book when uncontrolled.No
onActiveChange(id, book) => voidundefinedCalled as (id, book) when the open book changes. Both are null when the shelf closes.No
bookHeightnumber260Default book height in px.No
thicknessnumber40Default spine width in px.No
gapnumber3Space between books in px.No
align"center" | "start""center"Where the row sits in its frame.No
perspectivenumber11003D perspective depth in px. Lower = stronger effect.No
transitionobject{ type: "spring", stiffness: 130, damping: 22, mass: 1, restDelta: 0.05, restSpeed: 1 }Framer Motion transition used for every movement. Keep its identity stable.No
fitbooleantruetrue: shelf scales down on narrow screens so every book stays visible. false: it scrolls horizontally instead.No
eagerCoversbooleanfalsefalse: cover images load when a book is hovered, focused, touched or opened. true: preload them all.No
unoptimizedImagesbooleanfalsetrue: next/image skips the optimizer. Use it for hosts missing from next.config.js, data: URLs or static exports.No
closeOnOutsideClickbooleantrueClose the open book when you click elsewhere.No
classNamestringundefinedExtra classes for the root element.No
shelfClassNamestringundefinedExtra classes for the shelf board.No
aria-labelstring"Bookshelf"Accessible name for the group.No