Input.tsx 696 B

1234567891011121314151617181920212223242526
  1. import { JSX } from "preact";
  2. interface InputProps extends JSX.InputHTMLAttributes<HTMLInputElement> {
  3. error?: boolean;
  4. label?: string;
  5. }
  6. export default function Input({
  7. error = false,
  8. label,
  9. className = "",
  10. ...props
  11. }: InputProps) {
  12. const inputClasses = `w-full block box-border rounded border ${error ? "border-red-600" : "border-gray-300"} text-sm outline-none h-[38px] leading-[30px] py-1 px-1.5 ${className}`;
  13. if (label) {
  14. return (
  15. <div className="mb-2">
  16. <label className="block mb-1 text-sm">{label}</label>
  17. <input className={inputClasses} {...props} />
  18. </div>
  19. );
  20. }
  21. return <input className={inputClasses} {...props} />;
  22. }