| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- import { pageMetadata } from "@/lib/page-metadata"
- export const metadata = pageMetadata("docs/api/shadcn")
- # @json-render/shadcn
- Pre-built [shadcn/ui](https://ui.shadcn.com/) components for json-render. 36 components built on Radix UI + Tailwind CSS, ready to use with `defineCatalog` and `defineRegistry`.
- ## Installation
- ```bash
- npm install @json-render/shadcn @json-render/core @json-render/react zod
- ```
- Your app must have Tailwind CSS configured.
- ## Entry Points
- <table>
- <thead>
- <tr>
- <th>Entry Point</th>
- <th>Exports</th>
- <th>Use For</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>@json-render/shadcn</code></td>
- <td><code>shadcnComponents</code></td>
- <td>React implementations</td>
- </tr>
- <tr>
- <td><code>@json-render/shadcn/catalog</code></td>
- <td><code>shadcnComponentDefinitions</code></td>
- <td>Catalog schemas (no React dependency, safe for server)</td>
- </tr>
- </tbody>
- </table>
- ## Usage
- Pick the components you need from the standard definitions:
- ```typescript
- import { defineCatalog } from "@json-render/core";
- import { schema } from "@json-render/react/schema";
- import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog";
- import { defineRegistry } from "@json-render/react";
- import { shadcnComponents } from "@json-render/shadcn";
- // Catalog: pick definitions
- const catalog = defineCatalog(schema, {
- components: {
- Card: shadcnComponentDefinitions.Card,
- Stack: shadcnComponentDefinitions.Stack,
- Heading: shadcnComponentDefinitions.Heading,
- Button: shadcnComponentDefinitions.Button,
- Input: shadcnComponentDefinitions.Input,
- },
- actions: {},
- });
- // Registry: pick matching implementations
- const { registry } = defineRegistry(catalog, {
- components: {
- Card: shadcnComponents.Card,
- Stack: shadcnComponents.Stack,
- Heading: shadcnComponents.Heading,
- Button: shadcnComponents.Button,
- Input: shadcnComponents.Input,
- },
- });
- ```
- State actions (`setState`, `pushState`, `removeState`) are built into the React schema and handled by `ActionProvider` automatically. You don't need to declare them in your catalog.
- ## Extending with Custom Components
- Add custom components alongside standard ones:
- ```typescript
- import { z } from "zod";
- const catalog = defineCatalog(schema, {
- components: {
- // Standard
- Card: shadcnComponentDefinitions.Card,
- Stack: shadcnComponentDefinitions.Stack,
- Button: shadcnComponentDefinitions.Button,
- // Custom
- Metric: {
- props: z.object({
- label: z.string(),
- value: z.string(),
- trend: z.enum(["up", "down", "neutral"]).nullable(),
- }),
- description: "KPI metric display",
- },
- },
- actions: {},
- });
- const { registry } = defineRegistry(catalog, {
- components: {
- Card: shadcnComponents.Card,
- Stack: shadcnComponents.Stack,
- Button: shadcnComponents.Button,
- Metric: ({ props }) => (
- <div>
- <span>{props.label}</span>
- <span>{props.value}</span>
- </div>
- ),
- },
- });
- ```
- ## Available Components
- ### Layout
- <table>
- <thead>
- <tr>
- <th>Component</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>Card</code></td>
- <td>Container card with optional title, description, maxWidth, centered</td>
- </tr>
- <tr>
- <td><code>Stack</code></td>
- <td>Flex container with direction, gap, align, justify</td>
- </tr>
- <tr>
- <td><code>Grid</code></td>
- <td>Grid layout with columns (1-6) and gap</td>
- </tr>
- <tr>
- <td><code>Separator</code></td>
- <td>Visual separator line with orientation</td>
- </tr>
- </tbody>
- </table>
- ### Navigation
- <table>
- <thead>
- <tr>
- <th>Component</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>Tabs</code></td>
- <td>Tabbed navigation with tabs array, defaultValue, value</td>
- </tr>
- <tr>
- <td><code>Accordion</code></td>
- <td>Collapsible sections with items array and type (single/multiple)</td>
- </tr>
- <tr>
- <td><code>Collapsible</code></td>
- <td>Single collapsible section with title and defaultOpen</td>
- </tr>
- <tr>
- <td><code>Pagination</code></td>
- <td>Page navigation with totalPages and page</td>
- </tr>
- </tbody>
- </table>
- ### Overlay
- <table>
- <thead>
- <tr>
- <th>Component</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>Dialog</code></td>
- <td>Modal dialog with title, description, openPath</td>
- </tr>
- <tr>
- <td><code>Drawer</code></td>
- <td>Bottom drawer with title, description, openPath</td>
- </tr>
- <tr>
- <td><code>Tooltip</code></td>
- <td>Hover tooltip with content and text</td>
- </tr>
- <tr>
- <td><code>Popover</code></td>
- <td>Click-triggered popover with trigger and content</td>
- </tr>
- <tr>
- <td><code>DropdownMenu</code></td>
- <td>Dropdown menu with label and items array</td>
- </tr>
- </tbody>
- </table>
- ### Content
- <table>
- <thead>
- <tr>
- <th>Component</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>Heading</code></td>
- <td>Heading text with level (h1-h4)</td>
- </tr>
- <tr>
- <td><code>Text</code></td>
- <td>Paragraph with variant (body, caption, muted, lead, code)</td>
- </tr>
- <tr>
- <td><code>Image</code></td>
- <td>Image with alt, width, height</td>
- </tr>
- <tr>
- <td><code>Avatar</code></td>
- <td>User avatar with src, name, size</td>
- </tr>
- <tr>
- <td><code>Badge</code></td>
- <td>Status badge with text and variant</td>
- </tr>
- <tr>
- <td><code>Alert</code></td>
- <td>Alert banner with title, message, type</td>
- </tr>
- <tr>
- <td><code>Carousel</code></td>
- <td>Horizontally scrollable carousel with items</td>
- </tr>
- <tr>
- <td><code>Table</code></td>
- <td>Data table with columns and rows</td>
- </tr>
- </tbody>
- </table>
- ### Feedback
- <table>
- <thead>
- <tr>
- <th>Component</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>Progress</code></td>
- <td>Progress bar with value, max, label</td>
- </tr>
- <tr>
- <td><code>Skeleton</code></td>
- <td>Loading placeholder with width, height, rounded</td>
- </tr>
- <tr>
- <td><code>Spinner</code></td>
- <td>Loading spinner with size and label</td>
- </tr>
- </tbody>
- </table>
- ### Input
- <table>
- <thead>
- <tr>
- <th>Component</th>
- <th>Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><code>Button</code></td>
- <td>Clickable button with label, variant, disabled</td>
- </tr>
- <tr>
- <td><code>Link</code></td>
- <td>Anchor link with label and href</td>
- </tr>
- <tr>
- <td><code>Input</code></td>
- <td>Text input with label, name, type, placeholder, value, checks</td>
- </tr>
- <tr>
- <td><code>Textarea</code></td>
- <td>Multi-line text input with label, name, placeholder, rows, value, checks</td>
- </tr>
- <tr>
- <td><code>Select</code></td>
- <td>Dropdown select with label, name, options, value, checks</td>
- </tr>
- <tr>
- <td><code>Checkbox</code></td>
- <td>Checkbox with label, name, checked</td>
- </tr>
- <tr>
- <td><code>Radio</code></td>
- <td>Radio button group with label, name, options, value</td>
- </tr>
- <tr>
- <td><code>Switch</code></td>
- <td>Toggle switch with label, name, checked</td>
- </tr>
- <tr>
- <td><code>Slider</code></td>
- <td>Range slider with label, min, max, step, value</td>
- </tr>
- <tr>
- <td><code>Toggle</code></td>
- <td>Toggle button with label, pressed, variant</td>
- </tr>
- <tr>
- <td><code>ToggleGroup</code></td>
- <td>Group of toggle buttons with items, type, value</td>
- </tr>
- <tr>
- <td><code>ButtonGroup</code></td>
- <td>Group of buttons with buttons array and selected</td>
- </tr>
- </tbody>
- </table>
- ## Notes
- - The `/catalog` entry point has no React dependency -- use it for server-side prompt generation
- - Components use Tailwind CSS classes -- your app must have Tailwind configured
- - Component implementations use bundled shadcn/ui primitives (not your app's `components/ui/`)
- - Form inputs support `checks` for validation (type + message pairs)
- - Events: inputs emit `change`/`submit`/`focus`/`blur`; buttons emit `press`; selects emit `change`/`select`
|