@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
25 lines (22 loc) • 854 B
JavaScript
import { getCurrentInstance, toRef, computed, camelize } from 'vue';
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;
}, {});
});
}
export { useForwardProps };