UNPKG

@ark-ui/vue

Version:

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

32 lines (31 loc) 1 kB
let vue = require("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 = (0, vue.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 = (0, vue.toRef)(props); return (0, vue.computed)(() => { const preservedProps = {}; const assignedProps = vm?.vnode.props ?? {}; Object.keys(assignedProps).forEach((key) => { preservedProps[(0, vue.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 exports.useForwardProps = useForwardProps;