Il toggle è un campo <input> di tipo checkbox con una levetta che modifica lo stato del campo. Per ottenere questo effetto, viene resettato lo stile predefinito del checkbox e viene aggiunto uno <span> con classe .lever. Il contenitore del toggle deve avere le classi .form-check e .form-check-inline.
<div><divclass="row"><fieldsetclass="col-12 col-md-6"><legend>Gruppo di toggle</legend><divclass="form-check form-check-group"><divclass="toggles"><labelfor="toggleEsempio3a">
Toggle acceso
<inputtype="checkbox"id="toggleEsempio3a"checked><spanclass="lever"></span></label></div></div><divclass="form-check form-check-group"><divclass="toggles"><labelfor="toggleEsempio3b">
Toggle spento
<inputtype="checkbox"id="toggleEsempio3b"><spanclass="lever"></span></label></div></div><divclass="form-check form-check-group"><divclass="toggles"><labelfor="toggleEsempio3c">
Toggle disabilitato
<inputtype="checkbox"id="toggleEsempio3c"disabled><spanclass="lever"></span></label></div></div></fieldset><fieldsetclass="col-12 col-md-6"><legend>Gruppo di toggle</legend><divclass="form-check form-check-group"><divclass="toggles"><labelfor="toggleEsempio3d">
Toggle acceso
<inputtype="checkbox"id="toggleEsempio3d"aria-describedby="toggle3d-help"checked><spanclass="lever"></span></label></div><smallid="toggle3d-help"class="form-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas molestie libero</small></div><divclass="form-check form-check-group"><divclass="toggles"><labelfor="toggleEsempio3e">
Toggle spento
<inputtype="checkbox"id="toggleEsempio3e"aria-describedby="toggle3e-help"><spanclass="lever"></span></label></div><smallid="toggle3e-help"class="form-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas molestie libero</small></div><divclass="form-check form-check-group"><divclass="toggles"><labelfor="toggleEsempio3f">
Toggle disabilitato
<inputtype="checkbox"id="toggleEsempio3f"aria-describedby="toggle3f-help"disabled><spanclass="lever"></span></label></div><smallid="toggle3f-help"class="form-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas molestie libero</small></div></fieldset></div></div>
Properties
Il selettore da utilizzare per le sovrascrittura delle property è .toggles.
La descrizione delle custom properties è in inglese perché risiede nei files .scss dei componenti.
Properties statiche
Variabile CSS
Descrizione (Inglese)
Predefinito
--bsi-toggle-track-width
Controls the width of the toggle track.
56px
--bsi-toggle-track-height
Controls the height of the toggle track.
32px
--bsi-toggle-track-border-radius
Controls the border radius of the track, using radius tokens.
var(--bsi-radius-rounded)
--bsi-toggle-track-background
Controls the default background of the track, using color tokens.
var(--bsi-color-background-secondary-light)
--bsi-toggle-track-transition
Controls the transition for the track background.
background 0.3s ease
--bsi-toggle-knob-size
Controls the width and height of the knob.
24px
--bsi-toggle-knob-offset
Controls the top and left offset of the knob inside the track.
4px
--bsi-toggle-knob-border-radius
Controls the border radius of the knob.
50%
--bsi-toggle-knob-background
Controls the background color of the knob, using color tokens.
var(--bsi-color-background-inverse)
--bsi-toggle-knob-shadow-color
Controls the shadow/aura color behind the knob.
#{color.adjust($primary, $alpha: -0.85)}
--bsi-toggle-knob-offset-checked
Controls the left offset of the knob when checked.
28px
--bsi-toggle-knob-transition
Controls the transition for the knob.
left 0.3s ease, background 0.1s ease, transform 0.1s ease
--bsi-toggle-label-spacing
Controls the right margin of the label, using spacing tokens.
var(--bsi-spacing-xs)
Breaking change
Il “raggruppamento” di campi di input deve prevedere l’elemento nativo <fieldset>.