{ "version": 3, "sources": ["../../javascript/components/QuantityPicker.tsx", "../../javascript/components/AddToBasket.tsx"], "sourcesContent": ["import React, { useState, useEffect, useRef } from \"react\"\n\ninterface QuantityPickerProps {\n quantity: number\n setQuantity: (quantity: number) => void\n variantId: number | null\n setCartQuantity?: (quantityValue: number) => void\n disabled?: boolean\n}\n\nconst QuantityPicker: React.FC = ({\n quantity,\n setQuantity,\n variantId,\n disabled = false,\n setCartQuantity = () => {}\n}) => {\n const updateQuantity = (amount: number) => {\n if (disabled) return\n const newAmount = quantity + amount\n setQuantity(newAmount >= 0 ? newAmount : 0)\n }\n\n const ref = useRef(null)\n\n const [isFreeForm, setIsFreeForm] = useState(false)\n\n const variantQuantityFormId = `variant-${variantId}`\n\n const inputClasses = disabled\n ? \"quantity-picker__amount--input quantity-picker__amount--input--disabled\"\n : \"quantity-picker__amount--input\"\n\n const buttonClasses = disabled\n ? \"quantity-picker__button quantity-picker__button--disabled\"\n : \"quantity-picker__button\"\n\n const freeFormQuantity = (event: React.ChangeEvent) => {\n const newQuantity = parseInt(event.target.value)\n setQuantity(newQuantity)\n setIsFreeForm(true)\n }\n\n const handleKeyPress = (event: React.KeyboardEvent) => {\n // Only applies to non-selected variants on CPP\n if (event.key === \"Enter\" && quantity > 0) {\n setCartQuantity(quantity)\n setIsFreeForm(false)\n }\n }\n\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n // Only applies to non-selected variants on CPP\n if (ref?.current?.contains(event.target as Node)) return\n if (isFreeForm && quantity > 0) {\n setCartQuantity(quantity)\n setIsFreeForm(false)\n }\n }\n document.addEventListener(\"click\", handleClickOutside)\n return () => {\n document.removeEventListener(\"click\", handleClickOutside)\n }\n }, [quantity, setCartQuantity, isFreeForm])\n\n return (\n
\n {\n updateQuantity(-1)\n\n if (isFreeForm) {\n setCartQuantity(quantity - 1)\n setIsFreeForm(false)\n } else {\n setCartQuantity(quantity - 1)\n }\n }}\n >\n \u2212\n \n
\n \n
\n {\n updateQuantity(1)\n if (isFreeForm) {\n setCartQuantity(quantity + 1)\n setIsFreeForm(false)\n } else {\n setCartQuantity(quantity + 1)\n }\n }}\n >\n +\n \n
\n )\n}\n\nexport default QuantityPicker\n", "import React, { useState } from \"react\"\n\nimport TranslationContext, { Translations } from \"./TranslationContext\"\nimport ActionButton from \"./ActionButton\"\n\nconst AddToBasket = ({\n onClick = () => {},\n disabled = false,\n fullWidth = false,\n inStock = true,\n hoverable = false,\n disabledText = null\n}) => {\n const [buttonText, setButtonText] = useState()\n\n const handleClick = async (translations: Translations) => {\n onClick()\n setButtonText(translations.added)\n await new Promise((resolve) => setTimeout(resolve, 1500))\n setButtonText(translations.add_to_basket)\n }\n\n const getButtonText = (translations: Translations) => {\n if (!inStock) return translations.out_of_stock\n return buttonText ? buttonText : translations.add_to_basket\n }\n\n return (\n \n {(translations: Translations) => (\n
\n handleClick(translations)}\n disabled={disabled}\n fullWidth={fullWidth}\n hoverable={hoverable}\n />\n
\n )}\n
\n )\n}\n\nexport default AddToBasket\n"], "mappings": "2OAAA,IAAAA,EAAmD,SAU7CC,EAAgD,CAAC,CACrD,SAAAC,EACA,YAAAC,EACA,UAAAC,EACA,SAAAC,EAAW,GACX,gBAAAC,EAAkB,IAAM,CAAC,CAC3B,IAAM,CACJ,IAAMC,EAAkBC,GAAmB,CACzC,GAAIH,EAAU,OACd,IAAMI,EAAYP,EAAWM,EAC7BL,EAAYM,GAAa,EAAIA,EAAY,CAAC,CAC5C,EAEMC,KAAM,UAAuB,IAAI,EAEjC,CAACC,EAAYC,CAAa,KAAI,YAAS,EAAK,EAE5CC,EAAwB,WAAWT,IAEnCU,EAAeT,EACjB,0EACA,iCAEEU,EAAgBV,EAClB,4DACA,0BAEEW,EAAoBC,GAA+C,CACvE,IAAMC,EAAc,SAASD,EAAM,OAAO,KAAK,EAC/Cd,EAAYe,CAAW,EACvBN,EAAc,EAAI,CACpB,EAEMO,EAAkBF,GAAiD,CAEnEA,EAAM,MAAQ,SAAWf,EAAW,IACtC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e,IACjB,IAAM,CACJ,GAAM,CAACC,EAAYC,CAAa,KAAI,YAAiB,EAE/CC,EAAqBC,GAA+BC,EAAA,wBACxDV,EAAQ,EACRO,EAAcE,EAAa,KAAK,EAChC,MAAM,IAAI,QAASE,GAAY,WAAWA,EAAS,IAAI,CAAC,EACxDJ,EAAcE,EAAa,aAAa,CAC1C,GAEMG,EAAiBH,GAChBN,EACEG,GAA0BG,EAAa,cADzBA,EAAa,aAIpC,OACE,EAAAI,QAAA,cAACC,EAAmB,SAAnB,KACGL,GACA,EAAAI,QAAA,cAAC,OAAI,UAAU,mCACb,EAAAA,QAAA,cAACE,EAAA,CACC,KACEd,GAAY,CAAC,CAACI,EACVA,EACAO,EAAcH,CAAY,EAEhC,eAAc,GACd,QAAS,IAAMD,EAAYC,CAAY,EACvC,SAAUR,EACV,UAAWC,EACX,UAAWE,EACb,CACF,CAEJ,CAEJ,EAEOY,EAAQjB", "names": ["import_react", "QuantityPicker", "quantity", "setQuantity", "variantId", "disabled", "setCartQuantity", "updateQuantity", "amount", "newAmount", "ref", "isFreeForm", "setIsFreeForm", "variantQuantityFormId", "inputClasses", "buttonClasses", "freeFormQuantity", "event", "newQuantity", "handleKeyPress", "handleClickOutside", "_a", "React", "QuantityPicker_default", "import_react", "AddToBasket", "onClick", "disabled", "fullWidth", "inStock", "hoverable", "disabledText", "buttonText", "setButtonText", "handleClick", "translations", "__async", "resolve", "getButtonText", "React", "TranslationContext", "ActionButton_default", "AddToBasket_default"] }