diff options
author | 2025-06-05 12:45:04 +0000 | |
---|---|---|
committer | 2025-06-05 12:45:04 +0000 | |
commit | b4feb81355f9832c5698f81f8fdf33121e0189a5 (patch) | |
tree | 5b326153146a75a1e99ce8df0f04832b8cc79868 /src/components/AddToCartForm.tsx | |
download | astro-b4feb81355f9832c5698f81f8fdf33121e0189a5.tar.gz astro-b4feb81355f9832c5698f81f8fdf33121e0189a5.tar.zst astro-b4feb81355f9832c5698f81f8fdf33121e0189a5.zip |
Sync from 0947a69192ad6820970902c7c951fb0cf31fcf4bexamples/with-nanostores
Diffstat (limited to 'src/components/AddToCartForm.tsx')
-rw-r--r-- | src/components/AddToCartForm.tsx | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/components/AddToCartForm.tsx b/src/components/AddToCartForm.tsx new file mode 100644 index 000000000..7498443f6 --- /dev/null +++ b/src/components/AddToCartForm.tsx @@ -0,0 +1,18 @@ +import { isCartOpen, addCartItem } from '../cartStore'; +import type { CartItemDisplayInfo } from '../cartStore'; +import type { ComponentChildren } from 'preact'; + +type Props = { + item: CartItemDisplayInfo; + children: ComponentChildren; +}; + +export default function AddToCartForm({ item, children }: Props) { + function addToCart(e: SubmitEvent) { + e.preventDefault(); + isCartOpen.set(true); + addCartItem(item); + } + + return <form onSubmit={addToCart}>{children}</form>; +} |