Abstracts away the input select

This commit is contained in:
Vazhin Tayeb 2021-01-15 14:41:39 +03:00
parent be69a64474
commit 23d40dfada
2 changed files with 23 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import Card from "./Card";
import Heading3 from "./Heading3";
import Button from "./Button";
import InputText from "./inputs/InputText";
import InputSelect from "./inputs/InputSelect";
const VehicleRegisterForm = () => {
const [model, setModel] = useState("");
@ -50,19 +51,18 @@ const VehicleRegisterForm = () => {
name="color"
onChangeEvent={(e) => setColor(e.target.value)}
/>
<label>Type: </label>
<select
<InputSelect
label="Type"
value={type}
name="type"
onChange={(e) => setType(e.target.value)}
>
<option value="1">Sedan</option>
<option value="2">SUV</option>
<option value="3">Pickup</option>
</select>
onChangeEvent={(e) => setType(e.target.value)}
options={[
{ value: "1", text: "Sedan" },
{ value: "2", text: "SUV" },
{ value: "3", text: "Pickup" },
]}
/>
</div>
<Button text="Register" onClickEvent={registerVehicle} />
</form>
</Card>

View File

@ -1,7 +1,18 @@
import React from "react";
const InputSelect = () => {
return <div></div>;
const InputSelect = ({ label, value, name, onChangeEvent, options }) => {
return (
<div>
<label>{label}</label>
<select value={value} name={name} onChange={onChangeEvent}>
{options.map((option, i) => (
<option key={i} value={option.value}>
{option.text}
</option>
))}
</select>
</div>
);
};
export default InputSelect;