-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathpreview.ts
More file actions
71 lines (64 loc) · 1.93 KB
/
preview.ts
File metadata and controls
71 lines (64 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type {
Preview,
WebComponentsRenderer,
} from '@storybook/web-components-vite';
import '../src/styles/cp.css';
import './preview.css';
import {icons} from '@lion/ui/icon.js';
import {html} from 'lit';
import {withThemeByDataAttribute} from '@storybook/addon-themes';
import {setCustomElementsManifest} from '@storybook/web-components';
import manifest from '../dist/custom-elements.json' with {type: 'json'};
import {setStorybookHelpersConfig} from '@wc-toolkit/storybook-helpers';
import {within as withinShadow} from 'shadow-dom-testing-library';
setStorybookHelpersConfig({
/** hides the `arg ref` label on each control */
hideArgRef: false,
/** sets the custom type reference in the Custom Elements Manifest */
typeRef: 'parsedTypes',
/** Adds a <script> tag where a `component` variable will reference the story's component */
setComponentVariable: false,
/** renders default values for attributes and CSS properties */
renderDefaultValues: false,
});
setCustomElementsManifest(manifest);
icons.addIconResolver('craft', (iconSet: string, name: string) => {
return html`<div>${iconSet} - ${name}</div>`;
});
const preview: Preview = {
beforeEach({canvasElement, canvas}) {
Object.assign(canvas, {...withinShadow(canvasElement)});
},
parameters: {
controls: {
expanded: true,
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
options: {
storySort: {
method: 'alphabetical',
},
},
a11y: {
// 'todo' - show a11y violations in the test UI only
// 'error' - fail CI on a11y violations
// 'off' - skip a11y checks entirely
test: 'todo',
},
},
decorators: [
withThemeByDataAttribute<WebComponentsRenderer>({
themes: {
light: 'light',
dark: 'dark',
},
defaultTheme: 'light',
attributeName: 'data-theme',
}),
],
tags: ['autodocs'],
};
export default preview;