diff options
Diffstat (limited to 'examples/with-nanostores/src/components/CartFlyout.tsx')
-rw-r--r-- | examples/with-nanostores/src/components/CartFlyout.tsx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/with-nanostores/src/components/CartFlyout.tsx b/examples/with-nanostores/src/components/CartFlyout.tsx new file mode 100644 index 000000000..29fd7a882 --- /dev/null +++ b/examples/with-nanostores/src/components/CartFlyout.tsx @@ -0,0 +1,26 @@ +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> + ); +} |