@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
269 lines • 9.62 kB
CSS
/*
* Switch component
*
*/
/*
* Utilities
*/
.eufemia-scope--11_0_0 .dnb-switch {
--switch-width--medium: 2.5rem;
--switch-height--medium: 1.5rem;
--switch-button-size-off--medium: 0.75rem;
--switch-button-size-on--medium: 1.125rem;
--switch-button-size-off--large: 1rem;
--switch-button-size-on--large: 1.625rem;
--switch-width--large: 3.25rem;
--switch-height--large: 2rem;
--switch-border-width--medium: 0.0625rem;
--switch-border-width--large: 0.125rem;
display: inline-flex;
flex-direction: column;
font-size: var(--font-size-small);
line-height: var(--line-height-basis);
}
.eufemia-scope--11_0_0 .dnb-switch__inner {
display: inline-flex;
flex-direction: column;
justify-content: center;
font-size: var(--font-size-basis);
}
.eufemia-scope--11_0_0 .dnb-switch__shell {
position: relative;
display: flex;
align-items: center;
-webkit-user-select: none;
user-select: none;
}
.eufemia-scope--11_0_0 .dnb-switch--large {
line-height: var(--switch-height--large);
}
.eufemia-scope--11_0_0 .dnb-switch--large .dnb-switch__shell {
height: var(--switch-height--large);
}
.eufemia-scope--11_0_0 .dnb-switch__row {
display: inline-flex;
align-items: center;
height: var(--switch-height--medium);
}
.eufemia-scope--11_0_0 .dnb-switch__button {
position: absolute;
z-index: 4;
left: 0;
border-radius: 50%;
width: var(--switch-button-size-off--medium);
height: var(--switch-button-size-off--medium);
background-color: var(--token-color-background-action-alternative);
transition: transform 160ms ease-out 125ms;
}
.eufemia-scope--11_0_0 .dnb-switch--large .dnb-switch__button {
width: var(--switch-button-size-off--large);
height: var(--switch-button-size-off--large);
border-width: var(--switch-border-width--large);
}
.eufemia-scope--11_0_0 .dnb-switch {
/* stylelint-disable no-descending-specificity */
/*
* When switched OFF
* aka when the switch is not :checked
*/
}
.eufemia-scope--11_0_0 .dnb-switch__input:not(:checked) ~ .dnb-switch__button {
transform: translateX(0.375rem);
}
.eufemia-scope--11_0_0 .dnb-switch {
/*
* When switched ON
* aka when the switch is :checked
*/
}
.eufemia-scope--11_0_0 .dnb-switch__input:checked ~ .dnb-switch__button {
width: var(--switch-button-size-on--medium);
height: var(--switch-button-size-on--medium);
background-color: var(--token-color-background-selected-subtle);
transform: translateX(calc(var(--switch-width--medium) - var(--switch-button-size-on--medium) - 0.1875rem));
}
.eufemia-scope--11_0_0 .dnb-switch--large .dnb-switch__input:not(:checked) ~ .dnb-switch__button {
transform: translateX(0.5rem);
}
.eufemia-scope--11_0_0 .dnb-switch--large .dnb-switch__input:checked ~ .dnb-switch__button {
width: var(--switch-button-size-on--large);
height: var(--switch-button-size-on--large);
transform: translateX(calc(var(--switch-width--large) - var(--switch-button-size-on--large) - 0.1875rem));
}
.eufemia-scope--11_0_0 .dnb-switch__background {
position: relative;
display: flex;
flex-direction: row;
align-items: center;
overflow: hidden;
width: var(--switch-width--medium);
height: var(--switch-height--medium);
background-color: var(--token-color-background-neutral);
border: 1px solid var(--token-color-stroke-action-alternative);
border-radius: 1.5rem;
}
.eufemia-scope--11_0_0 .dnb-switch--large .dnb-switch__background {
width: var(--switch-width--large);
height: var(--switch-height--large);
}
.eufemia-scope--11_0_0 .dnb-switch__input:checked ~ .dnb-switch__background {
background-color: var(--token-color-background-selected);
border-color: var(--token-color-background-selected);
}
.eufemia-scope--11_0_0 .dnb-switch__input {
opacity: 0;
position: absolute;
left: 0;
right: 0;
z-index: 5;
display: block;
width: var(--switch-width--medium);
height: var(--switch-height--medium);
}
.eufemia-scope--11_0_0 .dnb-switch--large .dnb-switch__input {
width: var(--switch-width--large);
height: var(--switch-height--large);
}
.eufemia-scope--11_0_0 .dnb-switch__input {
margin: 0;
padding: 0;
border: 0;
}
.eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]) {
cursor: pointer;
}
.eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):focus ~ .dnb-switch__background, .eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):active ~ .dnb-switch__background {
outline: none;
}
html[data-whatinput=keyboard] .eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):focus ~ .dnb-switch__background, html[data-whatinput=keyboard] .eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):active ~ .dnb-switch__background {
--border-color: var(--token-color-stroke-action-focus);
--border-width: var(--focus-ring-width);
box-shadow: 0 0 0 var(--border-width) var(--border-color);
border-color: transparent;
}
.eufemia-scope--11_0_0 .dnb-switch .dnb-form-label {
padding-right: 0.5rem;
margin-right: 0;
margin-left: 0;
margin-bottom: 0;
}
.eufemia-scope--11_0_0 .dnb-switch__order {
display: inline-flex;
}
.eufemia-scope--11_0_0 .dnb-switch__suffix {
order: 4;
}
.eufemia-scope--11_0_0 .dnb-switch--label-position-left .dnb-switch__suffix {
padding-left: 1rem;
}
.eufemia-scope--11_0_0 .dnb-switch--label-position-left .dnb-switch__order .dnb-switch__inner {
order: 2;
}
.eufemia-scope--11_0_0 .dnb-switch--label-position-left .dnb-switch__order .dnb-form-label {
order: 1;
align-self: center;
}
.eufemia-scope--11_0_0 .dnb-switch--label-position-left .dnb-switch__order .dnb-form-status {
order: 3;
margin-top: 0.5rem;
}
.eufemia-scope--11_0_0 .dnb-switch--label-position-right .dnb-switch__order .dnb-switch__inner {
order: 1;
}
.eufemia-scope--11_0_0 .dnb-switch--label-position-right .dnb-switch__order .dnb-form-label {
order: 2;
padding-left: 0.5rem;
}
.eufemia-scope--11_0_0 .dnb-switch--label-position-right .dnb-switch__order .dnb-form-status {
order: 3;
margin-top: 0.5rem;
}
.eufemia-scope--11_0_0 .dnb-switch.dnb-skeleton .dnb-switch__input[disabled] ~ .dnb-switch__background {
background-color: var(--skeleton-color);
border-color: var(--skeleton-color);
}
.eufemia-scope--11_0_0 .dnb-switch {
/*
* On hover state
*
*/
}
.eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):not(:focus):not(:active):hover ~ .dnb-switch__background {
border-color: var(--token-color-stroke-action-hover);
background-color: var(--token-color-background-action-hover-subtle);
}
.eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):not(:focus):not(:active):hover ~ .dnb-switch__button {
background-color: var(--token-color-background-action-hover);
--border-color: var(--token-color-stroke-action-hover);
--border-width: 0.0625rem;
box-shadow: 0 0 0 var(--border-width) var(--border-color);
border-color: transparent;
}
.eufemia-scope--11_0_0 .dnb-switch__input:checked:not([disabled]):not(:focus):not(:active):hover ~ .dnb-switch__button {
box-shadow: none;
}
.eufemia-scope--11_0_0 .dnb-switch {
/*
* On active state
*
*/
}
.eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):active ~ .dnb-switch__background {
border-color: var(--token-color-stroke-action-pressed);
background-color: var(--token-color-background-action-pressed-subtle);
}
.eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):active ~ .dnb-switch__button {
background-color: var(--token-color-background-action-pressed);
}
.eufemia-scope--11_0_0 .dnb-switch {
/*
* On focus state
*
*/
}
html[data-whatinput=keyboard] .eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):focus ~ .dnb-switch__background {
background-color: var(--token-color-background-action-focus-subtle);
}
html[data-whatinput=keyboard] .eufemia-scope--11_0_0 .dnb-switch__input:not([disabled]):focus ~ .dnb-switch__button {
background-color: var(--token-color-background-action-focus);
--border-color: var(--token-color-stroke-action-focus);
--border-width: 0.0625rem;
box-shadow: 0 0 0 var(--border-width) var(--border-color);
border-color: transparent;
}
html[data-whatinput=keyboard] .eufemia-scope--11_0_0 .dnb-switch__input:checked:not([disabled]):focus ~ .dnb-switch__button {
box-shadow: none;
}
.eufemia-scope--11_0_0 .dnb-switch {
/*
* On disabled state
*
*/
}
.eufemia-scope--11_0_0 .dnb-switch:not(.dnb-skeleton) .dnb-switch__input[disabled] ~ .dnb-switch__background {
background-color: var(--token-color-background-neutral);
border-color: var(--token-color-stroke-action-disabled);
}
.eufemia-scope--11_0_0 .dnb-switch:not(.dnb-skeleton) .dnb-switch__input[disabled] ~ .dnb-switch__button {
background-color: var(--token-color-background-action-disabled);
}
.eufemia-scope--11_0_0 .dnb-switch:not(.dnb-skeleton) .dnb-switch__input[disabled]:checked ~ .dnb-switch__background {
background-color: var(--token-color-background-action-disabled);
border-color: var(--token-color-background-action-disabled);
}
.eufemia-scope--11_0_0 .dnb-switch:not(.dnb-skeleton) .dnb-switch__input[disabled]:checked ~ .dnb-switch__button {
background-color: var(--token-color-background-neutral);
}
.eufemia-scope--11_0_0 .dnb-switch {
/*
* On error state
*
*/
}
.eufemia-scope--11_0_0 .dnb-switch__status--error .dnb-switch__input:not([disabled]) ~ .dnb-switch__background {
background-color: var(--token-color-background-error-subtle);
border-color: var(--token-color-stroke-error);
}
.eufemia-scope--11_0_0 .dnb-switch__status--error .dnb-switch__input:not([disabled]) ~ .dnb-switch__button {
background-color: var(--token-color-background-error);
}