icon

Morainev0.5.0

CheckboxGroup
formscheckbox-group

CheckboxGroup

Multi-select checkbox group with card, list, and table layout variants.

Import#

import { CheckboxGroup } from 'moraine'

Slot Structure#

Fieldset with an optional legend grouping multiple Checkbox items.

root
└── fieldset
├── legend (optional)
└── root (Checkbox, ×n)

Examples#

Variants#

List, card, and table variants with shared items data.

function Variants() {
const ITEMS = [
{ value: 'alpha', label: 'Alpha', description: 'Primary rollout channel' },
{ value: 'beta', label: 'Beta', description: 'Early access channel' },
{ value: 'stable', label: 'Stable', description: 'Production channel' },
]
return (
<div class="gap-4 grid lg:grid-cols-3 sm:grid-cols-2">
<div class="p-4 b-(1 border) rounded-lg">
<CheckboxGroup legend="List" items={ITEMS} defaultValue={['alpha']} />
</div>
<div class="p-4 b-(1 border) rounded-lg">
<CheckboxGroup legend="Card" items={ITEMS} variant="card" defaultValue={['beta']} />
</div>
<div class="p-4 b-(1 border) rounded-lg">
<CheckboxGroup legend="Table" items={ITEMS} variant="table" defaultValue={['stable']} />
</div>
</div>
)
}

Sizes#

Size scale from xs to xl in card variant.

function Sizes() {
const ITEMS = [
{ value: 'alpha', label: 'Alpha', description: 'Primary rollout channel' },
{ value: 'beta', label: 'Beta', description: 'Early access channel' },
{ value: 'stable', label: 'Stable', description: 'Production channel' },
]
const SIZES = ['xs', 'sm', 'md', 'lg', 'xl'] as const
return (
<div class="gap-3 grid lg:grid-cols-3 sm:grid-cols-2">
<For each={SIZES}>
{(size) => (
<div class="p-4 b-(1 border) rounded-lg">
<CheckboxGroup
legend={`Size ${size}`}
items={ITEMS}
variant="card"
size={size}
defaultValue={size === 'xs' ? ['alpha'] : ['stable']}
/>
</div>
)}
</For>
</div>
)
}

Orientation#

Vertical and horizontal layouts with the same item set.

function Orientation() {
return (
<div class="gap-4 grid md:grid-cols-2">
<div class="p-4 b-(1 border) rounded-lg space-y-1">
<CheckboxGroup legend="Vertical" items={ITEMS} defaultValue={['beta']} />
</div>
<div class="p-4 b-(1 border) rounded-lg space-y-1">
<CheckboxGroup
legend="Horizontal"
items={HORIZONTAL_ITEMS}
orientation="horizontal"
defaultValue={['alpha']}
classes={{
fieldset: 'flex-wrap',
item: 'min-w-26 flex-1',
}}
/>
</div>
</div>
)
}

Indicator#

Start/end/hidden indicator positions in list layout.

function Indicator() {
return (
<div class="gap-4 grid md:grid-cols-2 xl:grid-cols-3">
<For each={INDICATORS}>
{(indicator) => (
<div class="p-4 b-(1 border) rounded-lg space-y-1">
<p class="text-xs text-muted-foreground">Indicator: {indicator}</p>
<CheckboxGroup
legend="Channels"
items={ITEMS}
indicator={indicator}
defaultValue={['beta']}
/>
</div>
)}
</For>
</div>
)
}

Controlled + Disabled Items#

Controlled selected values with per-item disabled state.

function ControlledDisabledItems() {
const ITEMS = [
{ value: 'alpha', label: 'Alpha', description: 'Primary rollout channel' },
{ value: 'beta', label: 'Beta', description: 'Early access channel' },
{ value: 'stable', label: 'Stable', description: 'Production channel' },
]
const [value, setValue] = createSignal<string[]>(['beta'])
return (
<div class="max-w-2xl space-y-3">
<CheckboxGroup
legend="Controlled channels"
variant="table"
orientation="horizontal"
items={[
...ITEMS,
{ value: 'legacy', label: 'Legacy', description: 'Frozen channel', disabled: true },
]}
value={value()}
onChange={setValue}
/>
<p class="text-xs text-muted-foreground">Selected: {value().join(', ') || 'none'}</p>
</div>
)
}

API Reference#

Attributes#

Slotroot0 attributes
Group container that owns checkbox collection state and layout.
No attribute metadata for this slot.

Props#

PropTypeDefaultDescription
checkedIconIconT.Name
Default checked icon for all items.
classClassValue
Class applied to the component root or trigger element.
classesCheckboxGroupT.Classes | undefined
defaultValuestring[] | undefined
The default value of the input (uncontrolled).
disabledboolean | undefinedfalse
Whether the input is disabled.
idstring | undefined
The ID of the input element.
indeterminateIconIconT.Name
Default indeterminate icon for all items.
indicator"hidden" | "end" | "start" | undefined
Default indicator position for all items.
items(string | CheckboxGroupT.Item<TTrue, TFalse>)[] | undefined
Array of items to render in the group.
legendJSX.Element
Legend for the checkbox group.
namestring | undefined
The name of the input element, used for form submission.
onChange((value: string[]) => void) | undefined
Callback when the selected values change.
orientation"horizontal" | "vertical" | undefined
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
stylesCheckboxGroupT.Styles | undefined
valuestring[] | undefined
The current value of the input (controlled).
variant"list" | "table" | "card" | undefined

Items#

PropTypeDefaultDescription
checkedIconIconT.Name
Custom checked icon for this item.
descriptionJSX.Element
Description for the group item.
disabledboolean | undefined
Whether the item is disabled.
indeterminateboolean | undefined
Whether the item is indeterminate.
indeterminateIconIconT.Name
Custom indeterminate icon for this item.
labelJSX.Element
Label for the group item.
valuestring | undefined
Value of the group item.