import index from './index'; import { common, createLowlight } from 'lowlight'; import { toHtml } from 'hast-util-to-html'; /* For dark mode */ if (window.matchMedia('(prefers-color-scheme: dark)').matches) { document.documentElement.setAttribute('data-bs-theme', 'dark'); } // Just for including in bundle console.log(index); const lowlight = createLowlight(common); function highlight(unsafe: string): string { const tree = lowlight.highlight('html', unsafe); return toHtml(tree); } // More on how to set up stories at: https://storybook.js.org/docs/writing-stories export default { title: 'Examples', }; const myElementString = ` /** * An example element. */ class MyElement extends window.admin.Element { render() { if (!this.dataSignal) { return window.lit.html\`
No data
\`; } const data = this.dataSignal.get(); return data ? window.lit.map(data.attribute, (item) => window.lit.html\`\${item?.name}: \${item?.value}
\`) : window.lit.html\`\`; } } window.customElements.define('my-element', MyElement); `; eval(myElementString); const myFormSring = ` /** * A form element. */ class MyForm extends window.admin.Form { render() { return window.lit.html\` \`; } } window.customElements.define('my-form', MyForm); `; eval(myFormSring); const myFormErrorString = ` /** * A form element error. */ class MyFormError extends window.admin.Form { render() { return window.lit.html\` \`; } } window.customElements.define('my-form-error', MyFormError); `; eval(myFormErrorString); const header = ` `; const head_hide = ` `; const justFetchString = `Just fetch an URL and display the content.
${justFetchString}${highlight(``)}
${highlight(justFetchString)}
${highlight(header)}`;
}
const regularlyFetchString = `
${highlight(``)}
${highlight(regularlyFetchString)}
${highlight(header)}`;
}
const refreshString = `
Click on the button to reload the content.
${refreshString}${highlight(``)}
${highlight(refreshString)}
${highlight(header)}`;
}
const actionLinkString = `
${highlight(``)}
${highlight(actionLinkString)}
${highlight(header)}`;
}
const customFormString = `
${highlight(``)}
${highlight(customFormString)}
${highlight(header)}`;
}
const customFormErrorString = `
${highlight(``)}
${highlight(myFormErrorString)}
${highlight(header)}`;
}
const errorString = `
${highlight(``)}
${highlight(errorString)}
${highlight(header)}`;
}
const simpleTableFormString = `
${highlight(``)}
${highlight(simpleTableFormString)}
${highlight(header)}`;
}
const simpleLineFormString = `
{
"action": "src/data/action.json",
"type": "line",
"fields": [
{
"name": "name",
"placeholder": "Name"
},
{
"name": "value",
"placeholder": "Value"
}
]
}
${highlight(``)}
${highlight(simpleLineFormString)}
${highlight(header)}`;
}