Skip to main content

Form Controls

Toggle

Switch-style checkbox with role="switch" and animated thumb.

Element
<input>
Module
@basenative/components
Function
renderToggle

Quick start

Import the render function and call it from your server template.

import { renderToggle } from '@basenative/components';

renderToggle({ name: 'notifications', label: 'Email notifications' });
    

Examples

Each block is a real server render — no mockups, no virtual DOM.

Switch role

role="switch" — same data shape as checkbox, different semantics.

Live render
Source
renderToggle({ name: 'notifications', label: '...', checked: true })

Theme toggle

Mirrors the toggle state into a data attribute on the demo container.

Live render
Source
const dim = signal(false);
effect(() => card.dataset.dim = dim() ? 'on' : 'off');

toggle.onchange = (e) => dim.set(e.target.checked);
        

Options

Arguments accepted by renderToggle().

renderToggle option reference
Option Type Default Description
name string — Form field name.
label string — Adjacent label text.
checked boolean false Initial state.