|
| 1 | +import { cn } from '../../cn'; |
| 2 | +import { Severity } from '../../types/severity'; |
| 3 | +import { InputShake } from './input-shake'; |
| 4 | + |
| 5 | +export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> { |
| 6 | + severity?: Severity; |
| 7 | + message?: string; |
| 8 | +} |
| 9 | + |
| 10 | +export function Input({ severity, message, ...props }: InputProps) { |
| 11 | + return ( |
| 12 | + <div |
| 13 | + // todo: discuss colors with designers. |
| 14 | + // dark mode colors are kinda bad, but we don't really need |
| 15 | + // them just yet as this is used on yellow backgrounds |
| 16 | + className={cn( |
| 17 | + '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', |
| 18 | + 'focus-visible:outline-green-800/40', |
| 19 | + '[&:focus-within:has([aria-invalid],:invalid)]:outline-critical-dark [&:has([aria-invalid],:invalid)]:border-critical-dark/50', |
| 20 | + severity === 'warning' && |
| 21 | + 'border-warning-bright/50 outline-warning-bright dark:border-warning-bright/50', |
| 22 | + severity === 'positive' && |
| 23 | + 'border-positive-dark/50 outline-positive-dark dark:border-positive-dark/50', |
| 24 | + )} |
| 25 | + > |
| 26 | + <InputShake severity={severity} /> |
| 27 | + <input |
| 28 | + aria-invalid={severity === 'critical' ? true : undefined} |
| 29 | + className={cn( |
| 30 | + 'w-full rounded-lg bg-white py-3 indent-4 font-medium transition-[background-color,padding] 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', |
| 31 | + message && 'rounded-b-none py-2', |
| 32 | + props.className, |
| 33 | + )} |
| 34 | + {...props} |
| 35 | + /> |
| 36 | + <div |
| 37 | + style={{ height: message ? '25px' : '0px' }} |
| 38 | + className={cn( |
| 39 | + 'overflow-hidden rounded-b-lg pl-4 pr-1 text-sm transition-all *:animate-in *:fade-in', |
| 40 | + severity === 'critical' && 'bg-critical-dark/10 dark:bg-critical-bright/20', |
| 41 | + severity === 'warning' && 'bg-warning-bright/10', |
| 42 | + severity === 'positive' && 'bg-positive-dark/10', |
| 43 | + )} |
| 44 | + > |
| 45 | + {message && |
| 46 | + (severity === 'critical' ? ( |
| 47 | + <p className="py-0.5 text-sm text-critical-dark dark:text-white">{message}</p> |
| 48 | + ) : severity === 'warning' ? ( |
| 49 | + <p className="py-0.5 text-sm text-warning-bright">{message}</p> |
| 50 | + ) : ( |
| 51 | + <p className="py-0.5 text-sm text-positive-dark">{message}</p> |
| 52 | + ))} |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + ); |
| 56 | +} |
0 commit comments