Skip to content

Commit

Permalink
Storybook: Add more max-width containers (#68080)
Browse files Browse the repository at this point in the history
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent 53dc79e commit f3ab0c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 16 additions & 14 deletions storybook/decorators/with-max-width-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
*/
import styled from '@emotion/styled';

/**
* A Storybook decorator to wrap a story in a div applying a max width and
* padding. This can be used to simulate real world constraints on components
* such as being located within the WordPress editor sidebars.
*/

const Wrapper = styled.div`
max-width: 248px;
`;
const maxWidthWrapperMap = {
none: 0,
'wordpress-sidebar': 248,
'small-container': 600,
'large-container': 960,
};

const Indicator = styled.div`
display: flex;
Expand All @@ -27,14 +24,19 @@ const Indicator = styled.div`
`;

export const WithMaxWidthWrapper = ( Story, context ) => {
if ( context.globals.maxWidthWrapper === 'none' ) {
/**
* A Storybook decorator to wrap a story in a div applying a max width.
* This can be used to simulate real world constraints on components
* such as being located within the WordPress editor sidebars.
*/
const maxWidth = maxWidthWrapperMap[ context.globals.maxWidthWrapper ];
if ( ! maxWidth ) {
return <Story { ...context } />;
}

return (
<Wrapper>
<div style={ { maxWidth } }>
<Story { ...context } />
<Indicator>Max-Width Wrapper - 248px</Indicator>
</Wrapper>
<Indicator>{ `Max-Width Wrapper - ${ maxWidth }px` }</Indicator>
</div>
);
};
2 changes: 2 additions & 0 deletions storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export const globalTypes = {
items: [
{ value: 'none', title: 'None' },
{ value: 'wordpress-sidebar', title: 'WP Sidebar' },
{ value: 'small-container', title: 'Small container' },
{ value: 'large-container', title: 'Large container' },
],
},
},
Expand Down

0 comments on commit f3ab0c2

Please sign in to comment.