forked from qld-gov-au/qgds-bootstrap5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update storybook to surface desigh (Light, Light alt, Dark, Dark alt)…
… switcher for the default view and include viewports, add viewports to chromatic snapshots Accordion shows how to override theme switcher on individual stories
- Loading branch information
Showing
6 changed files
with
206 additions
and
1,359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// .storybook/modes.js | ||
|
||
export const allModes = { | ||
mobile: { | ||
viewport: "small", | ||
}, | ||
desktop: { | ||
viewport: "large", | ||
}, | ||
"Light": { | ||
theme: "light", | ||
}, | ||
"Light alternative": { | ||
theme: "alt", | ||
}, | ||
"Dark": { | ||
theme: "dark", | ||
}, | ||
"Dark alternative": { | ||
theme: "dark-alt", | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,95 @@ | ||
|
||
import "../dist/assets/js/bootstrap.min.js"; | ||
import "../dist/assets/js/main.js"; | ||
import "../dist/assets/css/qld.bootstrap.css"; | ||
import {withThemeByClassName} from '@storybook/addon-themes'; | ||
import {allModes} from "./modes.js"; | ||
// import { withThemeByDataAttribute } from '@storybook/addon-themes'; | ||
|
||
|
||
/** @type { import('@storybook/html-vite').Preview } */ | ||
const preview = { | ||
|
||
parameters: { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
hideNoControlsWarning: true, | ||
expanded: true, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/i, | ||
}, | ||
}, | ||
html: { | ||
highlighter: { | ||
wrapLines: false, | ||
}, | ||
parameters: { | ||
// actions: {argTypesRegex: "^on[A-Z].*"}, | ||
backgrounds: { | ||
values: [ | ||
{name: 'default', value: '#FFFFFF'}, | ||
{name: 'light', value: '#EFF4F9'}, | ||
{name: 'alternative', value: '#E8E8E8'}, | ||
], | ||
}, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/i, | ||
}, | ||
}, | ||
chromatic: { | ||
//🔶 Test each story for ArticleCard in two modes | ||
modes: { | ||
// Light: allModes["Light"], | ||
// "Light alternative": allModes["Light alternative"], | ||
// Dark: allModes["Dark"], | ||
// "Dark alternative": allModes["Dark alternative"], | ||
mobile: allModes["mobile"], | ||
desktop: allModes["desktop"], | ||
"1200px": { viewport: 1200 }, //original non-modes based baseline | ||
}, | ||
}, | ||
docs: { | ||
source: { | ||
excludeDecorators: true, | ||
}, | ||
}, | ||
expanded: true, | ||
hideNoControlsWarning: true, | ||
html: { | ||
highlighter: { | ||
wrapLines: false, | ||
}, | ||
}, | ||
viewport: { | ||
viewports: { | ||
small: {name: "Small", styles: {width: "640px", height: "800px"}}, | ||
//TODO: add tablet style | ||
large: {name: "Large", styles: {width: "1024px", height: "1000px"}}, | ||
}, | ||
}, | ||
}, | ||
docs: { | ||
source: { | ||
excludeDecorators: true, | ||
}, | ||
|
||
}, | ||
backgrounds: { | ||
values: [ | ||
{ name: 'default', value: '#FFFFFF' }, | ||
{ name: 'light', value: '#EFF4F9' }, | ||
{ name: 'alternative', value: '#E8E8E8' }, | ||
], | ||
}, | ||
}, | ||
decorators: [ | ||
|
||
decorators: [ | ||
(Story) => { | ||
return ` | ||
// data-bs-theme="dark" does not work, use legacy way | ||
withThemeByClassName({ | ||
themes: { | ||
"Light": 'light', | ||
"Light alternative": 'alt', | ||
"Dark": 'dark', | ||
"Dark alternative": 'dark-alt', | ||
}, | ||
defaultTheme: 'light', | ||
}), | ||
//QGDS BS theming is not using data-bs-theme="dark" correctly. https://getbootstrap.com/docs/5.3/customize/color-modes/ | ||
// withThemeByDataAttribute({ | ||
// themes: { | ||
// light: 'light', | ||
// dark: 'dark', | ||
// }, | ||
// defaultTheme: 'light', | ||
// attributeName: 'data-bs-theme', | ||
// }), | ||
(Story) => { | ||
return ` | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
${Story()} | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
export default preview; |
Oops, something went wrong.