2020-07-04 16:13:41 +00:00
|
|
|
import styled, { css } from 'styled-components/macro';
|
|
|
|
import tw from 'twin.macro';
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
isLight?: boolean;
|
|
|
|
hasError?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const light = css<Props>`
|
2021-01-08 17:48:11 +00:00
|
|
|
${tw`bg-white border-neutral-200 text-neutral-800`};
|
2020-07-04 16:13:41 +00:00
|
|
|
&:focus { ${tw`border-primary-400`} }
|
2021-01-08 17:48:11 +00:00
|
|
|
|
2020-07-04 16:13:41 +00:00
|
|
|
&:disabled {
|
|
|
|
${tw`bg-neutral-100 border-neutral-200`};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-07-04 23:26:07 +00:00
|
|
|
const checkboxStyle = css<Props>`
|
2020-12-27 18:44:56 +00:00
|
|
|
${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`};
|
2020-07-04 23:26:07 +00:00
|
|
|
color-adjust: exact;
|
|
|
|
background-origin: border-box;
|
|
|
|
transition: all 75ms linear, box-shadow 25ms linear;
|
|
|
|
|
|
|
|
&:checked {
|
|
|
|
${tw`border-transparent bg-no-repeat bg-center`};
|
|
|
|
background-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");
|
|
|
|
background-color: currentColor;
|
|
|
|
background-size: 100% 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
${tw`outline-none border-primary-300`};
|
|
|
|
box-shadow: 0 0 0 1px rgba(9, 103, 210, 0.25);
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2020-07-04 16:28:03 +00:00
|
|
|
const inputStyle = css<Props>`
|
2020-07-04 16:13:41 +00:00
|
|
|
// Reset to normal styling.
|
2020-07-10 04:00:03 +00:00
|
|
|
resize: none;
|
|
|
|
${tw`appearance-none outline-none w-full min-w-0`};
|
2020-12-26 19:53:36 +00:00
|
|
|
${tw`p-3 border-2 rounded text-sm transition-all duration-150`};
|
2020-12-27 18:52:40 +00:00
|
|
|
${tw`bg-neutral-600 border-neutral-500 hover:border-neutral-400 text-neutral-200 shadow-none focus:ring-0`};
|
2021-01-08 17:48:11 +00:00
|
|
|
|
2020-07-04 16:13:41 +00:00
|
|
|
& + .input-help {
|
|
|
|
${tw`mt-1 text-xs`};
|
2021-05-20 22:00:46 +00:00
|
|
|
${props => props.hasError ? tw`text-red-200` : tw`text-neutral-400`};
|
2020-07-04 16:13:41 +00:00
|
|
|
}
|
2021-01-08 17:48:11 +00:00
|
|
|
|
2020-07-04 16:13:41 +00:00
|
|
|
&:required, &:invalid {
|
|
|
|
${tw`shadow-none`};
|
|
|
|
}
|
2021-01-08 17:48:11 +00:00
|
|
|
|
2020-07-10 04:00:03 +00:00
|
|
|
&:not(:disabled):not(:read-only):focus {
|
2020-12-26 19:53:36 +00:00
|
|
|
${tw`shadow-md border-primary-300 ring-2 ring-primary-400 ring-opacity-50`};
|
2020-12-27 18:52:40 +00:00
|
|
|
${props => props.hasError && tw`border-red-300 ring-red-200`};
|
2020-07-04 16:13:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
${tw`opacity-75`};
|
|
|
|
}
|
2021-01-08 17:48:11 +00:00
|
|
|
|
2021-02-02 21:11:54 +00:00
|
|
|
&:not(.ignoreReadOnly):read-only {
|
2021-01-08 17:48:11 +00:00
|
|
|
${tw`border-neutral-800 bg-neutral-900`};
|
|
|
|
}
|
|
|
|
|
2020-07-04 16:13:41 +00:00
|
|
|
${props => props.isLight && light};
|
2020-12-27 18:52:40 +00:00
|
|
|
${props => props.hasError && tw`text-red-100 border-red-400 hover:border-red-300`};
|
2020-07-04 16:13:41 +00:00
|
|
|
`;
|
|
|
|
|
2020-07-04 23:26:07 +00:00
|
|
|
const Input = styled.input<Props>`
|
|
|
|
&:not([type="checkbox"]):not([type="radio"]) {
|
|
|
|
${inputStyle};
|
|
|
|
}
|
2021-01-08 17:48:11 +00:00
|
|
|
|
2020-07-04 23:26:07 +00:00
|
|
|
&[type="checkbox"], &[type="radio"] {
|
|
|
|
${checkboxStyle};
|
2021-01-08 17:48:11 +00:00
|
|
|
|
2020-07-04 23:26:07 +00:00
|
|
|
&[type="radio"] {
|
|
|
|
${tw`rounded-full`};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-07-04 16:28:03 +00:00
|
|
|
const Textarea = styled.textarea<Props>`${inputStyle}`;
|
|
|
|
|
|
|
|
export { Textarea };
|
2020-07-04 16:13:41 +00:00
|
|
|
export default Input;
|