11import React from 'react' ;
22import Rect from '@reach/rect' ;
3- import { styled , css } from '@storybook/theming' ;
3+ import { styled , cx , css } from '@storybook/theming' ;
44
55const layout = React . createContext ( { } ) ;
66
@@ -14,7 +14,7 @@ const panelDimensions = rect =>
1414 : { } ;
1515
1616const AddonHolder = styled ( 'div' ) `
17- height: 100;
17+ height: 100% ;
1818 label: addon-holder;
1919` ;
2020
@@ -31,7 +31,21 @@ export const LayoutProvider = ({ children }) => (
3131 </ Rect >
3232) ;
3333
34- const StyledLayout = styled ( 'div' ) `
34+
35+ const StyledOverridden = ( {
36+ className,
37+ overrides,
38+ children,
39+ isLandscape,
40+ size,
41+ ...props
42+ } ) => (
43+ < div className = { `${ className } ${ overrides } ` } { ...props } >
44+ { children }
45+ </ div >
46+ ) ;
47+
48+ const StyledLayout = styled ( StyledOverridden ) `
3549 display: flex;
3650 flex-direction: ${ ( { isLandscape } ) => ( isLandscape ? 'row' : 'column' ) } ;
3751 justify-content: space-between;
@@ -40,30 +54,28 @@ const StyledLayout = styled('div')`
4054 label: addon-layout;
4155` ;
4256
43- export const Layout = ( { children } ) => (
57+ export const Layout = ( { className , children } ) => (
4458 < layout . Consumer >
4559 { ( { isLandscape } ) => (
46- < StyledLayout isLandscape = { isLandscape } > { children } </ StyledLayout >
60+ < StyledLayout isLandscape = { isLandscape } overrides = { className } > { children } </ StyledLayout >
4761 ) }
4862 </ layout . Consumer >
4963) ;
5064
51- const StyledBlock = styled . div ( ( { isLandscape, size } ) => ( {
52- flexGrow : 1 ,
53- ...( size
54- ? {
55- ...( isLandscape ? { width : size } : { height : size } ) ,
56- flexGrow : undefined ,
57- }
58- : {
59- ...( isLandscape ? { width : 2 } : { height : 2 } ) ,
60- } ) ,
61- } ) ) ;
6265
63- export const Block = ( { size, children } ) => (
66+ const px = v => `${ v } px` ;
67+
68+ const StyledBlock = styled ( StyledOverridden ) `
69+ ${ ( { isLandscape } ) => ( isLandscape ? 'width' : 'height' ) } : ${ ( { size } ) =>
70+ size ? px ( size ) : '2px' } ;
71+ ${ ( { size } ) => ( size ? '' : 'flex-grow: 1;' ) }
72+ label: addon-block;
73+ ` ;
74+
75+ export const Block = ( { size, children, className } ) => (
6476 < layout . Consumer >
6577 { ( { isLandscape } ) => (
66- < StyledBlock size = { size } isLandscape = { isLandscape } >
78+ < StyledBlock size = { size } isLandscape = { isLandscape } overrides = { className } >
6779 { children }
6880 </ StyledBlock >
6981 ) }
0 commit comments