Skip to content

Under developmentMica is experimental at v0.10.0 and not ready for production.Follow the releases.

Docs/Fields

Reference

Fields

Every field builder of @micacms/core, its options, and what it stores in the repository.

7 min read

Import the builders from @micacms/core. Each builder gives plain data, so the editor can read the model from .mica/schema.json. An item without a version exists since 0.2.0.

Options of every field

OptionEffect
labelThe label in the editor. Default: the key, as words.
descriptionHelp text below the field.
requiredAn empty value cannot be published. Editors can save it before that.
listedShows the value as a column in the list of a collection.
readonlyThe editor shows the value, but cannot change it.
hiddenMica keeps the value, but the editor does not show it.
groupFields with the same group show in one box.
width"full", "half" or "third" of the form row.

The build stops on an option that is not in these tables, for example a typo. A field with an option from a newer @micacms/astro is read-only in an older Mica until you upgrade it.

The builders

BuilderStoresOptions
text()A string.minLength, maxLength, placeholder, default, pattern (a regular expression; since 0.6.0 it must match the whole value, with the u flag; a group that repeats cannot contain a repeat, so (a+)+ is refused, but (-[0-9]+)? is allowed), patternMessage (0.7.0).
textarea()A string with line breaks.minLength, maxLength, rows, placeholder, default.
richText()Markdoc, in a <key>.mdoc file beside the entry.toolbar: "minimal" (bold, italic, link), "default" (also headings and lists), "full" (also strike, blockquote, horizontalRule, table, image), or a list of these features (presets, table and image: 0.8.0). Also maxLength, default.
number()A number.min, max, step, integer, unit (shown in the field, for example "m²"), default.
boolean()true or false, never empty.default.
date()"2026-10-13", or with includeTime a date and time with its offset.includeTime, min, max, default.
email()An email address.placeholder, default.
url()A web address.placeholder, default.
slug()Lower-case letters, digits and hyphens.from: the key of the field that gives the slug while the editor types. maxLength.
select({ options })The value of the choice, or a list with multiple.options: a list of { label, value }. multiple, default.
object({ fields })An object with the given fields.fields, collapsible, collapsed.
repeater({ fields })A list of objects.fields, min, max, itemLabel (the key that names a row), addLabel.
relation({ collection })The slug of an entry, or a list with multiple.collection, multiple.
media()The path of a file, or { path, alt } with alt. A list with multiple.accept: "image", "document" or "any". multiple, max, alt: "required" or "optional" (0.6.0).
color()A hex colour, for example "#0f766e".presets: colours to choose from. default.
coordinates(){ lat, lng }.None.
tags()A list of short words, never null: no tags is [].max, maxLength, suggestions, default. Added in 0.8.0.

Defaults and empty values

A default fills the field of a new entry, and of a singleton that has no file yet. It never fills a value that is missing in a stored entry: such a value is empty, null, false or [], and your templates must handle it. So a changed default does not change the stored entries, and a cleared field stays cleared.

Values that the model does not have

A save keeps a key in index.json and a .mdoc file that the model does not declare, for example content for a field that a newer model adds. Your templates do not get them, and npx mica check warns about them. To delete them, see Change the model. A key in a list row without _key is not kept, because such a row has no identity when the order changes.

The slug of a collection

The first slug() among the fields of a collection is the entry's slug. It is also the name of the entry's folder, so it is never empty. A second slug() among the same fields stops the build. A slug() in an object or in a singleton is an ordinary value, for example one URL for each language.

Where an entry is stored

Each entry is a folder <slug>/ with index.json, the .mdoc files and the entry's media, and each singleton is a folder <name>/ with the same files. See Content model.

Each rich-text field has its own .mdoc file, named by the field's path: body.mdoc, seo.intro.mdoc. In a repeater(), each row with rich text has a key, _key, in index.json, and the file names the row by its key: sections.k3f9a2.body.mdoc. Then a new order of the rows changes only index.json. Mica writes the key; do not change it. Your templates do not get it.

Collections and singletons

import { collection, defineSite, singleton, slug, text } from "@micacms/core";

export const site = defineSite({
  root: "./content",
  collections: {
    news: collection({ label: "News", fields: { title: text({ required: true }), slug: slug({ from: "title" }) } }),
  },
  singletons: {
    settings: singleton({ label: "Website", fields: { tagline: text() } }),
  },
});
Option of collection()Effect
label, labelSingularThe names in the editor, for example "News" and "Article".
descriptionText below the title of the list.
fieldsThe fields.
titleFieldThe key that names an entry in lists. Default: title, else the first text(), else the slug.
slugFieldThe key of the slug. Default: the first slug().
defaultSort{ field, direction } for the list in the editor. field is a field of the collection or "position". Text sorts alphabetically in English, and a date with a time by its instant. It does not sort your pages.
sortableEditors can put the entries in an order. Mica keeps it in _order.json.

singleton() takes label, description and fields. defineSite() takes root, collections and singletons.