component: add Backdrop component

master
oscarzhou 2020-12-12 20:31:01 +13:00
parent aa5fc21a5d
commit 670aeeccdf
4 changed files with 45 additions and 8 deletions

View File

@ -0,0 +1,9 @@
.Backdrop {
width: 100%;
height: 100%;
position: fixed;
z-index: 100;
left: 0;
top: 0;
background-color: rgba(0, 0, 0, 0.5);
}

View File

@ -0,0 +1,13 @@
import React from 'react';
import classes from './Backdrop.css';
const backdrop = (props) => {
return (
props.show ?
<div className={classes.Backdrop}
onClick={props.clicked}>
</div> : null
)
}
export default backdrop;

View File

@ -1,16 +1,25 @@
import React from 'react'; import React from 'react';
import Aux from '../../../hoc/Auxiliary';
import Backdrop from '../Backdrop/Backdrop';
import classes from './Modal.css'; import classes from './Modal.css';
const modal = (props) => { const modal = (props) => {
return ( return (
<Aux>
<Backdrop
show={props.show}
clicked={props.modalClosed}></Backdrop>
<div <div
className={classes.Modal} className={classes.Modal}
style={{ style={{
transform: props.show ? 'translateY(0)' : 'translateY(-100vh)' transform: props.show ? 'translateY(0)' : 'translateY(-100vh)',
opacity: props.show ? '1' : '0',
}}> }}>
{props.children} {props.children}
</div> </div>
</Aux>
); );
}; };

View File

@ -82,6 +82,10 @@ class BurgerBuilder extends Component {
this.setState({ purchasing: true }); this.setState({ purchasing: true });
} }
purchaseCancelHandler = () => {
this.setState({ purchasing: false });
}
render() { render() {
const disabledInfo = { const disabledInfo = {
...this.state.ingredients ...this.state.ingredients
@ -93,7 +97,9 @@ class BurgerBuilder extends Component {
return ( return (
<Aux> <Aux>
<Modal show={this.state.purchasing}> <Modal
show={this.state.purchasing}
modalClosed={this.purchaseCancelHandler}>
<OrderSummary ingredients={this.state.ingredients}></OrderSummary> <OrderSummary ingredients={this.state.ingredients}></OrderSummary>
</Modal> </Modal>
<Burger ingredients={this.state.ingredients} /> <Burger ingredients={this.state.ingredients} />