icon

Morainev0.5.0

Checkbox
formscheckbox

Checkbox

Single checkbox control with card and list variants and custom true/false values.

Import#

import { Checkbox } from 'moraine'

Slot Structure#

Checkbox indicator with optional label and description.

root
├── container
│ ├── input
│ └── control
│ └── indicator (optional)
└── wrapper (optional)
├── label (optional)
└── description (optional)

Examples#

Variants#

List and card variants with start/end/hidden indicator positions.

function Variants() {
return (
<div class="gap-8 grid sm:grid-cols-2">
<div class="space-y-3">
<Checkbox label="List / start" description="Default list style" defaultChecked />
<Checkbox
label="List / end"
description="Indicator at the end"
indicator="end"
defaultChecked
/>
<Checkbox
label="List / hidden"
description="Only text, no visible indicator"
indicator="hidden"
defaultChecked
/>
</div>
<div class="space-y-3">
<Checkbox
variant="card"
label="Card variant"
description="Whole card area is clickable"
defaultChecked
/>
<Checkbox
variant="card"
label="Card / end"
description="Card with trailing indicator"
indicator="end"
/>
<Checkbox variant="card" label="Card / disabled" description="Disabled state" disabled />
</div>
</div>
)
}

Sizes#

Scale from xs to xl with unified label spacing.

function Sizes() {
const SIZES: CheckboxSizeName[] = ['xs', 'sm', 'md', 'lg', 'xl']
type CheckboxSizeName = Exclude<CheckboxT.Variant['size'], undefined>
return (
<div class="flex flex-col gap-2 max-w-xl">
<For each={SIZES}>
{(size) => (
<Checkbox
size={size}
label={`Size ${size}`}
description={`Checkbox size: ${size}`}
defaultChecked={size === 'md' || size === 'xl'}
/>
)}
</For>
</div>
)
}

Indeterminate + Custom Icons#

Custom checked/indeterminate icons with controlled indeterminate transition.

function IndeterminateCustomIcons() {
const [indeterminate, setIndeterminate] = createSignal<'indeterminate' | boolean>('indeterminate')
return (
<div class="max-w-xl space-y-3">
<Checkbox
label="Permissions"
description={`Current: ${String(indeterminate())}`}
checked={indeterminate()}
onChange={setIndeterminate}
checkedIcon="i-lucide:check-check"
indeterminateIcon="i-lucide:ellipsis"
/>
<div class="flex flex-wrap gap-2">
<Button variant="outline" size="sm" onClick={() => setIndeterminate('indeterminate')}>
Set indeterminate
</Button>
<Button variant="outline" size="sm" onClick={() => setIndeterminate(true)}>
Set checked
</Button>
<Button variant="outline" size="sm" onClick={() => setIndeterminate(false)}>
Set unchecked
</Button>
</div>
</div>
)
}

Custom True/False Values#

Map checked state to domain values instead of boolean.

function CustomTrueFalseValues() {
const INDICATORS: CheckboxIndicatorName[] = ['start', 'end', 'hidden']
const [featureFlag, setFeatureFlag] = createSignal<'enabled' | 'disabled'>('enabled')
type CheckboxIndicatorName = Exclude<CheckboxT.Variant['indicator'], undefined>
return (
<div class="max-w-xl space-y-3">
<Checkbox<'enabled', 'disabled'>
label="Feature flag"
description="Controlled with custom values"
trueValue="enabled"
falseValue="disabled"
checked={featureFlag()}
onChange={setFeatureFlag}
indicator="end"
/>
<p class="text-xs text-muted-foreground">Current value: {featureFlag()}</p>
<div class="p-3 b-(1 border) rounded-lg">
<p class="text-xs text-muted-foreground mb-2">Indicator matrix:</p>
<div class="flex flex-col gap-2">
<For each={INDICATORS}>
{(indicator) => (
<Checkbox
indicator={indicator}
label={`Indicator ${indicator}`}
description="Uncontrolled"
defaultChecked
/>
)}
</For>
</div>
</div>
</div>
)
}

API Reference#

Attributes#

Slotroot0 attributes
Labelable checkbox wrapper that coordinates input, indicator, and text content.
No attribute metadata for this slot.

Props#

PropTypeDefaultDescription
checked"indeterminate" | TTrue | TFalse | undefined
Whether the checkbox is checked (controlled).
checkedIconIconT.Nameicon-check
Icon to show when checked.
classClassValue
Class applied to the component root or trigger element.
classesCheckboxT.Classes | undefined
defaultCheckedboolean | "indeterminate" | undefinedfalse
Whether the checkbox is checked by default (uncontrolled).
descriptionJSX.Element
Description text for the checkbox.
disabledboolean | undefinedfalse
Whether the input is disabled.
falseValueTFalse | undefinedfalse
Value to use when the checkbox is unchecked.
formFieldBindboolean | undefinedtrue
Whether to bind the checkbox value to the parent FormField.
idstring | undefined
The ID of the input element.
indeterminateboolean | undefinedfalse
Whether the checkbox is in an indeterminate state.
indeterminateIconIconT.Nameicon-minus
Icon to show when indeterminate.
indicator"hidden" | "end" | "start" | undefined
labelJSX.Element
Label for the checkbox.
namestring | undefined
The name of the input element, used for form submission.
onChange((value: TTrue | TFalse) => void) | undefined
Callback when the checked state changes.
onPointerDownJSX.EventHandlerUnion<HTMLButtonElement, PointerEvent> | undefined
Pointer down handler for the checkbox control.
readOnlyboolean | undefinedfalse
Whether the input is read-only.
refJSX.HTMLElementTags["div"] extends { ref?: infer Ref; } ? Ref : never | undefined
requiredboolean | undefinedfalse
Whether the input is required.
size"xs" | "sm" | "md" | "lg" | "xl" | undefined
styleJSX.CSSProperties | undefined
stylesCheckboxT.Styles | undefined
trueValueTTrue | undefinedtrue
Value to use when the checkbox is checked.
valuestring | undefinedon
Native value submitted when the checkbox is checked.
variant"list" | "card" | undefined