Skip to content

Safety Plan

Beta

The six steps of the Stanley-Brown Safety Planning Intervention, in order, with the crisis step rendered open and uncloseable.

5 states6 props30.2 KB installedsince 0.3.0
npx @zoblocks/cli add safety-plan
View sourceRegistry JSON ↗

Why it exists

A safety plan is written collaboratively in a room and read alone, often on a phone, often at the worst hour of someone's week.

That reading context is the whole design. The crisis step holds the phone numbers, so it renders open and its trigger reports itself disabled — a person in crisis does not scroll, does not scan, and should not have to make a correct decision about a chevron to reach a number. The step order is the intervention rather than a layout: the escalation from what someone can do alone to who they call is the clinical content, so nothing here sorts or filters. And a step nobody has filled in says so instead of vanishing, because a five-step plan numbered one to five claims the sixth was never part of the instrument.

Playground

Change a prop and watch the component and its code change with it.

Design language

988
Suicide & Crisis Lifeline24 hours
County crisis team
555 014824 hours

This part of your plan stays open. You do not have to look for it.

Props
Playground.tsx
import { SafetyPlan } from "@/components/zoblocks/safety-plan";export default function Example() {  return (    <SafetyPlan      steps={steps}      revisedAt="2026-08-11"      headingLevel={3}      pinCrisisStep      density="patient"    />  );}

Examples

The cases worth copying. Open one in StackBlitz to run it with its dependencies installed.

Complete patient plan

A completed six-step patient-facing safety plan. The crisis contacts remain visible in the pinned-open step.

Unfinished plan

Only some steps have been completed. The remaining steps stay visible and are identified as unfinished.

Empty plan

An empty plan still displays all six steps, including the pinned-open crisis step.

Clinician editing view

The clinician editing view disables crisis-step pinning and uses standard density.

Installation

Terminal
npx @zoblocks/cli add safety-plan

First install? Run zoblocks init once to say where your @/ alias points. The source is copied into your repository, along with anything it depends on.

Dependenciesclsxtailwind-merge

Usage

Props are the FHIR resource.

usage.tsx
import { SafetyPlan } from "@/components/zoblocks/safety-plan";<SafetyPlan  revisedAt="2026-08-11"  headingLevel={2}  steps={{    warningSigns: { entries: ["Sleeping less than four hours", "Not answering messages for two days"] },    internalCoping: { entries: ["Walk to the end of the road and back", "Four in, six out, ten times"] },    distractions: { entries: ["The cafe on Bell Street before 11am"] },    supportContacts: { contacts: [{ name: "Priya", detail: "Sister", availability: "Any time" }] },    professionals: {      contacts: [        { name: "988", detail: "Suicide & Crisis Lifeline", availability: "24 hours" },        { name: "County crisis team", detail: "555 0148", availability: "24 hours" },      ],    },    environment: { entries: ["Priya is holding the spare keys to the garage"] },  }}/>

Use it when

  • Patient-facing portals and apps, which is what the default patient density and second-person wording are for.
  • A clinician's read-only view of a plan someone else wrote.
  • Printed copies — the crisis step prints expanded whatever else is closed.

Avoid it when

  • As the editor. This renders a plan; writing one is a form, with its own validation and consent.
  • With pinCrisisStep off on any surface a person in crisis might open. That switch is for an editing view.
  • As a substitute for a risk assessment. A plan is an intervention someone agreed to, not a score.

API

Every prop is typed. Props not listed are forwarded to the root element.

SafetyPlan

6 props
stepsrequired
Partial<Record<SafetyPlanStepKey, SafetyPlanStepContent>>
Default—
The six Stanley-Brown steps, in order. The order is the intervention; a plan rendered out of sequence is a different document.
density
AccordionDensity
Default"patient"
Row height and type scale. Inherited from the nearest density provider when omitted.
headingLevel
AccordionHeadingLevel
Default3
Where the plan's headings sit in the page outline. Set it to match the surrounding document rather than letting a plan start at h1 inside a chart.
labels
Partial<SafetyPlanLabels>
Default—
Replaces the built-in patient-facing wording.
pinCrisisStep
boolean
Defaulttrue
Keep the crisis step open and uncloseable. Defaults to true and should stay true on any surface a person in crisis might open. Turning it off is for a clinician's editing view, where every step is being worked on and none of them is the emergency.
revisedAt
string
Default—
ISO 8601. Shown so a reader knows how current the plan is.

Accessibility

Screen readers and semantics

  • The crisis step is reachable without an interaction. It renders expanded and its trigger carries aria-disabled=true, which is the case APG defines: the panel is visible and the accordion prevents collapsing it. The trigger stays focusable, so a keyboard or screen-reader user lands on it and hears the label rather than tabbing past it.
  • Pinning is stated in words. The header shows an "Always open" summary and the panel repeats the reason in a sentence, so the behaviour reads as intentional rather than as a stuck control — including in forced-colors mode, where the tint on the crisis panel is discarded.
  • Steps keep their numbers in text. The step number is part of the heading string rather than a separate element, so it survives being announced, copied, and printed.
  • Contacts are a description list. Names and how to reach them are marked up as dt/dd pairs, so a screen reader can navigate them as pairs instead of a run of text.

Source

Exactly what lands in your repository, read from the published registry so it can never drift from what the CLI installs.

Show source260 lines
safety-plan.tsx
"use client";/** * SafetyPlan — the six steps, with the fifth one open. * * The Stanley-Brown Safety Planning Intervention is six ordered steps: warning * signs, internal coping, people and settings that distract, people to ask for * help, professionals and agencies, and making the environment safer. It is * written collaboratively in a room and read alone, often on a phone, often at * the worst hour of someone's week. * * That reading context is the entire design. * *   **Step five does not collapse.** It holds the crisis numbers. A person in *   crisis does not scroll, does not scan, and should not have to make a *   correct decision about a chevron to reach a phone number. The step renders *   open and its trigger reports itself disabled — which is exactly the case *   APG carves out for aria-disabled: the panel is visible and the accordion *   prevents collapsing it. * *   **The order is the intervention, not a layout.** Steps are rendered in the *   sequence the instrument defines. The component does not sort, filter, or *   let a caller reorder them, because the escalation from "things I can do *   alone" to "who I call" is the clinical content. * *   **A missing step is stated, not skipped.** A plan written in one sitting *   often has gaps. Rendering five steps and numbering them 1–5 would claim the *   sixth was never part of the instrument. Each empty step says it is not *   filled in yet, which is also the prompt to finish it. * * Wording here is patient-facing and second person throughout — a different * catalog from the clinician's, not a softened version of it (CONTENT.md §7). */import * as React from "react";import { cn } from "@/lib/utils";import { Accordion, type AccordionDensity } from "@/components/zoblocks/accordion";import type { AccordionHeadingLevel, AccordionItem } from "@/lib/zoblocks-accordion";/** A person or service the plan names. */export interface SafetyPlanContact {  name: string;  /** How to reach them, as the plan records it. Rendered verbatim. */  detail?: string;  /** When they are reachable. "24 hours" is a fact worth stating. */  availability?: string;}export interface SafetyPlanStepContent {  /** Free text the person wrote. */  entries?: readonly string[];  /** People and services, for the steps that hold them. */  contacts?: readonly SafetyPlanContact[];}export type SafetyPlanStepKey =  | "warningSigns"  | "internalCoping"  | "distractions"  | "supportContacts"  | "professionals"  | "environment";export type SafetyPlanSteps = Partial<Record<SafetyPlanStepKey, SafetyPlanStepContent>>;export interface SafetyPlanLabels {  warningSigns: string;  internalCoping: string;  distractions: string;  supportContacts: string;  professionals: string;  environment: string;  /** Shown on the pinned crisis step. */  alwaysOpen: string;  /** Shown on the crisis step when it is not pinned, so the rail still has words. */  crisisStep: string;  /** Shown on a step nobody has filled in yet. */  empty: string;  /** Reassurance under the crisis step, so the pinning does not read as a glitch. */  pinnedExplanation: string;  revised: (date: string) => string;}/** * The six steps in the instrument's order. Exported so a product can label them * in its own words without being able to change the sequence. */export const SAFETY_PLAN_STEP_ORDER: readonly SafetyPlanStepKey[] = [  "warningSigns",  "internalCoping",  "distractions",  "supportContacts",  "professionals",  "environment",];export const DEFAULT_SAFETY_PLAN_LABELS: SafetyPlanLabels = {  warningSigns: "Signs that things are getting harder",  internalCoping: "Things I can do on my own",  distractions: "People and places that take my mind off it",  supportContacts: "People I can ask for help",  professionals: "If none of that is working",  environment: "Making home safer",  alwaysOpen: "Always open",  crisisStep: "Crisis contacts",  empty: "Not filled in yet. You can add to this with your clinician.",  pinnedExplanation: "This part of your plan stays open. You do not have to look for it.",  revised: (date) => `Revised ${date}`,};export interface SafetyPlanProps extends Omit<  React.HTMLAttributes<HTMLDivElement>,  "children" | "onChange"> {  /**   * The six Stanley-Brown steps, in order. The order is the intervention; a plan rendered out   * of sequence is a different document.   */  steps: SafetyPlanSteps;  /** ISO 8601. Shown so a reader knows how current the plan is. */  revisedAt?: string;  /** Replaces the built-in patient-facing wording. */  labels?: Partial<SafetyPlanLabels>;  /**   * Keep the crisis step open and uncloseable.   *   * Defaults to true and should stay true on any surface a person in crisis   * might open. Turning it off is for a clinician's editing view, where every   * step is being worked on and none of them is the emergency.   */  pinCrisisStep?: boolean;  /**   * Where the plan's headings sit in the page outline. Set it to match the surrounding   * document rather than letting a plan start at h1 inside a chart.   */  headingLevel?: AccordionHeadingLevel;  /** Row height and type scale. Inherited from the nearest density provider when omitted. */  density?: AccordionDensity;}function StepBody({  content,  emptyLabel,  explanation,}: {  content: SafetyPlanStepContent | undefined;  emptyLabel: string;  explanation?: string;}) {  const entries = content?.entries ?? [];  const contacts = content?.contacts ?? [];  if (!entries.length && !contacts.length) {    // Absence with a reason, never a blank — CONTENT.md §1.    return <p className="zb-safety-plan__empty">{emptyLabel}</p>;  }  return (    <>      {entries.length ? (        <ul className="zb-safety-plan__entries">          {entries.map((entry) => (            <li key={entry}>{entry}</li>          ))}        </ul>      ) : null}      {contacts.length ? (        <dl className="zb-safety-plan__contacts">          {contacts.map((contact) => (            <React.Fragment key={contact.name}>              <dt>{contact.name}</dt>              <dd>                {contact.detail ? (                  <span className="zb-safety-plan__detail">{contact.detail}</span>                ) : null}                {contact.availability ? (                  <span className="zb-safety-plan__availability">{contact.availability}</span>                ) : null}              </dd>            </React.Fragment>          ))}        </dl>      ) : null}      {explanation ? <p className="zb-safety-plan__explanation">{explanation}</p> : null}    </>  );}export function SafetyPlan({  steps,  revisedAt,  labels: labelOverride,  pinCrisisStep = true,  headingLevel = 3,  density = "patient",  className,  ...rest}: SafetyPlanProps) {  const labels = React.useMemo(    () => ({ ...DEFAULT_SAFETY_PLAN_LABELS, ...labelOverride }),    [labelOverride],  );  const items = React.useMemo<AccordionItem[]>(    () =>      SAFETY_PLAN_STEP_ORDER.map((key, index) => {        const isCrisis = key === "professionals";        const pinned = isCrisis && pinCrisisStep;        return {          key,          // The number is part of the label rather than a separate element, so          // it survives being read out, copied, or printed.          label: `${index + 1} · ${labels[key]}`,          ...(pinned ? { pinned: true } : {}),          // The crisis step always carries words beside its rail, pinned or          // not. In the clinician's editing view the step is closeable, so          // "Always open" would be a lie — but a red rail with nothing beside          // it is worse, because it is a signal only some readers receive.          ...(isCrisis            ? {                severity: "critical" as const,                summary: pinned ? labels.alwaysOpen : labels.crisisStep,              }            : {}),          children: (            <StepBody              content={steps[key]}              emptyLabel={labels.empty}              {...(pinned ? { explanation: labels.pinnedExplanation } : {})}            />          ),        };      }),    [labels, pinCrisisStep, steps],  );  return (    <div className={cn("zb-safety-plan", className)} {...rest}>      {revisedAt ? (        <p className="zb-safety-plan__revised">          <time dateTime={revisedAt}>{labels.revised(revisedAt)}</time>        </p>      ) : null}      <Accordion        items={items}        // One at a time: this is read under load, and a page of six open        // sections is a page nobody finishes.        accordion        variant="separate"        density={density}        headingLevel={headingLevel}      />    </div>  );}