Source

components/FormInputs/ImageInput/ImageInput.js

  1. // NPM module imports
  2. import React from "react";
  3. import PropTypes from "prop-types";
  4. // Style imports
  5. import styles from "./ImageInput.module.scss";
  6. /**
  7. * Renders the ImageInput component.
  8. * Allows the user to select an image from their file system.
  9. * @component
  10. * @category FormInputs
  11. * @author Dan Levy <danlevy124@gmail.com>
  12. */
  13. const ImageInput = (props) => {
  14. return (
  15. <div>
  16. <input
  17. id={props.inputName}
  18. className={styles.imageInput}
  19. type="file"
  20. name={props.inputName}
  21. accept="image/*"
  22. hidden
  23. onChange={props.onChange}
  24. files={props.file}
  25. required={props.isRequired}
  26. />
  27. <label className={styles.imageInputLabel} htmlFor={props.inputName}>
  28. {props.buttonTitle}
  29. </label>
  30. </div>
  31. );
  32. };
  33. // Prop types for the ImageInput component
  34. ImageInput.propTypes = {
  35. /**
  36. * The name for the input
  37. */
  38. inputName: PropTypes.string.isRequired,
  39. /**
  40. * The button title
  41. */
  42. buttonTitle: PropTypes.string.isRequired,
  43. /**
  44. * The file that is associated with this input
  45. */
  46. file: PropTypes.object,
  47. /**
  48. * Indicates if this input is required as part of its associated form
  49. */
  50. isRequired: PropTypes.bool.isRequired,
  51. /**
  52. * On input change handler
  53. */
  54. onChange: PropTypes.func.isRequired,
  55. };
  56. export default ImageInput;