@@ -7,6 +7,8 @@ import { withInfo } from '@storybook/addon-info';
77import { TableComponent } from './TableComponent' ;
88import { withStyleInfo } from './decorators/withStyleInfo' ;
99import { Fiori4ReactTheme } from './theme' ;
10+ import { document , history , window } from 'global' ;
11+ import qs from 'qs' ;
1012
1113export const propTablesExclude = [ ThemeProvider ] ;
1214
@@ -94,23 +96,66 @@ addParameters({
9496 }
9597} ) ;
9698
97- const themr = makeDecorator ( {
98- name : 'themr' ,
99- parameterName : 'themr' ,
100- skipIfNoParametersOrOptions : false ,
101- wrapper : ( getStory , context , { parameters } ) => {
99+ class ThemeContainer extends React . PureComponent {
100+ componentDidUpdate ( prevProps ) {
101+ const { contentDensity, setQueryParam } = this . props ;
102+ if ( contentDensity !== prevProps . contentDensity ) {
103+ setQueryParam ( {
104+ 'sap-ui-compactSize' : contentDensity === ContentDensity . Compact
105+ } ) ;
106+ }
107+ }
108+
109+ render ( ) {
110+ return this . props . children ;
111+ }
112+ }
113+
114+ const withQuery = makeDecorator ( {
115+ name : 'withQuery' ,
116+ parameterName : 'query' ,
117+ wrapper : ( getStory , context ) => {
118+ function setQueryParam ( queryObj ) {
119+ const iframe = window . parent . document . getElementById ( 'storybook-preview-iframe' ) ;
120+ const [ base , search ] = iframe . src . split ( '?' ) ;
121+ const currentQuery = qs . parse ( search , { ignoreQueryPrefix : true } ) ;
122+ iframe . src = `${ base } ?${ qs . stringify ( { ...currentQuery , ...queryObj } ) } ` ;
123+ }
124+ let contentDensity ;
125+ try {
126+ const iframe = window . parent . document . getElementById ( 'storybook-preview-iframe' ) ;
127+ const currentQuery = qs . parse ( iframe . src . split ( '?' ) [ 1 ] ) ;
128+ contentDensity =
129+ currentQuery [ 'sap-ui-compactSize' ] && currentQuery [ 'sap-ui-compactSize' ] !== 'false'
130+ ? ContentDensity . Compact
131+ : ContentDensity . Cozy ;
132+ } catch ( e ) {
133+ contentDensity = ContentDensity . Cozy ;
134+ }
135+
102136 return (
103- < ThemeProvider
104- theme = { select ( 'Theme' , [ Themes . sap_fiori3_light ] , Themes . sap_fiori3_light ) }
105- contentDensity = { select ( 'ContentDensity' , ContentDensity , ContentDensity . Compact ) }
106- withToastContainer
137+ < ThemeContainer
138+ theme = { select ( 'Theme' , [ Themes . sap_fiori_3 ] , Themes . sap_fiori_3 ) }
139+ contentDensity = { select ( 'ContentDensity' , ContentDensity , contentDensity ) }
140+ setQueryParam = { setQueryParam }
107141 >
108142 { getStory ( context ) }
109- </ ThemeProvider >
143+ </ ThemeContainer >
110144 ) ;
111145 }
112146} ) ;
113147
148+ const themr = makeDecorator ( {
149+ name : 'themr' ,
150+ parameterName : 'themr' ,
151+ skipIfNoParametersOrOptions : false ,
152+ wrapper : ( getStory , context ) => {
153+ // debugger;
154+ return < ThemeProvider withToastContainer > { getStory ( context ) } </ ThemeProvider > ;
155+ }
156+ } ) ;
157+
158+ addDecorator ( withQuery ) ;
114159addDecorator ( themr ) ;
115160
116161// Load all Stories
0 commit comments