Skip to content

Commit f6b0405

Browse files
committed
feat(storybook): decorator for chromatic alignment
1 parent 80b3b78 commit f6b0405

File tree

155 files changed

+3022
-3635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+3022
-3635
lines changed

.storybook/README.md

Lines changed: 88 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ argTypes: {
120120
121121
_Note:_ In your story, be sure to include the `if: false` override otherwise the control will only show up if you have a `setName` arg and it is equal to `workflow`.
122122
123-
Want to load UI icons instead? Use the following variable import instead:
123+
Want to load UI icons instead? Use the following variable import instead of the above:
124124
125125
```js
126126
argTypes: {
@@ -205,6 +205,70 @@ label: {
205205
},
206206
```
207207
208+
### args
209+
210+
In a story, the args object contains all the default values for the component. These values will be used to render the component in the storybook preview. The values can be overridden by the user via the controls or by setting a custom args object in a specific story.
211+
212+
The default story should _almost_ always have any empty args object because it is, by nature, using all the default settings.
213+
214+
```js
215+
export const Default = Template.bind({});
216+
Default.args = {};
217+
```
218+
219+
Subsequent stories can override the default args object by setting a new value for the desired property. i.e.,
220+
221+
```js
222+
export const Express = Template.bind({});
223+
Express.args = {
224+
express: true
225+
};
226+
```
227+
228+
Try to focus stories on a single property or set of properties. This will make it easier for users to find the story they are looking for and will help in debugging issues.
229+
230+
#### customStorybookStyles
231+
232+
All stories are wrapped in a custom decorator that applies a few standard display properties to the preview.
233+
234+
```css
235+
#root-inner {
236+
position: relative;
237+
gap: 1rem;
238+
padding: max(10px, 1rem);
239+
}
240+
```
241+
242+
If you need to override or add to these styles, you can do so by adding a `customStorybookStyles` property to your args object. This should be an object with CSS rules in the same `styleMap` format used by lit. i.e.,
243+
244+
```js
245+
args: {
246+
customStorybookStyles: {
247+
display: "flex",
248+
flexDirection: "column",
249+
alignItems: "flex-start",
250+
},
251+
},
252+
```
253+
254+
Leveraging an argType in your component that matches `staticColor` with allowed values of `white` or `black` will automatically set the background color of the preview to an appropriate value (white will use `rgb(15, 121, 125)`; black will use `rgb(181, 209, 211)`). If you need to override this value, you can do so by setting the `customStorybookStyles` property to an object with a `backgroundColor` property. i.e.,
255+
256+
```js
257+
args: {
258+
customStorybookStyles: {
259+
backgroundColor: "rgb(238, 14, 189)",
260+
},
261+
},
262+
```
263+
264+
Any settings added by the story will override these values. You can unset a value completely using undefined, i.e.:
265+
266+
```js
267+
customStorybookStyles: {
268+
padding: undefined,
269+
},
270+
```
271+
208272
## Templates
209273
210274
The goal of the template files is to create a definition for this component to enforce and demonstrate the allowed semantics and required classNames and settings to achieve the desired output (based on the user's selected controls).
@@ -240,14 +304,14 @@ All return values for Template functions should be outputting TemplateResults. S
240304
import { html } from "lit";
241305
import { classMap } from "lit/directives/class-map.js";
242306
import { ifDefined } from "lit/directives/if-defined.js";
307+
import { when } from "lit/directives/when.js";
243308

244309
import { Template as Icon } from "@spectrum-css/icon/stories/template.js";
245310
import { Template as Avatar } from "@spectrum-css/avatar/stories/template.js";
246311
import { Template as ClearButton } from "@spectrum-css/clearbutton/stories/template.js";
247312

248313
import "../index.css";
249314

250-
// More on component templates: https://storybook.js.org/docs/web-components/writing-stories/introduction#using-args
251315
export const Template = ({
252316
rootClass = "spectrum-Tag",
253317
size = "m",
@@ -272,37 +336,32 @@ export const Template = ({
272336
console.warn(e);
273337
}
274338

275-
return html`
276-
<div
277-
class=${classMap({
278-
[rootClass]: true,
279-
[`${rootClass}--size${size?.toUpperCase()}`]:
280-
typeof size !== "undefined",
281-
"is-emphasized": isEmphasized,
282-
"is-disabled": isDisabled,
283-
"is-invalid": isInvalid,
284-
"is-selected": isSelected,
285-
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
286-
})}
287-
id=${ifDefined(id)}
288-
tabindex="0"
339+
return html`<div
340+
class=${classMap({
341+
[rootClass]: true,
342+
[`${rootClass}--size${size?.toUpperCase()}`]:
343+
typeof size !== "undefined",
344+
"is-emphasized": isEmphasized,
345+
"is-disabled": isDisabled,
346+
"is-invalid": isInvalid,
347+
"is-selected": isSelected,
348+
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
349+
})}
350+
id=${ifDefined(id)}
351+
tabindex="0"
289352
>
290-
${avatarUrl && !iconName
291-
? Avatar({
353+
${when(avatarUrl && !iconName, () => Avatar({
292354
...globals,
293355
image: avatarUrl,
294356
size: "50",
295-
})
296-
: ""} ${iconName
297-
? Icon({
357+
}))}
358+
${when(iconName, () => Icon({
298359
...globals,
299360
iconName,
300361
customClasses: [`${rootClass}s-itemIcon`],
301-
})
302-
: ""}
362+
}))}}
303363
<span class="${rootClass}s-itemLabel">${label}</span>
304-
${hasClearButton
305-
? ClearButton({
364+
${when(hasClearButton, () => ClearButton({
306365
...globals,
307366
customClasses: [`${rootClass}-clearButton`],
308367
onclick: (evt) => {
@@ -312,10 +371,8 @@ export const Template = ({
312371
const wrapper = el.closest(rootClass);
313372
wrapper.parentNode.removeChild(wrapper);
314373
},
315-
})
316-
: ""}
317-
</div>
318-
`;
374+
}))}
375+
</div>`;
319376
};
320377
```
321378
@@ -339,142 +396,5 @@ Runs will generate a JUnit XML file with build results (`chromatic-build-{buildN
339396
340397
Running without publishing to Chromatic? Add the `--dry-run` flag. Need more information to debug a run? Try the `--diagnostics` flag (writes process context information to `chromatic-diagnostics.json`).
341398
342-
# Migration to Storybook 7.0(Draft)
343-
344-
## Updates
345-
346-
---
347-
`*` Added support for handler actions with ```withActions``` on each stories which have action handlers.
348-
349-
Example:
350-
351-
```js
352-
import globalThis from 'global';
353-
+ import { withActions } from '@storybook/addon-actions/decorator';
354-
355-
export default {
356-
component: globalThis.Components.Button,
357-
args: {
358-
label: 'Click Me!',
359-
},
360-
parameters: {
361-
chromatic: { disable: true },
362-
},
363-
};
364-
export const Basic = {
365-
parameters: {
366-
handles: [{ click: 'clicked', contextmenu: 'right clicked' }],
367-
},
368-
+ decorators: [withActions],
369-
};
370-
```
371-
372-
`*` Upgraded to ```Webpack 5``` for improved bundling and performance from ```webpack 4```
373-
374-
`*` @storybook addons dependencies are upgraded to v7 from v6
375-
376-
```js
377-
"@storybook/addon-docs": "^7.0.12",
378-
"@storybook/addon-essentials": "^7.0.12",
379-
"@storybook/api": "^7.0.12",
380-
"@storybook/client-api": "^7.0.12",
381-
"@storybook/components": "^7.0.12",
382-
"@storybook/core-events": "^7.0.12",
383-
"@storybook/manager-api": "^7.0.12",
384-
"@storybook/preview-api": "^7.0.12",
385-
"@storybook/theming": "^7.0.12",
386-
"@storybook/web-components-webpack5": "^7.0.12",
387-
"@whitespace/storybook-addon-html": "^5.1.4",
388-
```
389-
390-
`*` Added a new "Controls" addon for interactive component props editing.
391-
392-
`*` Introduced a new "Docs-only" mode for isolating component documentation.
393-
394-
`*` Improved the addon ecosystem with new and updated addons.
395-
396-
<br></br>
397-
398-
## Breaking Changes
399-
400-
---
401-
`*` client-api is deperacted and preview-api is introduced
402-
403-
```js
404-
- import { useEffect } from '@storybook/client-api';
405-
+ import { useEffect } from '@storybook/preview-api';
406-
```
407-
408-
`*` @storybook/addons is deperacted and replaced with @storybook/manager-api
409-
410-
```js
411-
- import { addons } from '@storybook/addons';
412-
+ import { addons } from '@storybook/manager-api';
413-
```
414-
415-
`*` ```@storybook-webcomponents``` is deprecated. ```@storybook/web-components-webpack'``` is added with webpack 5 support.
416-
417-
```js
418-
- framework: '@storybook/web-components',
419-
+ framework: {
420-
name: '@storybook/web-components-webpack5',
421-
options: {
422-
fastRefresh: true,
423-
builder: { lazyCompilation: true },
424-
},
425-
},
426-
427-
```
428-
429-
`*` Docs is now added to every component on the sidebar with the below code in Storybook 7
430-
431-
```js
432-
docs: {
433-
autodocs: true,
434-
defaultName: 'Docs',
435-
},
436-
```
437-
438-
`*` preview.js is exported as default in Storybook 7
439-
440-
```js
441-
- export const parameters = {
442-
- actions: { argTypesRegex: '^on[A-Z].*' },
443-
- };
444-
445-
+ export default {
446-
+ parameters: {
447-
+ actions: { argTypesRegex: '^on[A-Z].*' },
448-
+ },
449-
+ };
450-
```
451-
452-
## Deprecations(Addons)
453-
454-
---
455-
456-
`*` ```"@storybook/client-api"``` is deprecated
457-
458-
`*` ```"@storybook/addons"``` is deprecated
459-
460-
## Bug Fixes
461-
462-
---
463-
`*` Fixed various issues related to performance, rendering, and compatibility.
464-
465-
`*` Resolved problems with the Storybook UI, including layout glitches and navigation bugs.
466-
467-
`*` Fixed bugs in calender storybook
468-
469-
## Improvements
470-
471-
---
472-
`*` Improved the overall performance and stability of the Storybook development environment.
473-
474-
`*` Enhanced the documentation with updated examples and guides.
475-
476-
`*` Optimized the build process for faster bundling and reduced file sizes.
477-
478-
`*` Upgraded dependencies to their latest versions for improved compatibility and security.
479-
480-
---
399+
<!-- @todo Document the best practices for outputting multiple template examples in one view -->
400+
<!-- @todo Document the best practices for chromatic-only stories and settings -->

.storybook/assets/base.css

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
html,
2+
body {
3+
min-block-size: 100%;
4+
}
5+
16
body {
27
margin: 0;
38
font-size: 10px;
@@ -31,7 +36,7 @@ nav .spectrum-Site-logo {
3136

3237
.docblock-argstable-body td > span:has(select),
3338
.docblock-argstable-body td textarea {
34-
max-width: 280px !important;
39+
max-inline-size: 280px !important;
3540
}
3641

3742
#storybook-explorer-tree {
@@ -51,7 +56,7 @@ button.sidebar-item {
5156
font-weight: 400 !important;
5257
font-size: 14px !important;
5358
line-height: 1.4em !important;
54-
height: 32px !important;
59+
block-size: 32px !important;
5560
border-radius: 4px !important;
5661
padding-inline-start: 24px !important;
5762
padding-inline-end: 12px !important;
@@ -122,7 +127,7 @@ select:focus,
122127
}
123128

124129
[role="main"] > div > div:first-child .os-content > div > div > * {
125-
margin-top: 0 !important;
130+
margin-block-start: 0 !important;
126131
}
127132

128133
[role="main"] > div > div:first-child .os-content > div > div > div > a {
@@ -161,8 +166,8 @@ select:focus,
161166
button::after {
162167
content: "◢";
163168
position: absolute;
164-
bottom: -3px;
165-
right: -1px;
169+
inset-block-end: -3px;
170+
inset-inline-end: -1px;
166171
display: inline-block;
167172
transform: scale(0.5);
168173
color: rgb(177, 177, 177);
@@ -190,7 +195,7 @@ select:focus,
190195
> div
191196
> div
192197
:is(button, a:not(:has(button)), span) {
193-
height: 32px;
198+
block-size: 32px;
194199
}
195200

196201
[role="main"]
@@ -202,3 +207,14 @@ select:focus,
202207
:is(button:hover, a:hover:not(:has(button))) {
203208
background-color: rgb(230, 230, 230) !important;
204209
}
210+
211+
.docs-story {
212+
background-color: var(--spectrum-background-base-color, var(
213+
--spectrum-alias-background-color-default,
214+
var(--spectrum-global-color-gray-100)
215+
));
216+
}
217+
218+
.docs-story #root-inner {
219+
margin: 10px;
220+
}

0 commit comments

Comments
 (0)