Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cart page #19

Merged
merged 18 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions client/src/App.tsx
larkinds marked this conversation as resolved.
Show resolved Hide resolved
larkinds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
import { useState } from "react";
import Cart from "./pages/cart/Cart";
import cartStyles from "./pages/cart/cart.module.css";

function App() {
const [isCartOpen, setIsCartOpen] = useState(false);
return (
<>
{/* TODO: Add button to main navigation */}
<button
className={cartStyles.cartBtn}
onClick={() => setIsCartOpen(true)}
>
🛒
</button>
<Cart isOpen={isCartOpen} onClose={() => setIsCartOpen(false)} />
</>
);
export default function App() {
return <div></div>;
}

export default App;
20 changes: 6 additions & 14 deletions client/src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ type ModalProps = {
isOpen: boolean;
onClose: () => void;
children: React.ReactNode;
className?: string;
containerClassNames?: string;
buttonClassNames?: string;
};

export default function Modal({
onClose,
isOpen,
containerClassNames,
buttonClassNames,
children,
className,
}: ModalProps) {
const modalRef = useRef<HTMLDialogElement | null>(null);

Expand All @@ -27,18 +29,8 @@ export default function Modal({
}
}, [isOpen]);
return (
<dialog ref={modalRef} className={className}>
<button
onClick={onClose}
style={{
border: "none",
backgroundColor: "inherit",
position: "absolute",
right: "1rem",
marginBottom: "1rem",
cursor: "pointer",
}}
>
<dialog ref={modalRef} className={containerClassNames}>
<button onClick={onClose} className={buttonClassNames}>
X
</button>
{children}
Expand Down
1 change: 0 additions & 1 deletion client/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
// import "./index.css";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
Expand Down
7 changes: 6 additions & 1 deletion client/src/pages/cart/Cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ export default function Cart({ isOpen, onClose }: CartProps) {
}

return (
<Modal isOpen={isOpen} onClose={onClose} className={styles.modal}>
<Modal
isOpen={isOpen}
onClose={onClose}
containerClassNames={styles.modal}
buttonClassNames={styles.modalCloseBtn}
>
{/* Currently getting data from a constant but will eventually either need to make this dynamic */}
{items.map((item) => (
<CartItem key={item.id}>
Expand Down
10 changes: 10 additions & 0 deletions client/src/pages/cart/CartBtn.tsx
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my gosh, this icon is so cute!

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import styles from "./cart.module.css";

// TODO: This eventually needs to be part of a header component
export default function CartBtn({ handleClick }: { handleClick: () => void }) {
return (
<button className={styles.cartBtn} onClick={handleClick}>
🛒
</button>
);
}
14 changes: 14 additions & 0 deletions client/src/pages/cart/CartPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useState } from "react";
import Cart from "./Cart";
import CartBtn from "./CartBtn";

export default function CartPage() {
const [isCartOpen, setIsCartOpen] = useState(false);

return (
<>
<CartBtn handleClick={() => setIsCartOpen(true)} />
<Cart isOpen={isCartOpen} onClose={() => setIsCartOpen(false)} />
</>
);
}
9 changes: 9 additions & 0 deletions client/src/pages/cart/cart.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
left: inherit;
}

.modalCloseBtn {
border: none;
background-color: inherit;
position: absolute;
right: 1rem;
margin-bottom: 1rem;
cursor: pointer;
}

.cartBtn {
position: absolute;
top: 0;
Expand Down