component: add Backdrop component

This commit is contained in:
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 (
<div <Aux>
className={classes.Modal} <Backdrop
style={{ show={props.show}
transform: props.show ? 'translateY(0)' : 'translateY(-100vh)' clicked={props.modalClosed}></Backdrop>
}}> <div
{props.children} className={classes.Modal}
</div> style={{
transform: props.show ? 'translateY(0)' : 'translateY(-100vh)',
opacity: props.show ? '1' : '0',
}}>
{props.children}
</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} />