Skip to content

Commit

Permalink
Storybook: Add margin checker tool (#43223)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka authored Aug 16, 2022
1 parent f78effd commit 1cd4c46
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
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
);
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

0 comments on commit 1cd4c46

Please sign in to comment.