import type { CSSProperties, PropType } from 'vue'; import { computed, ref, defineComponent, nextTick } from 'vue'; import type { MouseEventHandler } from '../_util/EventInterface'; import Transition, { getTransitionProps } from '../_util/transition'; import dialogPropTypes from './IDialogPropTypes'; import { offset } from './util'; const sentinelStyle = { width: 0, height: 0, overflow: 'hidden', outline: 'none' }; export type ContentRef = { focus: () => void; changeActive: (next: boolean) => void; }; export default defineComponent({ name: 'Content', inheritAttrs: false, props: { ...dialogPropTypes(), motionName: String, ariaId: String, onVisibleChanged: Function as PropType<(visible: boolean) => void>, onMousedown: Function as PropType, onMouseup: Function as PropType, }, setup(props, { expose, slots, attrs }) { const sentinelStartRef = ref(); const sentinelEndRef = ref(); const dialogRef = ref(); expose({ focus: () => { sentinelStartRef.value?.focus(); }, changeActive: next => { const { activeElement } = document; if (next && activeElement === sentinelEndRef.value) { sentinelStartRef.value.focus(); } else if (!next && activeElement === sentinelStartRef.value) { sentinelEndRef.value.focus(); } }, }); const transformOrigin = ref(); const contentStyleRef = computed(() => { const { width, height } = props; const contentStyle: CSSProperties = {}; if (width !== undefined) { contentStyle.width = typeof width === 'number' ? `${width}px` : width; } if (height !== undefined) { contentStyle.height = typeof height === 'number' ? `${height}px` : height; } if (transformOrigin.value) { contentStyle.transformOrigin = transformOrigin.value; } return contentStyle; }); const onPrepare = () => { nextTick(() => { if (dialogRef.value) { const elementOffset = offset(dialogRef.value); transformOrigin.value = props.mousePosition ? `${props.mousePosition.x - elementOffset.left}px ${ props.mousePosition.y - elementOffset.top }px` : ''; } }); }; const onVisibleChanged = (visible: boolean) => { props.onVisibleChanged(visible); }; return () => { const { prefixCls, footer = slots.footer?.(), title = slots.title?.(), ariaId, closable, closeIcon = slots.closeIcon?.(), onClose, bodyStyle, bodyProps, onMousedown, onMouseup, visible, modalRender = slots.modalRender, destroyOnClose, motionName, } = props; let footerNode: any; if (footer) { footerNode =
{footer}
; } let headerNode: any; if (title) { headerNode = (
{title}
); } let closer: any; if (closable) { closer = ( ); } const content = (
{closer} {headerNode}
{slots.default?.()}
{footerNode}
); const transitionProps = getTransitionProps(motionName); return ( onVisibleChanged(true)} onAfterLeave={() => onVisibleChanged(false)} > {visible || !destroyOnClose ? (