Skip to content

Commit 71f0e56

Browse files
committed
feat(storybook): decorator for chromatic alignment
1 parent c8800a2 commit 71f0e56

File tree

167 files changed

+2730
-3228
lines changed

Some content is hidden

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

167 files changed

+2730
-3228
lines changed

.storybook/README.md

Lines changed: 93 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,75 @@ 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. If you need to override these styles, you can do so by adding a `customStorybookStyles` property to your args object. This should be a string of CSS rules. i.e.,
233+
234+
```js
235+
args: {
236+
customStorybookStyles: {
237+
flexDirection: "column",
238+
alignItems: "flex-start",
239+
},
240+
},
241+
```
242+
243+
The following properties are set on `#root-inner` by default:
244+
245+
```css
246+
display: flex;
247+
gap: 10px;
248+
```
249+
250+
If the display property is updated to something other than `*flex` or `*grid`, the gap property will be removed (`*flex` can equal `flex` or `inline-flex`). As long as the display property is not `contents`, the gap value will be assigned to `padding` instead.
251+
252+
For example, if the display value is set to `block`, the following styles will be applied:
253+
254+
```css
255+
display: block;
256+
padding: 10px;
257+
```
258+
259+
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.,
260+
261+
```js
262+
args: {
263+
customStorybookStyles: {
264+
backgroundColor: "rgb(238, 14, 189)",
265+
},
266+
},
267+
```
268+
269+
Any settings added by the story will override these values. You can unset a value completely using undefined, i.e.:
270+
271+
```js
272+
customStorybookStyles: {
273+
display: undefined,
274+
},
275+
```
276+
208277
## Templates
209278
210279
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 +309,14 @@ All return values for Template functions should be outputting TemplateResults. S
240309
import { html } from "lit";
241310
import { classMap } from "lit/directives/class-map.js";
242311
import { ifDefined } from "lit/directives/if-defined.js";
312+
import { when } from "lit/directives/when.js";
243313

244314
import { Template as Icon } from "@spectrum-css/icon/stories/template.js";
245315
import { Template as Avatar } from "@spectrum-css/avatar/stories/template.js";
246316
import { Template as ClearButton } from "@spectrum-css/clearbutton/stories/template.js";
247317

248318
import "../index.css";
249319

250-
// More on component templates: https://storybook.js.org/docs/web-components/writing-stories/introduction#using-args
251320
export const Template = ({
252321
rootClass = "spectrum-Tag",
253322
size = "m",
@@ -272,37 +341,32 @@ export const Template = ({
272341
console.warn(e);
273342
}
274343

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"
344+
return html`<div
345+
class=${classMap({
346+
[rootClass]: true,
347+
[`${rootClass}--size${size?.toUpperCase()}`]:
348+
typeof size !== "undefined",
349+
"is-emphasized": isEmphasized,
350+
"is-disabled": isDisabled,
351+
"is-invalid": isInvalid,
352+
"is-selected": isSelected,
353+
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
354+
})}
355+
id=${ifDefined(id)}
356+
tabindex="0"
289357
>
290-
${avatarUrl && !iconName
291-
? Avatar({
358+
${when(avatarUrl && !iconName, () => Avatar({
292359
...globals,
293360
image: avatarUrl,
294361
size: "50",
295-
})
296-
: ""} ${iconName
297-
? Icon({
362+
}))}
363+
${when(iconName, () => Icon({
298364
...globals,
299365
iconName,
300366
customClasses: [`${rootClass}s-itemIcon`],
301-
})
302-
: ""}
367+
}))}}
303368
<span class="${rootClass}s-itemLabel">${label}</span>
304-
${hasClearButton
305-
? ClearButton({
369+
${when(hasClearButton, () => ClearButton({
306370
...globals,
307371
customClasses: [`${rootClass}-clearButton`],
308372
onclick: (evt) => {
@@ -312,10 +376,8 @@ export const Template = ({
312376
const wrapper = el.closest(rootClass);
313377
wrapper.parentNode.removeChild(wrapper);
314378
},
315-
})
316-
: ""}
317-
</div>
318-
`;
379+
}))}
380+
</div>`;
319381
};
320382
```
321383
@@ -339,142 +401,5 @@ Runs will generate a JUnit XML file with build results (`chromatic-build-{buildN
339401
340402
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`).
341403
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-
---
404+
<!-- @todo Document the best practices for outputting multiple template examples in one view -->
405+
<!-- @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)