import * as React from 'react'; import styled from 'styled-components'; import { dim } from '../../utils/dim'; import * as tokens from "@tokens"; import { StyledError } from '.'; import { CheckboxProps, CheckboxInputProps, InputLabelProps } from './interface'; const Label = styled.label` cursor: ${({ disabled }: InputLabelProps) => (disabled ? 'not-allowed' : 'pointer')}; ${({ error, disabled }: InputLabelProps) => `color: ${error ? tokens.colorPink : disabled ? tokens.colorGrey15 : 'initial'}`}; ${({ disabled }: InputLabelProps) => !disabled && `&:hover { color: ${tokens.colorPink}; }`} `; const StyledInputLabel = styled.span` font-family: ${tokens.fontBody}; font-size: 12px; line-height: 21px; `; const Input = styled.input` width: 18px; height: 18px; vertical-align: middle; display: inline-block; margin: 0 ${dim()} 0 0; border-style: solid; border-width: 1px; border-color: ${tokens.colorBlack}; outline: none; box-shadow: inset 0 0 0 ${tokens.colorBlack}; appearance: none; margin-bottom: 3px; &:hover { border-color: ${tokens.colorPink}; } &:checked { background-color: ${tokens.colorBlack}; background-image: url('images/tick-white.svg'); background-repeat: no-repeat; background-position: center center; &:hover { border-color: ${tokens.colorPink}; background-color: ${tokens.colorPink}; } } ${({ error, disabled }: CheckboxInputProps) => { if (error) { return ` border: 1px solid ${tokens.colorPink} !important; color: ${tokens.colorPink}; &:checked { background-color: ${tokens.colorPink}; } `; } if (disabled) { return ` cursor: not-allowed; opacity: 0.3; `; } return ''; }} `; const StyledWrapper = styled.div` display: block; width: 100%; `; export const Checkbox: React.FC = ({ value = '', checked, disabled = false, defaultChecked, onClick, readOnly = false, inputLabel = '', onChange, name, error = false, ...props }: CheckboxProps) => ( {error && {error}} );