PiecesLibrary
Browse, search, and select canonical Puzzle Pieces from a responsive visual library with isolated previews.
PiecesLibrary is a compact visual picker for choosing a Piece to add in a
host editor. It renders a representative preview for every canonical Piece,
with a template filter and search by display name or canonical type. It is not
a page editor: it does not create, validate, persist, or arrange page
configurations.
Beta API maturity: Beta. This new picker API may evolve as usage is validated.
import { PiecesLibrary } from "@puzzle-ui/pieces/library";
export function InsertPiecePanel() {
return <PiecesLibrary initialTemplate="saas" />;
}Import and dependency
Import the picker and its public types from the dedicated
@puzzle-ui/pieces/library subpath. This entry point uses the existing Zod
registry, so install Zod 4 when using the library. Zod remains an optional
peer dependency; consumers importing only from @puzzle-ui/pieces do not
need it.
bun add @puzzle-ui/pieces zodProps
| Prop | Type | Description |
|---|---|---|
initialTemplate | Template (optional) | The initial template filter. Omit it to start with all Pieces. This is an initial value; rerendering the parent does not reset a user's later filter choice. |
sectionsOnly | boolean (optional; default false) | Show only complete section Pieces: hero/*-hero layouts and *-section types. |
onChange | (selection: PieceLibrarySelection) => void (optional) | Called once when the user selects a Piece card. |
className | string (optional) | Additional class on the library root. |
Template is exported by @puzzle-ui/pieces/zod. The filter options are read
from the same registry used to validate Piece configurations. The All
template option removes the template filter; when sectionsOnly is enabled,
that section filter remains in effect. Each named template shows only Pieces
that support it. Set sectionsOnly when the host needs complete page-section
compositions without standalone controls and utilities.
Selection
The callback receives the canonical Piece type, a supported template context, and its Zod definition:
import { useState } from "react";
import {
PiecesLibrary,
type PieceLibrarySelection,
} from "@puzzle-ui/pieces/library";
function InsertPiecePanel() {
const [selection, setSelection] =
useState<PieceLibrarySelection | null>(null);
return (
<>
<PiecesLibrary initialTemplate="saas" onChange={setSelection} />
{selection && (
<p>
Selected {selection.type} for the {selection.template} template.
</p>
)}
</>
);
}When a specific template is active, it is included in the selection. When
All is active, the selection uses the first template declared for that Piece
as a deterministic supported context. definition exposes the canonical Zod
definition and schema; preview-only demonstration props are never returned as
saved configuration.
Search, previews, and accessibility
Search updates immediately, ignores leading/trailing whitespace, and matches case-insensitively against both each display name and canonical type. Template filtering and search combine, and an empty message appears when no Piece matches.
The grid adapts to its container width. Cards are keyboard-operable with Enter and Space, have visible focus, and expose an accessible selection name. Preview subtrees are non-interactive: links, controls, and forms shown for visual context cannot take focus, navigate, submit, or invoke actions.
Previews use static representative content and local fixture media. Stateful commerce, CMS, and media-management Pieces are demonstrations only; they do not connect to a backend, upload assets, navigate, reserve availability, or perform mutations. Preview content scales uniformly to fit each tile's width, preserving its proportions. A preview's sample props are not a Piece's persisted configuration defaults. The consuming application owns configuration, validation, persistence, editor state, and any real actions.