{ "version": 3, "sources": ["../../assets/scripts/store/components/AnimateHeight.tsx"], "sourcesContent": ["import type { PropsWithChildren} from 'react';\r\nimport React, { useEffect, useRef, useState } from 'react';\r\n\r\ninterface IProps {\r\n isOpen: boolean;\r\n duration?: number;\r\n}\r\n\r\nexport default function AnimateHeight(props: PropsWithChildren) {\r\n const ref = useRef(null);\r\n const [isOpen, setIsOpen] = useState(props.isOpen);\r\n\r\n useEffect(() => {\r\n if (!ref.current) return;\r\n if (isOpen === props.isOpen) return;\r\n // setIsOpen(props.isOpen);\r\n\r\n const duration = props.duration || 300;\r\n const elStyles = window.getComputedStyle(ref.current);\r\n const elHeight = parseFloat(elStyles.getPropertyValue('height'));\r\n const elPaddingTop = parseFloat(elStyles.getPropertyValue('padding-top'));\r\n const elPaddingBottom = parseFloat(elStyles.getPropertyValue('padding-bottom'));\r\n const elMarginTop = parseFloat(elStyles.getPropertyValue('margin-top'));\r\n const elMarginBottom = parseFloat(elStyles.getPropertyValue('margin-bottom'));\r\n\r\n const stepHeight = elHeight / duration;\r\n const stepPaddingTop = elPaddingTop / duration;\r\n const stepPaddingBottom = elPaddingBottom / duration;\r\n const stepMarginTop = elMarginTop / duration;\r\n const stepMarginBottom = elMarginBottom / duration;\r\n\r\n let start: number | undefined;\r\n\r\n window.requestAnimationFrame(animationStep);\r\n\r\n function animationStep(timestamp: number) {\r\n if (start === undefined) start = timestamp;\r\n\r\n const elapsed = timestamp - start;\r\n if (props.isOpen) {\r\n ref.current!.style.height = stepHeight * elapsed + 'px';\r\n ref.current!.style.paddingTop = stepPaddingTop * elapsed + 'px';\r\n ref.current!.style.paddingBottom = stepPaddingBottom * elapsed + 'px';\r\n ref.current!.style.marginTop = stepMarginTop * elapsed + 'px';\r\n ref.current!.style.marginBottom = stepMarginBottom * elapsed + 'px';\r\n } else {\r\n ref.current!.style.height = elHeight - stepHeight * elapsed + 'px';\r\n ref.current!.style.paddingTop = elPaddingTop - stepPaddingTop * elapsed + 'px';\r\n ref.current!.style.paddingBottom = elPaddingBottom - stepPaddingBottom * elapsed + 'px';\r\n ref.current!.style.marginTop = elMarginTop - stepMarginTop * elapsed + 'px';\r\n ref.current!.style.marginBottom = elMarginBottom - stepMarginBottom * elapsed + 'px';\r\n }\r\n\r\n if (elapsed >= duration) {\r\n ref.current!.style.height = '';\r\n ref.current!.style.paddingTop = '';\r\n ref.current!.style.paddingBottom = '';\r\n ref.current!.style.marginTop = '';\r\n ref.current!.style.marginBottom = '';\r\n ref.current!.style.overflow = '';\r\n setIsOpen(props.isOpen);\r\n } else {\r\n window.requestAnimationFrame(animationStep);\r\n }\r\n }\r\n }, [isOpen, props.duration, props.isOpen]);\r\n\r\n return (\r\n
\r\n {props.children}\r\n
\r\n );\r\n}\r\n"], "mappings": ";;;;;;;;;AACA,mBAAmD;AAmE/C;AA5DW,SAAR,cAA+B,OAAkC;AACtE,QAAM,UAAM,qBAAuB,IAAI;AACvC,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAS,MAAM,MAAM;AAEjD,8BAAU,MAAM;AACd,QAAI,CAAC,IAAI,QAAS;AAClB,QAAI,WAAW,MAAM,OAAQ;AAG7B,UAAM,WAAW,MAAM,YAAY;AACnC,UAAM,WAAW,OAAO,iBAAiB,IAAI,OAAO;AACpD,UAAM,WAAW,WAAW,SAAS,iBAAiB,QAAQ,CAAC;AAC/D,UAAM,eAAe,WAAW,SAAS,iBAAiB,aAAa,CAAC;AACxE,UAAM,kBAAkB,WAAW,SAAS,iBAAiB,gBAAgB,CAAC;AAC9E,UAAM,cAAc,WAAW,SAAS,iBAAiB,YAAY,CAAC;AACtE,UAAM,iBAAiB,WAAW,SAAS,iBAAiB,eAAe,CAAC;AAE5E,UAAM,aAAa,WAAW;AAC9B,UAAM,iBAAiB,eAAe;AACtC,UAAM,oBAAoB,kBAAkB;AAC5C,UAAM,gBAAgB,cAAc;AACpC,UAAM,mBAAmB,iBAAiB;AAE1C,QAAI;AAEJ,WAAO,sBAAsB,aAAa;AAE1C,aAAS,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