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 */

    .gin--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);
      }

      .gin--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);
    }

    /* Hover/Focus state */
    &:active,
    &:focus {
      box-shadow:
        0 0 0 1px var(--admin-color-focus-border),
        0 0 0 4px var(--admin-color-focus);
    }

    /* 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);
        }

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

        .gin--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;
      }
    }

    @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. .gin--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. .gin--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. /* Hover/Focus state */
  62. &:active,
  63. &:focus {
  64. box-shadow:
  65. 0 0 0 1px var(--admin-color-focus-border),
  66. 0 0 0 4px var(--admin-color-focus);
  67. }
  68. /* Active state */
  69. &:checked {
  70. background-color: var(--admin-color-switch);
  71. /* @todo refactor out this specificity. Win over form--checkbox-radio.css. */
  72. &[class] {
  73. background-image: none;
  74. }
  75. &::before {
  76. transform: translateX(1rem);
  77. background-color: #fff;
  78. &:dir(rtl) {
  79. transform: translateX(-1rem);
  80. }
  81. .gin--dark-mode
  82. .gin--high-contrast-mode
  83. @media (forced-colors: active) {
  84. padding-inline-start: var(--admin-space-xs);
  85. background-color: LinkText !important;
  86. }
  87. }
  88. @media (forced-colors: active) {
  89. &::after {
  90. transform: translateX(1rem);
  91. mask-image: var(--admin-icon-checked);
  92. mask-position: 2px 2px;
  93. &:dir(rtl) {
  94. transform: translateX(-1rem);
  95. }
  96. }
  97. }
  98. }
  99. /* Disabled state */
  100. &:disabled {
  101. opacity: 0.75;
  102. background-color: var(--admin-color-text-disabled);
  103. box-shadow: none;
  104. &::before {
  105. opacity: 0.6;
  106. background-color: #fff;
  107. }
  108. }
  109. @media (forced-colors: active) {
  110. border-width: 2px;
  111. }
  112. @media (forced-colors: active) {
  113. &::after {
  114. position: absolute;
  115. width: 100%;
  116. height: 100%;
  117. content: "";
  118. transform: translateX(-1rem);
  119. background-color: Canvas;
  120. mask-image: var(--admin-icon-toggle-unchecked);
  121. mask-size: 1rem 1rem;
  122. mask-position: 1.0625rem 2px;
  123. mask-repeat: no-repeat;
  124. &:dir(rtl) {
  125. transform: translateX(1rem);
  126. }
  127. @media (prefers-reduced-motion: no-preference) {
  128. transition: transform 0.3s;
  129. }
  130. }
  131. }
  132. }
  133. label {
  134. position: relative;
  135. z-index: 1;
  136. padding-block-end: 0;
  137. padding-inline-start: var(--admin-space-2xs);
  138. color: var(--admin-color-text);
  139. }
  140. }

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