aboutsummaryrefslogtreecommitdiff
path: root/src/components/CartFlyout.tsx
diff options
context:
space:
mode:
authorGravatar github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> 2025-06-05 12:45:04 +0000
committerGravatar github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> 2025-06-05 12:45:04 +0000
commitb4feb81355f9832c5698f81f8fdf33121e0189a5 (patch)
tree5b326153146a75a1e99ce8df0f04832b8cc79868 /src/components/CartFlyout.tsx
downloadastro-b4feb81355f9832c5698f81f8fdf33121e0189a5.tar.gz
astro-b4feb81355f9832c5698f81f8fdf33121e0189a5.tar.zst
astro-b4feb81355f9832c5698f81f8fdf33121e0189a5.zip
Sync from 0947a69192ad6820970902c7c951fb0cf31fcf4bexamples/with-nanostores
Diffstat (limited to 'src/components/CartFlyout.tsx')
-rw-r--r--src/components/CartFlyout.tsx28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/components/CartFlyout.tsx b/src/components/CartFlyout.tsx
new file mode 100644
index 000000000..98fd8cbfb
--- /dev/null
+++ b/src/components/CartFlyout.tsx
@@ -0,0 +1,28 @@
+import { useStore } from '@nanostores/preact';
+import { cartItems, isCartOpen } from '../cartStore';
+import styles from './CartFlyout.module.css';
+
+export default function CartFlyout() {
+ const $isCartOpen = useStore(isCartOpen);
+ const $cartItems = useStore(cartItems);
+
+ return (
+ <aside hidden={!$isCartOpen} className={styles.container}>
+ {Object.values($cartItems).length ? (
+ <ul className={styles.list} role="list">
+ {Object.values($cartItems).map((cartItem) => (
+ <li className={styles.listItem}>
+ <img className={styles.listItemImg} src={cartItem.imageSrc} alt={cartItem.name} />
+ <div>
+ <h3>{cartItem.name}</h3>
+ <p>Quantity: {cartItem.quantity}</p>
+ </div>
+ </li>
+ ))}
+ </ul>
+ ) : (
+ <p>Your cart is empty!</p>
+ )}
+ </aside>
+ );
+}