Segmented Control Component

A CSS implementation of the Sprout segmented-control component.

Example

html
<div class="spr-segmented-control-container">
  <div class="spr-segmented-control-option active">Option 1</div>
  <div class="spr-segmented-control-option">Option 2</div>
  <div class="spr-segmented-control-option">Option 3</div>
  <div class="spr-segmented-control-option">Option 4</div>
</div>

Compiled CSS

Example

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

.spr-icon-rotate-90 {
  transform: rotate(90deg);
}

.spr-icon-rotate-180 {
  transform: rotate(180deg);
}

.spr-icon-rotate-270 {
  transform: rotate(270deg);
}

.spr-segmented-control-container {
  display: flex;
  font-size: 16px;
  background: #e4e5e7;
  border-radius: 0.125rem;
  border: 2px solid #e4e5e7;
  width: fit-content;
}

@media only screen and (max-width: 37.49rem) {
  .spr-segmented-control-container {
    width: 100%;
  }
}

.spr-segmented-control-container.small .spr-segmented-control-option {
  font-size: 0.875rem;
}

.spr-segmented-control-option {
  padding-left: 1rem;
  padding-right: 1rem;
  border-radius: 0.125rem;
  text-align: center;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

@media only screen and (max-width: 37.49rem) {
  .spr-segmented-control-option {
    flex: 1;
  }
}

.spr-segmented-control-option.active {
  font-weight: 600;
  box-shadow: 0 4px 8px 0 rgba(24, 25, 27, 0.15);
  background: #fff;
}

.spr-segmented-control-option:not(.active) {
  transition-property: background;
  transition-duration: 0.15s;
  transition-timing-function: ease-in-out;
}

.spr-segmented-control-option:not(.active):hover {
  background: #ced0d4;
}