You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { primitiveComponentDefinitions } from"@/lib/ui-builder/registry/primitive-component-definitions"; // Example registry
182
184
183
185
// Component registry is needed for the renderer too
@@ -197,7 +199,7 @@ export function MyPage() {
197
199
198
200
## Add your custom components to the registry
199
201
200
-
You add custom components by defining them in a `ComponentRegistry` object and passing that object to the `UIBuilder` component via the `componentRegistry` prop.
202
+
You add custom components by defining them in a `ComponentRegistry` object and passing that object to the `UIBuilder` component via the `componentRegistry` prop. The registry maps a unique component type name (string) to its definition.
201
203
202
204
Here is an example of how to define a custom component within the registry object:
-`from`: The source path of the component. Used when exporting the page as code.
247
-
-`fieldOverrides`: Customizes auto-form fields for the component's properties.
248
-
249
-
-`schema`: A Zod schema defining the properties and validation rules for the component props. We use zod to define the component schema which represents the props that the component accepts. The required props **MUST** have a default value, this allows the UI Builder to render the component with the default value when the user adds the component to the page. This project leverages [Auto-Form](https://github.com/vantezzen/autoform/tree/pure-shadcn) to dynamically render component property forms based on the component definitions zod schema. Currently only these zod types are supported:
250
-
- boolean
251
-
- date
252
-
- number
253
-
- string
254
-
- enum of supported zod types
255
-
- object with properties of the supported zod types
256
-
- array of objects with properties of the supported zod types
258
+
**Component Definition Fields:**
259
+
260
+
-`component`: **Required**. The React component function or class.
261
+
-`schema`: **Required**. A Zod schema defining the component's props, their types, and validation rules.
262
+
- This schema powers the automatic generation of a properties form in the editor using [Auto-Form](https://github.com/vantezzen/autoform/tree/pure-shadcn).
263
+
- Props intended to be configurable in the UI Builder **MUST** have a default value specified in the schema (using `.default(...)`). This allows the UI Builder to render the component correctly when it's first added, before the user configures it.
264
+
- Currently supported Zod types for auto-form generation include: `boolean`, `date`, `number`, `string`, `enum` (of supported types), `object` (with supported property types), and `array` (of objects with supported property types).
265
+
-`from`: **Required**. The source import path for the component. This is used when exporting the page structure as React code.
266
+
-`fieldOverrides`: Optional. An object to customize the auto-generated form fields for the component's properties in the editor's sidebar.
267
+
- The keys of this object correspond to the prop names defined in the Zod schema.
268
+
- The values are typically functions that receive the current `layer` object and return configuration options for the `AutoForm` field. These options can control the field's label, input type (`fieldType`), visibility (`isHidden`), placeholder text, render logic, and more. See the AutoForm documentation for available options.
269
+
- This is useful for:
270
+
* Providing more descriptive labels or help text.
271
+
* Using specific input components (e.g., a color picker, a custom slider).
272
+
* Hiding props that shouldn't be user-editable (like internal state).
273
+
* Implementing conditional logic (e.g., showing/hiding a field based on another prop's value).
274
+
- The example uses `classNameFieldOverrides` and `childrenFieldOverrides` from `@/lib/ui-builder/registry/form-field-overrides` to provide standardized handling for common props like `className` (using a textarea) and `children` (often hidden or handled specially). You can create your own override functions or objects.
257
275
258
276
259
277
---
@@ -264,9 +282,10 @@ For more detailed documentation read the [docs](https://uibuilder.app/)
264
282
## Changelog
265
283
266
284
### v1.0.0
267
-
- Removed _page_ layer type in favor of using any component as a page. This allows for more fexibility, like react-email components. You should migrate any layers stored in the database to use the new components. You can use the [migrateV2ToV3](lib/ui-builder/store/layer-utils.ts) function in layer-utils.ts to help with the migration.
268
-
- Component registry is now a prop of the UIBuilder component instead of a standalone file.
269
-
- Removed script to generate component definitions from the registry. As these were problematic to maintain and were not functioning correctly for complex components.
285
+
- Removed _page_ layer type in favor of using any component type (like `div`, `main`, or custom containers) as the root page layer. This enhances flexibility, enabling use cases like building react-email templates directly. You should migrate any layers stored in the database to use a standard component type as the root. The [migrateV2ToV3](lib/ui-builder/store/layer-utils.ts) function in `layer-utils.ts` can assist with this migration.
286
+
- The `componentRegistry` is now passed as a prop to the `UIBuilder` component instead of being defined in a standalone file.
287
+
- Removed the script used to generate component schema definitions. This approach proved problematic to maintain and didn't function correctly for complex components or varying project setups. Component schema definitions should now be manually created or generated using project-specific tooling if desired.
288
+
-`pagePropsForm` prop added to `UIBuilder` to allow customization of the form used for editing page-level (root layer) properties.
270
289
271
290
272
291
### v0.0.2
@@ -301,13 +320,18 @@ npm run test
301
320
## Roadmap
302
321
303
322
-[ ] Add user friendly styling component instead of directly using tailwind classes
323
+
-[ ] Add tiptap editor for markdown content
324
+
-[ ] Add global variables for component props
304
325
-[ ] Add Blocks. Reusable component blocks that can be used in multiple pages
305
326
-[ ] Add data sources to component layers (ex, getUser() binds prop user.name)
0 commit comments