page.mdx 5.8 KB

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