Concrete
GuidesDeclare slots

Add an address slot

A section shows where the home is — two postal lines, a short label, the city — and the parts must never disagree with each other or with the pin.

Goal

A location block that holds the property's address as one slot: the editor edits it as one place, a short label and a city line read their text off it, and the render lays the parts out however the design wants.

Prerequisites

Steps

1. Decide whether you need a line or the place

Two declarations show an address, and they are not interchangeable.

  • One line of it is a text slot bound to one of the property address's members: text.short({ source: fact.property.address.city }). The editor edits that slot as text, on this page only.
  • The place is an address(): street, unit, city, state, postal code and the pin, held as one value because they have to agree. The editor edits it as one value, and the slot's parts are members other slots read.

Reach for address() when the section shows more than one part, or when anything reads the coordinates. Two text slots bound to the street and the city are two values the editor lets drift apart; one address is not.

2. Declare the address from the property's

An address always declares its source:, and the origins it admits are listed on its reference entry. This one is the property's own address, which fact.property.address reads whole — so the slot binds it:

sections/location.tsx
import { address, fact } from "@homepages/concrete";

const place = address({ label: "Address", source: fact.property.address });

The slot holds an AddressValue: every part, each null when absent, and the pin. A pin is a pair, so a property with only one coordinate, or one out of range, holds none. A property with no part and no pin reads null itself, never a value of empty strings. The whole address is one stored fact, so an edit to the slot is offered as Update everywhere. Only an address slot binds the whole address: a text slot bound to it is refused at check time (contract/source), because a line of it is your formatting — step 3.

An address takes no other option. Which parts show is your render's, and a partial line is a compute() over the value — step 3.

3. Read its parts from other slots

The value address() returns reads its parts as members, the way a row() reads a table's: place.street, place.unit, place.city, place.state, place.postal, place.latitude and place.longitude — its parts and its pin, and nothing derived. A member is a legal source: and a legal entry in any reads:

sections/location.tsx
import { address, compute, text } from "@homepages/concrete";

declare const place: ReturnType<typeof address>;

const street = text.short({ label: "Street", source: place.street });

const locality = text.short({
  label: "City line",
  source: compute({ reads: [place] }, (home) =>
    home == null ? "" : [home.city, home.state].filter((part) => part !== null).join(", "),
  ),
});

Every member is read-only: a part edited on its own would break the agreement the address holds, so an edit to a slot bound to one stays on this page (where an edit goes). An absent part reads null. A compute() that reads the address itself receives the whole value, which is how a line the members do not offer is built — the city and state together, or the whole address on one line:

sections/location.tsx
import { address, compute, text } from "@homepages/concrete";

declare const place: ReturnType<typeof address>;

const oneLine = text.medium({
  label: "Address",
  source: compute({ reads: [place] }, (home) => {
    if (home == null) return "";
    const region = [home.state, home.postal].filter((part) => part !== null).join(" ");
    return [home.street, home.unit, home.city, region].filter((part) => part !== null && part !== "").join(", ");
  }),
});

An address offers no formatted line of its own, and Concrete exports no formatter: how the address reads on one line, or which part a short label keeps, is your formatting, written once in a compute() or in the render.

Members are read where the address is in scope: at the section's top level, or as fields of the same object() (contract/row-rule). Another section mirrors the whole address with source: Location.slots.place on an address of its own.

4. Render it

Slot.Address marks one element and hands your function the value — its parts and its coordinates, each null when absent — or null when the slot holds no place. The lines are yours to format:

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

const place = address({ label: "Address", source: fact.property.address });

export const Location = section(
  {
    key: "location",
    label: "Location",
    slots: {
      place,
      street: text.short({ label: "Street", source: place.street }),
      locality: text.short({
        label: "City line",
        source: compute({ reads: [place] }, (home) =>
          home == null ? "" : [home.city, home.state].filter((part) => part !== null).join(", "),
        ),
      }),
    },
  },
  ({ slot }) => (
    <Section>
      <Slot.Text slot={slot.street} as="h2" />
      <Slot.Address slot={slot.place} as="address" className="not-italic">
        {(home) =>
          home === null ? (
            "Address to come"
          ) : (
            <>
              {home.street}
              {home.unit === null ? null : `, ${home.unit}`}
              <br />
              {home.city}, {home.state} {home.postal}
            </>
          )
        }
      </Slot.Address>
      <Slot.Text slot={slot.locality} as="p" />
    </Section>
  ),
);

The element is marked in every branch, the empty one included, so an address that holds no place stays selectable and the empty branch is yours to write. It is never a text leaf: the parts are your markup, and the address is edited in the sidebar, never typed in place. The slots reading it are ordinary slots and render through their own primitives (render/missing-slot-marker).

Verify

Run concrete dev and select the address on the canvas. The sidebar edits it as one value — street, line 2, city, state and postal code as fields. Editing any part clears the coordinates, because a pin that no longer matches the text is worse than none. concrete dev has no address lookup, so it offers no suggestions and no pin map; the coordinates come from the sample property. The street and the city line follow the address.

Then run concrete check. The contracts stage refuses an address with no origin and a member read out of scope, and the render stage grades every marker:

concrete check
concrete check passed: 13 stages.

On this page