Toggle buttons. Typically used for things like toggling filters on search results.
@mixin toggleButton()
None.
<label class="toggleButton -outline" tabindex="0">
<input class="toggleButton__input" type="checkbox">
<span class="toggleButton__label">
<div class="toggleButton__checkbox">
<svg class="toggleButton__icon" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none">
<path d="M9 12l2 2l4 -4" />
</svg>
</div>
Checkbox
</span>
</label>
<label class="toggleButton -outline -disabled">
<input disabled class="toggleButton__input" type="checkbox">
<span class="toggleButton__label">
<div class="toggleButton__checkbox">
<svg class="toggleButton__icon" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none">
<path d="M9 12l2 2l4 -4" />
</svg>
</div>
Disabled
</span>
</label>
<label class="toggleButton -outline" tabindex="0">
<input name="example-1" class="toggleButton__input" type="radio">
<span class="toggleButton__label">
<div class="toggleButton__checkbox -radio">
<svg class="toggleButton__icon" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none">
<circle cx="12" cy="12" r="2" fill="currentColor" />
</svg>
</div>
Radio
</span>
</label>
<label class="toggleButton -outline" tabindex="0">
<input name="example-1" class="toggleButton__input" type="radio">
<span class="toggleButton__label">
<div class="toggleButton__checkbox -radio">
<svg class="toggleButton__icon" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none">
<circle cx="12" cy="12" r="2" fill="currentColor" />
</svg>
</div>
Radio
</span>
</label>
<label class="toggleButton -outline -disabled">
<input disabled class="toggleButton__input" type="radio">
<span class="toggleButton__label">
<div class="toggleButton__checkbox -radio">
<svg class="toggleButton__icon" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none">
<circle cx="12" cy="12" r="2" fill="currentColor" />
</svg>
</div>
Disabled
</span>
</label>
<label class="toggleButton -outline -primary" tabindex="0">
<input class="toggleButton__input" type="checkbox" checked="checked">
<span class="toggleButton__label">
<div class="toggleButton__checkbox">
<svg class="toggleButton__icon" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none">
<path d="M9 12l2 2l4 -4" />
</svg>
</div>
Primary
</span>
</label>
<label class="toggleButton -outline -secondary" tabindex="0">
<input class="toggleButton__input" type="checkbox">
<span class="toggleButton__label">
<div class="toggleButton__checkbox">
<svg class="toggleButton__icon" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none">
<path d="M9 12l2 2l4 -4" />
</svg>
</div>
Secondary
</span>
</label>
///
/// A toggle button mixin.
///
/// $checked-color
/// button color when checked
/// $unchecked-color
/// button color when unchecked
/// $disabled-color
/// button color when disabled
///
@mixin toggleButton(
$color: $gray-500,
$text-color: $white,
$hover-color: $link-hover,
$checked-color: $gray-600,
$disabled-color: $disabled,
) {
$b: &;
display: inline-block;
&__input {
display: none;
}
&__label {
display: block;
user-select: none;
padding: $thin-padding;
}
&__checkbox {
border-radius: .25em;
border: 2px solid;
display: inline-block;
height: 1.5em;
margin-right: .382em;
transform: translateY(-.125em);
vertical-align: middle;
width: 1.5em;
&.-radio {
border-radius: 1.5em;
}
}
&__icon {
width: 100%;
display: none;
}
&:focus {
.toggleButton__checkbox {
box-shadow: 0 0 0 2px red;
}
}
@include color-modifiers(primary secondary) using ($color) {
#{$b}__checkbox {
border-color: $color;
}
#{$b}.-checked #{$b}__label,
#{$b}__input:checked ~ #{$b}__label {
#{$b}__checkbox {
border-color: $black;
background-color: $color;
color: blackwhite($color);
}
}
}
&.-checked &__label,
&__input:checked ~ &__label {
#{$b}__icon {
display: block;
}
}
&.-blank {
border: 2px solid $color;
#{$b}.-checked #{$b}__label,
#{$b}__input:checked ~ #{$b}__label {
background-color: $color;
color: blackwhite($color);
}
@include color-modifiers(primary secondary) using ($color) {
border-color: $color;
#{$b}.-checked #{$b}__label,
#{$b}__input:checked ~ #{$b}__label {
background-color: $color;
color: blackwhite($color);
#{$b}__checkbox {
border-color: blackwhite($color);
}
}
}
}
&.-disabled {
border-color: $disabled-color;
color: $disabled-color;
cursor: default;
}
&.-outline {
border: 2px solid $color;
#{$b}.-checked #{$b}__label,
#{$b}__input:checked ~ #{$b}__label {
background-color: $color;
color: blackwhite($color);
}
@include color-modifiers(primary secondary) using ($color) {
border-color: $color;
#{$b}__checkbox {
border-color: $color;
}
#{$b}.-checked #{$b}__label,
#{$b}__input:checked ~ #{$b}__label {
background-color: $color;
color: blackwhite($color);
#{$b}__checkbox {
border-color: blackwhite($color);
}
}
}
}
&.-disabled {
border-color: $disabled-color;
color: $disabled-color;
cursor: default;
}
}
.toggleButton {
@include toggleButton;
}