Path: blob/1.0-develop/resources/scripts/components/elements/Input.tsx
7461 views
import styled, { css } from 'styled-components/macro';1import tw from 'twin.macro';23export interface Props {4isLight?: boolean;5hasError?: boolean;6}78const light = css<Props>`9${tw`bg-white border-neutral-200 text-neutral-800`};10&:focus {11${tw`border-primary-400`}12}1314&:disabled {15${tw`bg-neutral-100 border-neutral-200`};16}17`;1819const checkboxStyle = css<Props>`20${tw`bg-neutral-500 cursor-pointer appearance-none inline-block align-middle select-none flex-shrink-0 w-4 h-4 text-primary-400 border border-neutral-300 rounded-sm`};21color-adjust: exact;22background-origin: border-box;23transition: all 75ms linear, box-shadow 25ms linear;2425&:checked {26${tw`border-transparent bg-no-repeat bg-center`};27background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M5.707 7.293a1 1 0 0 0-1.414 1.414l2 2a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0-1.414-1.414L7 8.586 5.707 7.293z'/%3e%3c/svg%3e");28background-color: currentColor;29background-size: 100% 100%;30}3132&:focus {33${tw`outline-none border-primary-300`};34box-shadow: 0 0 0 1px rgba(9, 103, 210, 0.25);35}36`;3738const inputStyle = css<Props>`39// Reset to normal styling.40resize: none;41${tw`appearance-none outline-none w-full min-w-0`};42${tw`p-3 border-2 rounded text-sm transition-all duration-150`};43${tw`bg-neutral-600 border-neutral-500 hover:border-neutral-400 text-neutral-200 shadow-none focus:ring-0`};4445& + .input-help {46${tw`mt-1 text-xs`};47${(props) => (props.hasError ? tw`text-red-200` : tw`text-neutral-200`)};48}4950&:required,51&:invalid {52${tw`shadow-none`};53}5455&:not(:disabled):not(:read-only):focus {56${tw`shadow-md border-primary-300 ring-2 ring-primary-400 ring-opacity-50`};57${(props) => props.hasError && tw`border-red-300 ring-red-200`};58}5960&:disabled {61${tw`opacity-75`};62}6364${(props) => props.isLight && light};65${(props) => props.hasError && tw`text-red-100 border-red-400 hover:border-red-300`};66`;6768const Input = styled.input<Props>`69&:not([type='checkbox']):not([type='radio']) {70${inputStyle};71}7273&[type='checkbox'],74&[type='radio'] {75${checkboxStyle};7677&[type='radio'] {78${tw`rounded-full`};79}80}81`;82const Textarea = styled.textarea<Props>`83${inputStyle}84`;8586export { Textarea };87export default Input;888990