page.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import Link from "next/link";
  2. import { Button } from "@/components/ui/button";
  3. import { Demo } from "@/components/demo";
  4. import { Code } from "@/components/code";
  5. import { CopyButton } from "@/components/copy-button";
  6. export default function Home() {
  7. return (
  8. <>
  9. {/* Hero */}
  10. <section className="max-w-5xl mx-auto px-6 pt-24 pb-16 text-center">
  11. <h1 className="text-5xl sm:text-6xl md:text-7xl font-bold tracking-tighter mb-6">
  12. AI → json-render → UI
  13. </h1>
  14. <p className="text-lg text-muted-foreground max-w-2xl mx-auto mb-12 leading-relaxed">
  15. Define a component catalog. Users prompt. AI outputs JSON constrained
  16. to your catalog. Your components render it.
  17. </p>
  18. <Demo />
  19. <div className="flex items-center justify-center gap-2 border border-border rounded px-4 py-3 mt-12 mx-auto w-fit">
  20. <code className="text-sm bg-transparent">
  21. npm install @json-render/core @json-render/react
  22. </code>
  23. <CopyButton text="npm install @json-render/core @json-render/react" />
  24. </div>
  25. <div className="flex gap-3 justify-center mt-6">
  26. <Button size="lg" asChild>
  27. <Link href="/docs">Get Started</Link>
  28. </Button>
  29. <Button size="lg" variant="outline" asChild>
  30. <a
  31. href="https://github.com/vercel-labs/json-render"
  32. target="_blank"
  33. rel="noopener noreferrer"
  34. >
  35. <svg viewBox="0 0 24 24" fill="currentColor" className="w-5 h-5">
  36. <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
  37. </svg>
  38. GitHub
  39. </a>
  40. </Button>
  41. </div>
  42. </section>
  43. {/* How it works */}
  44. <section className="border-t border-border">
  45. <div className="max-w-5xl mx-auto px-6 py-24">
  46. <div className="grid md:grid-cols-3 gap-12">
  47. <div>
  48. <div className="text-xs text-muted-foreground font-mono mb-3">
  49. 01
  50. </div>
  51. <h3 className="text-lg font-semibold mb-2">
  52. Define Your Catalog
  53. </h3>
  54. <p className="text-sm text-muted-foreground leading-relaxed">
  55. Set the guardrails. Define which components, actions, and data
  56. bindings AI can use.
  57. </p>
  58. </div>
  59. <div>
  60. <div className="text-xs text-muted-foreground font-mono mb-3">
  61. 02
  62. </div>
  63. <h3 className="text-lg font-semibold mb-2">Users Prompt</h3>
  64. <p className="text-sm text-muted-foreground leading-relaxed">
  65. End users describe what they want. AI generates JSON constrained
  66. to your catalog.
  67. </p>
  68. </div>
  69. <div>
  70. <div className="text-xs text-muted-foreground font-mono mb-3">
  71. 03
  72. </div>
  73. <h3 className="text-lg font-semibold mb-2">Render Instantly</h3>
  74. <p className="text-sm text-muted-foreground leading-relaxed">
  75. Stream the response. Your components render progressively as
  76. JSON arrives.
  77. </p>
  78. </div>
  79. </div>
  80. </div>
  81. </section>
  82. {/* Code example */}
  83. <section className="border-t border-border">
  84. <div className="max-w-5xl mx-auto px-6 py-24">
  85. <div className="grid lg:grid-cols-2 gap-12">
  86. <div className="min-w-0">
  87. <h2 className="text-2xl font-semibold mb-4">
  88. Define your catalog
  89. </h2>
  90. <p className="text-muted-foreground mb-6">
  91. Components, actions, and validation functions.
  92. </p>
  93. <Code lang="typescript">{`import { createCatalog } from '@json-render/core';
  94. import { z } from 'zod';
  95. export const catalog = createCatalog({
  96. components: {
  97. Card: {
  98. props: z.object({
  99. title: z.string(),
  100. description: z.string().nullable(),
  101. }),
  102. hasChildren: true,
  103. },
  104. Metric: {
  105. props: z.object({
  106. label: z.string(),
  107. valuePath: z.string(),
  108. format: z.enum(['currency', 'percent']),
  109. }),
  110. },
  111. },
  112. actions: {
  113. export: { params: z.object({ format: z.string() }) },
  114. },
  115. });`}</Code>
  116. </div>
  117. <div className="min-w-0">
  118. <h2 className="text-2xl font-semibold mb-4">AI generates JSON</h2>
  119. <p className="text-muted-foreground mb-6">
  120. Constrained output that your components render natively.
  121. </p>
  122. <Code lang="json">{`{
  123. "root": "dashboard",
  124. "elements": {
  125. "dashboard": {
  126. "type": "Card",
  127. "props": {
  128. "title": "Revenue Dashboard"
  129. },
  130. "children": ["revenue"]
  131. },
  132. "revenue": {
  133. "type": "Metric",
  134. "props": {
  135. "label": "Total Revenue",
  136. "valuePath": "/metrics/revenue",
  137. "format": "currency"
  138. }
  139. }
  140. }
  141. }`}</Code>
  142. </div>
  143. </div>
  144. </div>
  145. </section>
  146. {/* Code Export */}
  147. <section className="border-t border-border">
  148. <div className="max-w-5xl mx-auto px-6 py-24">
  149. <div className="text-center mb-12">
  150. <h2 className="text-2xl font-semibold mb-4">Export as Code</h2>
  151. <p className="text-muted-foreground max-w-2xl mx-auto">
  152. Export generated UI as standalone React components. No runtime
  153. dependencies required.
  154. </p>
  155. </div>
  156. <div className="grid lg:grid-cols-2 gap-12">
  157. <div className="min-w-0">
  158. <h3 className="text-lg font-semibold mb-4">Generated UI Tree</h3>
  159. <p className="text-muted-foreground mb-6 text-sm">
  160. AI generates a JSON structure from the user&apos;s prompt.
  161. </p>
  162. <Code lang="json">{`{
  163. "root": "card",
  164. "elements": {
  165. "card": {
  166. "type": "Card",
  167. "props": { "title": "Revenue" },
  168. "children": ["metric", "chart"]
  169. },
  170. "metric": {
  171. "type": "Metric",
  172. "props": {
  173. "label": "Total Revenue",
  174. "valuePath": "analytics/revenue",
  175. "format": "currency"
  176. }
  177. },
  178. "chart": {
  179. "type": "Chart",
  180. "props": {
  181. "dataPath": "analytics/salesByRegion"
  182. }
  183. }
  184. }
  185. }`}</Code>
  186. </div>
  187. <div className="min-w-0">
  188. <h3 className="text-lg font-semibold mb-4">
  189. Exported React Code
  190. </h3>
  191. <p className="text-muted-foreground mb-6 text-sm">
  192. Export as a standalone Next.js project with all components.
  193. </p>
  194. <Code lang="tsx">{`"use client";
  195. import { Card, Metric, Chart } from "@/components/ui";
  196. const data = {
  197. analytics: {
  198. revenue: 125000,
  199. salesByRegion: [
  200. { label: "US", value: 45000 },
  201. { label: "EU", value: 35000 },
  202. ],
  203. },
  204. };
  205. export default function Page() {
  206. return (
  207. <Card data={data} title="Revenue">
  208. <Metric
  209. data={data}
  210. label="Total Revenue"
  211. valuePath="analytics/revenue"
  212. format="currency"
  213. />
  214. <Chart data={data} dataPath="analytics/salesByRegion" />
  215. </Card>
  216. );
  217. }`}</Code>
  218. </div>
  219. </div>
  220. <div className="mt-8 text-center">
  221. <p className="text-sm text-muted-foreground">
  222. The export includes{" "}
  223. <code className="text-foreground">package.json</code>, component
  224. files, styles, and everything needed to run independently.
  225. </p>
  226. </div>
  227. </div>
  228. </section>
  229. {/* Features */}
  230. <section className="border-t border-border">
  231. <div className="max-w-5xl mx-auto px-6 py-24">
  232. <h2 className="text-2xl font-semibold mb-12 text-center">Features</h2>
  233. <div className="grid sm:grid-cols-2 lg:grid-cols-3 gap-8">
  234. {[
  235. {
  236. title: "Guardrails",
  237. desc: "AI can only use components you define in the catalog",
  238. },
  239. {
  240. title: "Streaming",
  241. desc: "Progressive rendering as JSON streams from the model",
  242. },
  243. {
  244. title: "Code Export",
  245. desc: "Export as standalone React code with no runtime dependencies",
  246. },
  247. {
  248. title: "Data Binding",
  249. desc: "Two-way binding with JSON Pointer paths",
  250. },
  251. {
  252. title: "Actions",
  253. desc: "Named actions handled by your application",
  254. },
  255. {
  256. title: "Visibility",
  257. desc: "Conditional show/hide based on data or auth",
  258. },
  259. ].map((feature) => (
  260. <div key={feature.title}>
  261. <h3 className="font-semibold mb-2">{feature.title}</h3>
  262. <p className="text-sm text-muted-foreground">{feature.desc}</p>
  263. </div>
  264. ))}
  265. </div>
  266. </div>
  267. </section>
  268. {/* CTA */}
  269. <section className="border-t border-border">
  270. <div className="max-w-4xl mx-auto px-6 py-24 text-center">
  271. <h2 className="text-2xl font-semibold mb-4">Get started</h2>
  272. <div className="flex items-center justify-center gap-2 border border-border rounded px-4 py-3 mb-8 mx-auto w-fit">
  273. <code className="text-sm bg-transparent">
  274. npm install @json-render/core @json-render/react
  275. </code>
  276. <CopyButton text="npm install @json-render/core @json-render/react" />
  277. </div>
  278. <div>
  279. <Button asChild>
  280. <Link href="/docs">Documentation</Link>
  281. </Button>
  282. </div>
  283. </div>
  284. </section>
  285. </>
  286. );
  287. }