Developer Docs
Quick reference guides with props tables, usage examples, and best practices for rapid development
Checkbox
Custom checkbox with grid overlay and animated SVG checkmark
✨ Quick Examples
Custom checkbox with SVG checkmark overlay using grid pattern. Supports custom colors, sizes, circular variant, and custom icons.
🔧 Props
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | auto-generated | Unique identifier (auto-generated if not provided) |
| label | string | undefined | Label text for the checkbox |
| checked | State | boolean | false | Current checked state (can be van.state or boolean) |
| disabled | boolean | false | Whether checkbox is disabled |
| required | boolean | false | Whether the field is required (shows red asterisk) |
| onchange | Function | undefined | Change handler (receives event object) |
| class | string | '' | Checkbox input classes (overrides defaults via filterClassName) |
| containerClass | string | '' | Container wrapper classes (use for vwfsize-*, vwfcolor-*) |
| wrapperClass | string | '' | Checkbox wrapper (grid container) classes |
| svgClass | string | '' | SVG checkmark classes |
| svgPathClass | string | '' | SVG path classes (controls checkmark appearance) |
| labelClass | string | '' | Label classes |
| children | any | [] | Label content (alternative to label prop) |
💻 Usage
Basic Usage
const terms = van.state(false);
Checkbox({
id: 'basic-terms',
label: 'I agree to the terms and conditions',
checked: terms,
required: true,
onchange: e => terms.val = e.target.checked
})With Custom Label (Children)
const newsletter = van.state(false);
Checkbox(
{
id: 'custom-label',
checked: newsletter,
onchange: e => newsletter.val = e.target.checked
},
'Subscribe to ',
span({ class: 'font-semibold text-sky' }, 'weekly newsletter'),
' for updates'
)📏 Size Variants
Control checkbox size via containerClass with vwfsize-* utilities.
// Small
Checkbox({ containerClass: 'vwfsize-sm', checked: false }, 'Small')
// Default (no size class needed)
Checkbox({ checked: false }, 'Default size')
// Large
Checkbox({ containerClass: 'vwfsize-lg', checked: false }, 'Large')
// Extra Large
Checkbox({ containerClass: 'vwfsize-xl', checked: false }, 'Extra Large')🎨 Color Customization
Control colors via containerClass with vwfcolor-* utilities.
Checkbox({ containerClass: 'vwfcolor-success', checked: true }, 'Success')
Checkbox({ containerClass: 'vwfcolor-warning', checked: true }, 'Warning')
Checkbox({ containerClass: 'vwfcolor-error', checked: true }, 'Error')
Checkbox({ containerClass: 'vwfcolor-earth', checked: true }, 'Earth')⭕ Circular Checkbox
Create circular checkboxes by adding rounded-full to the class prop.
// Simple circular
Checkbox({
class: 'rounded-full',
checked: true
}, 'Circular checkbox')
// Large circular with custom label
Checkbox({
containerClass: 'vwfsize-xl',
class: 'rounded-full',
labelClass: 'font-semibold',
checked: false
}, 'Large circular checkbox')⭐ Custom Icon Checkbox
Hide the default SVG checkmark and use Oracle JET icons, emoji, or any other svg as checkbox indicators.
// Star icon checkbox
Checkbox({
class: 'oj-ux-ico-star-s vwfcolor-warning bg-peach border-none text-transparent bg-clip-text',
svgClass: 'hidden', // Hide default checkmark
labelClass: 'text-warning',
containerClass: 'text-xl leading-none',
checked: true
}, 'Star checkbox')
// Heart icon checkbox
Checkbox({
class: 'oj-ux-ico-heart-s text-transparent bg-clip-text',
svgClass: 'hidden',
checked: false
}, 'Heart checkbox')🚫 Disabled State
Checkbox automatically styles disabled state with opacity reduction.
Checkbox({
label: 'Disabled unchecked',
checked: false,
disabled: true
})
Checkbox({
label: 'Disabled checked',
checked: true,
disabled: true
})🏗️ Grid Overlay Pattern
Checkbox uses a grid layout to overlay the custom SVG checkmark on top of the native input. Both elements occupy the same grid cell.
Container- flex items-center gap-3Wrapper- grid grid-cols-1Input- col-start-1 row-start-1SVG- col-start-1 row-start-1 pointer-events-none- No absolute positioning needed - SVG scales automatically
- Checkmark always perfectly centered
- Maintains accessibility - native input receives events
⚡️ Best Practices
- Provide clear, concise labels - use short, descriptive text
- Use
requiredprop for mandatory fields - Use
containerClassfor size/color control (vwfsize-*, vwfcolor-*) - Group related checkboxes with fieldset and legend
- Always provide an
onchangehandler to update state - Don't rely only on color for meaning - use labels or icons
- Don't apply vwfsize-* to
classprop - use containerClass instead
✨ Key Features
Checkbox component capabilities and design patterns.
Grid overlay pattern- Custom SVG checkmark without absolute positioningCSS variable sizing- Scales proportionally using --vwf-size variableAnimated checkmark- SVG path with opacity transitionCircular variant- Add rounded-full to class propCustom icon support- Hide SVG and use Oracle JET icons or emojiDisabled state styling- Automatic opacity reductionRequired indicator- Red asterisk on label when required={true}Auto-generated IDs- Ensures proper label-checkbox associationFull Tailwind override- Complete customization via filterClassName
Explore More Components
Browse other component categories