Add an interactive island
A section needs state, an event handler or a browser API — and a section renderer may have none of them.
Goal
Give the starter's hero a description that opens and closes — the first thing in your workspace that runs in a browser.
Prerequisites
- The workspace Start leaves you with, and
concrete devrunning. - Server and client for why the browser half lives in a file of its own.
Steps
Declare the slot the island will render
An island renders slot content through the same primitives a section does, so the slot is declared exactly as any other. Add one to the hero:
import { fact, fill, text } from "@homepages/concrete";
const description = text.long({
label: "Description",
cap: 600,
source: fill.write({
reads: [fact.property.description],
brief: "Describe the property in two short paragraphs, under 600 characters. Warm and specific, never salesy.",
}),
});Write the island
A new file beside the section, opening with "use client". Everything a section
may not do — state, an event handler, a browser API — lives on this side of that
line.
"use client";
import { Slot, useIslandId, type IslandEditor, type SlotBinding, type TextSlot } from "@homepages/concrete";
import { useState } from "react";
export const editor = { live: true } satisfies IslandEditor;
export default function ReadMore({ slot, preview }: { slot: SlotBinding<TextSlot>; preview: number }) {
const [open, setOpen] = useState(false);
const id = useIslandId();
if (slot.value.length <= preview) {
return <Slot.Text slot={slot} as="p" multiline />;
}
return (
<div>
<Slot.Text slot={slot} as="p" id={`${id}-text`}>
{open ? slot.value : `${slot.value.slice(0, preview).trimEnd()}…`}
</Slot.Text>
<button type="button" aria-controls={`${id}-text`} aria-expanded={open} onClick={() => setOpen(!open)}>
{open ? "Read less" : "Read more"}
</button>
</div>
);
}Three things in that file are the contract:
editoris required and says whether the island runs its published behaviour inside the editor canvas. A read-more control should, soliveis true — seeislands/editor-declaration.- The prop is the slot's binding, not its text. The binding carries the
marker, so the
Slot.Textin this file is what the editor selects; pass the string instead and the slot is editable nowhere (render/missing-slot-marker). - Ids come from
useIslandId, never React's own id hook: the server renders a whole page under one counter and the browser hydrates one marker, so the two disagree by construction (islands/island-ids).
Render it from the section
Import the island and render it like any component — the build splits it into its own chunk and emits the marker for you.
import { fact, fill, Section, section, Slot, text, type SlotBinding, type TextSlot } from "@homepages/concrete";
import type { ReactNode } from "react";
// import ReadMore from "./ReadMore";
declare const ReadMore: (props: { slot: SlotBinding<TextSlot>; preview: number }) => ReactNode;
export const Hero = section(
{
key: "hero",
label: "Hero",
slots: {
description: text.long({
label: "Description",
cap: 600,
source: fill.write({
reads: [fact.property.description],
brief: "Name what makes the property worth seeing. Write one sentence. Warm and specific, no superlatives.",
}),
}),
},
},
({ slot }) => (
<Section>
<ReadMore slot={slot.description} preview={180} />
</Section>
),
);Props cross into the browser as JSON, embedded in the page the server produced. A
binding is plain data and travels fine; a function, a class instance or a Date
does not (islands/serializable-props).
State it in the fixture
The hero is placed once, so its instance is hero-1:
{
"$schema": "../.concrete/schema/content-fixture.schema.json",
"property": "properties/starter/property.json",
"content": {
"hero-1": {
"slots": { "description": "Three bedrooms over two floors, with an updated kitchen." }
}
}
}Verify
In concrete dev, the description clips and the control opens it. Select the
paragraph on the canvas: it is still an ordinary slot card, because the marker
came from the island's own Slot.Text.
Then run concrete check. Its bundle report now names the island beside the
renderer — hero renderer 8.9 KB gzip · 1 island, largest 3.5 KB gzip — which is
the budget bundles/island-size grades.
