-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add AutoField component for using Puck fields inside custom fields
- Loading branch information
Showing
7 changed files
with
181 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"auto-field": {}, | ||
"drawer": {}, | ||
"drawer-item": {}, | ||
"drop-zone": {}, | ||
|
96 changes: 96 additions & 0 deletions
96
apps/docs/pages/docs/api-reference/components/auto-field.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--- | ||
title: <AutoField> | ||
--- | ||
|
||
import { ConfigPreview } from "@/docs/components/Preview"; | ||
import { AutoField } from "@/core/components/AutoField"; | ||
|
||
# \<AutoField\> | ||
|
||
Render a Puck field based on a [Field](/docs/api-reference/fields) object. Use this when building [custom fields](/docs/extending-puck/custom-fields) that need to use Puck-style fields internally. | ||
|
||
<ConfigPreview | ||
label="Example" | ||
componentConfig={{ | ||
fields: { | ||
title: { | ||
type: "custom", | ||
render: ({ onChange, value }) => { | ||
return ( | ||
<AutoField | ||
field={{ type: "text" }} | ||
onChange={onChange} | ||
value={value} | ||
/> | ||
); | ||
}, | ||
}, | ||
}, | ||
defaultProps: { | ||
title: "Hello, world", | ||
}, | ||
render: ({ title }) => { | ||
return <p style={{ margin: 0 }}>{title}</p>; | ||
}, | ||
}} | ||
/> | ||
|
||
```tsx {1,4} copy | ||
import { Autofield } from "@measured/puck"; | ||
|
||
const CustomField = ({ onChange, value }) => ( | ||
<AutoField field={{ type: "text" }} onChange={onChange} value={value} /> | ||
); | ||
|
||
const config = { | ||
components: { | ||
Example: { | ||
fields: { | ||
title: { | ||
type: "custom", | ||
render: MyCustomField, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
``` | ||
|
||
## Props | ||
|
||
| Prop | Example | Type | Status | | ||
| ----------------------- | ---------------------------- | ----------------------------------- | -------- | | ||
| [`field`](#field) | `{ type: "text" }` | [Field](/docs/api-reference/fields) | Required | | ||
| [`onChange`](#onchange) | `onChange("Goodbye, world")` | Function | Required | | ||
| [`value`](#value) | `"Hello, world"` | Any | Required | | ||
| [`id`](#id) | `"my-input"` | String | - | | ||
| [`readOnly`](#readonly) | `true` | Boolean | - | | ||
|
||
## Required Props | ||
|
||
### `field` | ||
|
||
An object containing the user defined [Field](/docs/api-reference/fields) configuration. | ||
|
||
### `onChange` | ||
|
||
A callback that triggers when the value changes. | ||
|
||
### `value` | ||
|
||
The current value for the field. | ||
|
||
## Optional Props | ||
|
||
### `id` | ||
|
||
An optional ID for this field. Will be generated if not specified. | ||
|
||
### `readOnly` | ||
|
||
A boolean describing whether or not this field is `readOnly`. | ||
|
||
## Further reading | ||
|
||
- [Custom fields](/docs/extending-puck/custom-fields) | ||
- [The `<FieldLabel>` API reference](/docs/api-reference/components/field-label) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters