Add an image slot with a crop
A photo has to land at one shape on every property, and often a different shape on a phone.
Goal
Give the starter's hero image a crop the editor's cropper enforces, and a second cut served to narrow viewports.
Prerequisites
- The workspace Start leaves you with, and
concrete devrunning. - Slots for what a slot's type and source decide between them.
Steps
1. Declare the crop
crop is the asset's contract, not a box on the page: it tells the cropper
what to cut out of whatever photo lands in the slot, and the renderer which cut a
viewport is served.
import { fact, fill, image } from "@homepages/concrete";
const heroImage = image({
label: "Hero image",
crop: { mode: "locked", aspect: 3 / 2, aspectLabel: "3:2" },
from: fact.property.property_media,
source: fill.pick({ brief: "The photo that best shows the front of the property." }),
});mode picks the cropper's behaviour. "locked" holds aspect while the user
moves the frame — every property's hero then lands at the same shape, which is
what a layout can be built on. "free" lets them resize any edge, for a slot
whose shape is genuinely theirs to choose; a slot that declares no crop crops
free form too. aspectLabel is the pill text beside
the cropper; write the ratio a designer would say out loud, not the number.
from names the list the user picks a replacement from: fact.property.property_media,
what shows the property, of which an image slot offers the photos. A filled image is
bound to no fact, so those are its candidates, and they are what the fill's pick
chooses from too; fact.property.uploads widens them to every image the property
holds, its floor plans included. A slot with no from owns its image — the user
uploads one into it, and no fill picks it.
2. Add a cut for narrow viewports
A 3:2 hero that works on a laptop is a letterbox on a phone. mobile declares a
second cut of the same asset:
import { image } from "@homepages/concrete";
const heroImage = image({
label: "Hero image",
crop: {
mode: "locked",
aspect: 3 / 2,
aspectLabel: "3:2",
mobile: { aspect: 4 / 5, breakpoint: 640 },
},
});The cropper grows a desktop/mobile toggle, and each cut is positioned once per
property. breakpoint is a viewport width in pixels — the only thing a
responsive source element can switch on — so it is not the image's own width and
not a Tailwind screen name.
3. Render the box yourself
The crop is baked into the served asset; the box it sits in is your own classes, and the framework applies no framing maths of its own.
import { fact, fill, image, Section, section, Slot } from "@homepages/concrete";
export const Hero = section(
{
key: "hero",
label: "Hero",
slots: {
hero_image: image({
label: "Hero image",
crop: { mode: "locked", aspect: 3 / 2 },
from: fact.property.property_media,
source: fill.pick({ brief: "The photo that best shows the front of the property." }),
}),
},
},
({ slot }) => (
<Section>
<Slot.Image slot={slot.hero_image} className="aspect-[3/2] w-full rounded-lg" />
</Section>
),
);Slot.Image reads the mobile cut off the slot and emits the responsive sources
for you. Render the slot at least once, or the editor has a field it cannot
select on the page — render/missing-slot-marker.
4. State it in the fixture
An image is stated as a pick of one of this fixture's own property's uploads, by its id — never a path:
{
"$schema": "../.concrete/schema/content-fixture.schema.json",
"property": "properties/starter/property.json",
"content": {
"hero-1": {
"slots": {
"hero_image": { "media": "exterior-front" }
}
}
}
}To preview a crop someone chose, state it beside the pick, each edge a share of the
image from 0 to 1, and the mobile cut under mobile:
{ "media": "exterior-front", "crop": { "x": 0, "y": 0.1, "width": 1, "height": 0.67 }, "mobile": { "crop": { "x": 0.2, "y": 0, "width": 0.6, "height": 1 } } }.
An upload the property does not carry is
fixtures/media-not-in-property.
Verify
In concrete dev, select the image on the canvas and open the cropper: it opens
locked at the 3:2 pill and carries a mobile toggle. Narrow the window past
640px and the 4:5 cut is served in its place.
Then run concrete check. The render stage renders every fixture and one
synthesized empty per slot, so an unmarked slot or an <img> with no source
fails there rather than on a customer's page:
concrete check passed: 13 stages.