JSFiddle - React, Tailwind, and code Playground

by Sergey Linnick

HTML

<div class="toggle toggle--inverse">
  <input type="checkbox" id="gravatars">
  <label for="gravatars"><span class="on label">On</span><span class="toggler"></span><span class="off label">Off</span></label>
</div>

SCSS

.toggle {
  position: relative;
  input {
    display: none;
    & + label {
      display: flex;
      flex-flow: row nowrap;
      align-items: center;
      cursor: pointer;
      font-weight: 400;
      .on,
      .off,
      .toggler {
        display: block;
        width: auto;
        flex: 0 0 auto;
      }
      .on,
      .off {
        font-weight: 300;
        color: #6d6e70;
      }
      .toggler {
        position: relative;
        width: 60px;
        height: 30px;
        flex: 0 0 60px;
        border-radius: 15px;
        overflow: hidden;
        &,
        &:after,
        &:before {
          transition: all .15s ease-in-out;
        }
        &:after {
          content: "";
          display: block;
          position: absolute;
          border-radius: 50%;
          width: 25px;
          height: 25px;
          top: 50%;
          left: 2.5px;
          transform: translateY(-50%);
          background: #fff;
        }
        &:before {
          content: "";
          border-radius: 15px;
          display: block;
          position: absolute;
          width: 100%;
          height: 100%;
          left: 0;
          top: 0;
          background: #e6e7e8;
        }
      }
      .label+.toggler {
        margin-left: 15px;
      }
      .toggler+.label {
        margin-left: 15px;
      }
    }
    &:not(:checked) {
      &+label {
        .off {
          color: #000;
        }
      }
    }
    &:checked {
      &+label {
        .on {
          color: #1b75bb;
        }
        .toggler {
          &:before {
            background: #26a9e0;
          }
          &:after {
            left: calc(100% - 25px - 2.5px);
          }
        }
      }
    }
    &[disabled],
    &:disabled,
    &.disabled {
      &+label {
        .toggler {
          &:before {
            background: darken(#d0d2d3, 5%);
          }
        }
      }
      &:checked {
        &+label {
          .on {
            color: #000;
          }
         ...