UNPKG

@empathyco/x-components

Version:
76 lines (73 loc) 2.33 kB
import { defineComponent, ref, computed } from 'vue'; import '../../composables/create-use-device.js'; import 'vuex'; import '@vue/devtools-api'; import '../../plugins/devtools/timeline.devtools.js'; import '@empathyco/x-utils'; import 'rxjs/operators'; import 'rxjs'; import '../../plugins/devtools/colors.utils.js'; import '../../plugins/x-bus.js'; import '../../plugins/x-plugin.js'; import { useXBus } from '../../composables/use-x-bus.js'; import '@vueuse/core'; import BaseEventButton from '../base-event-button.vue.js'; /** * Component containing an event button that emits * {@link XEventsTypes.UserClickedPanelToggleButton} when clicked with * the panelId as payload. * * It has a default slot to customize its contents. * * @public */ var _sfc_main = defineComponent({ name: 'BaseIdTogglePanelButton', components: { BaseEventButton }, props: { /** * The panelId to use for the toggle event listeners. */ panelId: { type: String, required: true, }, }, setup(props) { const bus = useXBus(); /** * The panel state to pass through the slot. */ const isPanelOpen = ref(false); /** * List of events to emit by the BaseEventButton. * * @returns An object with the event and payload. * * @internal */ const events = computed(() => ({ UserClickedPanelToggleButton: props.panelId })); /** * The subscription to the {@link XEventsTypes.TogglePanelStateChanged} event * to update the `isPanelOpen` property. * * @param newState - The new isOpen state of the panel. * @param id - The `panelId`. * @param id.id - The ID of the `panelId`. */ const updatePanelState = (newState, { id }) => { if (props.panelId === id) { isPanelOpen.value = newState; } }; bus .on('TogglePanelStateChanged', false) .subscribe(newState => updatePanelState(newState, { id: props.panelId, moduleName: null })); return { isPanelOpen, events, }; }, }); export { _sfc_main as default }; //# sourceMappingURL=base-id-toggle-panel-button.vue2.js.map