page.mdx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. export const metadata = { title: "@json-render/shadcn API" }
  2. # @json-render/shadcn
  3. 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`.
  4. ## Installation
  5. ```bash
  6. npm install @json-render/shadcn @json-render/core @json-render/react zod
  7. ```
  8. Your app must have Tailwind CSS configured.
  9. ## Entry Points
  10. | Entry Point | Exports | Use For |
  11. |-------------|---------|---------|
  12. | `@json-render/shadcn` | `shadcnComponents` | React implementations |
  13. | `@json-render/shadcn/catalog` | `shadcnComponentDefinitions` | Catalog schemas (no React dependency, safe for server) |
  14. ## Usage
  15. Pick the components you need from the standard definitions:
  16. ```typescript
  17. import { defineCatalog } from "@json-render/core";
  18. import { schema } from "@json-render/react/schema";
  19. import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog";
  20. import { defineRegistry } from "@json-render/react";
  21. import { shadcnComponents } from "@json-render/shadcn";
  22. // Catalog: pick definitions
  23. const catalog = defineCatalog(schema, {
  24. components: {
  25. Card: shadcnComponentDefinitions.Card,
  26. Stack: shadcnComponentDefinitions.Stack,
  27. Heading: shadcnComponentDefinitions.Heading,
  28. Button: shadcnComponentDefinitions.Button,
  29. Input: shadcnComponentDefinitions.Input,
  30. },
  31. actions: {},
  32. });
  33. // Registry: pick matching implementations
  34. const { registry } = defineRegistry(catalog, {
  35. components: {
  36. Card: shadcnComponents.Card,
  37. Stack: shadcnComponents.Stack,
  38. Heading: shadcnComponents.Heading,
  39. Button: shadcnComponents.Button,
  40. Input: shadcnComponents.Input,
  41. },
  42. });
  43. ```
  44. 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.
  45. ## Extending with Custom Components
  46. Add custom components alongside standard ones:
  47. ```typescript
  48. import { z } from "zod";
  49. const catalog = defineCatalog(schema, {
  50. components: {
  51. // Standard
  52. Card: shadcnComponentDefinitions.Card,
  53. Stack: shadcnComponentDefinitions.Stack,
  54. Button: shadcnComponentDefinitions.Button,
  55. // Custom
  56. Metric: {
  57. props: z.object({
  58. label: z.string(),
  59. value: z.string(),
  60. trend: z.enum(["up", "down", "neutral"]).nullable(),
  61. }),
  62. description: "KPI metric display",
  63. },
  64. },
  65. actions: {},
  66. });
  67. const { registry } = defineRegistry(catalog, {
  68. components: {
  69. Card: shadcnComponents.Card,
  70. Stack: shadcnComponents.Stack,
  71. Button: shadcnComponents.Button,
  72. Metric: ({ props }) => (
  73. <div>
  74. <span>{props.label}</span>
  75. <span>{props.value}</span>
  76. </div>
  77. ),
  78. },
  79. });
  80. ```
  81. ## Available Components
  82. ### Layout
  83. | Component | Description |
  84. |-----------|-------------|
  85. | `Card` | Container card with optional title, description, maxWidth, centered |
  86. | `Stack` | Flex container with direction, gap, align, justify |
  87. | `Grid` | Grid layout with columns (1-6) and gap |
  88. | `Separator` | Visual separator line with orientation |
  89. ### Navigation
  90. | Component | Description |
  91. |-----------|-------------|
  92. | `Tabs` | Tabbed navigation with tabs array, defaultValue, value |
  93. | `Accordion` | Collapsible sections with items array and type (single/multiple) |
  94. | `Collapsible` | Single collapsible section with title and defaultOpen |
  95. | `Pagination` | Page navigation with totalPages and page |
  96. ### Overlay
  97. | Component | Description |
  98. |-----------|-------------|
  99. | `Dialog` | Modal dialog with title, description, openPath |
  100. | `Drawer` | Bottom drawer with title, description, openPath |
  101. | `Tooltip` | Hover tooltip with content and text |
  102. | `Popover` | Click-triggered popover with trigger and content |
  103. | `DropdownMenu` | Dropdown menu with label and items array |
  104. ### Content
  105. | Component | Description |
  106. |-----------|-------------|
  107. | `Heading` | Heading text with level (h1-h4) |
  108. | `Text` | Paragraph with variant (body, caption, muted, lead, code) |
  109. | `Image` | Image with alt, width, height |
  110. | `Avatar` | User avatar with src, name, size |
  111. | `Badge` | Status badge with text and variant |
  112. | `Alert` | Alert banner with title, message, type |
  113. | `Carousel` | Horizontally scrollable carousel with items |
  114. | `Table` | Data table with columns and rows |
  115. ### Feedback
  116. | Component | Description |
  117. |-----------|-------------|
  118. | `Progress` | Progress bar with value, max, label |
  119. | `Skeleton` | Loading placeholder with width, height, rounded |
  120. | `Spinner` | Loading spinner with size and label |
  121. ### Input
  122. | Component | Description |
  123. |-----------|-------------|
  124. | `Button` | Clickable button with label, variant, disabled |
  125. | `Link` | Anchor link with label and href |
  126. | `Input` | Text input with label, name, type, placeholder, value, checks |
  127. | `Textarea` | Multi-line text input with label, name, placeholder, rows, value, checks |
  128. | `Select` | Dropdown select with label, name, options, value, checks |
  129. | `Checkbox` | Checkbox with label, name, checked |
  130. | `Radio` | Radio button group with label, name, options, value |
  131. | `Switch` | Toggle switch with label, name, checked |
  132. | `Slider` | Range slider with label, min, max, step, value |
  133. | `Toggle` | Toggle button with label, pressed, variant |
  134. | `ToggleGroup` | Group of toggle buttons with items, type, value |
  135. | `ButtonGroup` | Group of buttons with buttons array and selected |
  136. ## Notes
  137. - The `/catalog` entry point has no React dependency -- use it for server-side prompt generation
  138. - Components use Tailwind CSS classes -- your app must have Tailwind configured
  139. - Component implementations use bundled shadcn/ui primitives (not your app's `components/ui/`)
  140. - Form inputs support `checks` for validation (type + message pairs)
  141. - Events: inputs emit `change`/`submit`/`focus`/`blur`; buttons emit `press`; selects emit `change`/`select`