Components
BodyMap
A neutral, non-realistic body schematic for pointing to a location. It records region keys and interprets nothing, so the product owns every meaning.
Usage
pnpm dlx shadcn@latest add @opsinjs/body-map
The @opsinjs namespace is declared in your components.json. Everything it installs is code you then own. There is no runtime package to keep in step.
import { BodyMap } from "@/components/ui/body-map"<BodyMap
label="Where are you noticing something?"
value={regions}
onValueChange={setRegions}
/>Examples
body-map · base base · style base-lyraOpen under the product themePointing at what hurts
A controlled multi-select over both figures, driven by value and onValueChange.
A marked region stands out in greyscale, without colour.
body-map-pointing-at-what-hurts · base base · style base-lyraOpen under the product theme"use client"
import { useState } from "react"
import { BodyMap } from "@/components/ui/body-map"
export default function BodyMapPointingAtWhatHurts() {
const [regions, setRegions] = useState<string[]>(["left-arm"])
return (
<div className="flex w-full max-w-md flex-col gap-opsin-4">
<BodyMap
label="Example: where are you noticing something?"
value={regions}
onValueChange={setRegions}
/>
<p className="text-opsin-footnote [color:var(--muted-foreground)]">
{regions.length === 0
? "No region marked yet."
: "Marked: " +
regions.length +
" region" +
(regions.length === 1 ? "" : "s") +
"."}
</p>
</div>
)
}Pairing the map with a checkbox list
The map and a native checkbox list share one value, so a keyboard or
assistive-technology user has a robust path to the same answer. Ship both together.
body-map-with-a-checkbox-list · base base · style base-lyraOpen under the product theme"use client"
import { useState } from "react"
import { BodyMap } from "@/components/ui/body-map"
const REGIONS = [
{ key: "head", label: "Head" },
{ key: "chest", label: "Chest" },
{ key: "abdomen", label: "Abdomen" },
{ key: "left-arm", label: "Left arm" },
{ key: "right-arm", label: "Right arm" },
{ key: "left-leg", label: "Left leg" },
{ key: "right-leg", label: "Right leg" },
{ key: "upper-back", label: "Upper back" },
{ key: "lower-back", label: "Lower back" },
]
export default function BodyMapWithACheckboxList() {
const [value, setValue] = useState<string[]>([])
function toggle(key: string) {
setValue((prev) => (prev.includes(key) ? prev.filter((k) => k !== key) : [...prev, key]))
}
return (
<div className="flex w-full max-w-2xl flex-col gap-opsin-6 sm:flex-row sm:items-start">
<BodyMap
label="Example: mark where something is"
regions={REGIONS}
value={value}
onValueChange={setValue}
view="both"
/>
<fieldset className="flex flex-col gap-opsin-2 border-0 p-0">
<legend className="text-opsin-headline text-foreground">
The same regions as a list
</legend>
{REGIONS.map((r) => (
<label
key={r.key}
className="flex items-center gap-opsin-2 text-opsin-body text-foreground"
>
<input
type="checkbox"
checked={value.includes(r.key)}
onChange={() => toggle(r.key)}
className="size-5"
/>
{r.label}
</label>
))}
</fieldset>
</div>
)
}When to use it
Use it when
- Letting someone point at one or more general regions of the body, as structured input a product interprets on its own terms.
- Capturing a coarse location beside a free-text note or a reading, where a key like left-arm is more reliable than a sentence.
- Offering a faster alternative to a long checkbox list, while keeping that list available for keyboard and assistive-technology users.
Do not use it when
- You are recording one specific measurement or reading rather than a location.Use
reading-inputinstead. - You need a realistic figure that represents a particular body, age or condition.Use
fieldinstead. - You are asking how strong or how bad something is rather than where it is.Use
scale-inputinstead. - The answer is really free text and a diagram would only get in the way.Use
fieldinstead.
Clinical meaning
Asserts. Only that the reader indicated these regions, not what is there, whether it hurts, how strongly, since when, or what it means. The shipped labels are generic placeholders, and the consuming product owns the region words and any interpretation.
Never read as. A symptom checker, a triage or a diagnosis. A product that treats a marked region as evidence of a condition has added a judgement the component does not make, and owns it.
Colour axis. Neither. A selection is a muted fill, a hairline and a tick, never a hue, and a marked region carries no clinical level and names no category. See Two colour axes.
Thresholds. None. The component runs no rules over a selection and reaches no conclusion from it, and whether a selection triggers anything is the product's decision.
Accessibility
Each region is a real button, named by its label, with aria-pressed for its state,
inside a group named by label. Unselected shows a plus, the selected state survives
greyscale with aria-pressed as its carrier, and each marker meets the 44 by 44 floor
on both axes in rem. Every colour is a role token, no type size is in px, and no
banned word appears. Left and right are the subject's own sides, so the left-arm
marker sits on the viewer's right, matching clinical convention.
The audit fixed one defect. The rem markers outgrew the px-pinned figure box at
200% text and collided, so they could not be tapped separately (1.4.4, 1.4.10). The
box now scales in rem in lockstep with the markers, so the spacing ratio holds at
every text size and the default view is unchanged.
Residual items.
- The Front and Back captions are
<p>, not headings, by design, so the component hardcodes no heading level into a host document of unknown depth. Each figure still carries a namedrole="group". - Screen-reader output in VoiceOver, NVDA and TalkBack, the nine-stop tab sequence and forced colours are not gated.
- The paired checkbox list stays the primary path for readers who cannot point at a target.
| Key | Action | Notes |
|---|---|---|
| Tab | Moves to the next region | Each region is its own stop, so the default map is nine stops. |
| Shift+Tab | Moves to the previous region | The same sequence in reverse. |
| Space or Enter | Toggles the focused region | Native button activation. aria-pressed flips, and the fill and tick follow it. |
Contrast: 36 measured token pairs, 15 below floor
| Pair | Theme | APCA Lc | WCAG 2.2 | Floor |
|---|---|---|---|---|
| body text on the page | light | 101.6 | 17.18:1 | Pass |
| body text on the page | dark | -100.5 | 18.00:1 | Pass |
| body text on a card | light | 104.7 | 17.96:1 | Pass |
| body text on a card | dark | -99.6 | 16.32:1 | Pass |
| body text on the muted ground | light | 98.1 | 16.32:1 | Pass |
| body text on the muted ground | dark | -97.5 | 13.77:1 | Pass |
| secondary text on the page | light | 83.9 | 7.42:1 | Pass |
| secondary text on the page | dark | -80.7 | 13.44:1 | Pass |
| secondary text on a card | light | 87.0 | 7.76:1 | Pass |
| secondary text on a card | dark | -79.8 | 12.19:1 | Pass |
| secondary text on the muted ground | light | 80.4 | 7.05:1 | Pass |
| secondary text on the muted ground | dark | -77.8 | 10.28:1 | Pass |
| a hairline boundary on the page | light | 19.3 | 1.41:1 | Below floor |
| a hairline boundary on the page | dark | -8.2 | 1.90:1 | Below floor |
| a hairline boundary on a card | light | 22.4 | 1.47:1 | Below floor |
| a hairline boundary on a card | dark | -7.3 | 1.72:1 | Below floor |
| a hairline boundary on the muted ground | light | 15.8 | 1.34:1 | Below floor |
| a hairline boundary on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on the page | light | 69.8 | 4.52:1 | Pass |
| a placeholder boundary on the page | dark | -51.0 | 7.62:1 | Pass |
| a placeholder boundary on a card | light | 72.8 | 4.72:1 | Pass |
| a placeholder boundary on a card | dark | -50.1 | 6.91:1 | Pass |
| a placeholder boundary on the muted ground | light | 66.2 | 4.29:1 | Pass |
| a placeholder boundary on the muted ground | dark | -48.1 | 5.83:1 | Pass |
| a placeholder fill on the page | light | 8.3 | 1.18:1 | Below floor |
| a placeholder fill on the page | dark | -8.2 | 1.90:1 | Below floor |
| a placeholder fill on a card | light | 11.4 | 1.23:1 | Below floor |
| a placeholder fill on a card | dark | -7.3 | 1.72:1 | Below floor |
| a placeholder fill on the muted ground | light | 0.0 | 1.12:1 | Below floor |
| a placeholder fill on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on its own fill | light | 58.9 | 3.84:1 | Pass |
| a placeholder boundary on its own fill | dark | -41.5 | 4.01:1 | Below floor |
| the card hairline on the page | light | 69.8 | 4.52:1 | Pass |
| the card hairline on the page | dark | -28.7 | 4.19:1 | Below floor |
| the card hairline on a card | light | 72.8 | 4.72:1 | Pass |
| the card hairline on a card | dark | -27.9 | 3.80:1 | Below floor |
These are the measured token pairs this component draws colour from, not a measurement of the component itself.
Props interface
Prop
Type
Generated from BodyMapProps in registry/bases/base/body-map.tsx.
label is required and has no default. Name it as the question the reader is
answering. A region key with no built-in place on the figure is warned once in
development and skipped rather than drawn. view defaults to both.