form--checkbox-toggle.pcss.css

Same filename and directory in other branches
  1. 11.x core/themes/default_admin/css/components/form--checkbox-toggle.pcss.css
/*
 * @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(-16px);
      border-radius: 21px;
      background-color: #fff;

      &:dir(rtl) {
        transform: translateX(16px);
      }

      .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(16px);
        background-color: #fff;

        &:dir(rtl) {
          transform: translateX(-16px);
        }

        .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(16px);
          mask-image: var(--admin-icon-checked);
          mask-position: 2px 2px;

          &:dir(rtl) {
            transform: translateX(-16px);
          }
        }
      }
    }

    /* 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(-16px);
        background-color: Canvas;
        mask-image: var(--admin-icon-toggle-unchecked);
        mask-size: 16px 16px;
        mask-position: 17px 2px;
        mask-repeat: no-repeat;

        &:dir(rtl) {
          transform: translateX(16px);
        }

        @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.pcss.css

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

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