Skip to content

Commit 2084775

Browse files
committed
refactor: update c-popover and c-tooltips import and exports
1 parent 99942a6 commit 2084775

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

src/directives/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CTooltip } from './CTooltip'
2-
import { CPopover } from './CPopover'
1+
import vctooltip from './v-c-tooltip'
2+
import vcpopover from './v-c-popover'
33

4-
export { CTooltip, CPopover }
4+
export { vctooltip, vcpopover }

src/directives/CPopover.ts renamed to src/directives/v-c-popover.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DirectiveBinding } from 'vue'
12
import { createPopper } from '@popperjs/core'
23

34
const getUID = (prefix: string) => {
@@ -43,10 +44,10 @@ const togglePopoverElement = (popover: HTMLDivElement, el: HTMLElement, popperOp
4344
addPopoverElement(popover, el, popperOptions)
4445
}
4546

46-
const CPopover = {
47+
export default {
4748
name: 'c-popover',
4849
uid: '',
49-
mounted(el: HTMLElement, binding: any) {
50+
mounted(el: HTMLElement, binding: DirectiveBinding): void {
5051
const value = binding.value
5152
const content = typeof value === 'string' ? value : value.content ? value.content : ''
5253
const header = value.header ? value.header : ''
@@ -69,7 +70,7 @@ const CPopover = {
6970
}
7071

7172
const popoverUID = getUID('popover')
72-
binding.dir.uid = popoverUID
73+
binding.arg = popoverUID
7374
const popover = createPopoverElement(popoverUID, header, content)
7475

7576
trigger.includes('click') &&
@@ -95,10 +96,8 @@ const CPopover = {
9596
})
9697
}
9798
},
98-
unmounted(binding: any) {
99-
const popover = document.getElementById(binding.dir.uid)
99+
unmounted(binding: DirectiveBinding): void {
100+
const popover = binding.arg && document.getElementById(binding.arg)
100101
popover && popover.remove()
101102
},
102103
}
103-
104-
export { CPopover }

src/directives/CTooltip.ts renamed to src/directives/v-c-tooltip.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DirectiveBinding } from 'vue'
12
import { createPopper } from '@popperjs/core'
23

34
const getUID = (prefix: string) => {
@@ -42,10 +43,10 @@ const toggleTooltipElement = (tooltip: HTMLDivElement, el: HTMLElement, popperOp
4243
addTooltipElement(tooltip, el, popperOptions)
4344
}
4445

45-
const CTooltip = {
46-
name: 'c-tooltip',
47-
uid: '',
48-
mounted(el: HTMLElement, binding: any) {
46+
export default {
47+
mounted(el: HTMLElement, binding: DirectiveBinding): void {
48+
console.log(binding)
49+
4950
const value = binding.value
5051
const content = typeof value === 'string' ? value : value.content ? value.content : ''
5152
const trigger = value.trigger ? value.trigger : 'hover'
@@ -67,7 +68,7 @@ const CTooltip = {
6768
}
6869

6970
const tooltipUID = getUID('tooltip')
70-
binding.dir.uid = tooltipUID
71+
binding.arg = tooltipUID
7172
const tooltip = createTooltipElement(tooltipUID, content)
7273

7374
trigger.includes('click') &&
@@ -93,10 +94,8 @@ const CTooltip = {
9394
})
9495
}
9596
},
96-
unmounted(binding: any) {
97-
const tooltip = document.getElementById(binding.dir.uid)
97+
beforeUnmount(binding: DirectiveBinding): void {
98+
const tooltip = binding.arg && document.getElementById(binding.arg)
9899
tooltip && tooltip.remove()
99100
},
100101
}
101-
102-
export { CTooltip }

0 commit comments

Comments
 (0)