Created
January 16, 2022 07:25
-
-
Save mhsattarian/10bf42b18341923d717f951367b43a37 to your computer and use it in GitHub Desktop.
Tippyjs plugin to use `textContent` of the child as content.
This file contains hidden or 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
import type { Props, Plugin, LifecycleHooks } from 'tippy.js'; | |
// eslint-disable-next-line @typescript-eslint/no-empty-interface | |
interface CustomProps {} | |
type FilteredProps = CustomProps & | |
Omit<Props, keyof CustomProps | keyof LifecycleHooks>; | |
type ExtendedProps = FilteredProps & LifecycleHooks<FilteredProps>; | |
const textContent: Plugin<ExtendedProps> = { | |
// Required | |
fn(instance) { | |
return { | |
onShow() { | |
instance.setProps({ | |
content: instance.reference.textContent ?? undefined, | |
}); | |
}, | |
}; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment