Compare commits

...

3 Commits

Author SHA1 Message Date
Jesse Mazzella
86c2662148 feat: programmatically disable create button via API events 2023-12-21 16:45:43 -08:00
Jesse Mazzella
f0f3733ac1 feat: add isEditing composable 2023-12-21 16:45:24 -08:00
Jesse Mazzella
f5d57374fb feat: add useEventListener composable 2023-12-21 16:45:07 -08:00
3 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import { ref } from 'vue';
import { useEventListener } from './event';
/**
* @param {import('../../../openmct').OpenMCT} openmct
* @returns {{isEditing: import('vue').Ref<boolean>}} isEditing
*/
export function useIsEditing(openmct) {
const isEditing = ref(false);
// eslint-disable-next-line func-style
const handler = (value) => (isEditing.value = value);
// Use the base event listener composable
useEventListener(openmct.editor, 'isEditing', handler);
return { isEditing };
}

View File

@@ -0,0 +1,18 @@
import { onBeforeMount, onBeforeUnmount } from 'vue';
/**
* @param {*} api the specific openmct API to use i.e. openmct.editor
* @param {string} eventName
* @param {() => void} handler
*/
export function useEventListener(api, eventName, handler) {
onBeforeMount(() => {
// Add the event listener before the component is mounted
api.on(eventName, handler);
});
onBeforeUnmount(() => {
// Remove the event listener before the component is unmounted
api.off(eventName, handler);
});
}

View File

@@ -23,6 +23,7 @@
<div ref="createButton" class="c-create-button--w">
<button
class="c-create-button c-button--menu c-button--major icon-plus"
:disabled="isEditing"
@click.prevent.stop="showCreateMenu"
>
<span class="c-button__label">Create</span>
@@ -31,10 +32,19 @@
</template>
<script>
import { inject } from 'vue';
import CreateAction from '@/plugins/formActions/CreateAction';
import { useIsEditing } from '../composables/editor';
export default {
inject: ['openmct'],
setup() {
const openmct = inject('openmct');
const { isEditing } = useIsEditing(openmct);
return { isEditing };
},
data: function () {
return {
menuItems: {},