@@ -57,63 +57,66 @@ class Document extends Component<DocumentProps, DocumentState> {
5757 }
5858
5959 state : DocumentState = {
60- selectedDetailsTabIndex : 0 ,
60+ selectedDetailsTabId : undefined ,
6161 pageRef : null ,
62- componentTheme : { }
62+ componentTheme : undefined
6363 }
6464
6565 ref : HTMLDivElement | null = null
6666
6767 componentDidMount ( ) {
6868 this . props . makeStyles ?.( )
69- this . setState ( { pageRef : this . ref } )
70- this . fetchGenerateComponentTheme ( )
69+ this . setState ( {
70+ pageRef : this . ref ,
71+ selectedDetailsTabId : this . props . doc . id
72+ } )
7173 }
7274
7375 fetchGenerateComponentTheme = async ( ) => {
7476 const { doc, themeVariables } = this . props
75- const generateTheme = doc ?. componentInstance ?. generateComponentTheme
77+ let generateTheme
78+ if ( this . state . selectedDetailsTabId === doc . id ) {
79+ generateTheme = doc ?. componentInstance ?. generateComponentTheme
80+ } else {
81+ generateTheme = doc ?. children ?. find (
82+ ( value ) => value . id === this . state . selectedDetailsTabId
83+ ) ?. componentInstance ?. generateComponentTheme
84+ }
7685 const generateThemeFunctional =
7786 functionalComponentThemes [
7887 doc . id as keyof typeof functionalComponentThemes
7988 ]
80- if (
81- generateTheme &&
82- typeof generateTheme === 'function' &&
83- themeVariables
84- ) {
89+ if ( typeof generateTheme === 'function' && themeVariables ) {
8590 this . setState ( { componentTheme : generateTheme ( themeVariables ) } )
8691 } else if ( generateThemeFunctional && themeVariables ) {
8792 const componentTheme = await generateThemeFunctional ( themeVariables )
8893 this . setState ( { componentTheme : componentTheme } )
94+ } else {
95+ this . setState ( { componentTheme : undefined } )
8996 }
9097 }
9198
92- componentDidUpdate ( prevProps : typeof this . props ) {
99+ componentDidUpdate ( prevProps : typeof this . props , prevState : DocumentState ) {
93100 this . props . makeStyles ?.( )
94- if ( this . props . themeVariables ?. key !== prevProps . themeVariables ?. key ) {
101+ if (
102+ this . props . themeVariables ?. key !== prevProps . themeVariables ?. key ||
103+ this . state . selectedDetailsTabId != prevState . selectedDetailsTabId
104+ ) {
95105 this . fetchGenerateComponentTheme ( )
96106 }
97107 }
98108
99109 handleDetailsTabChange : TabsProps [ 'onRequestTabChange' ] = (
100110 _event ,
101- { index }
111+ tabData
102112 ) => {
103- this . setState ( {
104- selectedDetailsTabIndex : index
105- } )
113+ this . setState ( { selectedDetailsTabId : tabData . id } )
106114 }
107115
108116 renderProps ( doc : DocDataType ) {
109- const { id , props } = doc
117+ const { props } = doc
110118 return props ? (
111- < View margin = "x-large 0" display = "block" >
112- < Heading level = "h2" as = "h3" id = { `${ id } Properties` } margin = "0 0 small 0" >
113- Properties
114- </ Heading >
115- < Properties props = { props } layout = { this . props . layout } />
116- </ View >
119+ < Properties props = { props } layout = { this . props . layout } />
117120 ) : null
118121 }
119122
@@ -123,7 +126,10 @@ class Document extends Component<DocumentProps, DocumentState> {
123126
124127 const themeVariableKeys = componentTheme && Object . keys ( componentTheme )
125128
126- return themeVariables && componentTheme && themeVariableKeys . length > 0 ? (
129+ return themeVariables &&
130+ componentTheme &&
131+ themeVariableKeys &&
132+ themeVariableKeys . length > 0 ? (
127133 < View margin = "x-large 0" display = "block" >
128134 < Heading level = "h2" as = "h3" id = { `${ doc . id } Theme` } margin = "0 0 small 0" >
129135 Default Theme Variables
@@ -345,20 +351,25 @@ import { ${importName} } from '${esPath}'
345351 < Tabs . Panel
346352 renderTitle = { doc . title }
347353 key = { `${ doc . id } TabPanel` }
348- isSelected = { this . state . selectedDetailsTabIndex === 0 }
354+ id = { doc . id }
355+ isSelected = { this . state . selectedDetailsTabId === doc . id }
349356 >
350357 { this . renderDetails ( doc ) }
351358 </ Tabs . Panel >
352- { children . map ( ( child , index ) => (
353- < Tabs . Panel
354- renderTitle = { child . title }
355- key = { `${ child . id } TabPanel` }
356- isSelected = { this . state . selectedDetailsTabIndex === index + 1 }
357- >
358- { this . renderDescription ( child , child . description ) }
359- { this . renderDetails ( child ) }
360- </ Tabs . Panel >
361- ) ) }
359+ {
360+ // Details of the child components (if any)
361+ children . map ( ( child ) => (
362+ < Tabs . Panel
363+ renderTitle = { child . title }
364+ key = { `${ child . id } TabPanel` }
365+ id = { child . id }
366+ isSelected = { this . state . selectedDetailsTabId === child . id }
367+ >
368+ { this . renderDescription ( child , child . description ) }
369+ { this . renderDetails ( child ) }
370+ </ Tabs . Panel >
371+ ) )
372+ }
362373 </ Tabs >
363374 ) : (
364375 this . renderDetails ( doc )
0 commit comments