Rost

← All components

component

Checkbox

A choice that's on or off and waits for the form. A 20px box that fills green with a tick, and the words beside it.

In code Contract: review Guidance: proposed Contract on GitHub Figma 733:64 As markdown

Try it

Every variant

Default · Not checked · Not indeterminate
Disabled · Not checked · Not indeterminate
Default · Checked · Not indeterminate
Disabled · Checked · Not indeterminate
Default · Checked · Indeterminate
Disabled · Checked · Indeterminate

Hover, press or tab to one to see the other 9 states.

Install

npx github:Runceanu/rost add checkbox

It lands in src/rost/checkbox/, with what it needs and its contract. Install has the rest.

When to use

  • Choices that wait for Save

    Settings in a form that only count when it's sent: what goes on an invoice, which months to include.

  • Agreeing to something

    One box before a button, like "I've checked these figures".

When not to use

Behaviour

Empty is a field's edge around the page colour. Ticked fills with the primary green, with a dark tick, the way a primary button looks. Hover, press and focus come from the browser. Disabled fades the whole row, words too. Half-ticked (indeterminate) is the ticked look with a dash, for a box that stands for a group where only some are ticked, like a table's "select all".

Accessibility

  • Element

    A real <input type="checkbox"> inside a <label>. The input is hidden from sight, not from screen readers.

  • Name

    The words beside it, through the label. Without words, give it an aria-label.

  • Keyboard

    Tab reaches it. Space ticks and unticks it.

  • Focus

    focus-ring around the box, on :focus-visible.

  • Colour

    Ticked isn't only green: the tick is there too. The empty box's edge is 4.3:1 on the dark page. Ticked, the edge is the fill's green in dark and a dark green in light, so the box stands out at 3:1 or more on both.

Content

Say what's true when it's ticked, in sentence case: "Include VAT", not "VAT: yes/no".

Props

PropTypeValuesDefault
checked boolean false
indeterminate boolean false
children slot

States: Default, Hover, Pressed, Focus, Disabled.

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • gap 8px spacing/gap/small

displayinline-flex · align-itemscenter · vertical-alignmiddle · positionrelative · cursorpointer

input

positionabsolute · width1px · height1px · opacity0 · pointer-eventsnone

box

  • width 20px spacing/size/xsmall
  • height 20px spacing/size/xsmall
  • border-radius 4px spacing/radius/xsmall
  • outline-width 1px spacing/outline/small
  • outline-offset calc(-1 * var(--spacing-outline-small)) on purpose: Composed from a token: the edge sits inside the box.

positionrelative · flex-shrink0 · outline-stylesolid

check

  • inset 2px spacing/gap/3xsmall

positionabsolute · mask-imageurl(./icon-check.svg) · mask-size100% 100% · mask-repeatno-repeat · pointer-eventsnone

focus-ring

  • border-style solid no token yet
  • border-width 2px spacing/outline/medium
  • border-radius 8px spacing/radius/small

displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · pointer-eventsnone

label

  • font-family 'General Sans Variable' font-family/base
  • font-weight 400 typography/paragraph/font-weight/regular
  • font-size 14px typography/paragraph/font-size
  • line-height 20px typography/paragraph/line-height
  • letter-spacing 0px typography/paragraph/letter-spacing
  • color #d3d9d5 checkbox/label

Changes by variant

11 variants. Each table is what one thing changes with: a column per state, a row per property. Where every row starts with the same token path, it's written once, under the property.

Follows state

Checked

PropertyDefaultHoverPressedFocusDisabled
check.backgroundcheckbox/on/… default/check #060805 hover/check #060805 pressed/check #060805 focus/check #060805 disabled/check #060805

Follows checked

All but Indeterminate

PropertyNot checkedChecked
check.display none block

Focus

PropertyNot checkedChecked
focus-ring.border-colorcheckbox/… off/focus/focus-ring #999 on/focus/focus-ring #b6ffda

Follows state and checked

Not checked

PropertyDefaultHoverPressedFocusDisabled
box.backgroundcheckbox/off/… default/box #060805 hover/box #171717 pressed/box #171717 focus/box #060805 disabled/box #060805
box.outline-colorcheckbox/off/… default/edge #747573 hover/edge #999999 pressed/edge #999999 focus/edge #747573 disabled/edge #747573

Checked

PropertyDefaultHoverPressedFocusDisabled
box.backgroundcheckbox/on/… default/box #00d669 hover/box #00b450 pressed/box #00913a focus/box #00d669 disabled/box #00d669
box.outline-colorcheckbox/on/… edge #00d669 edge #00d669 edge #00d669 edge #00d669 edge #00d669

Only in some variants

These don't change: they're just set in some variants and not others.

Indeterminate

  • check.mask-image url(./icon-minus.svg) Figma frame size

Focus

  • focus-ring.display block layout

Disabled

  • root.cursor default Figma frame size
  • root.opacity 0.24 opacity/gentle