component: show/hide Modal with animation

master
oscarzhou 2020-12-12 19:22:54 +13:00
parent 8ff6175355
commit aa5fc21a5d
3 changed files with 29 additions and 18 deletions

View File

@ -22,7 +22,8 @@ const buildControls = (props) => (
disabled={props.disabled[ctrl.type]} /> disabled={props.disabled[ctrl.type]} />
))} ))}
<button className={classes.OrderButton} <button className={classes.OrderButton}
disabled={!props.purchasable}>ORDER NOW</button> disabled={!props.purchasable}
onClick={props.ordered}>ORDER NOW</button>
</div> </div>
) )

View File

@ -4,7 +4,11 @@ import classes from './Modal.css';
const modal = (props) => { const modal = (props) => {
return ( return (
<div className={classes.Modal}> <div
className={classes.Modal}
style={{
transform: props.show ? 'translateY(0)' : 'translateY(-100vh)'
}}>
{props.children} {props.children}
</div> </div>
); );

View File

@ -24,6 +24,7 @@ class BurgerBuilder extends Component {
}, },
totalPrice: 0, totalPrice: 0,
purchasable: false, purchasable: false,
purchasing: false,
} }
updatePurchaseState(ingredients) { updatePurchaseState(ingredients) {
@ -77,6 +78,10 @@ class BurgerBuilder extends Component {
this.updatePurchaseState(updatedIngredients); this.updatePurchaseState(updatedIngredients);
} }
purchaseHandler = () => {
this.setState({ purchasing: true });
}
render() { render() {
const disabledInfo = { const disabledInfo = {
...this.state.ingredients ...this.state.ingredients
@ -88,13 +93,14 @@ class BurgerBuilder extends Component {
return ( return (
<Aux> <Aux>
<Modal> <Modal show={this.state.purchasing}>
<OrderSummary ingredients={this.state.ingredients}></OrderSummary> <OrderSummary ingredients={this.state.ingredients}></OrderSummary>
</Modal> </Modal>
<Burger ingredients={this.state.ingredients} /> <Burger ingredients={this.state.ingredients} />
<BuildControls <BuildControls
ingredientAdded={this.addIngredientHandler} ingredientAdded={this.addIngredientHandler}
ingredientRemoved={this.removeIngredientHandler} ingredientRemoved={this.removeIngredientHandler}
ordered={this.purchaseHandler}
disabled={disabledInfo} disabled={disabledInfo}
purchasable={this.state.purchasable} purchasable={this.state.purchasable}
price={this.state.totalPrice} /> price={this.state.totalPrice} />