Concrete
GuidesDeclare slots

Add a select slot

A value that has to be one of a handful of keys — a listing status, an item's emphasis, an icon.

Goal

Give a section a slot the editor offers as a closed set of choices, and render the chosen key as the words a visitor should read.

Prerequisites

Steps

1. At the top level, a select is bound

Every top-level slot declares exactly one origin, and a select has only one of the two available to it: no fill writes a top-level select. So it is bound — and the binding is what supplies the vocabulary as well as the value, because the field's own domain is the set:

sections/overview.tsx
import { fact, select } from "@homepages/concrete";

const intent = select({ source: fact.property.listing_intent, label: "Listing intent" });

One binding, both halves. A fact only offers a domain if the fact registry declares its choices, and a select bound to one that declares none, or declaring a hand-written vocabulary and a bound one, is contract/select.

A top-level select({ label, from }) with no origin is sections/schema-invalid — nothing would ever write it. If the keys you want are not a fact's domain, the value belongs on a list's item or on the section's display axis, below.

2. Write the vocabulary out on a list's item

select({ label, from }) is the hand-authored form: from is the set of keys the value is chosen from, and an object item of a list is where it lives. Like every field of an object it declares its own origin — here a fill.pick that picks one key per item, beside fields that read the item's own row:

sections/comps.tsx
import { fact, fill, list, number, object, row, select, text } from "@homepages/concrete";

const EMPHASIS = ["regular", "highlight"] as const;

const comps = list({
  label: "Comparable sales",
  source: fact.property.comparables,
  max: 6,
  item: (el) => {
    const comp = row({ label: "Comparable", from: fact.property.comparables, source: el });
    return object({
      label: comp.address.street,
      fields: {
        comp,
        price: number({ label: "Price", thousandsSep: true, locked: true, source: comp.price }),
        emphasis: select({
          label: "Emphasis",
          from: EMPHASIS,
          source: fill.pick({
            reads: [comp.distance_m, comp.sale_date],
            unique: false,
            brief: "Highlight the two or three strongest sales — the closest, most recent ones.",
          }),
        }),
      },
    });
  },
});

A bare string in from is its own label; the { value, label } form separates the stored key from the display text, which is what lets you reword a choice later without rewriting stored content. That form may also carry an icon from the editor's set and a one-line description saying what the choice means — the dropdown draws the icon before the label and the description beneath it, and concrete check refuses an icon name outside the set. creatable: true lets a user add a key the vocabulary does not carry — reach for it only where the set is genuinely open-ended, because every new key is a value your markup has never seen.

The field's source: fill.pick({ brief }) is a per-item pick from the keys its from names, in the list's batched call. The field's from is what the user may choose from and what the model may, so the two cannot drift (AI fill). The vocabulary is not restated in the brief, and the pick's reads name the members of the item's row it judges by. A pick never repeats a candidate across the items; two keys over six sales must repeat, so this one says unique: false. A list of bare choices (list({ label, max, source: fill.pick({ brief }), item: select({ label, from }) })) picks its items from the same vocabulary one level up.

3. Or make it the section's own axis

When the choice is which layout the section renders rather than a value it stores, the same select export called with from and no label declares a display entry instead — see Add a display variant:

sections/overview.tsx
import { compute, fact, fill, select } from "@homepages/concrete";

const LAYOUTS = ["classic", "editorial"] as const;

const visibility = select({
  from: ["visible", "hidden"],
  source: compute({ reads: [fact.property.property_media] }, (media) =>
    media.some((asset) => asset.kind === "image") ? "visible" : "hidden",
  ),
});

const variant = select({
  from: LAYOUTS,
  source: fill.pick({ reads: [fact.property.description], brief: "Prefer editorial where the description tells a story." }),
});

A display entry takes no label — a label is what makes a select a slot — and exactly one source:, a compute(…) or a fill.pick. A pick on it takes no none: the entry always resolves to one of its from cases, the first being the default.

4. Render the key as words

Slot.Select marks the slot and renders the stored key. format turns it into display text without withholding the value from the editor:

sections/overview.tsx
import { fact, Section, section, select, Slot } from "@homepages/concrete";

const INTENT_TEXT = { for_sale: "For sale", for_rent: "For rent" };

export const Overview = section(
  {
    key: "overview",
    label: "Overview",
    slots: {
      intent: select({ source: fact.property.listing_intent, label: "Listing intent" }),
    },
  },
  ({ slot }) => (
    <Section>
      <Slot.Select
        slot={slot.intent}
        as="span"
        format={(value) => INTENT_TEXT[value as keyof typeof INTENT_TEXT] ?? ""}
      />
    </Section>
  ),
);

The marker survives the empty branch, so an unset value still renders a selectable element rather than vanishing from the editor. Give the element a class that collapses when the text is blank instead of branching the slot away — a slot no branch renders is render/missing-slot-marker, and on a list's item it is the field that goes unselectable.

Verify

Run concrete dev and select the slot: a bound select shows the field's own domain with the Update everywhere toggle beside it when the field is writable, and an item's authored select shows exactly your from and nothing else.

Then run concrete check. The sections stage refuses a select nothing would write and the contracts stage grades the vocabulary:

concrete check
concrete check passed: 13 stages.

On this page