|
| 1 | +--- |
| 2 | +title: "Quick Start" |
| 3 | +description: "Get up and running with ObjectUI in 5 minutes - install, configure, and render your first server-driven UI" |
| 4 | +--- |
| 5 | + |
| 6 | +# Quick Start |
| 7 | + |
| 8 | +Get up and running with ObjectUI in **5 minutes**. This guide walks you through installation, basic setup, and rendering your first server-driven UI. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +- **Node.js** 20+ |
| 13 | +- **pnpm** 9+ (recommended) or npm/yarn |
| 14 | +- Basic knowledge of **React** and **TypeScript** |
| 15 | + |
| 16 | +## Step 1: Create a React Project |
| 17 | + |
| 18 | +If you don't have an existing React project, create one with Vite: |
| 19 | + |
| 20 | +```bash |
| 21 | +pnpm create vite my-app --template react-ts |
| 22 | +cd my-app |
| 23 | +``` |
| 24 | + |
| 25 | +## Step 2: Install ObjectUI |
| 26 | + |
| 27 | +Install the core ObjectUI packages: |
| 28 | + |
| 29 | +```bash |
| 30 | +pnpm add @object-ui/react @object-ui/core @object-ui/types @object-ui/components @object-ui/fields |
| 31 | +``` |
| 32 | + |
| 33 | +Install Tailwind CSS (required for styling): |
| 34 | + |
| 35 | +```bash |
| 36 | +pnpm add -D tailwindcss @tailwindcss/vite |
| 37 | +``` |
| 38 | + |
| 39 | +## Step 3: Configure Tailwind CSS |
| 40 | + |
| 41 | +Add Tailwind to your `vite.config.ts`: |
| 42 | + |
| 43 | +```ts |
| 44 | +import { defineConfig } from 'vite'; |
| 45 | +import react from '@vitejs/plugin-react'; |
| 46 | +import tailwindcss from '@tailwindcss/vite'; |
| 47 | + |
| 48 | +export default defineConfig({ |
| 49 | + plugins: [react(), tailwindcss()], |
| 50 | +}); |
| 51 | +``` |
| 52 | + |
| 53 | +Add to your `src/index.css`: |
| 54 | + |
| 55 | +```css |
| 56 | +@import "tailwindcss"; |
| 57 | +``` |
| 58 | + |
| 59 | +## Step 4: Register Components |
| 60 | + |
| 61 | +Create `src/setup.ts` to register the built-in components: |
| 62 | + |
| 63 | +```ts |
| 64 | +import { Registry } from '@object-ui/core'; |
| 65 | +import { registerAllComponents } from '@object-ui/components'; |
| 66 | +import { registerAllFields } from '@object-ui/fields'; |
| 67 | + |
| 68 | +// Register the built-in component renderers |
| 69 | +registerAllComponents(Registry); |
| 70 | +registerAllFields(Registry); |
| 71 | +``` |
| 72 | + |
| 73 | +## Step 5: Render Your First UI |
| 74 | + |
| 75 | +Replace `src/App.tsx` with: |
| 76 | + |
| 77 | +```tsx |
| 78 | +import './setup'; |
| 79 | +import { SchemaRenderer } from '@object-ui/react'; |
| 80 | + |
| 81 | +// Define your UI as JSON schema |
| 82 | +const schema = { |
| 83 | + type: 'form', |
| 84 | + fields: [ |
| 85 | + { |
| 86 | + name: 'name', |
| 87 | + label: 'Full Name', |
| 88 | + type: 'string', |
| 89 | + required: true, |
| 90 | + }, |
| 91 | + { |
| 92 | + name: 'email', |
| 93 | + label: 'Email Address', |
| 94 | + type: 'string', |
| 95 | + widget: 'email', |
| 96 | + }, |
| 97 | + { |
| 98 | + name: 'role', |
| 99 | + label: 'Role', |
| 100 | + type: 'string', |
| 101 | + widget: 'select', |
| 102 | + options: [ |
| 103 | + { label: 'Admin', value: 'admin' }, |
| 104 | + { label: 'Editor', value: 'editor' }, |
| 105 | + { label: 'Viewer', value: 'viewer' }, |
| 106 | + ], |
| 107 | + }, |
| 108 | + ], |
| 109 | + submitLabel: 'Create User', |
| 110 | +}; |
| 111 | + |
| 112 | +function App() { |
| 113 | + return ( |
| 114 | + <div className="max-w-md mx-auto p-8"> |
| 115 | + <h1 className="text-2xl font-bold mb-6">ObjectUI Demo</h1> |
| 116 | + <SchemaRenderer |
| 117 | + schema={schema} |
| 118 | + onSubmit={(data) => { |
| 119 | + console.log('Form submitted:', data); |
| 120 | + alert(JSON.stringify(data, null, 2)); |
| 121 | + }} |
| 122 | + /> |
| 123 | + </div> |
| 124 | + ); |
| 125 | +} |
| 126 | + |
| 127 | +export default App; |
| 128 | +``` |
| 129 | + |
| 130 | +## Step 6: Run the App |
| 131 | + |
| 132 | +```bash |
| 133 | +pnpm dev |
| 134 | +``` |
| 135 | + |
| 136 | +Open [http://localhost:5173](http://localhost:5173) — you should see a fully functional form rendered from JSON! |
| 137 | + |
| 138 | +## What Just Happened? |
| 139 | + |
| 140 | +1. **JSON Schema** → You defined a form as a JSON object with fields, types, and labels |
| 141 | +2. **Registry** → Built-in components were registered to handle each schema type |
| 142 | +3. **SchemaRenderer** → Converted the JSON into interactive React components (Shadcn UI) |
| 143 | +4. **Zero UI Code** → No JSX needed for the form fields — it's all driven by data |
| 144 | + |
| 145 | +## Next Steps |
| 146 | + |
| 147 | +### Add a Data Table |
| 148 | + |
| 149 | +```tsx |
| 150 | +const tableSchema = { |
| 151 | + type: 'crud', |
| 152 | + resource: 'users', |
| 153 | + columns: [ |
| 154 | + { name: 'name', label: 'Name' }, |
| 155 | + { name: 'email', label: 'Email' }, |
| 156 | + { name: 'role', label: 'Role' }, |
| 157 | + ], |
| 158 | +}; |
| 159 | +``` |
| 160 | + |
| 161 | +### Add Internationalization |
| 162 | + |
| 163 | +```bash |
| 164 | +pnpm add @object-ui/i18n |
| 165 | +``` |
| 166 | + |
| 167 | +```tsx |
| 168 | +import { I18nProvider } from '@object-ui/i18n'; |
| 169 | + |
| 170 | +function App() { |
| 171 | + return ( |
| 172 | + <I18nProvider config={{ defaultLanguage: 'zh' }}> |
| 173 | + <SchemaRenderer schema={schema} /> |
| 174 | + </I18nProvider> |
| 175 | + ); |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | +### Use Lazy Loading for Plugins |
| 180 | + |
| 181 | +```tsx |
| 182 | +import { createLazyPlugin } from '@object-ui/react'; |
| 183 | + |
| 184 | +const ObjectGrid = createLazyPlugin( |
| 185 | + () => import('@object-ui/plugin-grid'), |
| 186 | + { fallback: <div>Loading grid...</div> } |
| 187 | +); |
| 188 | +``` |
| 189 | + |
| 190 | +### Learn More |
| 191 | + |
| 192 | +- [Architecture Overview](/docs/guide/architecture) — Understand how ObjectUI works |
| 193 | +- [Schema Rendering](/docs/guide/schema-rendering) — Deep dive into schema rendering |
| 194 | +- [Component Registry](/docs/guide/component-registry) — Customize and extend components |
| 195 | +- [Plugins](/docs/guide/plugins) — Add views like Grid, Kanban, Charts |
| 196 | +- [Fields Guide](/docs/guide/fields) — All 30+ field types |
0 commit comments