Checkbox handbook
v1.3.0 · @snowui-design-system/components
License: Before reading component documentation, source, or npm usage instructions for the first time, read the full LICENSE. Reuse that review for the same task and version. Public API configuration and internal implementation changes have different license implications. All components use the unified runtime package; source rights remain governed by the license.
Overview
Choose independent options with checked, unchecked, and mixed states, suitable for forms and batch selection.
When to use it
Use Checkbox for independent choices or multi-selection. Use Radio for mutually exclusive choices and Switch for an immediately applied setting.
Independent Boolean states use
bind:checked; multiple arrays usebind:groupand provide stable value for each item.Indeterminate means partially selected; managed separately from checked. Provide labels or ariaLabel, and disable disabled.
Quick start
This example shows the recommended basic composition. See the sections below for more cases and composition limits.
API
See the base component documentation for inherited capabilities not redeclared here. This table lists only named public Props declared by this component.
Usage boundaries and details
Layout model
Main layout model: Inline shell layout. See the definition.. /.. /../specs/maintainers/LayoutProtocol.md §12.4 (source code reference: specs/maintainers/LayoutProtocol.md).
Checkbox belongs to the inline shell subclass of "control visual body + label":
The root node keeps
inline-flex, and the content is Hug as a whole..snowui-checkbox-visualis the control visual body of fixed Hug..snowui-checkbox-labelis an optional label. It hugs its contents when there is room and can shrink with a single-line ellipsis when constrained. Original content and the complete native accessible name are preserved.visual and label spacing uses
--snowui-checkbox-gap. Set a preferred value with gap or--snowui-checkbox-gap-override; effective spacing stays at least 4 CSS px.sizeindicates the space size of the control containing transparent white space, which does not change the layout strategy of the label.The white space around is
size / 16, and the width and height of the visible graphic aresize × 0.875; for example,size={32}occupies 32×32px, the graphic is 28×28px, and the four sides are 2px each. The white and graphics are scaled with the size, root font size and size Token, and the white white can still be clicked.The white space is held by the shared control shell, and the label is located outside the shell; the inner frame continues to be calculated according to the nominal size of
0.0625, and the rounded corners, Dot and selected rings are calculated according to the visible graphic size.
Usage examples
Unchecked (unchecked)
Empty box
Gray border
Checked (selected)
Display the check icon
Theme color background and border
Indeterminate (uncertain)
Display the horizontal line icon
Theme color background and border
It is often used in the "select all" scene.
Icon
Tck the icon: The selected status is displayed
Horizontal icon: Uncertain status display
Draw with 28×28 SVG stroke path, scale with component size and inherit selected state color
Accessibility
Use the native
<input type="checkbox">to ensure keyboard navigationSupport Tab key focus
Support Space key switching
Support
indeterminateattributeIn the disabled state,
tabindex=-1
Single checkbox
Select all/select partially
Style Rules (Style Spec)
2. Default style (Defaults)
Display:
inline-flex,align-items: centerGap: Prefer
var(--gap-1)and retain at least 4 CSS px after scaling or an explicit zero.Cursor:
pointer(Disabled isdefault)Font:
var(--text-14)(14px),line-height: var(--leading-14)(20px)
3. CSS Variables (Variables)
Components use CSS variables to achieve equal scaling:
Unchecked
Visual: Transparent background +
var(--black-20)borderIcon: The check and the horizontal line are not visible.
Hover: The filling remains unchanged; the independent inset coverage is superimposed on the basic 20% black border 20% black, the default equivalent is about 36% black; only this state applies to
StyleSpec §2.4.3exception
Checked / Indeterminate
Trigger:
:checked/:indeterminateof native input is driven by sibling selectorVisual:
var(--primary)background + borderIcon: color:
var(--static-white-100); checked uses path drawing, indeterminate retains scaling / transparency transitionHover: Fill and inset border uniformly mixed on the main color 20% Static White
Disabled
Attr:
[data-disabled="true"]Style:
opacity: 0.5,pointer-events: none,cursor: default
5. Details of interaction
Click area: Native
<input>usesposition: absolute; inset: 0to cover the entire label area to ensure that the click response is sensitive.Focus: Support keyboard navigation, and display
20% primaryRing when focusing.Animation:
Container: hover filling and inset border use the same color and timing
Checked: Refer to the pathLength semantics of Fluid Functionalism, and use
200ms ease-outto draw; when unselecting, use the regular150ms ease-outto fade out with the background color, and do not draw in reverse.Indeterminate horizontal line: consistent with Radio state dynamic effect, using
150ms ease-outprefers-reduced-motion: reduce: Cancel the visual body, check the transition with the horizontal line, and directly display the final state
Checkbox style overlay
Read the full LICENSE first; reuse that review for the same task, version, and scope.
First use public component Props to match the desired appearance, preserving the existing look where possible. If changes are necessary, follow the style selection and override order: use your own class (including Tailwind already in the project) or an instance style. The names below are public overrides actually consumed by source; check their scope and do not modify private DOM. Choose the correct SnowUI token family. External apps need not install SnowUI website utilities.
Checkbox type and status
Required Props: no named required Props.
Two-way binding: bind:checked, bind:group, bind:indeterminate.
Inheritance statement: Omit<FrameProps, "size">. The inheritance ability is subject to the public document of the base class; the fields in Omit have been excluded and cannot be used as they are according to the base class.
The following type declarations are actually referenced by public Props and come from source. A Svelte Snippet denotes a content fragment; ComponentProps denotes the Props of the corresponding component.
ResourceSize
Source: components/src/context.ts