add meal item form component

This commit is contained in:
oscar 2023-03-18 12:25:19 +13:00
parent b2fcdfe8cd
commit cf733097b8
4 changed files with 46 additions and 1 deletions

View File

@ -32,6 +32,7 @@ const DUMMY_MEALS = [
const AvailableMeals = () => { const AvailableMeals = () => {
const mealsList = DUMMY_MEALS.map((meal) => ( const mealsList = DUMMY_MEALS.map((meal) => (
<MealItem <MealItem
id={meal.id}
key={meal.id} key={meal.id}
name={meal.name} name={meal.name}
description={meal.description} description={meal.description}

View File

@ -1,4 +1,5 @@
import classes from "./MealItem.module.css"; import classes from "./MealItem.module.css";
import MealItemForm from "./MealItemForm";
const MealItem = (props) => { const MealItem = (props) => {
const price = `$${props.price.toFixed(2)}`; const price = `$${props.price.toFixed(2)}`;
@ -11,7 +12,7 @@ const MealItem = (props) => {
<div className={classes.price}>{price}</div> <div className={classes.price}>{price}</div>
</div> </div>
<div> <div>
<MealItemForm id={props.id} />
</div> </div>
</li> </li>
); );

View File

@ -0,0 +1,23 @@
import classes from "./MealItemForm.module.css";
import Input from "../../UI/Input";
const MealItemForm = (props) => {
return (
<form className={classes.form}>
<Input
label="Amount"
input={{
id: "amount_" + props.id,
type: "number",
min: "1",
max: "5",
step: "1",
defaultValue: "1",
}}
/>
<button>+ Add</button>
</form>
);
};
export default MealItemForm;

View File

@ -0,0 +1,20 @@
.form {
text-align: right;
}
.form button {
font: inherit;
cursor: pointer;
background-color: #8a2b06;
border: 1px solid #8a2b06;
color: white;
padding: 0.25rem 2rem;
border-radius: 20px;
font-weight: bold;
}
.form button:hover,
.form button:active {
background-color: #641e03;
border-color: #641e03;
}