Skip to content

Commit d615fad

Browse files
committed
docs: fix alert doc page Default Theme Variables section in v11.7
1 parent 45b2a33 commit d615fad

3 files changed

Lines changed: 37 additions & 14 deletions

File tree

docs/upgrading/upgrade-guide.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ Focus rings are now styled in a central pseudo-component called `SharedTokens`.
4040
type: example
4141
---
4242
<InstUISettingsProvider
43-
theme={{
44-
newTheme: { // TODO remove this when we remove the old theme
45-
sharedTokens: {
46-
focusOutline: {
47-
infoColor: 'green',
48-
width: '0.4rem',
49-
offset: '0rem'
43+
themeOverride={{
44+
sharedTokens: {
45+
focusOutline: {
46+
infoColor: 'green',
47+
width: '0.4rem',
48+
offset: '0rem'
5049
}
5150
}
52-
}
53-
}}>
54-
<TextInput renderLabel="Name" placeholder="Note: Change example when the old theme is renamed!"/>
51+
}}
52+
>
53+
<TextInput
54+
renderLabel="Name"
55+
placeholder="Note: Change example when the old theme is renamed!"
56+
/>
5557
</InstUISettingsProvider>
5658
```
5759

packages/__docs__/buildScripts/build-docs.mts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,27 @@ function tryParseReadme(dirName: string) {
362362
return undefined
363363
}
364364

365+
function resolveComponents(theme: typeof legacyCanvas | typeof legacyCanvasHighContrast) {
366+
const sem = theme.semantics(theme.primitives)
367+
const resolved: Record<string, any> = {}
368+
for (const [key, fn] of Object.entries(theme.components)) {
369+
if (typeof fn === 'function') {
370+
resolved[key] = fn(sem)
371+
}
372+
}
373+
return resolved
374+
}
375+
365376
function parseThemes() {
366377
const parsed: MainDocsData['themes'] = {}
367378
// legacy-canvas first so it becomes the default rendering theme
368-
parsed['legacy-canvas'] = { resource: canvas }
369-
parsed['legacy-canvas-high-contrast'] = { resource: canvasHighContrast }
379+
// resolvedComponents: pre-computed plain objects (functions can't survive JSON.stringify)
380+
parsed['legacy-canvas'] = {
381+
resource: { ...canvas, resolvedComponents: resolveComponents(legacyCanvas) }
382+
}
383+
parsed['legacy-canvas-high-contrast'] = {
384+
resource: { ...canvasHighContrast, resolvedComponents: resolveComponents(legacyCanvasHighContrast) }
385+
}
370386
parsed['canvas'] = { resource: legacyCanvas }
371387
parsed['canvas-high-contrast'] = { resource: legacyCanvasHighContrast }
372388
parsed[light.key] = { resource: light }

packages/__docs__/src/Document/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ class Document extends Component<DocumentProps, DocumentState> {
9494
const isLegacyTheme = this.context?.componentVersion == 'v11_6'
9595
// new theme
9696
if (!isLegacyTheme) {
97-
const newThemeEntry = themeVariables?.newTheme?.components?.[themeKey]
97+
// resolvedComponents contains pre-computed plain objects (built at build time)
98+
const resolvedComponents = (themeVariables as Record<string, unknown>)
99+
?.resolvedComponents as Record<string, unknown> | undefined
100+
const newThemeEntry = resolvedComponents?.[themeKey as string]
98101
const componentInstance =
99102
selectedId === doc.id
100103
? doc?.componentInstance
@@ -104,7 +107,9 @@ class Document extends Component<DocumentProps, DocumentState> {
104107
typeof componentInstance?.generateComponentTheme !== 'function'
105108
) {
106109
// new theme - use pre-computed theme object directly
107-
this.setState({ componentTheme: newThemeEntry })
110+
this.setState({
111+
componentTheme: newThemeEntry as DocumentState['componentTheme']
112+
})
108113
return
109114
}
110115
}

0 commit comments

Comments
 (0)