import { onBeforeUnmount, watch, onActivated, defineComponent, ref } from 'vue';
import Tooltip, { tooltipProps } from '../tooltip';
import type { RafFrame } from '../_util/raf';
import raf from '../_util/raf';
export default defineComponent({
name: 'SliderTooltip',
inheritAttrs: false,
props: tooltipProps(),
setup(props, { attrs, slots }) {
const innerRef = ref<any>(null);
const rafRef = ref<RafFrame>(null);
function cancelKeepAlign() {
raf.cancel(rafRef.value!);
rafRef.value = null;
}
function keepAlign() {
rafRef.value = raf(() => {
innerRef.value?.forcePopupAlign();
});
const align = () => {
cancelKeepAlign();
if (props.visible) {
keepAlign();
};
watch(
[() => props.visible, () => props.title],
() => {
align();
},
{ flush: 'post', immediate: true },
);
onActivated(() => {
onBeforeUnmount(() => {
return () => {
return <Tooltip ref={innerRef} {...props} {...attrs} v-slots={slots} />;