| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- // Switches
- // *******************************************************************************
-
- .switch {
- --#{$prefix}switch-bg: #{$switch-off-bg};
- --#{$prefix}switch-color: #{$switch-off-color};
- --#{$prefix}switch-border-color: #{$switch-off-border};
- --#{$prefix}switch-box-shadow: #{$form-switch-box-shadow};
- --#{$prefix}switch-holder-bg: #{$switch-holder-bg};
- --#{$prefix}switch-holder-shadow: #{$switch-holder-shadow};
-
- /* Checked state */
- .switch-input:checked ~ .switch-toggle-slider {
- --#{$prefix}switch-bg: var(--#{$prefix}primary);
- --#{$prefix}switch-color: var(--#{$prefix}white);
- --#{$prefix}switch-border-color: var(--#{$prefix}primary);
- --#{$prefix}switch-box-shadow: 0 .125rem .375rem 0 rgba(var(--#{$prefix}primary-rgb), .3);
- }
-
- &[class*="switch-outline-"],
- &.switch-outline {
- --#{$prefix}switch-bg: transparent;
- --#{$prefix}switch-box-shadow: none;
- --#{$prefix}switch-holder-bg: #{$switch-off-bg};
- --#{$prefix}switch-holder-shadow: none;
-
- // Checked state
- .switch-input:checked ~ .switch-toggle-slider {
- --#{$prefix}switch-bg: transparent;
- --#{$prefix}switch-box-shadow: none;
- }
- }
- &.switch-outline {
- // Checked state
- .switch-input:checked ~ .switch-toggle-slider {
- --#{$prefix}switch-color: var(--#{$prefix}primary);
- --#{$prefix}switch-border-color: var(--#{$prefix}primary);
- --#{$prefix}switch-holder-bg: var(--#{$prefix}primary);
- }
- }
- position: relative;
- display: inline-block;
- @include border-radius($switch-border-radius);
- cursor: pointer;
- margin-inline-end: $switch-spacer-x;
- vertical-align: middle;
-
- &:has(.switch-input:disabled) {
- cursor: not-allowed;
- }
-
- @include template-switch-size-base(
- "",
- $switch-width,
- $switch-height,
- $switch-font-size,
- $switch-label-font-size,
- $switch-label-line-height,
- $switch-inner-spacer
- );
-
- .switch-input {
- &.is-invalid ~ .switch-label,
- .was-validated &:invalid ~ .switch-label {
- color: var(--#{$prefix}form-invalid-border-color);
- }
- &.is-valid ~ .switch-label,
- .was-validated &:valid ~ .switch-label {
- color: var(--#{$prefix}form-valid-border-color);
- }
- &.is-invalid ~ .switch-toggle-slider,
- .was-validated &:invalid ~ .switch-toggle-slider {
- --#{$prefix}switch-border-color: var(--#{$prefix}form-invalid-border-color);
- }
- &.is-valid ~ .switch-toggle-slider,
- .was-validated &:valid ~ .switch-toggle-slider {
- --#{$prefix}switch-border-color: var(--#{$prefix}form-valid-border-color);
- }
- &.is-invalid:checked ~ .switch-toggle-slider,
- .was-validated &:invalid:checked ~ .switch-toggle-slider {
- --#{$prefix}switch-bg: var(--#{$prefix}form-invalid-color);
- --#{$prefix}switch-box-shadow: none;
- }
- &.is-valid:checked ~ .switch-toggle-slider,
- .was-validated &:valid:checked ~ .switch-toggle-slider {
- --#{$prefix}switch-bg: var(--#{$prefix}form-valid-color);
- --#{$prefix}switch-box-shadow: none;
- }
- }
- }
-
- /* Input
- ******************************************************************************* */
-
- .switch-input {
- position: absolute;
- z-index: -1;
- opacity: 0;
-
- .was-validated &:invalid ~ .valid-feedback,
- .was-validated &:invalid ~ .valid-tooltip,
- &.is-invalid ~ .valid-feedback,
- &.is-invalid ~ .valid-tooltip,
- .was-validated &:valid ~ .valid-feedback,
- .was-validated &:valid ~ .valid-tooltip,
- &.is-valid ~ .valid-feedback,
- &.is-valid ~ .valid-tooltip {
- display: block;
- }
- }
-
- /* Toggle slider
- ******************************************************************************* */
-
- .switch-toggle-slider {
- position: absolute;
- overflow: hidden;
- border: 1px solid var(--#{$prefix}switch-border-color);
- @include border-radius($switch-border-radius);
- background: var(--#{$prefix}switch-bg);
- box-shadow: var(--#{$prefix}switch-box-shadow);
- color: var(--#{$prefix}switch-color);
- font-size: $switch-font-size;
- inset-block-start: 50%;
- transform: translateY(-50%);
- transition-duration: .2s;
- transition-property: inset-inline-start, inset-inline-end, background, box-shadow;
- user-select: none;
- &::after {
- position: absolute;
- display: block;
- @include border-radius(50%);
- background: var(--#{$prefix}switch-holder-bg);
- box-shadow: var(--#{$prefix}switch-holder-shadow);
- content: "";
- inset-block-start: 50%;
- inset-inline: 8% auto;
- transform: translateY(-50%);
- transition-duration: .2s;
- transition-property: inset-inline-start, inset-inline-end, background;
- }
- }
-
- /* Label switch
- ******************************************************************************* */
-
- .switch-label {
- position: relative;
- display: inline-block;
- color: $switch-label-color;
- font-weight: 400;
- &:first-child {
- padding-inline-end: $switch-gutter;
- }
- }
-
- /* Checked / Unchecked states */
- .switch-off,
- .switch-on {
- position: absolute;
- block-size: 100%;
- inline-size: 100%;
- inset-block-start: 0;
- text-align: center;
- transition-duration: .2s;
- transition-property: inset-inline-start, inset-inline-end;
- }
-
- .switch-on {
- inset-inline-start: -100%;
-
- .switch-input:not(:checked) ~ .switch-toggle-slider & {
- color: transparent;
- }
- }
-
- .switch-off {
- inset-inline-start: 0;
- }
-
- /* Checked state */
- .switch-input:checked ~ .switch-toggle-slider {
- &::after {
- inset-inline: 95% auto;
- transform: translate(-100%, -50%);
- :dir(rtl) & {
- inset-inline: 94% auto;
- transform: translate(100%, -50%);
- }
- }
- .switch-on {
- inset-inline-start: 0;
- }
-
- .switch-off {
- color: transparent;
- inset-inline-start: 100%;
- }
- }
-
- /* Stacked switches
- ******************************************************************************* */
-
- .switches-stacked {
- @include clearfix ();
-
- .switch {
- display: block;
- margin-inline: 0;
- &:not(:last-child) {
- margin-block-end: $switch-spacer-y;
- }
- }
- }
-
- /* Square
- ******************************************************************************* */
-
- .switch-square,
- .switch-square .switch-toggle-slider {
- @if $enable-rounded {
- @include border-radius($switch-square-border-radius);
- } @else {
- @include border-radius(0);
- }
- }
-
- .switch-square .switch-toggle-slider::after {
- @if $enable-rounded {
- @include border-radius(calc(#{$switch-square-border-radius} - 2px));
- } @else {
- @include border-radius(0);
- }
- }
-
- /* Disabled
- ******************************************************************************* */
-
- .switch-input:disabled {
- ~ .switch-toggle-slider {
- opacity: $switch-disabled-opacity;
- }
-
- ~ .switch-label {
- color: $switch-label-disabled-color;
- }
- }
-
- /* Switch Sizes
- ******************************************************************************* */
-
- @include template-switch-size(
- "sm",
- $switch-width-sm,
- $switch-height-sm,
- $switch-font-size,
- $switch-label-font-size-sm,
- $switch-label-line-height-sm,
- $switch-inner-spacer-sm
- );
- @include template-switch-size(
- "lg",
- $switch-width-lg,
- $switch-height-lg,
- $switch-font-size,
- $switch-label-font-size-lg,
- $switch-label-line-height-lg
- );
-
- /* Validation states
- ******************************************************************************* */
-
- .switch .valid-feedback,
- .switch .invalid-feedback {
- padding-inline-start: $switch-gutter;
- }
-
- /* Generate contextual modifier classes for colorizing the alert */
- @each $state in map-keys($theme-colors) {
- .switch-#{$state} {
- .switch-input:checked ~ .switch-toggle-slider {
- --#{$prefix}switch-bg: var(--#{$prefix}#{$state});
- --#{$prefix}switch-border-color: var(--#{$prefix}#{$state});
- --#{$prefix}switch-box-shadow: 0 .125rem .375rem 0 rgba(var(--#{$prefix}#{$state}-rgb), .3);
- }
- }
- .switch-outline-#{$state} {
- .switch-input:checked ~ .switch-toggle-slider {
- --#{$prefix}switch-color: var(--#{$prefix}#{$state});
- --#{$prefix}switch-border-color: var(--#{$prefix}#{$state});
- --#{$prefix}switch-holder-bg: var(--#{$prefix}#{$state});
- }
- }
- }
|