form--checkbox-toggle.pcss.css

Same filename and directory in other branches
  1. main core/themes/default_admin/css/components/form--checkbox-toggle.pcss.css
/*
 * @file
 * Single checkbox: show as toggle.
 */

: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(--gin-border-l);
    background-color: var(--gin-color-disabled);
    clip-path: circle(var(--gin-spacing-l) at 50% 50%); /* Fix Safari bug */

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

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

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

      .gin--dark-mode & {
        background-color: var(--gin-border-color-form-element);
      }

      @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(--gin-color-focus-border),
        0 0 0 4px var(--gin-color-focus);
    }

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

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

      &::before {
        transform: translateX(16px);
        background-color: #fff;

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

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

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

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

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