8058
Ir
irvc / files
irvc / web / src / ui / Field.tsx
1.4 KB
1import type { ComponentProps, ReactNode } from "react"; 2import { cn } from "cn"; 3 4// Field is the one way to label a control, so every form looks the same. 5export function Field({ 6 label, 7 hint, 8 children, 9}: { 10 label: string; 11 hint?: string; 12 children: ReactNode; 13}) { 14 return ( 15 <label className="block space-y-1.5"> 16 <span className="text-xs text-muted">{label}</span> 17 {children} 18 {hint && <span className="block text-xs text-faint">{hint}</span>} 19 </label> 20 ); 21} 22 23export function TextInput({ 24 className, 25 scale = "md", 26 ...props 27}: ComponentProps<"input"> & { scale?: "md" | "lg" }) { 28 return <input className={cn("input", `input-${scale}`, className)} {...props} />; 29} 30 31export function TextArea({ className, ...props }: ComponentProps<"textarea">) { 32 return <textarea className={cn("input resize-none py-2 leading-6", className)} {...props} />; 33} 34 35export function Select({ 36 value, 37 onChange, 38 options, 39 className, 40}: { 41 value: string; 42 onChange: (value: string) => void; 43 options: { value: string; label: string }[]; 44 className?: string; 45}) { 46 return ( 47 <select 48 value={value} 49 onChange={(e) => onChange(e.target.value)} 50 className={cn("input input-md", className)} 51 > 52 {options.map((o) => ( 53 <option key={o.value} value={o.value}> 54 {o.label} 55 </option> 56 ))} 57 </select> 58 ); 59}