Switch
Switch component allows to use forms input checkbox styled like a switch element.
Quick demo
Preview of the switch component.
Go on interactive demo for look this component in action!
Usage
Styles
sass
@use "~@iraiser/biscuit-design-components/components/switch/styles";
JavaScript
javascript
import { BDCSwitch } from '@iraiser/biscuit-design-components/components/switch';
let switch = new BDCSwitch(document.querySelector('.bdc-switch'));
HTML structure
html
<div class="bdc-switch">
<input class="bdc-switch__input" type="checkbox">
<div class="bdc-switch__control">
<span class="bdc-switch__thumb"></span>
</div>
</div>
Theming
See the "Theming" section on theme documentation for more customization options.
Theming with CSS custom properties
Set custom styles on specific element in component:
sass
@use "~@iraiser/biscuit-design-components/components/switch";
.foo-switch {
--bdc-theme-primary: #0971b3;
}
Theming with Sass mixins
Set custom styles on specific element in component:
sass
@use "~@iraiser/biscuit-design-components/components/switch";
.foo-switch {
@include switch.toggled-on-track-color(#0971b3);
}
See Sass mixins section for more options.
Style customization
CSS classes
CSS Class | Description |
---|---|
bdc-switch | Mandatory. |
bdc-switch--checked | Style switch at checked status. |
bdc-switch--required | Style switch at required status. |
bdc-switch--disabled | Style switch at disabled status. |
bdc-switch__input | Indicates the native input container. |
bdc-switch__control | Indicates the control container. |
bdc-switch__thumb | Indicates the thumb container. |
Sass mixins
Custom your own switch easily with the public Sass mixins.
Mixin | Description |
---|---|
toggled-off-track-color($color) | Set the track fill color when toggle is off. |
toggled-on-track-color($color) | Set the track fill color when toggle is on. |
toggled-off-thumb-color($color) | Set the thumb color when toggle is off. |
toggled-on-thumb-color($color) | Set the thumb color when toggle is on. |
JavaScript API
Getters & Setters
Public accessors from BDCSwitch
class.
Accessor | Type | Description |
---|---|---|
value | string | Method for get & set the value. |
checked | boolean | Method for get & set the checked status. |
valid | boolean | Method for get & set the valid status. |
required | boolean | Method for get & set the required status. |
disabled | boolean | Method for get & set the disabled status. |