diff --git a/docs/pages/docs.md b/docs/pages/docs.md index 6b7919f5..777e3b9a 100644 --- a/docs/pages/docs.md +++ b/docs/pages/docs.md @@ -1,9 +1,8 @@ # Documentation - ## API -### `renderToString` +### renderToString This function takes a `URL` to a JavaScript file that defines a custom element, and returns the static HTML output of its rendered contents. @@ -11,15 +10,83 @@ This function takes a `URL` to a JavaScript file that defines a custom element, const { html } = await renderToString(new URL('./src/index.js', import.meta.url)); ``` -#### Options +```js +// index.js +import './components/footer.js'; +import './components/header.js'; + +const template = document.createElement('template'); + +template.innerHTML = ` + + + + +
+

My Blog Post

+
+ + +`; + +class Home extends HTMLElement { + + connectedCallback() { + if (!this.shadowRoot) { + this.attachShadow({ mode: 'open' }); + this.shadowRoot.appendChild(template.content.cloneNode(true)); + } + } +} + +export default Home; +``` -`renderToString` also supports a second parameter that is an object, called `options`, which supports the following configurations: +### renderFromHTML + +This function takes a string of HTML and an array of any top-level custom elements used with `import`, and returns the static HTML output of the rendered content. + +```js +const { html } = await renderToString(` + + + WCC + + + +

Home Page

+ + + +`, +[ + new URL('./src/components/footer.js', import.meta.url), + new URL('./src/components/header.js', import.meta.url) +]); +``` + +### Options + +`renderToString` and `renderFromHTML` also supports a second and third parameter respectively, that is an object, called `options` +```js +// default values +{ + lightMode: false +} +``` + +It supports the following configuration(s): - `lightMode`: For more static outcomes (e.g. no declarative shadow DOM), this option will omit all wrapping `