UNPKG

@ark-ui/vue

Version:

A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.

32 lines (31 loc) 995 B
import { camelize, computed, getCurrentInstance, toRef } from "vue"; //#region src/utils/use-forward-props.ts /** * Attribution: Radix Vue Team * Retrieved from: https://www.radix-vue.com/utilities/use-forward-props.html */ function useForwardProps(props) { const vm = getCurrentInstance(); const defaultProps = Object.keys(vm?.type.props ?? {}).reduce((prev, curr) => { const defaultValue = (vm?.type.props[curr]).default; if (defaultValue !== void 0) prev[curr] = defaultValue; return prev; }, {}); const refProps = toRef(props); return computed(() => { const preservedProps = {}; const assignedProps = vm?.vnode.props ?? {}; Object.keys(assignedProps).forEach((key) => { preservedProps[camelize(key)] = assignedProps[key]; }); return Object.keys({ ...defaultProps, ...preservedProps }).reduce((prev, curr) => { if (refProps.value[curr] !== void 0) prev[curr] = refProps.value[curr]; return prev; }, {}); }); } //#endregion export { useForwardProps };