aboutsummaryrefslogtreecommitdiffstats
path: root/public/projects/react-small-apps/apps/meme-generator/src/components/commons/Input.js
blob: 68e4e77cea1889f94306b40d02e992ac0e68d0f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { forwardRef } from "react";

function Input(
  {
    label,
    id,
    name,
    type = "text",
    value,
    onChangeHandler,
    onBlurHandler,
    additionalClasses = "",
  },
  ref
) {
  const classNames = `form__input ${additionalClasses}`;

  return (
    <>
      {label ? (
        <label className="form__label" htmlFor={id}>
          {label}
        </label>
      ) : (
        ""
      )}
      <input
        id={id}
        name={name}
        ref={ref}
        type={type}
        value={value}
        onChange={onChangeHandler}
        onBlur={onBlurHandler}
        className={classNames}
      />
    </>
  );
}

export default forwardRef(Input);