Liquid GlassAPI Reference
Liquid GlassAPI Reference
createLiquidSwitch
Toggle switch with spring-animated thumb.
createLiquidSwitch
Creates a glass-styled toggle switch. The switch thumb moves with spring physics for a tactile feel.
Basic Usage
import { createLiquidSwitch } from '@avenra/liquid-glass';
const toggle = createLiquidSwitch('#my-switch', {
checked: true
});
toggle.on('change', ({ checked }) => {
console.log('Switch is now:', checked);
});Props / Options
Extends LiquidGlassOptions plus:
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | false | Initial checked state |
Return Value — LiquidSwitchHandle
| Member | Type | Description |
|---|---|---|
element | Element | The switch container element |
checked | boolean (get/set) | Current checked state |
toggle() | () => this | Toggle state and emit 'change' |
destroy() | () => void | Clean up the component |
on('change', cb) | { checked: boolean, element: Element } | Fired on state change |
on('destroy', cb) | undefined | Fired on destruction |