Toggle
A two-state button that can be either on or off.
---import { BookmarkIcon } from '@lucide/astro';
import { Toggle } from '@bejamas/ui/components/toggle';---
<Toggle aria-label="Toggle bookmark" size="sm" variant="outline"> <BookmarkIcon /> Bookmark</Toggle>Installation
Section titled “Installation”bunx bejamas add togglenpx bejamas add togglepnpm dlx bejamas add toggleyarn dlx bejamas add toggle---import { Toggle } from '@bejamas/ui/components/toggle';import { BoldIcon } from '@lucide/astro';---
<Toggle aria-label="Toggle bold"> <BoldIcon /></Toggle>Examples
Section titled “Examples”Outline
Section titled “Outline”---import { BoldIcon, ItalicIcon } from '@lucide/astro';
import { Toggle } from '@bejamas/ui/components/toggle';---
<div class="flex items-center gap-2"> <Toggle variant="outline" aria-label="Toggle bold"> <BoldIcon /> Bold </Toggle> <Toggle variant="outline" aria-label="Toggle italic"> <ItalicIcon /> Italic </Toggle></div>With Text
Section titled “With Text”---import { ItalicIcon } from '@lucide/astro';
import { Toggle } from '@bejamas/ui/components/toggle';---
<Toggle variant="outline" aria-label="Toggle italic"> <ItalicIcon /> Italic</Toggle>---import { Toggle } from '@bejamas/ui/components/toggle';---
<div class="flex items-center gap-2"> <Toggle size="sm" variant="outline" aria-label="Toggle small"> Small </Toggle> <Toggle size="default" variant="outline" aria-label="Toggle default"> Default </Toggle> <Toggle size="lg" variant="outline" aria-label="Toggle large"> Large </Toggle></div>Disabled
Section titled “Disabled”---import { Toggle } from '@bejamas/ui/components/toggle';---
<div class="flex items-center gap-2"> <Toggle disabled aria-label="Toggle bold"> Disabled </Toggle> <Toggle disabled variant="outline" aria-label="Toggle italic"> Disabled </Toggle></div>API Reference
Section titled “API Reference”Events
Section titled “Events”| Event | Detail | Description |
|---|---|---|
toggle:change | { pressed: boolean } | Fired when the toggle state changes |
Programmatic Control
Section titled “Programmatic Control”// Set toggle state programmaticallyelement.dispatchEvent(new CustomEvent('toggle:set', { detail: { value: true } }));Data Attributes
Section titled “Data Attributes”| Attribute | Element | Description |
|---|---|---|
data-state | toggle | Current state: on or off |
data-disabled | toggle | Present when toggle is disabled |