Skip to main content

8.16 Outputting Multiple Build Controls

New BuildControls.js

BuildControls.js
import React from "react";
import BuildControl from "./BuildControl/BuildControl";
import classes from "./BuildControls.module.css";
const controls = [
{ label: "Salad", type: "salad" },
{ label: "Bacon", type: "bacon" },
{ label: "Cheese", type: "cheese" },
{ label: "Meat", type: "meat" },
];

const buildControls = (props) => (
<div className={classes.BuildControls}>
{controls.map((ctrl) => (
<BuildControl key={ctrl.label} label={ctrl.label} />
))}
</div>
);

export default buildControls;

New BuildControls.module.css

BuildControls.module.css
.BuildControls {
width: 100%;
background-color: #cf8f2e;
display: flex;
flex-flow: column;
align-items: center;
box-shadow: 0 2px 1px #ccc;
margin: auto;
padding: 10px 0;
}

BurgerBuilder.js

BurgerBuilder.js
import React, { Component, Fragment } from "react";
import BuildControls from "../components/Burger/BuildControls/BuildControls";
import Burger from "../components/Burger/Burger";

class BurgerBuilder extends Component {
// constructor(props) {
// super(props);
// this.state = {...}
// }
state = {
ingredients: {
salad: 0,
bacon: 0,
cheese: 0,
meat: 0,
},
};
render() {
return (
<Fragment>
<Burger ingredients={this.state.ingredients} />
<BuildControls />
</Fragment>
);
}
}
export default BurgerBuilder;