@roadtrip/css
Version:
CSS framework for Roadtrip Design System
192 lines (156 loc) • 3.82 kB
CSS
/*
* Switch
*
* For accessibility, we provide a style for focus only on Tab,
* for that add the javascript polyfill for focus-visible
* (https://github.com/WICG/focus-visible).
*
* Index
* - Switch
* - Switch label
* - Switch lever
* - Switch feedback
* - Switch position
*
*/
/* SWITCH
-------------------- */
.form-switch {
position: relative;
display: block;
margin-bottom: 1rem;
font-family: var(--road-font);
font-size: 1rem;
color: var(--road-grey-900);
}
/**
* Hide input
*/
.form-switch-input {
position: absolute;
z-index: -1;
opacity: 0;
}
/* SWITCH LABEL
-------------------- */
.form-switch-label {
display: inline-flex;
align-items: center;
cursor: pointer;
}
/* SWITCH LEVER
-------------------- */
.form-switch-lever {
position: relative;
box-sizing: border-box;
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: flex-end;
width: 4.5rem;
height: 2rem;
padding: 0.5rem 0.625rem;
margin-right: 0.75rem;
font-size: 0.625rem;
font-weight: 700;
line-height: 1.6;
content: "";
background: var(--road-grey-300);
border: 0.125rem solid transparent;
border-radius: 1.125rem;
transition: background 0.2s ease-in-out;
}
/**
* Text in the switch widget
*/
.form-switch-lever::before {
font-size: 0.625rem;
font-weight: 700;
color: var(--road-grey-000);
text-transform: uppercase;
content: attr(data-off);
}
/**
* Round lever in the widget
*/
.form-switch-lever::after {
position: absolute;
top: 0.0625rem;
left: 0.0625rem;
display: block;
width: 1.625rem;
height: 1.625rem;
content: "";
background: var(--road-grey-000);
border-radius: 50%;
box-shadow: 0 0.125rem 0.125rem rgba(0, 0, 0, 0.1);
transition: transform 0.2s ease-in-out;
}
/**
* Checked state
*/
.form-switch-input:checked ~ .form-switch-label .form-switch-lever {
justify-content: flex-start;
background: var(--road-primary-500);
}
.form-switch-input:checked ~ .form-switch-label .form-switch-lever::before {
color: var(--road-primary-contrast);
content: attr(data-on);
}
.form-switch-input:checked ~ .form-switch-label .form-switch-lever::after {
transform: translateX(2.5rem);
}
/**
* Focus on Tab
*/
.form-switch-input.focus-visible ~ .form-switch-label .form-switch-lever {
box-shadow: 0 0 0 0.125rem var(--road-grey-000), 0 0 0 0.1875rem var(--road-primary-700);
}
/* SWITCH FEEDBACK
-------------------- */
/**
* Information
*/
.form-switch-info .form-switch-input:checked ~ .form-switch-label .form-switch-lever {
background: var(--road-info-default);
}
.form-switch-info .form-switch-input:checked ~ .form-switch-label .form-switch-lever::before {
color: var(--road-info-contrast);
}
/**
* Success
*/
.form-switch-success .form-switch-input:checked ~ .form-switch-label .form-switch-lever {
background: var(--road-success-default);
}
.form-switch-success .form-switch-input:checked ~ .form-switch-label .form-switch-lever::before {
color: --road-success-contrast;
}
/**
* Warning
*/
.form-switch-warning .form-switch-input:checked ~ .form-switch-label .form-switch-lever {
background: var(--road-warning-default);
}
.form-switch-warning .form-switch-input:checked ~ .form-switch-label .form-switch-lever::before {
color: var(--road-warning-contrast);
}
/**
* Danger
*/
.form-switch-danger .form-switch-input:checked ~ .form-switch-label .form-switch-lever {
background: var(--road-danger-default);
}
.form-switch-danger .form-switch-input:checked ~ .form-switch-label .form-switch-lever::before {
color: var(--road-danger-contrast);
}
/* SWITCH POSITION
-------------------- */
.form-switch-right .form-switch-lever {
margin-right: 0;
margin-left: 0.75rem;
}
.form-switch-spaced {
display: flex;
justify-content: space-between;
}