Easily find and modify a VDOM node's children.
This util was sponsored by Kagi Search, an ad-free search engine and is released as open source for the wider Flarum community to benefit.
- Download the attached Typescript file
yarn add css-what
ORnpm i css-what
- Enjoy!
To add a Dropdown to .DiscussionListItem-content
...
extend(DiscussionListItem.prototype, 'view', function (this: DiscussionListItem, vdom: Mithril.Vnode) {
findFirstVdomChild(vdom, '.DiscussionListItem-content', (vdom) => {
// Must be an array (Mithril fragment)
if (!Array.isArray(vdom.children)) {
vdom.children = [vdom.children];
}
// Add a new item to the fragment
vdom.children.push(
<Dropdown className="MyDropdown" buttonClassName="Button" label={label}>
<Button onclick={() => {}}>
My button
</Button>
<Button onclick={() => {}}>
My other button
</Button>
</Dropdown>
);
});
});