Concrete
GuidesDeclare slots

Group slots into one editor card

Four slots that are really one thing — an address, a stat block — and the editor sidebar lists them as four.

Goal

Turn a section's street, city, beds and baths into two editor cards — Property address and Key stats — each declared once, as an object among the section's slots.

Prerequisites

  • The workspace Start leaves you with, and concrete dev running.
  • The marker contract for why an object's fields render inside its own container.

Steps

1. Declare each card as an object

Slots that belong together are the fields of one object(). The object's key in slots is the card's identity; its label is the card's title in the editor sidebar, and takes its text from a source the way a text slot's source: does — a constant title is compute(() => "Property address"). The object holds no value of its own — its value is its fields' — so each field keeps its own source:, exactly as it would as a slot:

sections/sheet.tsx
import { compute, fact, number, object, row, Section, section, Slot, text } from "@homepages/concrete";

const unit = row({ label: "Unit", from: fact.property.units, locked: true });

export const Sheet = section(
  {
    key: "sheet",
    label: "Fact sheet",
    slots: {
      address: object({
        label: compute(() => "Property address"),
        fields: {
          street: text.short({ label: "Street", source: fact.property.address.street }),
          city: text.short({ label: "City", source: fact.property.address.city }),
        },
      }),
      stats: object({
        label: compute(() => "Key stats"),
        fields: {
          unit,
          beds: number({ label: "Beds", source: unit.beds }),
          baths: number({ label: "Baths", source: unit.baths }),
        },
      }),
    },
  },
  ({ slot }) => (
    <Section>
      <Slot.Object slot={slot.address} as="address" className="not-italic">
        <Slot.Text slot={slot.address.street} as="span" />
        <Slot.Text slot={slot.address.city} as="span" />
      </Slot.Object>
      <Slot.Object slot={slot.stats} as="dl">
        <Slot.Number slot={slot.stats.beds} as="dd" />
        <Slot.Number slot={slot.stats.baths} as="dd" />
      </Slot.Object>
    </Section>
  ),
);

A field is a value slot, a row(), a list of value slots, or a list of objects one level deep — never another object (contract/nested-slot-types). Its fields appear in the card in the order you declare them, and two adjacent short fields share one row, exactly as a section's slots do.

Each field is read straight off its object's binding — slot.address.street — so no field takes a name the binding owns itself: id, slot, index, def, value or present. A field named value would read as the object's own value; it is a compile error, and concrete check refuses it by name (contract/object). Name the field for what it holds — a figure, an amount.

2. Render every field inside its own Slot.Object

Slot.Object takes the object's binding and nothing else: the marker it emits comes from the binding, and only an object's binding type-checks there. Each field renders through its own binding, slot.address.street, inside that container — the editor finds which card a field belongs to by the object marker around it:

  • A field marked outside its own Slot.Object — after the container, or inside another slot's element — is render/group-ancestry.
  • A field that renders nowhere at all is render/missing-slot-marker; declare it locked: true instead if nobody should edit it.

Rendering the same card twice is fine and needs nothing new — a clone, a second responsive branch, a print variant. Each copy is another Slot.Object over the same binding, and every copy stays live:

sections/sheet.tsx
import { compute, fact, object, Section, section, Slot, text } from "@homepages/concrete";

export const Sheet = section(
  {
    key: "sheet",
    label: "Fact sheet",
    slots: {
      address: object({
        label: compute(() => "Property address"),
        fields: { street: text.short({ label: "Street", source: fact.property.address.street }) },
      }),
    },
  },
  ({ slot }) => (
    <Section>
      <Slot.Object slot={slot.address} as="p" className="lg:hidden">
        <Slot.Text slot={slot.address.street} as="span" />
      </Slot.Object>
      <Slot.Object slot={slot.address} as="p" className="hidden lg:block">
        <Slot.Text slot={slot.address.street} as="span" />
      </Slot.Object>
    </Section>
  ),
);

A copy that should never take a click — a carousel clone, a decorative mirror — adds selectable={false}, and keeps its identity and its live patching.

3. Hold one row of a table in the card

A card that shows one row of a property table — the listing agent, the primary unit — holds the row() among its own fields, and its other fields read the row's members (Bind a slot to a property fact). No primitive renders a row: its readers render its members, and the row itself is the card's bar in the editor, which the user re-picks the agent from. A row among an object's fields owes the canvas no marker. The card's title here is the agent's name, which the user edits: the label names the name field by its const, so the header follows that field rather than holding a value of its own:

sections/sheet.tsx
import { fact, object, row, Section, section, Slot, text } from "@homepages/concrete";

const agent = row({ label: "Agent", from: fact.property.contacts });
const name = text.short({ label: "Name", source: agent.name });

export const Sheet = section(
  {
    key: "sheet",
    label: "Fact sheet",
    slots: {
      contact: object({
        label: name,
        fields: {
          agent,
          name,
          phone: text.short({ label: "Phone", source: agent.phone }),
        },
      }),
    },
  },
  ({ slot }) => (
    <Section>
      <Slot.Object slot={slot.contact} as="address" className="not-italic">
        <Slot.Text slot={slot.contact.name} as="p" />
        <Slot.Text slot={slot.contact.phone} as="p" />
      </Slot.Object>
    </Section>
  ),
);

4. Reach for the same object when the card repeats

An object is the one grouping there is, at the top level and as a list's item alike. A list whose item returns an object({ label, fields }) is edited one card per item, and each item renders through one Slot.Object over its binding from bindItems — the same primitive, with identity by index rather than by key (Add a list slot). Declare a top-level object when the slots are one thing that appears once, and a list of objects when that thing repeats. A list of objects declared as an object's field — a unit's floor plans inside a unit card — is the exception: it is one field of its card, and a click on any of its items selects that field (object).

Verify

Run concrete dev and open the section in the sidebar: the four fields are now two cards, titled Property address and Key stats, and selecting either card's element on the canvas selects the card rather than one field.

Then run concrete check. The contracts stage grades each object's shape, and the render stage grades every field's marker and its ancestry over every fixture and its synthesized empties:

concrete check
concrete check passed: 13 stages.

On this page