// @ts-nocheck import * as React from 'react'; import styled from '../styled'; import sx from '@styled-system/css'; import { compose } from 'styled-system'; import variant from '@styled-system/variant'; import shouldForwardProp from '@styled-system/should-forward-prop'; import View from '../view'; import Text from '../text'; import { Theme } from '../theme'; import { InputProps } from '../input'; const CheckIcon = props => ( ); const DotIcon = props => ( ); const inputVariant = variant({ variants: { onWhite: { '& ~ [data-indicator]': { color: 'white', }, [`&:checked ~ [data-indicator]`]: { backgroundColor: 'gray.0', boxShadow: (theme: Theme) => `inset 0 0 0 2px ${theme.colors.gray[0]}`, }, }, onBlack: { '& ~ [data-indicator]': { color: 'white', }, [`&:checked ~ [data-indicator]`]: { backgroundColor: 'TEDRed.0', boxShadow: (theme: Theme) => `inset 0 0 0 2px ${theme.colors.TEDRed[1]}`, }, }, }, }); const Indicator = styled(View, { shouldForwardProp })( sx({ backgroundColor: 'inherit', color: 'currentColor', position: 'absolute', userSelect: 'none', top: 0, bottom: 0, left: 0, right: 0, }), ); const Control = styled('input', { shouldForwardProp })( props => sx({ opacity: 0, position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, '&:focus ~ [data-indicator]': { boxShadow: (theme: Theme) => `inset 0 0 0 2px ${theme.colors.gray[1]}, 0 0 ${theme.space[1]} 1px ${theme.colors.TEDRed[0]}`, }, '&:focus:checked ~ [data-indicator]': { boxShadow: (theme: Theme) => `inset 0 0 0 2px ${theme.colors.gray[0]}, 0 0 ${theme.space[1]} 1px ${theme.colors.TEDRed[1]}`, }, '& ~ [data-indicator]': { transition: 'background-color .1s linear, color .1s linear', boxShadow: (theme: Theme) => `inset 0 0 0 2px ${theme.colors.gray[2]}`, backgroundColor: 'currentColor', borderRadius: props.type === 'checkbox' ? 1 : '50%', }, '& ~ [data-indicator] > [data-indicator-icon]': { transition: 'opacity .1s linear, color .1s linear', opacity: 0, color: 'currentColor', }, '&:checked ~ [data-indicator] > [data-indicator-icon]': { opacity: 1, }, '&[disabled]': { cursor: 'not-allowed', '& ~ [data-indicator]': { cursor: 'not-allowed', boxShadow: (theme: Theme) => `inset 0 0 0 2px ${theme.colors.gray[1]}`, backgroundColor: 'gray.2', color: 'gray.1', }, '&:checked ~ [data-indicator]': { boxShadow: (theme: Theme) => `inset 0 0 0 2px ${theme.colors.gray[1]}`, backgroundColor: 'gray.2', color: 'gray.1', }, '& ~ [data-indicator] > [data-indicator-icon]': { opacity: 0, color: 'currentColor', }, '&:checked ~ [data-indicator] > [data-indicator-icon]': { opacity: 1, }, }, }), compose(inputVariant), ); const Selectable = ({ valid, invalid, ...props }: InputProps & { label: React.ReactNode; type: 'checkbox' | 'radio' }) => { const labelColor: string = React.useMemo( () => props.disabled ? 'gray.1' : props.variant === 'onBlack' ? 'white' : 'gray.0', [props.disabled, props.variant], ); return ( {props.type === 'checkbox' ? ( ) : ( )} {props.label} ); }; Selectable.defaultProps = { type: 'checkbox', variant: 'onWhite', }; export default Selectable;