Menu

Menu

On this page

On this page

Switch

Allow users to toggle between a binary option.

npm install @vrembem/switch
Copied!
SCSS
@use "@vrembem/switch";
Copied!

Options

Switch uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.

VariableFallback
--vb-switch-color
Copied!
--vb-switch-accent
Copied!
--vb-switch-fill
Copied!
--vb-switch-size
Copied!
--vb-switch-border-width
Copied!
2px
Copied!
--vb-switch-border-radius
Copied!

Basic usage

Switch form controls are composed using the <input type="checkbox"> element along with the .switch class.

HTML
<input class="switch" type="checkbox" />
Copied!

Labels

For switch with labels, just wrap the switch element along with label text using the <label> element.


HTML
<label>
  <input class="switch" type="checkbox" />
  <span>Switch with a label</span>
</label>
Copied!

Disabled

Adding the boolean disabled attribute to the input element will provide visual indication that the switch is not available for use.



HTML
<input class="switch" type="checkbox" disabled />
Copied!

Invalid

Adding the is-invalid class or aria-invalid="true" attribute to the switch component will provide visual indication that the form-control value is invalid. Invalid state is also triggered by the native :user-invalid state.

HTML
<input class="switch is-invalid" type="checkbox" />
Copied!