page.mdx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. import { pageMetadata } from "@/lib/page-metadata"
  2. export const metadata = pageMetadata("docs/api/shadcn-svelte")
  3. # @json-render/shadcn-svelte
  4. 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`.
  5. ## Installation
  6. ```bash
  7. npm install @json-render/shadcn-svelte @json-render/core @json-render/svelte zod
  8. ```
  9. Your app must have Tailwind CSS configured.
  10. ## Entry Points
  11. <table>
  12. <thead>
  13. <tr>
  14. <th>Entry Point</th>
  15. <th>Exports</th>
  16. <th>Use For</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. <tr>
  21. <td><code>@json-render/shadcn-svelte</code></td>
  22. <td><code>shadcnComponents</code>, <code>shadcnComponentDefinitions</code></td>
  23. <td>Svelte implementations + catalog schemas</td>
  24. </tr>
  25. <tr>
  26. <td><code>@json-render/shadcn-svelte/catalog</code></td>
  27. <td><code>shadcnComponentDefinitions</code></td>
  28. <td>Catalog schemas only (no Svelte dependency, safe for server)</td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. ## Usage
  33. Pick the components you need from the standard definitions:
  34. ```typescript
  35. import { defineCatalog } from "@json-render/core";
  36. import { schema } from "@json-render/svelte/schema";
  37. import { shadcnComponentDefinitions } from "@json-render/shadcn-svelte/catalog";
  38. import { defineRegistry } from "@json-render/svelte";
  39. import { shadcnComponents } from "@json-render/shadcn-svelte";
  40. // Catalog: pick definitions
  41. const catalog = defineCatalog(schema, {
  42. components: {
  43. Card: shadcnComponentDefinitions.Card,
  44. Stack: shadcnComponentDefinitions.Stack,
  45. Heading: shadcnComponentDefinitions.Heading,
  46. Button: shadcnComponentDefinitions.Button,
  47. Input: shadcnComponentDefinitions.Input,
  48. },
  49. actions: {},
  50. });
  51. // Registry: pick matching implementations
  52. const { registry } = defineRegistry(catalog, {
  53. components: {
  54. Card: shadcnComponents.Card,
  55. Stack: shadcnComponents.Stack,
  56. Heading: shadcnComponents.Heading,
  57. Button: shadcnComponents.Button,
  58. Input: shadcnComponents.Input,
  59. },
  60. });
  61. ```
  62. Then render in your Svelte component:
  63. ```svelte
  64. <script lang="ts">
  65. import { Renderer, JsonUIProvider } from "@json-render/svelte";
  66. export let spec;
  67. export let registry;
  68. </script>
  69. <JsonUIProvider initialState={spec?.state ?? {}}>
  70. <Renderer {spec} {registry} />
  71. </JsonUIProvider>
  72. ```
  73. ## Available Components
  74. ### Layout
  75. <table>
  76. <thead>
  77. <tr>
  78. <th>Component</th>
  79. <th>Description</th>
  80. </tr>
  81. </thead>
  82. <tbody>
  83. <tr>
  84. <td><code>Card</code></td>
  85. <td>Container card with optional title, description, maxWidth, centered</td>
  86. </tr>
  87. <tr>
  88. <td><code>Stack</code></td>
  89. <td>Flex container with direction, gap, align, justify</td>
  90. </tr>
  91. <tr>
  92. <td><code>Grid</code></td>
  93. <td>Grid layout with columns (1-6) and gap</td>
  94. </tr>
  95. <tr>
  96. <td><code>Separator</code></td>
  97. <td>Visual separator line with orientation</td>
  98. </tr>
  99. </tbody>
  100. </table>
  101. ### Navigation
  102. <table>
  103. <thead>
  104. <tr>
  105. <th>Component</th>
  106. <th>Description</th>
  107. </tr>
  108. </thead>
  109. <tbody>
  110. <tr>
  111. <td><code>Tabs</code></td>
  112. <td>Tabbed navigation with tabs array, defaultValue, value</td>
  113. </tr>
  114. <tr>
  115. <td><code>Accordion</code></td>
  116. <td>Collapsible sections with items array and type (single/multiple)</td>
  117. </tr>
  118. <tr>
  119. <td><code>Collapsible</code></td>
  120. <td>Single collapsible section with title and defaultOpen</td>
  121. </tr>
  122. <tr>
  123. <td><code>Pagination</code></td>
  124. <td>Page navigation with totalPages and page</td>
  125. </tr>
  126. </tbody>
  127. </table>
  128. ### Overlay
  129. <table>
  130. <thead>
  131. <tr>
  132. <th>Component</th>
  133. <th>Description</th>
  134. </tr>
  135. </thead>
  136. <tbody>
  137. <tr>
  138. <td><code>Dialog</code></td>
  139. <td>Modal dialog with title, description, openPath</td>
  140. </tr>
  141. <tr>
  142. <td><code>Drawer</code></td>
  143. <td>Bottom drawer with title, description, openPath</td>
  144. </tr>
  145. <tr>
  146. <td><code>Tooltip</code></td>
  147. <td>Hover tooltip with content and text</td>
  148. </tr>
  149. <tr>
  150. <td><code>Popover</code></td>
  151. <td>Click-triggered popover with trigger and content</td>
  152. </tr>
  153. <tr>
  154. <td><code>DropdownMenu</code></td>
  155. <td>Dropdown menu with label and items array</td>
  156. </tr>
  157. </tbody>
  158. </table>
  159. ### Content
  160. <table>
  161. <thead>
  162. <tr>
  163. <th>Component</th>
  164. <th>Description</th>
  165. </tr>
  166. </thead>
  167. <tbody>
  168. <tr>
  169. <td><code>Heading</code></td>
  170. <td>Heading text with level (h1-h4)</td>
  171. </tr>
  172. <tr>
  173. <td><code>Text</code></td>
  174. <td>Paragraph with variant (body, caption, muted, lead, code)</td>
  175. </tr>
  176. <tr>
  177. <td><code>Image</code></td>
  178. <td>Image with alt, width, height</td>
  179. </tr>
  180. <tr>
  181. <td><code>Avatar</code></td>
  182. <td>User avatar with src, name, size</td>
  183. </tr>
  184. <tr>
  185. <td><code>Badge</code></td>
  186. <td>Status badge with text and variant</td>
  187. </tr>
  188. <tr>
  189. <td><code>Alert</code></td>
  190. <td>Alert banner with title, message, type</td>
  191. </tr>
  192. <tr>
  193. <td><code>Carousel</code></td>
  194. <td>Horizontally scrollable carousel with items</td>
  195. </tr>
  196. <tr>
  197. <td><code>Table</code></td>
  198. <td>Data table with columns and rows</td>
  199. </tr>
  200. </tbody>
  201. </table>
  202. ### Feedback
  203. <table>
  204. <thead>
  205. <tr>
  206. <th>Component</th>
  207. <th>Description</th>
  208. </tr>
  209. </thead>
  210. <tbody>
  211. <tr>
  212. <td><code>Progress</code></td>
  213. <td>Progress bar with value, max, label</td>
  214. </tr>
  215. <tr>
  216. <td><code>Skeleton</code></td>
  217. <td>Loading placeholder with width, height, rounded</td>
  218. </tr>
  219. <tr>
  220. <td><code>Spinner</code></td>
  221. <td>Loading spinner with size and label</td>
  222. </tr>
  223. </tbody>
  224. </table>
  225. ### Input
  226. <table>
  227. <thead>
  228. <tr>
  229. <th>Component</th>
  230. <th>Description</th>
  231. </tr>
  232. </thead>
  233. <tbody>
  234. <tr>
  235. <td><code>Button</code></td>
  236. <td>Clickable button with label, variant, disabled</td>
  237. </tr>
  238. <tr>
  239. <td><code>Link</code></td>
  240. <td>Anchor link with label and href</td>
  241. </tr>
  242. <tr>
  243. <td><code>Input</code></td>
  244. <td>Text input with label, name, type, placeholder, value, checks</td>
  245. </tr>
  246. <tr>
  247. <td><code>Textarea</code></td>
  248. <td>Multi-line text input with label, name, placeholder, rows, value, checks</td>
  249. </tr>
  250. <tr>
  251. <td><code>Select</code></td>
  252. <td>Dropdown select with label, name, options, value, checks</td>
  253. </tr>
  254. <tr>
  255. <td><code>Checkbox</code></td>
  256. <td>Checkbox with label, name, checked</td>
  257. </tr>
  258. <tr>
  259. <td><code>Radio</code></td>
  260. <td>Radio button group with label, name, options, value</td>
  261. </tr>
  262. <tr>
  263. <td><code>Switch</code></td>
  264. <td>Toggle switch with label, name, checked</td>
  265. </tr>
  266. <tr>
  267. <td><code>Slider</code></td>
  268. <td>Range slider with label, min, max, step, value</td>
  269. </tr>
  270. <tr>
  271. <td><code>Toggle</code></td>
  272. <td>Toggle button with label, pressed, variant</td>
  273. </tr>
  274. <tr>
  275. <td><code>ToggleGroup</code></td>
  276. <td>Group of toggle buttons with items, type, value</td>
  277. </tr>
  278. <tr>
  279. <td><code>ButtonGroup</code></td>
  280. <td>Group of buttons with buttons array and selected</td>
  281. </tr>
  282. </tbody>
  283. </table>
  284. ## Notes
  285. - The `/catalog` entry point has no Svelte dependency -- use it for server-side prompt generation
  286. - Components use Tailwind CSS classes -- your app must have Tailwind configured
  287. - Component implementations use bundled shadcn-svelte primitives (not your app's `$lib/components/ui/`)
  288. - Form inputs support `checks` for validation (type + message pairs) and `validateOn` for timing
  289. - Events: inputs emit `change`/`submit`/`focus`/`blur`; buttons emit `press`; selects emit `change`/`select`