// Toggles
//
//  - When you can, use a `<button>` element and include `aria-pressed` or `role="switch"` for your toggles.
//  - You can add optional labels to your toggles, just make sure the label element includes an `id` and the toggle button includes an `aria-labelledby` tag that match.
//  - Make sure you include `aria-checked` on toggles, with JavaScript changing the state on click from true to false (or the reverse).
//  - Make sure you check the contrast of the toggle text against the background (if text is used).
//
// <section data-action="aria-toggle" class="atblock"><h3 class="atblock__title"><a href="#toggle_res">Resources</a></h3><div id="toggle_res" class="atblock__panel"><ul><li><a href="https://github.com/scottaohara/aria-switch-button" target="_blank">ARIA Switch Button</a></li><li><a href="https://inclusive-components.club/toggle-button" target="_blank">Inclusive Components - Toggle Buttons</a></li><li><a href="https://www.w3.org/TR/wai-aria-1.1/#switch" target="_blank">Switch Role (WAI-ARIA)</a></li></ul></div></section>
//
//
//
// <section data-action="aria-toggle" class="atblock"><h3 class="atblock__title"><a href="#toggle_guide">WCAG 2.1 Guidelines</a></h3><div id="toggle_guide" class="atblock__panel guidelines"><p><a href="https://www.w3.org/WAI/WCAG21/quickref/?showtechniques=131#text-equiv-all" target="_blank">1.1.1 Non-text Content</a> - All non-text content that is presented to the user has a text alternative that serves the equivalent purpose (some exceptions). (Level A)<br><br><strong>Note:</strong> If non-text content is pure decoration, is used only for visual formatting, or is not presented to users, then it does not need text alternatives.<br><br><a href="https://www.w3.org/WAI/WCAG21/quickref/#qr-ensure-compat-rsv" target="_blank">4.1.2 Name, Role, Value</a> - For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies. (Level A)</p></div><div class="markup"></div></section>
//
//
//
// Markup: toggles.twig
//
// Style guide: Forms.toggles

// Import site utilities.
@import '../../global/utils/init';

[data-action='aria-switch'] {
  background: $color-gallery;
  border-radius: $border-rd-lg;
  display: inline-block;
  position: relative;
  transition: background 0.1s ease-in-out;
  border: 0;
  width: 75px;
  min-height: 34px;
  overflow: hidden;
  clear: both;
  float: left;

  &:focus {
    background: $color-gallery;
  }

  &:hover {
    background-color: $color-gallery;
  }

  &:not([disabled]):hover,
  &:not([disabled]):focus {
    border: 0;
  }

  span {
    border-radius: $border-rd-lg;
    display: inline-block;
    font-weight: bold;
    pointer-events: none;
    text-transform: uppercase;
    position: absolute;
  }

  &[aria-checked='false'] {

    span {
      background: $color-white;
      border: 1px solid $color-alto;
      border-radius: 50%;
      height: 30px;
      width: 30px;
      top: 2px;
      left: 2px;
      transition: 0.4s;
    }
  }

  &[aria-checked='true'] span {
    background: $color-white;
    border: 1px solid $color-alto;
    border-radius: 50%;
    height: 30px;
    width: 30px;
    top: 2px;
    left: 43px;
    transition: 0.4s;
  }

  &[aria-checked='true'] {
    background: $color-grass;
  }

  &.text[aria-checked='false'] span::after {
    content: 'OFF';
    display: block;
    color: $color-midnight;
    position: absolute;
    right: -36px;
    top: 7px;
  }

  &.text[aria-checked='true'] span::before {
    content: 'ON';
    display: block;
    color: $color-midnight;
    position: absolute;
    left: -32px;
    top: 7px;
  }

  &.reverse[aria-checked='false'] {
    background: $color-white;

    span {
      background: $color-alto;
      border: 1px solid $color-alto;
      border-radius: 50%;
      height: 30px;
      width: 30px;
      top: 2px;
      left: 2px;
      transition: 0.4s;
    }
  }

  &.reverse[aria-checked='true'] {
    background: $color-white;

    span {
      background: $color-grass;
      border: 1px solid $color-alto;
      border-radius: 50%;
      height: 30px;
      width: 30px;
      top: 2px;
      left: 43px;
      transition: 0.4s;
    }
  }

  &.flip {
    background: $color-gallery;
    border-radius: 0;
    display: inline-block;
    position: relative;
    transition: background 0.1s ease-in-out;
    border: 0;
    width: 75px;
    height: 75px;
    overflow: hidden;
    clear: both;
    float: left;

    &:hover {
      background: $color-gallery;
    }

    span {
      border: 1px solid;
      border-radius: 0;
      height: 100%;
      width: 100%;
      top: 0;
      left: 0;
      transition: 0.4s;

      &::after,
      &::before {
        display: block;
        position: absolute;
        left: 0;
        right: 0;
        margin: 0 auto;
        padding: $padding-xsm;
        top: 50%;
        transform: translateY(-50%);
      }
    }
  }

  &.flip[aria-checked='false'] {
    background: $color-white;

    span {
      background: $color-cherry;
      border-color: $color-alto;
    }
  }

  &.flip[aria-checked='true'] {
    background: $color-white;

    span {
      background: $color-grass;
      border-color: $color-alto;
    }
  }

  &.flip[aria-checked='false'] span::after {
    content: 'No way!';
    color: $color-white;
  }

  &.flip[aria-checked='true'] span::before {
    content: 'Heck Yes!';
    color: $color-midnight;
  }
}

.optional-label {
  display: inline-block;
  padding: 12px 18px;
}

.no-js [data-action='aria-switch']:not([aria-checked]) span {
  background: $color-white;
  border: 1px solid $color-alto;
  border-radius: 50%;
  height: 30px;
  width: 30px;
  top: 2px;
  left: 43px;
  transition: 0.4s;
}
