aboutsummaryrefslogtreecommitdiffstats
path: root/public/projects/react-small-apps/apps/meme-generator/src/components/commons/Select.js
blob: 9517b235afce415bd16a397417aac8061bc74736 (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
import Option from "./Option";

function Select({ id, name, label, options, value, onChangeHandler }) {
  const optionsList = options.map((option) => {
    const optionValue = option.replace(" ", "-");
    return <Option key={optionValue} value={optionValue} body={option} />;
  });

  return (
    <>
      {label ? (
        <label className="form__label" htmlFor={id}>
          {label}
        </label>
      ) : (
        ""
      )}
      <select
        id={id}
        name={name}
        className="form__select"
        value={value}
        onChange={onChangeHandler}
      >
        {optionsList}
      </select>
    </>
  );
}

export default Select;