Skip to content

Instantly share code, notes, and snippets.

@mhsattarian
Created January 16, 2022 07:25
Show Gist options
  • Save mhsattarian/10bf42b18341923d717f951367b43a37 to your computer and use it in GitHub Desktop.
Save mhsattarian/10bf42b18341923d717f951367b43a37 to your computer and use it in GitHub Desktop.
Tippyjs plugin to use `textContent` of the child as content.
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