import * as React from 'react'; import { RadioProps } from './interface'; import styled from 'styled-components'; import { StyledError } from '.'; import * as tokens from "@tokens"; import { dim } from '../../utils/dim'; import { InputLabelProps } from './interface'; const StyledText = styled.span` font-family: ${tokens.fontBody}; font-size: 12px; line-height: 21px; margin-left: ${dim(2)}; `; const StyledInput = styled.input` appearance: none; position: relative; &:before { content: ''; position: absolute; left: 0; top: -7px; display: inline-block; width: 12px; height: 12px; background-image: url('icons/radio-unchecked.svg'); background-size: 100%; background-repeat: no-repeat; } &:checked { &:before { background-image: url('icons/radio-checked.svg'); } } &:disabled { &:before { opacity: 0.3; } } `; const StyledLabel = styled.label` cursor: ${({ disabled }: InputLabelProps) => (disabled ? 'not-allowed' : 'pointer')}; color: ${tokens.colorBlack}; display: block; width: 100%; opacity: ${({ disabled }: InputLabelProps) => (disabled ? '0.3' : '1')}; & + & { margin-top: ${dim()}; } &:hover { ${StyledText} { color: ${tokens.colorPink}; } ${StyledInput} { &:before { background-image: url('icons/radio-unchecked-hover.svg') !important; } &:checked:before { background-image: url('icons/radio-checked-hover.svg') !important; } } } `; export const Radio: React.FC = ({ label, name, id, value, checked = false, disabled = false, required = false, defaultChecked = false, error = false, ...props }) => ( {label} {error && {error}} );