This commit is contained in:
Georges KABBOUCHI
2020-08-02 18:47:17 +03:00
parent 4198239067
commit 0a94a339a7
2 changed files with 60 additions and 10 deletions
+57 -9
View File
@@ -1,17 +1,65 @@
import { defineComponent, ref, h, PropType } from 'vue'
import { Content } from 'tippy.js'
import { defineComponent, ref, h, ComponentObjectPropsOptions } from 'vue'
import { TippyOptions } from '../types'
import { useTippy } from '../composables'
import tippy, { DefaultProps } from 'tippy.js'
declare module '@vue/runtime-core' {
interface ComponentCustomProps extends TippyOptions {}
}
const pluginProps = [
'animateFill',
'followCursor',
'inlinePositioning',
'sticky',
]
const booleanProps = [
'a11y',
'allowHTML',
'arrow',
'flip',
'flipOnUpdate',
'hideOnClick',
'ignoreAttributes',
'inertia',
'interactive',
'lazy',
'multiple',
'showOnInit',
'touch',
'touchHold',
]
let props: ComponentObjectPropsOptions = {}
Object.keys(tippy.defaultProps).forEach((prop: string) => {
if (pluginProps.includes(prop)) return
if (booleanProps.includes(prop)) {
props[prop] = {
type: Boolean,
default: function () {
console.log(tippy.defaultProps[prop as keyof DefaultProps])
return tippy.defaultProps[prop as keyof DefaultProps] as Boolean
},
}
} else {
props[prop] = {
default: function () {
return tippy.defaultProps[prop as keyof DefaultProps]
},
}
}
})
console.log(props)
export default defineComponent({
props: {
content: {} as PropType<Content>,
},
props,
setup(props) {
const elem = ref<Element>()
useTippy(elem, props)
return { elem }
return { elem, ...useTippy(elem, props) }
},
render() {
let slot = this.$slots.default ? this.$slots.default() : []
+3 -1
View File
@@ -4,5 +4,7 @@ import { useTippy } from './composables/useTippy'
import { TippyOptions } from './types'
import 'tippy.js/dist/tippy.css'
export { tippy, Tippy, useTippy }
const setDefaultProps = tippy.setDefaultProps
export { useTippy, tippy, setDefaultProps, Tippy }
export { TippyOptions }