reka-ui
Version:
Vue port for Radix UI Primitives.
26 lines (24 loc) • 1.08 kB
JavaScript
import { camelize, getCurrentInstance, toHandlerKey } from "vue";
//#region src/shared/useEmitAsProps.ts
/**
* The `useEmitAsProps` function is a TypeScript utility that converts emitted events into props for a
* Vue component.
* @param emit - The `emit` parameter is a function that is used to emit events from a component. It
* takes two parameters: `name` which is the name of the event to be emitted, and `...args` which are
* the arguments to be passed along with the event.
* @returns The function `useEmitAsProps` returns an object that maps event names to functions that
* call the `emit` function with the corresponding event name and arguments.
*/
function useEmitAsProps(emit) {
const vm = getCurrentInstance();
const events = vm?.type.emits;
const result = {};
if (!events?.length) console.warn(`No emitted event found. Please check component: ${vm?.type.__name}`);
events?.forEach((ev) => {
result[toHandlerKey(camelize(ev))] = (...arg) => emit(ev, ...arg);
});
return result;
}
//#endregion
export { useEmitAsProps };
//# sourceMappingURL=useEmitAsProps.js.map