FileInput.tsx 983 B

1234567891011121314151617181920212223242526
  1. import { JSX } from "preact";
  2. interface FileInputProps
  3. extends Omit<JSX.InputHTMLAttributes<HTMLInputElement>, "type" | "value"> {
  4. label?: string;
  5. }
  6. export default function FileInput({
  7. label,
  8. className = "",
  9. ...props
  10. }: FileInputProps) {
  11. const inputClasses =
  12. `w-full block box-border rounded border border-gray-300 dark:border-gray-600 text-sm outline-none h-[38px] leading-[30px] py-1 px-1.5 dark:bg-gray-800 dark:text-gray-100 file:mr-2 file:py-1 file:px-3 file:rounded file:border-0 file:text-sm file:font-medium file:cursor-pointer file:bg-gray-100 file:text-gray-700 file:hover:bg-gray-200 file:dark:bg-gray-600 file:dark:text-gray-100 file:dark:hover:bg-gray-500 ${className}`;
  13. if (label) {
  14. return (
  15. <div className="mb-2">
  16. <label className="block mb-1 text-sm">{label}</label>
  17. <input type="file" className={inputClasses} {...props} />
  18. </div>
  19. );
  20. }
  21. return <input type="file" className={inputClasses} {...props} />;
  22. }