Skip to content

Commit f37161d

Browse files
committed
docs: fix missing default component theme block in functional component doc pages
INSTUI-4493
1 parent 3a383f8 commit f37161d

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015 - present Instructure, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
const themes = {
26+
// TODO figure out subcomponents e.g.: Table.Cell
27+
avatar: async (theme) =>
28+
(await import('@instructure/ui-avatar/src/Avatar/theme.ts')).default(theme)
29+
}
30+
31+
export default themes

packages/__docs__/src/Document/index.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { SourceCodeEditor } from '@instructure/ui-source-code-editor'
3333
import { withStyle, jsx } from '@instructure/emotion'
3434

3535
import generateStyle from './styles'
36+
import functionalComponentThemes from '../../functionalComponentThemes'
3637

3738
import { Description } from '../Description'
3839
import { 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

packages/__docs__/src/Document/props.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import PropTypes from 'prop-types'
2626
import type { ComponentStyle, WithStyleProps } from '@instructure/emotion'
2727
import type {
2828
PropValidators,
29-
BaseThemeVariables
29+
BaseThemeVariables,
30+
ComponentTheme
3031
} from '@instructure/shared-types'
3132
import { DocData } from '../App/props'
3233

@@ -72,6 +73,7 @@ type DocumentStyle = ComponentStyle<'githubCornerOctoArm' | 'githubCorner'>
7273
type DocumentState = {
7374
selectedDetailsTabIndex: number
7475
pageRef: HTMLDivElement | null
76+
componentTheme: ComponentTheme
7577
}
7678

7779
const allowedProps: AllowedPropKeys = [

0 commit comments

Comments
 (0)