Components / Forms
Toggle
Displays a two-state button that can be pressed or unpressed.
<button type="button" class="toggle" aria-pressed="false">Bold</button>Installation
pnpm dlx loseta add togglenpx loseta add toggleExamples
Outline
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem">
<button type="button" class="toggle" data-variant="outline" aria-pressed="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" x2="10" y1="4" y2="4"/><line x1="14" x2="5" y1="20" y2="20"/><line x1="15" x2="9" y1="4" y2="20"/></svg>Italic</button>
<button type="button" class="toggle" data-variant="outline" aria-pressed="false"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"/></svg>Bold</button>
<button type="button" class="toggle" data-variant="outline" aria-pressed="false"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" x2="20" y1="20" y2="20"/></svg>Underline</button>
</div>With text
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem">
<button type="button" class="toggle" aria-pressed="false"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z"/></svg>Bookmark</button>
<button type="button" class="toggle" data-variant="outline" data-size="sm" aria-pressed="true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z"/></svg>Saved</button>
</div>Icon only
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem">
<button type="button" class="toggle" data-size="sm" aria-pressed="false" aria-label="Toggle bold"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"/></svg></button>
<button type="button" class="toggle" aria-pressed="true" aria-label="Toggle italic"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" x2="10" y1="4" y2="4"/><line x1="14" x2="5" y1="20" y2="20"/><line x1="15" x2="9" y1="4" y2="20"/></svg></button>
<button type="button" class="toggle" data-variant="outline" data-size="lg" aria-pressed="false" aria-label="Toggle underline"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" x2="20" y1="20" y2="20"/></svg></button>
</div>Sizes
<div style="display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem">
<button type="button" class="toggle" data-variant="outline" data-size="sm" aria-pressed="false">Small</button>
<button type="button" class="toggle" data-variant="outline" aria-pressed="false">Default</button>
<button type="button" class="toggle" data-variant="outline" data-size="lg" aria-pressed="false">Large</button>
</div>Disabled
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem">
<button type="button" class="toggle" aria-pressed="false" disabled>Disabled</button>
<button type="button" class="toggle" data-variant="outline" aria-pressed="true" disabled>Disabled</button>
</div>Right-to-left
<div dir="rtl" lang="ar" style="display: flex; flex-wrap: wrap; gap: 0.5rem">
<button type="button" class="toggle" data-variant="outline" data-size="sm" aria-pressed="false"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z"/></svg>إشارة مرجعية</button>
</div>Accessibility and behavior
- Use a button with aria-pressed="true|false". CSS styles aria-pressed, not a data-state alias. data-variant="outline" and data-size="sm|lg" are optional. Pair an icon with visible text; icon-only toggles need an aria-label and a decorative SVG with aria-hidden="true".
Files
components/toggle.cssbasestyles/nova/toggle.cssstyleInstall contract
The CLI writes the base file under components/, the visual file for the selected style under styles/<name>/, and any primitive dependency underprimitives/. The generated index.css imports them in the right layer order.