import { computed, defineComponent, onBeforeUpdate, onUnmounted, type PropType, Transition, } from 'vue'; import BCMSIcon from '../icon'; import { useTranslation } from '../../translations'; import BCMSButton from '../button'; const component = defineComponent({ props: { class: String, show: { type: Boolean, required: true, }, title: String, actionName: String, beforeDone: Function as PropType<() => boolean>, doNotShowFooter: Boolean, allowBodyScroll: { type: Boolean, default: true, }, confirmDisabledButton: { type: Boolean, required: false, default: false, }, }, emits: { done: (_?: unknown) => { return true; }, cancel: (_?: unknown) => { return true; }, scroll: (_event: UIEvent) => { return true; }, }, setup(props, ctx) { let escUnsub: () => void = () => { // Nothing }; const translations = computed(() => { return useTranslation(); }); function cancel() { ctx.emit('cancel'); } function done() { if (props.beforeDone) { if (!props.beforeDone()) { return; } } ctx.emit('done'); } // window.addEventListener('keyup', (event) => { // if (props.show) { // if (event.key === 'Enter') { // ctx.emit('done'); // } else if (event.key === 'Escape') { // ctx.emit('cancel'); // } // } // }); onBeforeUpdate(() => { if (props.show) { document.body.style.overflowY = 'hidden'; } else { document.body.style.overflowY = 'auto'; } }); // function handlerEscape() { // setTimeout(() => { // escUnsub = window.bcms.modal.escape.register(handlerEscape); // }, 100); // cancel(); // } onBeforeUpdate(() => { if (props.show) { escUnsub = window.bcms.modal.escape.register(cancel); } else { escUnsub(); } }); onUnmounted(() => { escUnsub(); }); return () => { return ( {props.show && (
{ if (event.key === 'Enter') { cancel(); } }} onClick={() => { cancel(); }} />
{ctx.slots.header ? ( ctx.slots.header() ) : props.title ? (
{props.title}
) : ( '' )}
{ ctx.emit('scroll', event); }} > {ctx.slots.default ? ctx.slots.default() : ''}
{props.doNotShowFooter ? ( '' ) : (
{ctx.slots.actions ? ( ctx.slots.actions() ) : ( <> {props.actionName ? props.actionName : translations.value.modal.actions.done} {translations.value.modal.actions.cancel} )}
)}
)} ); }; }, }); export default component;