reka-ui
Version:
Vue port for Radix UI Primitives.
1 lines • 5.73 kB
Source Map (JSON)
{"version":3,"file":"CollapsibleContent.cjs","sources":["../../src/Collapsible/CollapsibleContent.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { PrimitiveProps } from '@/Primitive'\n\nexport interface CollapsibleContentProps extends PrimitiveProps {\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with Vue animation libraries.\n */\n forceMount?: boolean\n}\n\nexport type CollapsibleContentEmits = {\n contentFound: [void]\n}\n</script>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, onMounted, ref, watch } from 'vue'\nimport { injectCollapsibleRootContext } from './CollapsibleRoot.vue'\nimport {\n Primitive,\n} from '@/Primitive'\nimport { Presence } from '@/Presence'\nimport { useForwardExpose, useId } from '@/shared'\nimport { useEventListener } from '@vueuse/core'\n\ndefineOptions({\n inheritAttrs: false,\n})\n\nconst props = defineProps<CollapsibleContentProps>()\nconst emits = defineEmits<CollapsibleContentEmits>()\n\nconst rootContext = injectCollapsibleRootContext()\nrootContext.contentId ||= useId(undefined, 'reka-collapsible-content')\n\nconst presentRef = ref<InstanceType<typeof Presence>>()\nconst { forwardRef, currentElement } = useForwardExpose()\n\nconst width = ref(0)\nconst height = ref(0)\n\n// when opening we want it to immediately open to retrieve dimensions\n// when closing we delay `present` to retrieve dimensions before closing\nconst isOpen = computed(() => rootContext.open.value)\nconst isMountAnimationPrevented = ref(isOpen.value)\nconst currentStyle = ref<Record<string, string>>()\n\nwatch(\n () => [isOpen.value, presentRef.value?.present],\n async () => {\n await nextTick()\n const node = currentElement.value\n if (!node)\n return\n currentStyle.value = currentStyle.value || {\n transitionDuration: node.style.transitionDuration,\n animationName: node.style.animationName,\n }\n // block any animations/transitions so the element renders at its full dimensions\n node.style.transitionDuration = '0s'\n node.style.animationName = 'none'\n\n // get width and height from full dimensions\n const rect = node.getBoundingClientRect()\n height.value = rect.height\n width.value = rect.width\n\n // kick off any animations/transitions that were originally set up if it isn't the initial mount\n if (!isMountAnimationPrevented.value) {\n node.style.transitionDuration = currentStyle.value.transitionDuration\n node.style.animationName = currentStyle.value.animationName\n }\n },\n {\n immediate: true,\n },\n)\n\nconst skipAnimation = computed(() => isMountAnimationPrevented.value && rootContext.open.value)\n\nonMounted(() => {\n requestAnimationFrame(() => {\n isMountAnimationPrevented.value = false\n })\n})\n\nuseEventListener(currentElement, 'beforematch', (ev) => {\n requestAnimationFrame(() => {\n rootContext.onOpenToggle()\n emits('contentFound')\n })\n})\n</script>\n\n<template>\n <Presence\n v-slot=\"{ present }\"\n ref=\"presentRef\"\n :present=\"forceMount || rootContext.open.value\"\n :force-mount=\"true\"\n >\n <Primitive\n v-bind=\"$attrs\"\n :id=\"rootContext.contentId\"\n :ref=\"forwardRef\"\n :as-child=\"props.asChild\"\n :as=\"as\"\n :hidden=\"!present ? rootContext.unmountOnHide.value ? '' : 'until-found' : undefined\"\n :data-state=\"skipAnimation ? undefined : rootContext.open.value ? 'open' : 'closed'\"\n :data-disabled=\"rootContext.disabled?.value ? '' : undefined\"\n :style=\"{\n [`--reka-collapsible-content-height`]: `${height}px`,\n [`--reka-collapsible-content-width`]: `${width}px`,\n }\"\n >\n <slot v-if=\"rootContext.unmountOnHide.value ? present : true\" />\n </Primitive>\n </Presence>\n</template>\n"],"names":["injectCollapsibleRootContext","useId","ref","useForwardExpose","computed","watch","nextTick","onMounted","useEventListener"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAA,MAAM,KAAQ,GAAA,OAAA;AACd,IAAA,MAAM,KAAQ,GAAA,MAAA;AAEd,IAAA,MAAM,cAAcA,wDAA6B,EAAA;AACjD,IAAY,WAAA,CAAA,SAAA,KAAcC,kBAAM,CAAA,MAAA,EAAW,0BAA0B,CAAA;AAErE,IAAA,MAAM,aAAaC,OAAmC,EAAA;AACtD,IAAA,MAAM,EAAE,UAAA,EAAY,cAAe,EAAA,GAAIC,wCAAiB,EAAA;AAExD,IAAM,MAAA,KAAA,GAAQD,QA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