Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(components): [popover] switch to script-setup syntax
- Loading branch information
Showing
8 changed files
with
149 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
import Popover from './src/index.vue' | ||
import PopoverDirective, { VPopover } from './src/directive' | ||
|
||
import type { App } from 'vue' | ||
import type { SFCWithInstall } from '@element-plus/utils' | ||
import { withInstall, withInstallDirective } from '@element-plus/utils' | ||
|
||
Popover.install = (app: App): void => { | ||
app.component(Popover.name, Popover) | ||
} | ||
;(PopoverDirective as SFCWithInstall<typeof PopoverDirective>).install = ( | ||
app: App | ||
) => { | ||
app.directive(VPopover, PopoverDirective) | ||
} | ||
|
||
const _PopoverDirective = PopoverDirective as SFCWithInstall< | ||
typeof PopoverDirective | ||
> | ||
import Popover from './src/popover.vue' | ||
import PopoverDirective, { VPopover } from './src/directive' | ||
|
||
Popover.directive = _PopoverDirective | ||
export const ElPopoverDirective = withInstallDirective( | ||
PopoverDirective, | ||
VPopover | ||
) | ||
|
||
const _Popover = Popover as any as SFCWithInstall<typeof Popover> & { | ||
directive: typeof _PopoverDirective | ||
} | ||
export const ElPopover = withInstall(Popover, { | ||
directive: ElPopoverDirective, | ||
}) | ||
export default ElPopover | ||
|
||
export default _Popover | ||
export const ElPopover = _Popover | ||
export const ElPopoverDirective = _PopoverDirective | ||
export * from './src/popover' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<template> | ||
<el-tooltip | ||
ref="tooltipRef" | ||
v-bind="$attrs" | ||
:trigger="trigger" | ||
:placement="placement" | ||
:disabled="disabled" | ||
:visible="visible" | ||
:transition="transition" | ||
:popper-options="popperOptions" | ||
:tabindex="tabindex" | ||
:content="content" | ||
:offset="offset" | ||
:show-after="showAfter" | ||
:hide-after="hideAfter" | ||
:auto-close="autoClose" | ||
:show-arrow="showArrow" | ||
:aria-label="title" | ||
:effect="effect" | ||
:enterable="enterable" | ||
:popper-class="kls" | ||
:popper-style="style" | ||
:teleported="teleported" | ||
:persistent="persistent" | ||
:gpu-acceleration="gpuAcceleration" | ||
@before-show="beforeEnter" | ||
@before-hide="beforeLeave" | ||
@show="afterEnter" | ||
@hide="afterLeave" | ||
> | ||
<template v-if="$slots.reference"> | ||
<slot name="reference" /> | ||
</template> | ||
|
||
<template #content> | ||
<div v-if="title" :class="ns.e('title')" role="title"> | ||
{{ title }} | ||
</div> | ||
<slot> | ||
{{ content }} | ||
</slot> | ||
</template> | ||
</el-tooltip> | ||
</template> | ||
<script lang="ts" setup> | ||
import { computed, ref, unref } from 'vue' | ||
import { ElTooltip } from '@element-plus/components/tooltip' | ||
import { addUnit } from '@element-plus/utils' | ||
import { useNamespace } from '@element-plus/hooks' | ||
import { popoverEmits, popoverProps } from './popover' | ||
import type { TooltipInstance } from '@element-plus/components/tooltip' | ||
defineOptions({ | ||
name: 'ElPopover', | ||
}) | ||
const props = defineProps(popoverProps) | ||
const emit = defineEmits(popoverEmits) | ||
const ns = useNamespace('popover') | ||
const tooltipRef = ref<TooltipInstance>() | ||
const popperRef = computed(() => { | ||
return unref(tooltipRef)?.popperRef | ||
}) | ||
const style = computed(() => { | ||
return [ | ||
{ | ||
width: addUnit(props.width), | ||
}, | ||
props.popperStyle!, | ||
] | ||
}) | ||
const kls = computed(() => { | ||
return [ns.b(), props.popperClass!, { [ns.m('plain')]: !!props.content }] | ||
}) | ||
const gpuAcceleration = computed(() => { | ||
return props.transition === 'el-fade-in-linear' | ||
}) | ||
const hide = () => { | ||
tooltipRef.value?.hide() | ||
} | ||
const beforeEnter = () => { | ||
emit('before-enter') | ||
} | ||
const beforeLeave = () => { | ||
emit('before-leave') | ||
} | ||
const afterEnter = () => { | ||
emit('after-enter') | ||
} | ||
const afterLeave = () => { | ||
emit('update:visible', false) | ||
emit('after-leave') | ||
} | ||
defineExpose({ | ||
/** @description popper ref */ | ||
popperRef, | ||
/** @description hide popover */ | ||
hide, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters