Docs
API Reference
Custom

Custom

Implement a field with a custom UI. Extends Base.

Example

Hello, world

import { FieldLabel } from "@measured/puck";
 
const config = {
  components: {
    Example: {
      fields: {
        title: {
          type: "custom",
          render: ({ name, onChange, value }) => (
            <input
              defaultValue={value}
              name={name}
              onChange={(e) => onChange(e.currentTarget.value)}
            />
          ),
        },
      },
      render: ({ title }) => {
        return <p>{title}</p>;
      },
    },
  },
};

Params

ParamExampleTypeStatus
typetype: "custom""custom"Required
render()render: () => <input />FunctionRequired

Required params

type

The type of the field. Must be "custom" for Custom fields.

const config = {
  components: {
    Example: {
      fields: {
        title: {
          type: "custom",
          render: ({ name, onChange, value }) => (
            <input
              defaultValue={value}
              name={name}
              onChange={(e) => onChange(e.currentTarget.value)}
            />
          ),
        },
      },
      // ...
    },
  },
};

render(params)

Render the custom field.

import { FieldLabel } from "@measured/puck";
 
const config = {
  components: {
    Example: {
      fields: {
        title: {
          type: "custom",
          render: ({ name, onChange, value }) => (
            <input
              defaultValue={value}
              name={name}
              onChange={(e) => onChange(e.currentTarget.value)}
            />
          ),
        },
      },
      // ...
    },
  },
};

params

ParamExampleType
field{ type: "custom" }Object
name"title"String
onChange(value)onChange("Hello, world")Function
value"Hello, world"Any

Further reading