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,eAC1CzB,IAEAR,SAAAA,IACJ,IAUKD,EACC,C","sources":["webpack://Kristiania.Web/./Features/Partials/Collapse/useCollapse.ts","webpack://Kristiania.Web/./Features/Partials/Collapse/Collapse.tsx"],"sourcesContent":["import type { RefObject } from 'react';\nimport { useEffect, useState } from 'react';\nimport { useIsMounted } from '~/Utils/Hooks/useIsMounted';\n\nexport interface UseCollapseProps {\n isOpen: boolean;\n content: RefObject;\n}\n\n// In case of nested collapse components, we need to inherit the visibility from the parent so that\n// focusable children inside expanded collapses nested inside collapsed collapses are not focusable.\n// Unfortunately, jest is not able to simulate this behavior thus we are not able to test it.\ntype InheritVisibility = undefined;\n\ntype Visibility = 'hidden' | InheritVisibility;\ntype Overflow = 'hidden' | 'visible';\n\nconst getHeight = (content: RefObject) => {\n if (content && content.current && content.current.scrollHeight) {\n return `${content.current.scrollHeight}px`;\n }\n\n return '0px';\n};\n\nexport const useCollapse = (props: UseCollapseProps) => {\n const { isOpen, content } = props;\n\n const [height, setHeight] = useState(isOpen ? 'auto' : '0');\n const [overflow, setOverflow] = useState(isOpen ? 'visible' : 'hidden');\n const [visibility, setVisibility] = useState(isOpen ? undefined : 'hidden');\n const isMounted = useIsMounted();\n\n const toggleStyles = () => {\n if (isOpen) {\n setHeight('auto');\n setOverflow('visible');\n setVisibility(undefined);\n } else {\n setVisibility('hidden');\n }\n };\n\n useEffect(() => {\n if (isOpen) {\n setVisibility(undefined);\n\n if (!isMounted) {\n setHeight('auto');\n setOverflow('visible');\n } else {\n setHeight(getHeight(content));\n }\n } else if (isMounted) {\n setHeight(getHeight(content));\n\n // The magic:\n // Setting collapsed style after setting height to enable smooth transition based on height.\n // It must be wrapped with setTimeout to ensure that the state update is not batched with the height update.\n setTimeout(() => {\n window.requestAnimationFrame(() => {\n setOverflow('hidden');\n setHeight('0');\n });\n });\n }\n }, [isOpen]);\n\n return {\n toggleStyles,\n style: {\n overflow,\n visibility,\n height,\n },\n };\n};\n","/*\n * Based on: https://github.com/SparebankenVest/react-css-collapse\n */\n\nimport * as React from 'react';\nimport type { AriaAttributes } from 'react';\nimport { useCollapse } from './useCollapse';\n\nexport interface CollapseProps extends AriaAttributes {\n children: React.ReactNode;\n isOpen?: boolean;\n onRest?: () => void;\n className?: string;\n withMarginTransition?: boolean;\n}\n\nexport const Collapse: React.FC = props => {\n const { children, onRest, isOpen = false, className, withMarginTransition, ...rest } = props;\n\n const content = React.useRef(null);\n\n const { toggleStyles, style } = useCollapse({\n isOpen,\n content,\n });\n\n const onTransitionEnd = (event: React.TransitionEvent) => {\n if (event.target === content.current && event.propertyName === 'height') {\n toggleStyles();\n\n onRest?.();\n }\n };\n\n const styles = {\n willChange: withMarginTransition ? 'height, margin' : 'height',\n ...style,\n };\n\n return (\n
\n {children}\n
\n );\n};\n"],"names":["getHeight","content","current","scrollHeight","concat","Collapse","props","children","onRest","isOpen","className","withMarginTransition","rest","_objectWithoutProperties","_excluded","React","toggleStyles","style","height","setHeight","useState","overflow","setOverflow","visibility","setVisibility","undefined","isMounted","useIsMounted","useEffect","setTimeout","window","requestAnimationFrame","useCollapse","styles","_objectSpread","willChange","_extends","ref","onTransitionEnd","event","target","propertyName"],"sourceRoot":""}