form--checkbox-toggle.css

Same filename and directory in other branches
  1. 11.x core/themes/default_admin/css/components/form--checkbox-toggle.css
/*
 * DO NOT EDIT THIS FILE.
 * See the following change record for more information,
 * https://www.drupal.org/node/3084859
 * @preserve
 */

/*
 * @file
 * Single checkbox: show as toggle.
 *
 * @todo Background color should use relative color notation, with lightness
 * hard coded while in dark mode.
 */

:not(.form-checkboxes, td, .tabledrag-cell-content__item, .media-library-item__click-to-select-checkbox, .field-content, .ajax-new-content, .tablesaw-cell-content) > .form-type--checkbox {
  position: relative;
  margin-inline-start: 0;

  input {
    all: unset;
    appearance: none;
    position: relative;
    display: inline-block;
    overflow: hidden;
    box-sizing: border-box;
    width: 2.5rem;
    height: 1.5rem;
    cursor: pointer;
    vertical-align: top;
    border: 3px solid transparent;
    border-radius: var(--admin-radius-l);
    background-color: var(--admin-color-text-disabled);
    clip-path: circle(var(--admin-space-l) at 50% 50%); /* Fix Safari bug */

    .dark-mode & {
      background-color: var(--admin-color-bg-input);
    }

    &::before {
      position: absolute;
      width: 100%;
      height: 100%;
      content: "";
      transform: translateX(-1rem);
      border-radius: 1.3125rem;
      background-color: #fff;

      &:dir(rtl) {
        transform: translateX(1rem);
      }

      .dark-mode & {
        background-color: var(--admin-color-border-input);
      }

      @media (prefers-reduced-motion: no-preference) {
        transition: transform 0.3s;
      }

      @media (forced-colors: active) {
        background-color: CanvasText;
      }
    }

    /* Disabled state: set cursor to not-allowed */
    &:disabled {
      cursor: not-allowed;
    }

    /* Hover state */
    &:hover {
      opacity: 0.9;
      box-shadow: 0 0 2px rgb(0, 0, 0, 0.2);
    }

    /* Active/Focus state */
    &:active,
    &:focus {
      outline: var(--focus-outline);
      outline-offset: var(--outline-offset);
    }

    /* Active state */
    &:checked {
      background-color: var(--admin-color-switch);

      /* @todo refactor out this specificity. Win over form--checkbox-radio.css. */
      &[class] {
        background-image: none;
      }

      &::before {
        transform: translateX(1rem);
        background-color: #fff;

        &:dir(rtl) {
          transform: translateX(-1rem);
        }

        .dark-mode & {
          background-color: var(--admin-color-primary-hover);
        }

        .high-contrast-mode & {
          background-color: var(--admin-color-border);
        }

        @media (forced-colors: active) {
          padding-inline-start: var(--admin-space-xs);
          background-color: LinkText !important;
        }
      }

      @media (forced-colors: active) {
        &::after {
          transform: translateX(1rem);
          mask-image: var(--admin-icon-checked);
          mask-position: 2px 2px;

          &:dir(rtl) {
            transform: translateX(-1rem);
          }
        }
      }
    }

    /* Disabled state */
    &:disabled {
      opacity: 0.75;
      background-color: var(--admin-color-text-disabled);
      box-shadow: none;

      &::before {
        opacity: 0.6;
        background-color: #fff;
      }

      ~ label {
        color: var(--input--disabled-fg-color);
      }
    }

    @media (forced-colors: active) {
      border-width: 2px;
    }

    @media (forced-colors: active) {
      &::after {
        position: absolute;
        width: 100%;
        height: 100%;
        content: "";
        transform: translateX(-1rem);
        background-color: Canvas;
        mask-image: var(--admin-icon-toggle-unchecked);
        mask-size: 1rem 1rem;
        mask-position: 1.0625rem 2px;
        mask-repeat: no-repeat;

        &:dir(rtl) {
          transform: translateX(1rem);
        }

        @media (prefers-reduced-motion: no-preference) {
          transition: transform 0.3s;
        }
      }
    }
  }

  label {
    position: relative;
    z-index: 1;
    padding-block-end: 0;
    padding-inline-start: var(--admin-space-2xs);
    color: var(--admin-color-text);
  }
}

File

core/themes/default_admin/css/components/form--checkbox-toggle.css

View source
  1. /*
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/3084859
  5. * @preserve
  6. */
  7. /*
  8. * @file
  9. * Single checkbox: show as toggle.
  10. *
  11. * @todo Background color should use relative color notation, with lightness
  12. * hard coded while in dark mode.
  13. */
  14. :not(.form-checkboxes, td, .tabledrag-cell-content__item, .media-library-item__click-to-select-checkbox, .field-content, .ajax-new-content, .tablesaw-cell-content) > .form-type--checkbox {
  15. position: relative;
  16. margin-inline-start: 0;
  17. input {
  18. all: unset;
  19. appearance: none;
  20. position: relative;
  21. display: inline-block;
  22. overflow: hidden;
  23. box-sizing: border-box;
  24. width: 2.5rem;
  25. height: 1.5rem;
  26. cursor: pointer;
  27. vertical-align: top;
  28. border: 3px solid transparent;
  29. border-radius: var(--admin-radius-l);
  30. background-color: var(--admin-color-text-disabled);
  31. clip-path: circle(var(--admin-space-l) at 50% 50%); /* Fix Safari bug */
  32. .dark-mode
  33. &::before {
  34. position: absolute;
  35. width: 100%;
  36. height: 100%;
  37. content: "";
  38. transform: translateX(-1rem);
  39. border-radius: 1.3125rem;
  40. background-color: #fff;
  41. &:dir(rtl) {
  42. transform: translateX(1rem);
  43. }
  44. .dark-mode
  45. @media (prefers-reduced-motion: no-preference) {
  46. transition: transform 0.3s;
  47. }
  48. @media (forced-colors: active) {
  49. background-color: CanvasText;
  50. }
  51. }
  52. /* Disabled state: set cursor to not-allowed */
  53. &:disabled {
  54. cursor: not-allowed;
  55. }
  56. /* Hover state */
  57. &:hover {
  58. opacity: 0.9;
  59. box-shadow: 0 0 2px rgb(0, 0, 0, 0.2);
  60. }
  61. /* Active/Focus state */
  62. &:active,
  63. &:focus {
  64. outline: var(--focus-outline);
  65. outline-offset: var(--outline-offset);
  66. }
  67. /* Active state */
  68. &:checked {
  69. background-color: var(--admin-color-switch);
  70. /* @todo refactor out this specificity. Win over form--checkbox-radio.css. */
  71. &[class] {
  72. background-image: none;
  73. }
  74. &::before {
  75. transform: translateX(1rem);
  76. background-color: #fff;
  77. &:dir(rtl) {
  78. transform: translateX(-1rem);
  79. }
  80. .dark-mode
  81. .high-contrast-mode
  82. @media (forced-colors: active) {
  83. padding-inline-start: var(--admin-space-xs);
  84. background-color: LinkText !important;
  85. }
  86. }
  87. @media (forced-colors: active) {
  88. &::after {
  89. transform: translateX(1rem);
  90. mask-image: var(--admin-icon-checked);
  91. mask-position: 2px 2px;
  92. &:dir(rtl) {
  93. transform: translateX(-1rem);
  94. }
  95. }
  96. }
  97. }
  98. /* Disabled state */
  99. &:disabled {
  100. opacity: 0.75;
  101. background-color: var(--admin-color-text-disabled);
  102. box-shadow: none;
  103. &::before {
  104. opacity: 0.6;
  105. background-color: #fff;
  106. }
  107. ~ label {
  108. color: var(--input--disabled-fg-color);
  109. }
  110. }
  111. @media (forced-colors: active) {
  112. border-width: 2px;
  113. }
  114. @media (forced-colors: active) {
  115. &::after {
  116. position: absolute;
  117. width: 100%;
  118. height: 100%;
  119. content: "";
  120. transform: translateX(-1rem);
  121. background-color: Canvas;
  122. mask-image: var(--admin-icon-toggle-unchecked);
  123. mask-size: 1rem 1rem;
  124. mask-position: 1.0625rem 2px;
  125. mask-repeat: no-repeat;
  126. &:dir(rtl) {
  127. transform: translateX(1rem);
  128. }
  129. @media (prefers-reduced-motion: no-preference) {
  130. transition: transform 0.3s;
  131. }
  132. }
  133. }
  134. }
  135. label {
  136. position: relative;
  137. z-index: 1;
  138. padding-block-end: 0;
  139. padding-inline-start: var(--admin-space-2xs);
  140. color: var(--admin-color-text);
  141. }
  142. }

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.