Skip to content

Commit f1902b4

Browse files
authored
feat(react-storybook-addon): add shared SB preview styles (#35949)
1 parent 8c1bfd7 commit f1902b4

File tree

8 files changed

+62
-31
lines changed

8 files changed

+62
-31
lines changed

.storybook/preview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import './docs-root.css';
1+
import '../packages/react-components/react-storybook-addon/src/styles.css';
22
import '../packages/react-components/react-storybook-addon-export-to-sandbox/src/styles.css';
33
import { withLinks } from '@storybook/addon-links';
44

apps/public-docsite-v9/.storybook/docs-root-v9.css

Lines changed: 0 additions & 24 deletions
This file was deleted.

apps/public-docsite-v9/.storybook/preview.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as rootPreview from '../../../.storybook/preview';
22

3-
import './docs-root-v9.css';
4-
53
/** @type {NonNullable<import('@storybook/react').Decorator[]>} */
64
export const decorators = rootPreview.decorators;
75

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "feat: add shared SB preview styles",
4+
"packageName": "@fluentui/react-storybook-addon",
5+
"email": "dmytrokirpa@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-storybook-addon/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export const ThemePicker: React.FC<{ context: FluentStoryContext }> = ({ context
3838
};
3939
```
4040

41+
### Shared Storybook Preview Styles
42+
43+
The package ships a `styles.css` file with shared Storybook preview styles (docs layout, table formatting, theme-aware backgrounds, etc.). Import it once in your Storybook `preview.js`/`preview.ts`:
44+
45+
```js
46+
// .storybook/preview.js
47+
import '@fluentui/react-storybook-addon/styles.css';
48+
```
49+
4150
### Augmented Docs Blocks
4251

4352
This presets uses [custom docs container and page](https://storybook.js.org/docs/7/writing-docs/autodocs#customize-the-docs-container) for unified FluentUI experience including:

packages/react-components/react-storybook-addon/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"main": "lib-commonjs/index.js",
66
"module": "lib/index.js",
77
"typings": "./dist/index.d.ts",
8-
"sideEffects": false,
98
"repository": {
109
"type": "git",
1110
"url": "https://github.com/microsoft/fluentui"
@@ -53,11 +52,16 @@
5352
"require": "./lib-commonjs/index.js"
5453
},
5554
"./preset": "./preset.js",
55+
"./styles.css": "./dist/styles.css",
5656
"./package.json": "./package.json"
5757
},
58+
"sideEffects": [
59+
"./dist/styles.css"
60+
],
5861
"files": [
5962
"*.md",
6063
"dist/*.d.ts",
64+
"dist/styles.css",
6165
"lib",
6266
"lib-commonjs",
6367
"preset.js"

packages/react-components/react-storybook-addon/project.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@
2626
],
2727
"target": "build"
2828
}
29-
]
29+
],
30+
"options": {
31+
"assets": [
32+
{
33+
"input": "{projectRoot}/src",
34+
"output": "dist",
35+
"glob": "styles.css"
36+
}
37+
]
38+
}
3039
}
3140
}
3241
}

.storybook/docs-root.css renamed to packages/react-components/react-storybook-addon/src/styles.css

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
padding: 0;
199199
border-collapse: collapse;
200200
}
201+
201202
#storybook-docs table:not(.docblock-argstable, .sbdocs-preview table) tr {
202203
border-top: 1px solid rgba(0, 0, 0, 0.1);
203204
}
@@ -428,9 +429,11 @@ h1.fluent {
428429

429430
h1.fluent .fluent-version {
430431
display: block;
431-
font-size: 24px; /* --font-size-base-600 */
432+
font-size: 24px;
433+
/* --font-size-base-600 */
432434
line-height: 32px;
433-
color: #707070; /* --color-neutral-foreground-3 */
435+
color: #707070;
436+
/* --color-neutral-foreground-3 */
434437
}
435438

436439
h2.fluent {
@@ -440,3 +443,28 @@ h2.fluent {
440443
line-height: 36px;
441444
letter-spacing: -0.16px;
442445
}
446+
447+
/* remove the docs wrapper bg to let page bg show through */
448+
/* remove unnecessary padding now that theme switcher is not taking up space */
449+
#storybook-docs .sbdocs-wrapper {
450+
background: transparent !important;
451+
padding: 0 48px;
452+
}
453+
454+
/* sb-show-main is missing during page transitions causing a page shift */
455+
/* todo: cleanup once we no longer inherit docs-root */
456+
.sb-show-main.sb-main-fullscreen,
457+
.sb-main-fullscreen {
458+
margin: 0;
459+
padding: 0;
460+
display: block;
461+
}
462+
463+
/* remove loading overlay */
464+
.sb-preparing-story,
465+
.sb-preparing-docs,
466+
.sb-nopreview,
467+
.sb-errordisplay,
468+
.sidebar-container .search-field + div {
469+
display: none !important;
470+
}

0 commit comments

Comments
 (0)