mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* refactor(utils-v2): migrate utils * refactor(utils-v2): migrate utils * refactor(utils-v2): migrate utils * refactor(utils): remove * refactor(utils): rename * refactor(utils): move EVENT_CODE to constants * refactor: remove generic
90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
import { createVNode, defineComponent, renderSlot, h } from 'vue'
|
|
import { PatchFlags, buildProps, definePropType } from '@element-plus/utils'
|
|
import { useNamespace, useSameTarget } from '@element-plus/hooks'
|
|
|
|
import type { ExtractPropTypes, CSSProperties } from 'vue'
|
|
import type { ZIndexProperty } from 'csstype'
|
|
|
|
export const overlayProps = buildProps({
|
|
mask: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
customMaskEvent: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
overlayClass: {
|
|
type: definePropType<string | string[] | Record<string, boolean>>([
|
|
String,
|
|
Array,
|
|
Object,
|
|
]),
|
|
},
|
|
zIndex: {
|
|
type: definePropType<ZIndexProperty>([String, Number]),
|
|
},
|
|
} as const)
|
|
export type OverlayProps = ExtractPropTypes<typeof overlayProps>
|
|
|
|
export const overlayEmits = {
|
|
click: (evt: MouseEvent) => evt instanceof MouseEvent,
|
|
}
|
|
export type OverlayEmits = typeof overlayEmits
|
|
|
|
export default defineComponent({
|
|
name: 'ElOverlay',
|
|
|
|
props: overlayProps,
|
|
emits: overlayEmits,
|
|
|
|
setup(props, { slots, emit }) {
|
|
const ns = useNamespace('overlay')
|
|
|
|
const onMaskClick = (e: MouseEvent) => {
|
|
emit('click', e)
|
|
}
|
|
|
|
const { onClick, onMousedown, onMouseup } = useSameTarget(
|
|
props.customMaskEvent ? undefined : onMaskClick
|
|
)
|
|
|
|
// init here
|
|
return () => {
|
|
// when the vnode meets the same structure but with different change trigger
|
|
// it will not automatically update, thus we simply use h function to manage updating
|
|
return props.mask
|
|
? createVNode(
|
|
'div',
|
|
{
|
|
class: [ns.b(), props.overlayClass],
|
|
style: {
|
|
zIndex: props.zIndex,
|
|
},
|
|
onClick,
|
|
onMousedown,
|
|
onMouseup,
|
|
},
|
|
[renderSlot(slots, 'default')],
|
|
PatchFlags.STYLE | PatchFlags.CLASS | PatchFlags.PROPS,
|
|
['onClick', 'onMouseup', 'onMousedown']
|
|
)
|
|
: h(
|
|
'div',
|
|
{
|
|
class: props.overlayClass,
|
|
style: {
|
|
zIndex: props.zIndex,
|
|
position: 'fixed',
|
|
top: '0px',
|
|
right: '0px',
|
|
bottom: '0px',
|
|
left: '0px',
|
|
} as CSSProperties,
|
|
},
|
|
[renderSlot(slots, 'default')]
|
|
)
|
|
}
|
|
},
|
|
})
|