Input.tsx 753 B

12345678910111213141516171819202122232425262728
  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 ${
  13. error ? "border-red-600" : "border-gray-300 dark:border-gray-600"
  14. } text-sm outline-none h-[38px] leading-[30px] py-1 px-1.5 dark:bg-gray-800 dark:text-gray-100 ${className}`;
  15. if (label) {
  16. return (
  17. <div className="mb-2">
  18. <label className="block mb-1 text-sm">{label}</label>
  19. <input className={inputClasses} {...props} />
  20. </div>
  21. );
  22. }
  23. return <input className={inputClasses} {...props} />;
  24. }