@@ -29,6 +29,7 @@ import { View } from '@instructure/ui-view'
2929import { Tabs } from '@instructure/ui-tabs'
3030import type { TabsProps } from '@instructure/ui-tabs'
3131import type { NewBaseTheme } from '@instructure/ui-themes'
32+ import type { ComponentTheme as ComponentThemeData } from '@instructure/shared-types'
3233import { SourceCodeEditor } from '@instructure/ui-source-code-editor'
3334import { withStyleForDocs as withStyleNew } from '../withStyleForDocs'
3435
@@ -78,47 +79,48 @@ class Document extends Component<DocumentProps, DocumentState> {
7879
7980 fetchGenerateComponentTheme = async ( ) => {
8081 const { doc, themeVariables } = this . props
81- let generateTheme
82- // Doc IDs use dot notation (e.g. "Menu.Item") but theme component keys
83- // use PascalCase without dots (e.g. "MenuItem").
84- // New-theme entries are in themeVariables.newTheme.components.
8582 const selectedId = this . state . selectedDetailsTabId
8683 type ComponentKey = keyof NewBaseTheme [ 'components' ]
84+ // When a child tab is selected, work from the child's doc/component;
85+ // otherwise from the main doc's.
8786 const childDoc =
8887 selectedId !== doc . id
8988 ? doc ?. children ?. find ( ( value ) => value . id === selectedId )
9089 : null
91- // in case of some components, we need to display the theme variables of other components based on themeId (like displaying the theme variables of Options in Drillsdown.Group)
90+ const currentComponentInstance =
91+ selectedId === doc . id
92+ ? doc ?. componentInstance
93+ : childDoc ?. componentInstance
94+ // Resolve the theme registry key. Default: doc id with dots stripped
95+ // (e.g. "Menu.Item" → "MenuItem"). Two ways to override the default:
96+ // - `themeId:` in YAML frontmatter (read from childDoc.themeId) — used
97+ // when a doc page wants to show another component's tokens
98+ // (e.g. Drilldown.Group → 'Options').
99+ // - `static themeId` on the component class — used when a component
100+ // borrows another's tokens via `useTokensFrom` at runtime
101+ // (e.g. Button → 'BaseButton', ColorMixer.Slider → 'Slider').
92102 const themeKey : ComponentKey = ( childDoc ?. themeId ||
103+ currentComponentInstance ?. themeId ||
93104 selectedId ?. replace ( / \. / g, '' ) ) as ComponentKey
94105 const isLegacyTheme = this . context ?. componentVersion == 'v11_6'
95- // new theme
106+ // New theme: tokens are pre-resolved into plain objects at build time
107+ // (the build emits JSON, so generator functions can't be carried through).
96108 if ( ! isLegacyTheme ) {
97- // resolvedComponents contains pre-computed plain objects (built at build time)
98109 const resolvedComponents = ( themeVariables as Record < string , unknown > )
99110 ?. resolvedComponents as Record < string , unknown > | undefined
100111 const newThemeEntry = resolvedComponents ?. [ themeKey as string ]
101- const componentInstance =
102- selectedId === doc . id
103- ? doc ?. componentInstance
104- : childDoc ?. componentInstance
105112 if (
106113 newThemeEntry &&
107- typeof componentInstance ?. generateComponentTheme !== 'function'
114+ typeof currentComponentInstance ?. generateComponentTheme !== 'function'
108115 ) {
109- // new theme - use pre-computed theme object directly
110116 this . setState ( {
111117 componentTheme : newThemeEntry as DocumentState [ 'componentTheme' ]
112118 } )
113119 return
114120 }
115121 }
116- // old theme - use generateComponentTheme function
117- if ( selectedId === doc . id ) {
118- generateTheme = doc ?. componentInstance ?. generateComponentTheme
119- } else {
120- generateTheme = childDoc ?. componentInstance ?. generateComponentTheme
121- }
122+ // Legacy theme: call the component's generateComponentTheme directly.
123+ const generateTheme = currentComponentInstance ?. generateComponentTheme
122124 if ( typeof generateTheme === 'function' && themeVariables ) {
123125 this . setState ( { componentTheme : generateTheme ( themeVariables ) } )
124126 } else {
@@ -179,9 +181,7 @@ class Document extends Component<DocumentProps, DocumentState> {
179181 </ code >
180182 </ View >
181183 ) : null }
182- < ComponentTheme
183- componentTheme = { componentTheme as any /* TODO-theme-types check */ }
184- />
184+ < ComponentTheme componentTheme = { componentTheme as ComponentThemeData } />
185185
186186 < View margin = "x-large 0 0" display = "block" >
187187 < Heading
0 commit comments