Skip to content
BearMinion

← Blog

Build your own section in BearMinion

One folder, three files, one command. A Timeline section with a list of milestones that the editor lets you add, remove and drag, with no editor code from you.

Sections are the blocks every page is made of: a hero, a FAQ, a call to action. Yours sit next to them in the Add section picker, and the editor builds their controls from your schema.

This post builds a Timeline: a heading and a list of milestones, each with a year, a title and a sentence.

1. Make the folder

Run:

mkdir src/components/sections/timeline

The folder name is the section's name, in kebab-case. In your content files the type is the same name in camelCase, and the component is named after it: Timeline.astro.

2. Write the three files

definition.ts says what the section holds, as a Zod schema. It checks every save and builds the fields in the editor. wireframe.ts draws the thumbnail in the picker. Timeline.astro renders it.

The files

Every value you want editable on the page gets a data-field with its path in the page file. The rest is ordinary Astro.

src/components/sections/timeline/definition.ts
import { z } from 'zod'import { defineSection, richTextSchema, textSchema, withEmphasis } from 'bearminion'import { accent, eyebrow, heading } from '../shared'import { timelineWireframe } from './wireframe' export const milestoneSchema = z  .object({ year: textSchema, title: textSchema, text: richTextSchema.optional() })  .strict() export const timeline = defineSection({  type: 'timeline',  label: 'Timeline',  description: 'Milestones in order: a year, a title and a sentence each.',  schema: withEmphasis({ eyebrow, heading, milestones: z.array(milestoneSchema).min(2).max(8) }),  defaults: {    eyebrow: 'Our story',    heading: 'How we got here.',    marks: accent('How we got here.', 'got here.'),    milestones: [      { year: '2019', title: 'The idea', text: 'Say what started it.' },      { year: '2021', title: 'The first customer', text: 'Name the moment it became real.' },      { year: '2024', title: 'Today', text: 'Say where you are now.' },    ],  },  variants: ['list', 'columns'] as const,  defaultVariant: 'list',  optional: { props: ['eyebrow', 'heading'], items: { milestones: ['text'] } },  counts: { milestones: { recommended: '3 to 5', min: 2, max: 8 } },  wireframe: timelineWireframe,})

3. Register it

Run:

npx bearminion sync

It finds every section folder with a definition.ts and writes them into definitions.gen.ts and components.gen.ts. Commit those two files, but don't edit them.

4. Try it

Restart npm run dev. Hover any section, choose Add, and Timeline is in the picker with its thumbnail. Add it, open Settings, and the milestones are a list: add a row, drag one to reorder, remove one. The buttons stop at 2 and 8, because the schema says so.

Click a year or a title on the page and type. Save, and the section is in the page's JSON exactly as your schema describes it.

The Add section picker showing section thumbnails
Your section shows up in the picker next to the built-in ones.

When something's off

  • Invalid defaults for section when astro dev starts: a default value fails your schema.
  • The section isn't in the picker: you didn't run npx bearminion sync, or didn't restart the dev server after it.
  • Clicking a value does nothing: its element has no data-field, or the path doesn't match the schema.
  • A field can't be cleared: optional and the schema's .optional() disagree about it.

The full walkthrough, with a second layout, is in Build your own section.

Wake the minion.

Run one command, answer three boring questions and watch it do the rest. Template copied, dependencies installed, first commit done.

Now it gets out of your way so you can actually work.

  1. npm create bearminion@latest
  2. Created My Site in my-site
  3. Installed dependencies
  4. →Next: cd my-site, npm run dev