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 margin checker tool #43223

Merged
merged 1 commit into from
Aug 16, 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
40 changes: 40 additions & 0 deletions storybook/decorators/with-margin-checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* External dependencies
*/
import styled from '@emotion/styled';

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

const Bumper = styled.div`
display: flex;
justify-content: center;
align-items: center;
height: 32px;
background-image: repeating-linear-gradient(
45deg,
transparent,
transparent 2px,
#e0e0e0 2px,
#e0e0e0 14px
);
Comment on lines +15 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This use of gradient is so much fun!

text-transform: uppercase;
font-size: 11px;
font-weight: 500;
color: #757575;
`;

export const WithMarginChecker = ( Story, context ) => {
if ( context.globals.marginChecker === 'hide' ) {
return <Story { ...context } />;
}

return (
<>
<Bumper>Margin Checker</Bumper>
<Story { ...context } />
<Bumper>Margin Checker</Bumper>
</>
);
};
16 changes: 15 additions & 1 deletion storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Internal dependencies
*/
import { WithGlobalCSS } from './decorators/with-global-css';
import { WithMarginChecker } from './decorators/with-margin-checker';
import { WithRTL } from './decorators/with-rtl';
import './style.scss';

Expand Down Expand Up @@ -32,9 +33,22 @@ export const globalTypes = {
],
},
},
marginChecker: {
name: 'Margin Checker',
description:
'Show a div before and after the component to check for unwanted margins.',
defaultValue: 'hide',
toolbar: {
icon: 'collapse',
items: [
{ value: 'hide', title: 'Hide' },
{ value: 'show', title: 'Show' },
],
},
},
};

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

export const parameters = {
controls: {
Expand Down