aboutsummaryrefslogtreecommitdiff
path: root/src/components/AddToCartForm.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/AddToCartForm.tsx')
-rw-r--r--src/components/AddToCartForm.tsx18
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>;
+}