Checkbox Component

A CSS implementation of the Sprout checkbox component.

Related

Example

html
<div class="spr-stack-container-xs">
  <div class="spr-checkbox-group-label">Checkboxes</div>
  <div class="spr-stack-container-sm">
    <input class="spr-checkbox" type="checkbox" value="checkbox" id="checkbox" checked>
    <label for="checkbox">
       <span class="checkbox-icon"></span>
       Checkbox
    </label>
  </div>
  <div class="spr-stack-container-sm">
    <input class="spr-checkbox" type="checkbox" value="checkbox" id="checkbox-disabled" disabled>
    <label for="checkbox-disabled">
       <span class="checkbox-icon"></span>
       Disabled checkbox
    </label>
  </div>
  <div class="spr-stack-container-sm">
    <input class="spr-checkbox spr-checkbox-error" type="checkbox" value="checkbox" id="checkbox-error">
    <label for="checkbox-error">
       <span class="checkbox-icon"></span>
       Checkbox with error
    </label>
  </div>
  <div class="spr-stack-container-sm">
    <input class="spr-checkbox spr-checkbox-error" type="checkbox" value="checkbox" id="checkbox-error-disabled" disabled>
    <label for="checkbox-error-disabled">
       <span class="checkbox-icon"></span>
       Disabled checkbox with error
    </label>
  </div>
</div>

Compiled CSS

Example

scss
@import 'components/checkbox';
css compiled
@keyframes openPopover {
  from {
    transform: scale(0.9);
  }
  to {
    transform: scale(1);
  }
}

.spr-checkbox-group-label {
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-family: "AvenirNext", "Helvetica Neue", Arial, sans-serif;
  font-size: 0.875rem;
  line-height: 1.25rem;
  letter-spacing: 0;
  font-weight: 400;
}

.spr-checkbox {
  transition-property: background-color, border-color, color;
  transition-duration: 0.11s;
  transition-timing-function: ease-in-out;
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  width: 0.0625rem;
  height: 0.0625rem;
  margin: -0.0625rem;
  padding: 0;
  border: 0;
}

.spr-checkbox:checked + label::before {
  background-color: #2ba148;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 0.125rem;
}

.spr-checkbox:checked + label:hover::before {
  background-color: #22813a;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 0.125rem;
}

.spr-checkbox:checked + label:focus + label::before {
  background-color: #22813a;
}

.spr-checkbox:checked + label .checkbox-icon {
  position: absolute;
  top: 0.9375rem;
  left: 0.4375rem;
  transform: rotate(225deg);
}

.spr-checkbox:checked + label .checkbox-icon::before, .spr-checkbox:checked + label .checkbox-icon::after {
  position: absolute;
  display: inline-block;
  margin: 0;
  content: '';
  border-radius: 3.125rem;
  background: #fff;
}

.spr-checkbox:checked + label .checkbox-icon::before {
  width: 0.375rem;
  height: 0.125rem;
}

.spr-checkbox:checked + label .checkbox-icon::after {
  width: 0.125rem;
  height: 0.625rem;
}

.spr-checkbox:disabled + label {
  cursor: default;
  pointer-events: none;
  opacity: 0.5;
}

.spr-checkbox:disabled + label::before {
  box-sizing: border-box;
  border: 1px solid #6b6f7b;
  border-radius: 0.125rem;
}

.spr-checkbox:focus + label::before {
  box-sizing: border-box;
  border: 2px solid #2ba148;
  border-radius: 0.125rem;
  box-shadow: 0 0 0 0.125rem rgba(43, 161, 72, 0.35);
}

.spr-checkbox:hover + label::before {
  box-sizing: border-box;
  border: 2px solid #2ba148;
  border-radius: 0.125rem;
}

.spr-checkbox:indeterminate + label::before {
  background-color: #2ba148;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 0.125rem;
}

.spr-checkbox:indeterminate + label::after {
  position: absolute;
  top: 0.625rem;
  left: 0.1875rem;
  width: 0.625rem;
  height: 0.125rem;
  content: '';
  border-radius: 3.125rem;
  background-color: #fff;
  transition-property: background-color, border-color, color;
  transition-duration: 0.11s;
  transition-timing-function: ease-in-out;
}

.spr-checkbox:indeterminate + label:hover::before {
  background-color: #22813a;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 0.125rem;
}

.spr-checkbox:indeterminate + label .checkbox-icon {
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  width: 0.0625rem;
  height: 0.0625rem;
  margin: -0.0625rem;
  padding: 0;
  border: 0;
}

.spr-checkbox + label {
  display: flex;
  position: relative;
  padding: 0;
  cursor: pointer;
  user-select: none;
  font-family: "AvenirNext", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.375rem;
  letter-spacing: 0;
  font-weight: 400;
}

.spr-checkbox + label::before {
  display: block;
  min-width: 1rem;
  height: 1rem;
  content: '';
  vertical-align: text-top;
  background-color: #fff;
  transition-property: background-color, border-color, color;
  transition-duration: 0.11s;
  transition-timing-function: ease-in-out;
  box-sizing: border-box;
  border: 1px solid #6b6f7b;
  border-radius: 0.125rem;
  margin-right: 0.5rem;
  margin-top: 0.125rem;
}

.spr-checkbox-error:checked + label::before {
  background-color: #dd1d33;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 0.125rem;
}

.spr-checkbox-error:checked + label:hover::before {
  background-color: #b9182b;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 0.125rem;
}

.spr-checkbox-error:checked + label:focus + label::before {
  background-color: #b9182b;
}

.spr-checkbox-error:checked + label .checkbox-icon {
  position: absolute;
  top: 0.9375rem;
  left: 0.4375rem;
  transform: rotate(225deg);
}

.spr-checkbox-error:checked + label .checkbox-icon::before, .spr-checkbox-error:checked + label .checkbox-icon::after {
  position: absolute;
  display: inline-block;
  margin: 0;
  content: '';
  border-radius: 3.125rem;
  background: #fff;
}

.spr-checkbox-error:checked + label .checkbox-icon::before {
  width: 0.375rem;
  height: 0.125rem;
}

.spr-checkbox-error:checked + label .checkbox-icon::after {
  width: 0.125rem;
  height: 0.625rem;
}

.spr-checkbox-error:disabled + label {
  cursor: default;
  pointer-events: none;
  opacity: 0.5;
}

.spr-checkbox-error:disabled + label::before {
  box-sizing: border-box;
  border: 1px solid #dd1d33;
  border-radius: 0.125rem;
}

.spr-checkbox-error:focus + label::before {
  box-sizing: border-box;
  border: 2px solid #dd1d33;
  border-radius: 0.125rem;
  box-shadow: 0 0 0 0.125rem rgba(221, 29, 51, 0.35);
}

.spr-checkbox-error:hover + label::before {
  box-sizing: border-box;
  border: 2px solid #dd1d33;
  border-radius: 0.125rem;
}

.spr-checkbox-error:indeterminate + label::before {
  background-color: #dd1d33;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 0.125rem;
}

.spr-checkbox-error:indeterminate + label::after {
  position: absolute;
  top: 0.625rem;
  left: 0.1875rem;
  width: 0.625rem;
  height: 0.125rem;
  content: '';
  border-radius: 3.125rem;
  background-color: #fff;
  transition-property: background-color, border-color, color;
  transition-duration: 0.11s;
  transition-timing-function: ease-in-out;
}

.spr-checkbox-error:indeterminate + label:hover::before {
  background-color: #b9182b;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 0.125rem;
}

.spr-checkbox-error:indeterminate + label .checkbox-icon {
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  width: 0.0625rem;
  height: 0.0625rem;
  margin: -0.0625rem;
  padding: 0;
  border: 0;
}

.spr-checkbox-error + label {
  color: #dd1d33;
}

.spr-checkbox-error + label::before {
  box-sizing: border-box;
  border: 1px solid #dd1d33;
  border-radius: 0.125rem;
}