Unlock seamless workflows and faster delivery with our latest releases – get the details

Heading custom component

By Arjen Scherff-de Water

Add a title between fields for some visual grouping

helper function

import React from "react";

export function createHeading(title) {
  return {
    inputComponent: (field) => (
      <div
        style={{
          borderBottom: "1px solid rgba(0,0,0,.1)",
          fontSize: "2rem",
          marginTop: "1em",
        }}
      >
        {field.type.title}
      </div>
    ),
    name: `heading${title
      .toLowerCase()
      .replace(/\s/g, "")
      .replace(/[^\w-]+/g, "")
      .replace(/--+/g, "-")}`,
    title,
    type: "string",
  };
}

schema

import { createHeading } from "./helpers";

export default {
  name: "mySchema",
  title: "My Schema",
  type: "document",
  fields: [
    createHeading("Hero"),
    ...,
    createHeading("Media"),
  ]
}

Contributor

Other schemas by author