overlay
This commit is contained in:
parent
0945ab2e2f
commit
bd28f11b59
@ -28,6 +28,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="overlays"></div>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
|
@ -1,8 +1,11 @@
|
||||
import Header from "./components/Layout/Header"
|
||||
import Meals from "./components/Meals/Meals"
|
||||
import Cart from "./components/Cart/Cart"
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<>
|
||||
<Cart />
|
||||
<Header />
|
||||
<main>
|
||||
<Meals />
|
||||
|
31
ordering/src/components/Cart/Cart.js
Normal file
31
ordering/src/components/Cart/Cart.js
Normal file
@ -0,0 +1,31 @@
|
||||
import React from "react"
|
||||
import classes from "./Cart.module.css"
|
||||
import Modal from "../UI/Modal"
|
||||
|
||||
function Cart(props) {
|
||||
const cartItems = (
|
||||
<ul className={classes["cart-items"]}>
|
||||
{[{ id: "c1", name: "Sushi", amount: 2, price: 12.99 }].map(
|
||||
(item) => (
|
||||
<li>{item.name}</li>
|
||||
)
|
||||
)}
|
||||
</ul>
|
||||
)
|
||||
|
||||
return (
|
||||
<Modal>
|
||||
{cartItems}
|
||||
<div className={classes.total}>
|
||||
<span>Total Amount</span>
|
||||
<span>35.62</span>
|
||||
</div>
|
||||
<div className={classes.actions}>
|
||||
<button className={classes['button--alt']}>Close</button>
|
||||
<button className={classes.button}>Order</button>
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default Cart
|
30
ordering/src/components/UI/Modal.js
Normal file
30
ordering/src/components/UI/Modal.js
Normal file
@ -0,0 +1,30 @@
|
||||
import React from "react"
|
||||
import ReactDOM from "react-dom"
|
||||
import classes from "./Modal.module.css"
|
||||
|
||||
const Backdrop = (props) => {
|
||||
return <div className={classes.backdrop} />
|
||||
}
|
||||
const ModalOverlay = (props) => {
|
||||
return (
|
||||
<div className={classes.modal}>
|
||||
<div className={classes.content}>{props.children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const portalElement = document.getElementById("overlays")
|
||||
|
||||
function Modal(props) {
|
||||
return (
|
||||
<>
|
||||
{ReactDOM.createPortal(<Backdrop />, portalElement)}
|
||||
{ReactDOM.createPortal(
|
||||
<ModalOverlay>{props.children}</ModalOverlay>,
|
||||
portalElement
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Modal
|
Loading…
Reference in New Issue
Block a user