UNPKG

@empathyco/x-components

Version:
48 lines (45 loc) 1.47 kB
import { defineComponent, ref } from 'vue'; import { use$x } from '../composables/use-_x.js'; /** * Component to be reused that renders a `<button>` with the logic of emitting events to the bus * on click. The events are passed as an object to prop {@link XEvent}. * The keys are the event name and the values are the payload of each event. All events are * emitted with its respective payload. If any event doesn't need payload a `undefined` must be * passed as value. * * @public */ var _sfc_main = defineComponent({ name: 'BaseEventButton', props: { /** An object where the keys are the {@link XEvent} and the values are the payload. */ events: { type: Object, required: true, }, /** * The metadata property for the request on each query preview. * * @public */ metadata: { type: Object, }, }, setup(props) { const $x = use$x(); const rootRef = ref(); /** * Emits `events` prop to the X bus with the payload given by it. */ function emitEvents() { Object.entries(props.events).forEach(([event, payload]) => $x.emit(event, payload, { target: rootRef.value, ...props.metadata })); } return { emitEvents, rootRef, }; }, }); export { _sfc_main as default }; //# sourceMappingURL=base-event-button.vue2.js.map