Advertisement
xcage88

component

Nov 29th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import React from 'react';
  2. import Spinner from '../../Spinner';
  3.  
  4. type CustomInputFileProps = { inputFileRef: any; isUpload: boolean; form: any; onChange: any; fileName: string; name?: string };
  5.  
  6. const CustomInputFile2 = ({ inputFileRef, isUpload, form, onChange, fileName, name }: CustomInputFileProps) => {
  7. return (
  8. <div className="flex items-center rounded-md border border-gray-300 shadow-sm w-full">
  9. <input ref={inputFileRef} id={fileName} name={name} type="file" className="custom-file-input hidden" onChange={onChange} />
  10. <label
  11. className="cursor-pointer rounded-l-md bg-[#F5F5F5] px-4 py-2 font-normal text-[#787A7D] hover:bg-[#F5F5F5]"
  12. style={{
  13. margin: '0',
  14. }}
  15. onClick={() => !isUpload && inputFileRef.current.click()}
  16. >
  17. Choose File
  18. </label>
  19. {isUpload ? (
  20. <div className="px-4">
  21. <Spinner />
  22. </div>
  23. ) : (
  24. <label
  25. htmlFor={fileName}
  26. className="w-[60%] cursor-pointer px-4 text-gray-600"
  27. style={{
  28. margin: '0',
  29. }}
  30. >
  31. {form[fileName]?.length !== 0 ? (typeof form[fileName] === 'string' ? form[fileName].replace(/uploads\/\d+-/, '') : 'No file selected') : 'No file selected'}
  32. </label>
  33. )}
  34. </div>
  35. );
  36. };
  37.  
  38. export default CustomInputFile2;
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement