@storybook/web-components 11.0.0-alpha.6 → 11.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_browser-chunks/{chunk-BNL7LBNI.js → chunk-CAPEJO4V.js} +2 -2
- package/dist/_browser-chunks/{chunk-TXUT6K6E.js → chunk-IPGO7UEM.js} +9 -6
- package/dist/_node-chunks/chunk-MMJPCIXK.js +45 -0
- package/dist/_node-chunks/{chunk-X7F7EONQ.js → chunk-P75AOQLO.js} +500 -106
- package/dist/docgen/docgen-worker.js +8 -8
- package/dist/docgen/index.d.ts +13 -15
- package/dist/docgen/index.js +8 -11
- package/dist/entry-preview-argtypes.js +7 -5
- package/dist/entry-preview.js +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +2 -2
- package/dist/preset.js +63 -15
- package/package.json +7 -4
- package/template/stories_lit-vite-default-ts/demo-wc-counter/DemoWcCounter.js +176 -0
- package/template/stories_lit-vite-default-ts/demo-wc-counter/index.js +3 -0
- package/template/stories_lit-vite-default-ts/demo-wc-counter.stories.js +217 -0
- package/dist/_node-chunks/chunk-GDY64HEP.js +0 -87
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { expect, fn, userEvent, waitFor } from 'storybook/test';
|
|
2
|
+
|
|
3
|
+
import './demo-wc-counter';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Every story uses the default render, which binds each arg by the category its key encodes in the
|
|
7
|
+
* Custom Elements Manifest: attributes and properties, `-event`, `-slot`, `-part`, `-state`, and
|
|
8
|
+
* `--` CSS custom properties.
|
|
9
|
+
*/
|
|
10
|
+
export default {
|
|
11
|
+
component: 'demo-wc-counter',
|
|
12
|
+
tags: ['autodocs'],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Attributes = {
|
|
16
|
+
args: { count: 3, step: 2, disabled: true },
|
|
17
|
+
play: async ({ canvasElement }) => {
|
|
18
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
19
|
+
await counter.updateComplete;
|
|
20
|
+
|
|
21
|
+
await expect(counter).toHaveAttribute('count', '3');
|
|
22
|
+
await expect(counter).toHaveAttribute('disabled');
|
|
23
|
+
await expect(counter.shadowRoot.querySelector('[part="value"]')).toHaveTextContent('3 clicks');
|
|
24
|
+
await expect(counter.shadowRoot.querySelector('[part="button"]')).toBeDisabled();
|
|
25
|
+
await expect(counter.shadowRoot.querySelector('[part="button"]')).toHaveTextContent('+2');
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const BooleanAttributeOff = {
|
|
30
|
+
args: { disabled: false },
|
|
31
|
+
play: async ({ canvasElement }) => {
|
|
32
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
33
|
+
await counter.updateComplete;
|
|
34
|
+
|
|
35
|
+
await expect(counter).not.toHaveAttribute('disabled');
|
|
36
|
+
await expect(counter.shadowRoot.querySelector('[part="button"]')).toBeEnabled();
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const EnumAttribute = {
|
|
41
|
+
args: { size: 'large' },
|
|
42
|
+
play: async ({ canvasElement }) => {
|
|
43
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
44
|
+
await counter.updateComplete;
|
|
45
|
+
|
|
46
|
+
const button = counter.shadowRoot.querySelector('[part="button"]');
|
|
47
|
+
await expect(counter).toHaveAttribute('size', 'large');
|
|
48
|
+
await expect(getComputedStyle(button).fontSize).toBe('20px');
|
|
49
|
+
await expect(getComputedStyle(button).paddingTop).toBe('8px');
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const TextAttribute = {
|
|
54
|
+
args: { label: 'Add a point' },
|
|
55
|
+
play: async ({ canvasElement }) => {
|
|
56
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
57
|
+
await counter.updateComplete;
|
|
58
|
+
|
|
59
|
+
await expect(counter.label).toBe('Add a point');
|
|
60
|
+
await expect(counter.shadowRoot.querySelector('[part="button"]')).toHaveAccessibleName(
|
|
61
|
+
'Add a point'
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const SelectAttribute = {
|
|
67
|
+
args: { tone: 'danger' },
|
|
68
|
+
play: async ({ canvasElement }) => {
|
|
69
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
70
|
+
await counter.updateComplete;
|
|
71
|
+
|
|
72
|
+
const value = counter.shadowRoot.querySelector('[part="value"]');
|
|
73
|
+
await expect(counter).toHaveAttribute('tone', 'danger');
|
|
74
|
+
await expect(getComputedStyle(value).color).toBe('rgb(220, 20, 60)');
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const Properties = {
|
|
79
|
+
args: { count: 1, unit: { singular: 'point', plural: 'points' } },
|
|
80
|
+
play: async ({ canvasElement }) => {
|
|
81
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
82
|
+
await counter.updateComplete;
|
|
83
|
+
|
|
84
|
+
await expect(counter.unit).toEqual({ singular: 'point', plural: 'points' });
|
|
85
|
+
await expect(counter.shadowRoot.querySelector('[part="value"]')).toHaveTextContent('1 point');
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const ArrayProperty = {
|
|
90
|
+
args: { badges: ['new', 'hot'] },
|
|
91
|
+
play: async ({ args, canvasElement }) => {
|
|
92
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
93
|
+
await counter.updateComplete;
|
|
94
|
+
|
|
95
|
+
const badges = [...counter.shadowRoot.querySelectorAll('[part="badge"]')];
|
|
96
|
+
await expect(counter.badges).toEqual(args.badges);
|
|
97
|
+
await expect(counter).not.toHaveAttribute('badges');
|
|
98
|
+
await expect(badges).toHaveLength(2);
|
|
99
|
+
await expect(badges.map((badge) => badge.textContent)).toEqual(['new', 'hot']);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const DateProperty = {
|
|
104
|
+
args: { deadline: new Date('2026-12-24T00:00:00.000Z') },
|
|
105
|
+
play: async ({ canvasElement }) => {
|
|
106
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
107
|
+
await counter.updateComplete;
|
|
108
|
+
|
|
109
|
+
await expect(counter).not.toHaveAttribute('deadline');
|
|
110
|
+
await expect(counter.shadowRoot.querySelector('[part="deadline"]')).toHaveTextContent(
|
|
111
|
+
'2026-12-24'
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const Events = {
|
|
117
|
+
args: { 'count-changed-event': fn() },
|
|
118
|
+
play: async ({ args, canvasElement }) => {
|
|
119
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
120
|
+
await counter.updateComplete;
|
|
121
|
+
|
|
122
|
+
await userEvent.click(counter.shadowRoot.querySelector('[part="button"]'));
|
|
123
|
+
|
|
124
|
+
await expect(args['count-changed-event']).toHaveBeenCalledWith(
|
|
125
|
+
expect.objectContaining({ type: 'count-changed', detail: { count: 1 } })
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const Slots = {
|
|
131
|
+
args: {
|
|
132
|
+
'default-slot': '<strong>Score</strong>',
|
|
133
|
+
'prefix-slot': '★',
|
|
134
|
+
},
|
|
135
|
+
play: async ({ canvasElement }) => {
|
|
136
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
137
|
+
await counter.updateComplete;
|
|
138
|
+
|
|
139
|
+
await expect(counter.querySelector(':scope > strong:not([slot])')).toHaveTextContent('Score');
|
|
140
|
+
await expect(counter.querySelector(':scope > [slot="prefix"]')).toHaveTextContent('★');
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const CssCustomProperties = {
|
|
145
|
+
args: { '--demo-wc-counter-accent': 'rgb(102, 51, 153)' },
|
|
146
|
+
play: async ({ canvasElement }) => {
|
|
147
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
148
|
+
await counter.updateComplete;
|
|
149
|
+
|
|
150
|
+
const button = counter.shadowRoot.querySelector('[part="button"]');
|
|
151
|
+
await expect(getComputedStyle(button).backgroundColor).toBe('rgb(102, 51, 153)');
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const NumberCssCustomProperty = {
|
|
156
|
+
args: { badges: ['new'], '--demo-wc-counter-badge-opacity': 0.5 },
|
|
157
|
+
play: async ({ canvasElement }) => {
|
|
158
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
159
|
+
await counter.updateComplete;
|
|
160
|
+
|
|
161
|
+
const badge = counter.shadowRoot.querySelector('[part="badge"]');
|
|
162
|
+
await expect(counter.style.getPropertyValue('--demo-wc-counter-badge-opacity')).toBe('0.5');
|
|
163
|
+
await expect(getComputedStyle(badge).opacity).toBe('0.5');
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const CssParts = {
|
|
168
|
+
args: { 'value-part': 'color: rgb(220, 20, 60); font-weight: 700;' },
|
|
169
|
+
play: async ({ canvasElement }) => {
|
|
170
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
171
|
+
await counter.updateComplete;
|
|
172
|
+
|
|
173
|
+
const value = counter.shadowRoot.querySelector('[part="value"]');
|
|
174
|
+
await expect(getComputedStyle(value).color).toBe('rgb(220, 20, 60)');
|
|
175
|
+
await expect(getComputedStyle(value).fontWeight).toBe('700');
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export const CssStates = {
|
|
180
|
+
args: {
|
|
181
|
+
count: 4,
|
|
182
|
+
max: 5,
|
|
183
|
+
'at-max-state': 'outline: 2px solid rgb(0, 128, 0);',
|
|
184
|
+
},
|
|
185
|
+
play: async ({ canvasElement }) => {
|
|
186
|
+
const counter = canvasElement.querySelector('demo-wc-counter');
|
|
187
|
+
await counter.updateComplete;
|
|
188
|
+
|
|
189
|
+
await expect(getComputedStyle(counter).outlineStyle).toBe('none');
|
|
190
|
+
|
|
191
|
+
await userEvent.click(counter.shadowRoot.querySelector('[part="button"]'));
|
|
192
|
+
|
|
193
|
+
await waitFor(() => expect(counter.matches(':state(at-max)')).toBe(true));
|
|
194
|
+
await expect(getComputedStyle(counter).outlineColor).toBe('rgb(0, 128, 0)');
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const AllCategories = {
|
|
199
|
+
args: {
|
|
200
|
+
count: 2,
|
|
201
|
+
step: 3,
|
|
202
|
+
disabled: false,
|
|
203
|
+
size: 'small',
|
|
204
|
+
tone: 'success',
|
|
205
|
+
label: 'Add a star',
|
|
206
|
+
badges: ['sale'],
|
|
207
|
+
unit: { singular: 'star', plural: 'stars' },
|
|
208
|
+
deadline: new Date('2026-12-24T00:00:00.000Z'),
|
|
209
|
+
'count-changed-event': fn(),
|
|
210
|
+
'default-slot': 'Rating',
|
|
211
|
+
'prefix-slot': '★',
|
|
212
|
+
'--demo-wc-counter-accent': 'rgb(178, 34, 34)',
|
|
213
|
+
'--demo-wc-counter-badge-opacity': 0.8,
|
|
214
|
+
'value-part': 'font-variant-numeric: tabular-nums;',
|
|
215
|
+
'at-max-state': 'opacity: 0.6;',
|
|
216
|
+
},
|
|
217
|
+
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import CJS_COMPAT_NODE_URL_3ov4ld79bt3 from 'node:url';
|
|
2
|
-
import CJS_COMPAT_NODE_PATH_3ov4ld79bt3 from 'node:path';
|
|
3
|
-
import CJS_COMPAT_NODE_MODULE_3ov4ld79bt3 from "node:module";
|
|
4
|
-
|
|
5
|
-
var __filename = CJS_COMPAT_NODE_URL_3ov4ld79bt3.fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = CJS_COMPAT_NODE_PATH_3ov4ld79bt3.dirname(__filename);
|
|
7
|
-
var require = CJS_COMPAT_NODE_MODULE_3ov4ld79bt3.createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
// ------------------------------------------------------------
|
|
10
|
-
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
-
// ------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
// src/docgen/component-docgen/utils.ts
|
|
14
|
-
function isRecord(value) {
|
|
15
|
-
return value !== null && typeof value == "object";
|
|
16
|
-
}
|
|
17
|
-
function namedItems(value) {
|
|
18
|
-
return Array.isArray(value) ? value.filter((item) => isRecord(item) && typeof item.name == "string") : [];
|
|
19
|
-
}
|
|
20
|
-
function errorMessage(error) {
|
|
21
|
-
return error instanceof Error ? error.message : String(error);
|
|
22
|
-
}
|
|
23
|
-
var trimmedOrUndefined = (text) => typeof text == "string" && text.trim() || void 0;
|
|
24
|
-
function deprecationMessage(deprecated) {
|
|
25
|
-
if (deprecated)
|
|
26
|
-
return typeof deprecated == "string" ? trimmedOrUndefined(deprecated) : "deprecated";
|
|
27
|
-
}
|
|
28
|
-
function firstValue(sources, read) {
|
|
29
|
-
for (let source of sources) {
|
|
30
|
-
let value = read(source);
|
|
31
|
-
if (value !== void 0)
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// src/docgen/component-docgen/arg-types/alt-type.ts
|
|
37
|
-
var DEFAULT_TYPE_PROPERTY = "parsedType";
|
|
38
|
-
function readTypeText(item, typeProperty) {
|
|
39
|
-
let alternate = Reflect.get(item, typeProperty);
|
|
40
|
-
return isRecord(alternate) && typeof alternate.text == "string" && alternate.text.trim() ? alternate.text : typeof item.type?.text == "string" ? item.type.text : void 0;
|
|
41
|
-
}
|
|
42
|
-
function readCssPropertySyntax(property, typeProperty) {
|
|
43
|
-
return property.syntax ?? readTypeText(property, typeProperty);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// src/docgen/component-docgen/resolve-component/resolve-component.ts
|
|
47
|
-
import { loadCsf, unwrapExpression } from "storybook/internal/csf-tools";
|
|
48
|
-
import { recast, types as t } from "storybook/internal/babel";
|
|
49
|
-
import { readFileSync } from "node:fs";
|
|
50
|
-
function parseStoryFile(storyFilePath, title) {
|
|
51
|
-
try {
|
|
52
|
-
let source = readFileSync(storyFilePath, "utf8");
|
|
53
|
-
return loadCsf(source, { makeTitle: () => title }).parse();
|
|
54
|
-
} catch {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
var expressionFor = (node) => recast.print(node).code;
|
|
59
|
-
function tagFromNode(node) {
|
|
60
|
-
let expression = expressionFor(node), unwrapped = unwrapExpression(node);
|
|
61
|
-
if (t.isStringLiteral(unwrapped) && unwrapped.value !== "")
|
|
62
|
-
return { tag: unwrapped.value };
|
|
63
|
-
if (t.isTemplateLiteral(unwrapped) && unwrapped.expressions.length === 0) {
|
|
64
|
-
let tag = unwrapped.quasis[0]?.value.cooked;
|
|
65
|
-
if (tag)
|
|
66
|
-
return { tag };
|
|
67
|
-
}
|
|
68
|
-
return { reason: "component-not-a-tag", expression };
|
|
69
|
-
}
|
|
70
|
-
function resolveStoryComponent(csf) {
|
|
71
|
-
let component = csf._metaAnnotations.component;
|
|
72
|
-
return component ? tagFromNode(component) : { reason: "no-meta-component" };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export {
|
|
76
|
-
isRecord,
|
|
77
|
-
namedItems,
|
|
78
|
-
errorMessage,
|
|
79
|
-
trimmedOrUndefined,
|
|
80
|
-
deprecationMessage,
|
|
81
|
-
firstValue,
|
|
82
|
-
DEFAULT_TYPE_PROPERTY,
|
|
83
|
-
readTypeText,
|
|
84
|
-
readCssPropertySyntax,
|
|
85
|
-
parseStoryFile,
|
|
86
|
-
resolveStoryComponent
|
|
87
|
-
};
|