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 = ` `; export function JustFetch(): string { return ` ${header} ${head_hide}

Just fetch

Just fetch an URL and display the content.

${justFetchString}

Code

${highlight(``)}
${highlight(justFetchString)}

Head

${highlight(header)}
`; } const regularlyFetchString = ` `; export function RegularlyFetch(): string { return ` ${header} ${head_hide}

Regularly fetch

Fetch an URL every 1s and display the content. ${regularlyFetchString}

Code

${highlight(``)}
${highlight(regularlyFetchString)}

Head

${highlight(header)}
`; } const refreshString = ` Reload
`; export function Refresh(): string { return ` ${header} ${head_hide}

With a refresh button

Click on the button to reload the content.

${refreshString}

Code

${highlight(``)}
${highlight(refreshString)}

Head

${highlight(header)}
`; } const actionLinkString = ` Do an action Loading: , Reloading: `; export function ActionLink(): string { return ` ${header} ${head_hide}

With an link that do an action and trigger a refresh

${actionLinkString}

Code

${highlight(``)}
${highlight(actionLinkString)}

Head

${highlight(header)}
`; } const customFormString = ` `; export function CustomForm(): string { return ` ${header} ${head_hide}

With a form that do an action and trigger a refresh

${customFormString}

Code

${highlight(``)}
${highlight(customFormString)}

Head

${highlight(header)}
`; } const customFormErrorString = ` `; export function CustomFormError(): string { return ` ${header} ${head_hide}

With a form that do an error

${customFormErrorString}

Code

${highlight(``)}
${highlight(myFormErrorString)}

Head

${highlight(header)}
`; } const errorString = ` Do an error`; export function Error(): string { return ` ${header} ${head_hide}

With an link on error

${errorString}

Code

${highlight(``)}
${highlight(errorString)}

Head

${highlight(header)}
`; } const simpleTableFormString = ` { "action": "src/data/action.json", "fields": [ { "name": "name", "label": "Name" }, { "name": "value", "label": "Value" } ] } `; export function SimpleTableForm(): string { return ` ${header} ${head_hide}

Simple form

${simpleTableFormString}

Code

${highlight(``)}
${highlight(simpleTableFormString)}

Head

${highlight(header)}
`; } const simpleLineFormString = `
  {
    "action": "src/data/action.json",
    "type": "line",
    "fields": [
      {
        "name": "name",
        "placeholder": "Name"
      },
      {
        "name": "value",
        "placeholder": "Value"
      }
    ]
  }
  
`; export function SimpleLineForm(): string { return ` ${header} ${head_hide}

Simple one line form

${simpleLineFormString}

Code

${highlight(``)}
${highlight(simpleLineFormString)}

Head

${highlight(header)}
`; }