|
| 1 | +import { cn } from '../cn'; |
| 2 | +import { Severity } from '../types/severity'; |
| 3 | + |
| 4 | +export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> { |
| 5 | + severity?: Severity; |
| 6 | + message?: string; |
| 7 | +} |
| 8 | + |
| 9 | +export function Input({ severity, message, ...props }: InputProps) { |
| 10 | + return ( |
| 11 | + <div |
| 12 | + // todo: discuss colors with designers. |
| 13 | + // dark mode colors are kinda bad, but we don't really need |
| 14 | + // them just yet as this is used on yellow backgrounds |
| 15 | + className={cn( |
| 16 | + 'rounded-[9px] border border-blue-400 bg-white outline-offset-2 focus-within:outline focus-within:outline-2 dark:border-neutral-400 dark:bg-neutral-800', |
| 17 | + 'focus-visible:outline-green-800/40', |
| 18 | + '[&:focus-within:has([aria-invalid],:invalid)]:outline-critical-dark [&:has([aria-invalid],:invalid)]:border-critical-dark/50', |
| 19 | + severity === 'warning' && |
| 20 | + 'border-warning-bright/50 outline-warning-bright dark:border-warning-bright/50', |
| 21 | + severity === 'positive' && |
| 22 | + 'border-positive-dark/50 outline-positive-dark dark:border-positive-dark/50', |
| 23 | + )} |
| 24 | + > |
| 25 | + <input |
| 26 | + aria-invalid={severity === 'critical' ? true : undefined} |
| 27 | + className={cn( |
| 28 | + 'w-full rounded-lg bg-white py-3 indent-4 font-medium transition-[background-color] placeholder:text-green-800 placeholder-shown:bg-blue-100 autofill:shadow-[inset_0_0_0px_1000px_rgb(255,255,255)] autofill:[-webkit-text-fill-color:theme(colors.green.1000)] autofill:first-line:font-sans hover:bg-white focus:bg-white focus-visible:outline-none focus-visible:ring-0 dark:bg-neutral-800 dark:text-white dark:placeholder:text-neutral-300 dark:placeholder-shown:bg-neutral-900 dark:hover:bg-neutral-800 dark:focus:bg-neutral-800', |
| 29 | + message && 'rounded-b-none', |
| 30 | + 'pr-6 [&:is(:invalid,[aria-invalid])]:border-critical-dark/20 [&:is(:invalid,[aria-invalid])]:placeholder-shown:bg-critical-dark/5', |
| 31 | + |
| 32 | + props.className, |
| 33 | + )} |
| 34 | + {...props} |
| 35 | + /> |
| 36 | + {message && |
| 37 | + (severity === 'critical' ? ( |
| 38 | + <p className="rounded-b-lg bg-critical-dark/10 py-0.5 pl-4 text-sm text-critical-dark dark:bg-critical-bright/20 dark:text-white"> |
| 39 | + {message} |
| 40 | + </p> |
| 41 | + ) : severity === 'warning' ? ( |
| 42 | + <p className="rounded-b-lg bg-warning-bright/10 py-0.5 pl-4 text-sm text-warning-bright"> |
| 43 | + {message} |
| 44 | + </p> |
| 45 | + ) : ( |
| 46 | + <p className="rounded-b-lg bg-positive-dark/10 py-0.5 pl-4 text-sm text-positive-dark"> |
| 47 | + {message} |
| 48 | + </p> |
| 49 | + ))} |
| 50 | + </div> |
| 51 | + ); |
| 52 | +} |
0 commit comments