|
|
@@ -0,0 +1,320 @@
|
|
|
+import { pageMetadata } from "@/lib/page-metadata"
|
|
|
+export const metadata = pageMetadata("docs/api/shadcn-svelte")
|
|
|
+
|
|
|
+# @json-render/shadcn-svelte
|
|
|
+
|
|
|
+Pre-built [shadcn-svelte](https://www.shadcn-svelte.com/) components for json-render. 36 components built on Svelte 5 + Tailwind CSS, ready to use with `defineCatalog` and `defineRegistry`.
|
|
|
+
|
|
|
+## Installation
|
|
|
+
|
|
|
+```bash
|
|
|
+npm install @json-render/shadcn-svelte @json-render/core @json-render/svelte 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-svelte</code></td>
|
|
|
+<td><code>shadcnComponents</code>, <code>shadcnComponentDefinitions</code></td>
|
|
|
+<td>Svelte implementations + catalog schemas</td>
|
|
|
+</tr>
|
|
|
+<tr>
|
|
|
+<td><code>@json-render/shadcn-svelte/catalog</code></td>
|
|
|
+<td><code>shadcnComponentDefinitions</code></td>
|
|
|
+<td>Catalog schemas only (no Svelte 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/svelte/schema";
|
|
|
+import { shadcnComponentDefinitions } from "@json-render/shadcn-svelte/catalog";
|
|
|
+import { defineRegistry } from "@json-render/svelte";
|
|
|
+import { shadcnComponents } from "@json-render/shadcn-svelte";
|
|
|
+
|
|
|
+// 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,
|
|
|
+ },
|
|
|
+});
|
|
|
+```
|
|
|
+
|
|
|
+Then render in your Svelte component:
|
|
|
+
|
|
|
+```svelte
|
|
|
+<script lang="ts">
|
|
|
+ import { Renderer, JsonUIProvider } from "@json-render/svelte";
|
|
|
+
|
|
|
+ export let spec;
|
|
|
+ export let registry;
|
|
|
+</script>
|
|
|
+
|
|
|
+<JsonUIProvider initialState={spec?.state ?? {}}>
|
|
|
+ <Renderer {spec} {registry} />
|
|
|
+</JsonUIProvider>
|
|
|
+```
|
|
|
+
|
|
|
+## 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 Svelte dependency -- use it for server-side prompt generation
|
|
|
+- Components use Tailwind CSS classes -- your app must have Tailwind configured
|
|
|
+- Component implementations use bundled shadcn-svelte primitives (not your app's `$lib/components/ui/`)
|
|
|
+- Form inputs support `checks` for validation (type + message pairs) and `validateOn` for timing
|
|
|
+- Events: inputs emit `change`/`submit`/`focus`/`blur`; buttons emit `press`; selects emit `change`/`select`
|