UNPKG

reka-ui

Version:

Vue port for Radix UI Primitives.

1 lines 4.27 kB
{"version":3,"file":"AccordionRoot.cjs","sources":["../../src/Accordion/AccordionRoot.vue"],"sourcesContent":["<script lang=\"ts\">\nimport type { ComputedRef, Ref } from 'vue'\nimport type { PrimitiveProps } from '@/Primitive'\nimport type { AcceptableValue, DataOrientation, Direction, SingleOrMultipleProps, SingleOrMultipleType } from '@/shared/types'\nimport { createContext, useDirection, useForwardExpose } from '@/shared'\n\nexport interface AccordionRootProps<T = string | string[]>\n extends PrimitiveProps, SingleOrMultipleProps<T> {\n /**\n * When type is \"single\", allows closing content when clicking trigger for an open item.\n * When type is \"multiple\", this prop has no effect.\n *\n * @defaultValue false\n */\n collapsible?: boolean\n\n /**\n * When `true`, prevents the user from interacting with the accordion and all its items\n *\n * @defaultValue false\n */\n disabled?: boolean\n\n /**\n * The reading direction of the accordion when applicable. If omitted, assumes LTR (left-to-right) reading mode.\n *\n * @defaultValue \"ltr\"\n */\n dir?: Direction\n\n /**\n * The orientation of the accordion.\n *\n * @defaultValue \"vertical\"\n */\n orientation?: DataOrientation\n\n /**\n * When `true`, the element will be unmounted on closed state.\n *\n * @defaultValue `true`\n */\n unmountOnHide?: boolean\n}\n\nexport type AccordionRootEmits<T extends SingleOrMultipleType = SingleOrMultipleType> = {\n /**\n * Event handler called when the expanded state of an item changes\n */\n 'update:modelValue': [value: (T extends 'single' ? string : string[]) | undefined]\n}\n\nexport type AccordionRootContext<P extends AccordionRootProps> = {\n disabled: Ref<P['disabled']>\n direction: Ref<P['dir']>\n orientation: P['orientation']\n parentElement: Ref<HTMLElement | undefined>\n changeModelValue: (value: string) => void\n isSingle: ComputedRef<boolean>\n modelValue: Ref<AcceptableValue | AcceptableValue[] | undefined>\n collapsible: boolean\n unmountOnHide: Ref<boolean>\n}\n\nexport const [injectAccordionRootContext, provideAccordionRootContext]\n = createContext<AccordionRootContext<AccordionRootProps>>('AccordionRoot')\n</script>\n\n<script setup lang=\"ts\" generic=\"T extends (string | string[]), ExplicitType extends SingleOrMultipleType\">\nimport { Primitive } from '@/Primitive'\nimport { useSingleOrMultipleValue } from '@/shared/useSingleOrMultipleValue'\nimport { toRefs } from 'vue'\n\nconst props = withDefaults(defineProps<AccordionRootProps<T>>(), {\n disabled: false,\n orientation: 'vertical',\n collapsible: false,\n unmountOnHide: true,\n})\n\nconst emits = defineEmits<AccordionRootEmits<ExplicitType>>()\n\ndefineSlots<{\n default: (props: {\n /** Current active value */\n modelValue: typeof modelValue.value\n }) => any\n}>()\n\nconst { dir, disabled, unmountOnHide } = toRefs(props)\nconst direction = useDirection(dir)\n\nconst { modelValue, changeModelValue, isSingle } = useSingleOrMultipleValue(props, emits)\n\nconst { forwardRef, currentElement: parentElement } = useForwardExpose()\n\nprovideAccordionRootContext({\n disabled,\n direction,\n orientation: props.orientation,\n parentElement,\n isSingle,\n collapsible: props.collapsible,\n modelValue,\n changeModelValue,\n unmountOnHide,\n})\n</script>\n\n<template>\n <Primitive\n :ref=\"forwardRef\"\n :as-child=\"asChild\"\n :as=\"as\"\n >\n <slot :model-value=\"modelValue\" />\n </Primitive>\n</template>\n"],"names":["createContext","toRefs","useDirection","useSingleOrMultipleValue","useForwardExpose"],"mappings":";;;;;;;;;AAgEO,MAAM,CAAC,0BAAA,EAA4B,2BAA2B,CAAA,GACjEA,mCAAwD,eAAe;;;;;;;;;;;;;;;;;AAQ3E,IAAA,MAAM,KAAQ,GAAA,OAAA;AAOd,IAAA,MAAM,KAAQ,GAAA,MAAA;AASd,IAAA,MAAM,EAAE,GAAK,EAAA,QAAA,EAAU,aAAc,EAAA,GAAIC,WAAO,KAAK,CAAA;AACrD,IAAM,MAAA,SAAA,GAAYC,iCAAa,GAAG,CAAA;AAElC,IAAA,MAAM,EAAE,UAAY,EAAA,gBAAA,EAAkB,UAAa,GAAAC,wDAAA,CAAyB,OAAO,KAAK,CAAA;AAExF,IAAA,MAAM,EAAE,UAAA,EAAY,cAAgB,EAAA,aAAA,KAAkBC,wCAAiB,EAAA;AAEvE,IAA4B,2BAAA,CAAA;AAAA,MAC1B,QAAA;AAAA,MACA,SAAA;AAAA,MACA,aAAa,KAAM,CAAA,WAAA;AAAA,MACnB,aAAA;AAAA,MACA,QAAA;AAAA,MACA,aAAa,KAAM,CAAA,WAAA;AAAA,MACnB,UAAA;AAAA,MACA,gBAAA;AAAA,MACA;AAAA,KACD,CAAA;;;;;;;;;;;;;;;;;;;"}