Skip to content

Commit

Permalink
Storybook: Add more max-width containers
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Dec 18, 2024
1 parent 287d653 commit 131baca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
25 changes: 10 additions & 15 deletions storybook/decorators/with-max-width-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
*/
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 Indicator = styled.div`
display: flex;
justify-content: center;
Expand All @@ -27,14 +17,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 = context.globals.maxWidthWrapper;
if ( ! context.globals.maxWidthWrapper ) {
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>
);
};
6 changes: 4 additions & 2 deletions storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ export const globalTypes = {
toolbar: {
icon: 'outline',
items: [
{ value: 'none', title: 'None' },
{ value: 'wordpress-sidebar', title: 'WP Sidebar' },
{ value: 0, title: 'None' },
{ value: 248, title: 'WP Sidebar' },
{ value: 960, title: 'Large container' },
{ value: 600, title: 'Small container' },
],
},
},
Expand Down

0 comments on commit 131baca

Please sign in to comment.