All files / components/Form/Toggle ToggleSlider.js

100% Statements 8/8
100% Branches 4/4
100% Functions 5/5
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36        13x         13x       2x     2x 2x               2x 2x           13x      
import styled from 'styled-components';
import { number, bool } from 'prop-types';
import { rem } from '../../Typography';
 
const propTypes = {
  h: number.isRequired,
  disabled: bool.isRequired,
};
 
const ToggleSlider = styled.span`
  position: relative;
  display: inline-block;
  width: 100%;
  height: ${({ h }) => rem(h)};
  border-radius: 9999px;
  transition: background-color 0.2s;
  cursor: ${({ disabled }) => (disabled ? 'default' : 'pointer')};
  opacity: ${({ disabled }) => (disabled ? 0.6 : 1)};
  &:before {
    content: '';
    position: absolute;
    top: 0;
    transition: left 0.2s;
    bottom: 0;
    margin: auto;
    height: ${({ h }) => rem(h - 8)};
    width: ${({ h }) => rem(h - 8)};
    background-color: #fff;
    border-radius: 100%;
  }
`;
 
ToggleSlider.propTypes = propTypes;
 
export default ToggleSlider;