Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storybook: Add theme switcher tool #44715

Merged
merged 2 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions storybook/decorators/with-theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Internal dependencies
*/
import Theme from '../../packages/components/src/theme';

/**
* A Storybook decorator to show a div before and after the story to check for unwanted margins.
*/

export const WithTheme = ( Story, context ) => {
const themes = {
default: {},
modern: {
accent: '#3858e9',
},
sunrise: {
// This color was chosen intentionally, because for sufficient contrast,
// the foreground text should be black when this orange is used as a background color.
accent: '#dd823b',
},
};

return (
<Theme { ...themes[ context.globals.componentsTheme ] }>
<Story { ...context } />
</Theme>
);
};
21 changes: 20 additions & 1 deletion storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { WithGlobalCSS } from './decorators/with-global-css';
import { WithMarginChecker } from './decorators/with-margin-checker';
import { WithRTL } from './decorators/with-rtl';
import { WithTheme } from './decorators/with-theme';
import './style.scss';

export const globalTypes = {
Expand All @@ -19,6 +20,19 @@ export const globalTypes = {
],
},
},
componentsTheme: {
name: 'Theme',
description: 'Change the components theme. (Work in progress)',
defaultValue: 'default',
toolbar: {
icon: 'paintbrush',
items: [
{ value: 'default', title: 'Default' },
{ value: 'modern', title: 'Modern' },
{ value: 'sunrise', title: 'Sunrise' },
],
},
},
css: {
name: 'Global CSS',
description:
Expand Down Expand Up @@ -51,7 +65,12 @@ export const globalTypes = {
},
};

export const decorators = [ WithGlobalCSS, WithMarginChecker, WithRTL ];
export const decorators = [
WithTheme,
WithGlobalCSS,
WithMarginChecker,
WithRTL,
];

export const parameters = {
controls: {
Expand Down