lion/packages/ui/components/helpers/src/renderLitAsNode.js
2022-11-07 11:39:40 +01:00

13 lines
535 B
JavaScript

import { render } from 'lit';
/**
* Helper to render a lit TemplateResult as an offline-created DOM node
* Make sure that the top-most element in the template has no siblings,
* as they won't be taken into account. We only return firstElementChild.
* @param {import('lit').TemplateResult} litHtmlTemplate
*/
export const renderLitAsNode = litHtmlTemplate => {
const offlineRenderContainer = document.createElement('div');
render(litHtmlTemplate, offlineRenderContainer);
return offlineRenderContainer.firstElementChild;
};