diff --git a/src/components/Tippy.ts b/src/components/Tippy.ts index 1b7f8d2..7a94c08 100644 --- a/src/components/Tippy.ts +++ b/src/components/Tippy.ts @@ -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, - }, + props, setup(props) { const elem = ref() - - useTippy(elem, props) - - return { elem } + return { elem, ...useTippy(elem, props) } }, render() { let slot = this.$slots.default ? this.$slots.default() : [] diff --git a/src/index.ts b/src/index.ts index 3d5ac63..5703d06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 }