@@ -33,6 +33,7 @@ import { SourceCodeEditor } from '@instructure/ui-source-code-editor'
3333import { withStyle , jsx } from '@instructure/emotion'
3434
3535import generateStyle from './styles'
36+ import functionalComponentThemes from '../../functionalComponentThemes'
3637
3738import { Description } from '../Description'
3839import { Properties } from '../Properties'
@@ -59,14 +60,34 @@ class Document extends Component<DocumentProps, DocumentState> {
5960
6061 state : DocumentState = {
6162 selectedDetailsTabIndex : 0 ,
62- pageRef : null
63+ pageRef : null ,
64+ componentTheme : { }
6365 }
6466
6567 ref : HTMLDivElement | null = null
6668
6769 componentDidMount ( ) {
6870 this . props . makeStyles ?.( )
6971 this . setState ( { pageRef : this . ref } )
72+ this . fetchGenerateComponentTheme ( )
73+ }
74+
75+ fetchGenerateComponentTheme = async ( ) => {
76+ const { doc, themeVariables } = this . props
77+ const generateComponentTheme =
78+ doc ?. componentInstance ?. generateComponentTheme
79+ if (
80+ generateComponentTheme &&
81+ typeof generateComponentTheme === 'function' &&
82+ themeVariables
83+ ) {
84+ this . setState ( { componentTheme : generateComponentTheme ( themeVariables ) } )
85+ } else {
86+ const componentTheme = await functionalComponentThemes [
87+ doc . id . toLowerCase ( )
88+ ] ( themeVariables )
89+ this . setState ( { componentTheme } )
90+ }
7091 }
7192
7293 componentDidUpdate ( ) {
@@ -96,17 +117,11 @@ class Document extends Component<DocumentProps, DocumentState> {
96117
97118 renderTheme ( doc : DocDataType ) {
98119 const { themeVariables } = this . props
99- const generateComponentTheme =
100- doc ?. componentInstance ?. generateComponentTheme
101-
102- const componentTheme =
103- themeVariables &&
104- typeof generateComponentTheme === 'function' &&
105- generateComponentTheme ( themeVariables )
120+ const { componentTheme } = this . state
106121
107- const themeVariableKeys = Object . keys ( componentTheme )
122+ const themeVariableKeys = componentTheme && Object . keys ( componentTheme )
108123
109- return componentTheme && themeVariableKeys . length > 0 ? (
124+ return themeVariables && componentTheme && themeVariableKeys . length > 0 ? (
110125 < View margin = "x-large 0" display = "block" >
111126 < Heading level = "h2" as = "h3" id = { `${ doc . id } Theme` } margin = "0 0 small 0" >
112127 Default Theme Variables
0 commit comments