page.mdx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import { pageMetadata } from "@/lib/page-metadata"
  2. export const metadata = pageMetadata("docs/api/shadcn")
  3. # @json-render/shadcn
  4. 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`.
  5. ## Installation
  6. ```bash
  7. npm install @json-render/shadcn @json-render/core @json-render/react 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</code></td>
  22. <td><code>shadcnComponents</code></td>
  23. <td>React implementations</td>
  24. </tr>
  25. <tr>
  26. <td><code>@json-render/shadcn/catalog</code></td>
  27. <td><code>shadcnComponentDefinitions</code></td>
  28. <td>Catalog schemas (no React 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/react/schema";
  37. import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog";
  38. import { defineRegistry } from "@json-render/react";
  39. import { shadcnComponents } from "@json-render/shadcn";
  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. 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.
  63. ## Extending with Custom Components
  64. Add custom components alongside standard ones:
  65. ```typescript
  66. import { z } from "zod";
  67. const catalog = defineCatalog(schema, {
  68. components: {
  69. // Standard
  70. Card: shadcnComponentDefinitions.Card,
  71. Stack: shadcnComponentDefinitions.Stack,
  72. Button: shadcnComponentDefinitions.Button,
  73. // Custom
  74. Metric: {
  75. props: z.object({
  76. label: z.string(),
  77. value: z.string(),
  78. trend: z.enum(["up", "down", "neutral"]).nullable(),
  79. }),
  80. description: "KPI metric display",
  81. },
  82. },
  83. actions: {},
  84. });
  85. const { registry } = defineRegistry(catalog, {
  86. components: {
  87. Card: shadcnComponents.Card,
  88. Stack: shadcnComponents.Stack,
  89. Button: shadcnComponents.Button,
  90. Metric: ({ props }) => (
  91. <div>
  92. <span>{props.label}</span>
  93. <span>{props.value}</span>
  94. </div>
  95. ),
  96. },
  97. });
  98. ```
  99. ## Available Components
  100. ### Layout
  101. <table>
  102. <thead>
  103. <tr>
  104. <th>Component</th>
  105. <th>Description</th>
  106. </tr>
  107. </thead>
  108. <tbody>
  109. <tr>
  110. <td><code>Card</code></td>
  111. <td>Container card with optional title, description, maxWidth, centered</td>
  112. </tr>
  113. <tr>
  114. <td><code>Stack</code></td>
  115. <td>Flex container with direction, gap, align, justify</td>
  116. </tr>
  117. <tr>
  118. <td><code>Grid</code></td>
  119. <td>Grid layout with columns (1-6) and gap</td>
  120. </tr>
  121. <tr>
  122. <td><code>Separator</code></td>
  123. <td>Visual separator line with orientation</td>
  124. </tr>
  125. </tbody>
  126. </table>
  127. ### Navigation
  128. <table>
  129. <thead>
  130. <tr>
  131. <th>Component</th>
  132. <th>Description</th>
  133. </tr>
  134. </thead>
  135. <tbody>
  136. <tr>
  137. <td><code>Tabs</code></td>
  138. <td>Tabbed navigation with tabs array, defaultValue, value</td>
  139. </tr>
  140. <tr>
  141. <td><code>Accordion</code></td>
  142. <td>Collapsible sections with items array and type (single/multiple)</td>
  143. </tr>
  144. <tr>
  145. <td><code>Collapsible</code></td>
  146. <td>Single collapsible section with title and defaultOpen</td>
  147. </tr>
  148. <tr>
  149. <td><code>Pagination</code></td>
  150. <td>Page navigation with totalPages and page</td>
  151. </tr>
  152. </tbody>
  153. </table>
  154. ### Overlay
  155. <table>
  156. <thead>
  157. <tr>
  158. <th>Component</th>
  159. <th>Description</th>
  160. </tr>
  161. </thead>
  162. <tbody>
  163. <tr>
  164. <td><code>Dialog</code></td>
  165. <td>Modal dialog with title, description, openPath</td>
  166. </tr>
  167. <tr>
  168. <td><code>Drawer</code></td>
  169. <td>Bottom drawer with title, description, openPath</td>
  170. </tr>
  171. <tr>
  172. <td><code>Tooltip</code></td>
  173. <td>Hover tooltip with content and text</td>
  174. </tr>
  175. <tr>
  176. <td><code>Popover</code></td>
  177. <td>Click-triggered popover with trigger and content</td>
  178. </tr>
  179. <tr>
  180. <td><code>DropdownMenu</code></td>
  181. <td>Dropdown menu with label and items array</td>
  182. </tr>
  183. </tbody>
  184. </table>
  185. ### Content
  186. <table>
  187. <thead>
  188. <tr>
  189. <th>Component</th>
  190. <th>Description</th>
  191. </tr>
  192. </thead>
  193. <tbody>
  194. <tr>
  195. <td><code>Heading</code></td>
  196. <td>Heading text with level (h1-h4)</td>
  197. </tr>
  198. <tr>
  199. <td><code>Text</code></td>
  200. <td>Paragraph with variant (body, caption, muted, lead, code)</td>
  201. </tr>
  202. <tr>
  203. <td><code>Image</code></td>
  204. <td>Image with alt, width, height</td>
  205. </tr>
  206. <tr>
  207. <td><code>Avatar</code></td>
  208. <td>User avatar with src, name, size</td>
  209. </tr>
  210. <tr>
  211. <td><code>Badge</code></td>
  212. <td>Status badge with text and variant</td>
  213. </tr>
  214. <tr>
  215. <td><code>Alert</code></td>
  216. <td>Alert banner with title, message, type</td>
  217. </tr>
  218. <tr>
  219. <td><code>Carousel</code></td>
  220. <td>Horizontally scrollable carousel with items</td>
  221. </tr>
  222. <tr>
  223. <td><code>Table</code></td>
  224. <td>Data table with columns and rows</td>
  225. </tr>
  226. </tbody>
  227. </table>
  228. ### Feedback
  229. <table>
  230. <thead>
  231. <tr>
  232. <th>Component</th>
  233. <th>Description</th>
  234. </tr>
  235. </thead>
  236. <tbody>
  237. <tr>
  238. <td><code>Progress</code></td>
  239. <td>Progress bar with value, max, label</td>
  240. </tr>
  241. <tr>
  242. <td><code>Skeleton</code></td>
  243. <td>Loading placeholder with width, height, rounded</td>
  244. </tr>
  245. <tr>
  246. <td><code>Spinner</code></td>
  247. <td>Loading spinner with size and label</td>
  248. </tr>
  249. </tbody>
  250. </table>
  251. ### Input
  252. <table>
  253. <thead>
  254. <tr>
  255. <th>Component</th>
  256. <th>Description</th>
  257. </tr>
  258. </thead>
  259. <tbody>
  260. <tr>
  261. <td><code>Button</code></td>
  262. <td>Clickable button with label, variant, disabled</td>
  263. </tr>
  264. <tr>
  265. <td><code>Link</code></td>
  266. <td>Anchor link with label and href</td>
  267. </tr>
  268. <tr>
  269. <td><code>Input</code></td>
  270. <td>Text input with label, name, type, placeholder, value, checks</td>
  271. </tr>
  272. <tr>
  273. <td><code>Textarea</code></td>
  274. <td>Multi-line text input with label, name, placeholder, rows, value, checks</td>
  275. </tr>
  276. <tr>
  277. <td><code>Select</code></td>
  278. <td>Dropdown select with label, name, options, value, checks</td>
  279. </tr>
  280. <tr>
  281. <td><code>Checkbox</code></td>
  282. <td>Checkbox with label, name, checked</td>
  283. </tr>
  284. <tr>
  285. <td><code>Radio</code></td>
  286. <td>Radio button group with label, name, options, value</td>
  287. </tr>
  288. <tr>
  289. <td><code>Switch</code></td>
  290. <td>Toggle switch with label, name, checked</td>
  291. </tr>
  292. <tr>
  293. <td><code>Slider</code></td>
  294. <td>Range slider with label, min, max, step, value</td>
  295. </tr>
  296. <tr>
  297. <td><code>Toggle</code></td>
  298. <td>Toggle button with label, pressed, variant</td>
  299. </tr>
  300. <tr>
  301. <td><code>ToggleGroup</code></td>
  302. <td>Group of toggle buttons with items, type, value</td>
  303. </tr>
  304. <tr>
  305. <td><code>ButtonGroup</code></td>
  306. <td>Group of buttons with buttons array and selected</td>
  307. </tr>
  308. </tbody>
  309. </table>
  310. ## Notes
  311. - The `/catalog` entry point has no React dependency -- use it for server-side prompt generation
  312. - Components use Tailwind CSS classes -- your app must have Tailwind configured
  313. - Component implementations use bundled shadcn/ui primitives (not your app's `components/ui/`)
  314. - Form inputs support `checks` for validation (type + message pairs)
  315. - Events: inputs emit `change`/`submit`/`focus`/`blur`; buttons emit `press`; selects emit `change`/`select`