|
1 | 1 | import type { Meta, StoryObj } from "@storybook/web-components"; |
2 | 2 | import { html } from "lit"; |
| 3 | +import { unsafeHTML } from "lit/directives/unsafe-html.js"; |
| 4 | + |
| 5 | +const makeSource = (name: string, min: number, max: number) => |
| 6 | + `<aa-session name="${name}"> |
| 7 | + <div style="display:flex; align-items:center; gap:12px;"> |
| 8 | + <button onclick=" |
| 9 | + var container = this.parentElement.querySelector('.result-container'); |
| 10 | + container.innerHTML = ''; |
| 11 | + var el = document.createElement('aa-function-random'); |
| 12 | + el.setAttribute('name', 'randomValue'); |
| 13 | + el.setAttribute('min', '${min}'); |
| 14 | + el.setAttribute('max', '${max}'); |
| 15 | + el.setAttribute('debug', ''); |
| 16 | + container.appendChild(el); |
| 17 | + this.parentElement.querySelector('.result-value').textContent = el.value; |
| 18 | + ">Generate</button> |
| 19 | + <span>Result: <strong class="result-value">—</strong></span> |
| 20 | + <span class="result-container" style="display:none;"></span> |
| 21 | + </div> |
| 22 | +</aa-session>`; |
3 | 23 |
|
4 | 24 | const meta = { |
5 | 25 | title: "Data & Utility/Function Random", |
6 | 26 | tags: ["autodocs"], |
7 | | - argTypes: { |
8 | | - min: { control: "number" }, |
9 | | - max: { control: "number" }, |
| 27 | + render: (args) => { |
| 28 | + const source = makeSource("random-demo", args.min, args.max); |
| 29 | + return html`${unsafeHTML(source)}`; |
| 30 | + }, |
| 31 | + parameters: { |
| 32 | + docs: { |
| 33 | + source: { |
| 34 | + code: `<aa-function-random name="randomValue" min="1" max="100"></aa-function-random>`, |
| 35 | + language: "html", |
| 36 | + }, |
| 37 | + }, |
10 | 38 | }, |
11 | | - render: (args) => html` |
12 | | - <aa-function-random |
13 | | - name="randomValue" |
14 | | - min="${args.min}" |
15 | | - max="${args.max}" |
16 | | - debug |
17 | | - ></aa-function-random> |
18 | | - `, |
19 | 39 | } satisfies Meta; |
20 | 40 |
|
21 | 41 | export default meta; |
|
0 commit comments