Skip to content

Commit d5fca8d

Browse files
committed
docs(ui-themes,ui-link,emotion): fix for outadted theme override links, JSDocs and fix for fast theme switch and fix Link theme override example
fix outdated JSDocs. Add the new-theme-overrides entry to LLM summaries. Fix Link v2 themeOverride example. Fix outdated theme override links. Cancel pending rAF in Theme on unmount/theme switch
1 parent f5457c2 commit d5fca8d

9 files changed

Lines changed: 75 additions & 138 deletions

File tree

packages/__docs__/buildScripts/ai-accessible-documentation/summaries-for-llms-file.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,12 @@
465465
"summary": "Quick start: Create a React app, add `@instructure/ui`, wrap with `InstUISettingsProvider`, and use components. Integrate with existing projects by adding the dependency and provider. Read about theme overrides and accessibility for best practices."
466466
},
467467
{
468-
"title": "using-theme-overrides",
469-
"summary": "Customize components via theme overrides while ensuring WCAG compliance. Use nested `InstUISettingsProvider` for subtree themes, override global or component themes, and leverage branding variables for user customization. Deprecated global theming causes issues with multiple InstUI versions."
468+
"title": "legacy-theme-overrides",
469+
"summary": "Theme overrides for version `/v11_6` and earlier. Apply via `themeOverride` on `InstUISettingsProvider` for a subtree or per-component `themeOverride` prop (component's own flat theme-variable map, object or function form)."
470+
},
471+
{
472+
"title": "new-theme-overrides",
473+
"summary": "Theme overrides for version `/v11_7` and later on the new token-based theming. Layered model: `primitives` → `semantics` → `components`, plus `sharedTokens` for cross-component patterns (focus rings, box shadows). Apply via structured `themeOverride` on `InstUISettingsProvider` keyed by token layer, or per-component `themeOverride` prop (object or `(componentTheme) => ({...})` function). Per-component overrides have highest priority."
470474
},
471475
{
472476
"title": "Upgrade Guide for Version 11",

packages/__docs__/src/Theme/index.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,41 @@ type ThemeState = { showColors: boolean }
5858

5959
state: ThemeState = { showColors: false }
6060

61+
private _showColorsRafId: number | null = null
62+
6163
componentDidMount() {
6264
this.props.makeStyles?.()
6365
// Defer color card rendering so the initial page paint is not blocked
64-
requestAnimationFrame(() => this.setState({ showColors: true }))
66+
this.scheduleShowColors()
6567
}
6668

6769
componentDidUpdate(prevProps: ThemeProps) {
6870
this.props.makeStyles?.()
6971
if (prevProps.themeKey !== this.props.themeKey) {
7072
// Reset on theme change so navigation feels instant
71-
this.setState({ showColors: false }, () => {
72-
requestAnimationFrame(() => this.setState({ showColors: true }))
73-
})
73+
this.setState({ showColors: false }, this.scheduleShowColors)
74+
}
75+
}
76+
77+
componentWillUnmount() {
78+
// Avoid a setState-on-unmounted warning when the user navigates away
79+
// before the deferred frame fires.
80+
if (this._showColorsRafId !== null) {
81+
cancelAnimationFrame(this._showColorsRafId)
82+
this._showColorsRafId = null
7483
}
7584
}
7685

86+
scheduleShowColors = () => {
87+
if (this._showColorsRafId !== null) {
88+
cancelAnimationFrame(this._showColorsRafId)
89+
}
90+
this._showColorsRafId = requestAnimationFrame(() => {
91+
this._showColorsRafId = null
92+
this.setState({ showColors: true })
93+
})
94+
}
95+
7796
_colorMap: Record<string, string> = {}
7897

7998
mapColors(colorKey: Record<string, string>) {
@@ -344,9 +363,6 @@ ReactDOM.render(
344363
element
345364
)
346365
${'```'}
347-
348-
349-
> You can read more about how our theming system works and how to use it [here](/#legacy-theme-overrides)
350366
`}
351367
title={`${themeKey} Theme Usage in applications`}
352368
/>

packages/__docs__/src/withStyleForDocs.tsx

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -114,77 +114,27 @@ const defaultValues = {
114114
* category: utilities/themes
115115
* ---
116116
*
117-
* Same as `withStyle`, used only for the docs app.
118-
*
119-
* A decorator or higher order component that makes a component themeable.
120-
*
121-
* It adds a `makeStyles` function and the generated `styles` object to the decorated Component's props. If it has an own theme, it also adds the `themeOverride` prop to the component.
122-
*
123-
* As a HOC:
117+
* Same shape as the legacy `withStyle` decorator, used only by the docs app.
118+
* Injects a `makeStyles` function and the generated `styles` object as props,
119+
* and forwards a `themeOverride` prop to the component.
124120
*
125121
* ```js-code
126-
* import { withStyleForDocs as withStyleNew } from '@instructure/emotion'
122+
* import { withStyleForDocs } from '../withStyleForDocs'
127123
* import generateStyle from './styles'
128124
* import generateComponentTheme from './theme'
129125
*
130-
* export default withStyleNew(generateStyle, generateComponentTheme)(ExampleComponent)
126+
* export default withStyleForDocs(generateStyle, generateComponentTheme)(ExampleComponent)
131127
* ```
132128
*
133-
* Themeable components inject their themed styles into the document
134-
* when they are mounted.
135-
*
136-
* ### Applying themes
137-
*
138-
* A themeable component’s theme can be configured via wrapping it in an
139-
* [InstUISettingsProvider](InstUISettingsProvider) component, and/or set
140-
* explicitly via its `themeOverride` prop.
141-
*
142-
* InstUISettingsProvider provides a theme object (e.g. the [canvas theme](/#canvas)).
143-
* These variables are mapped to the component's own variables in `theme.js`.
144-
*
145-
* With the `themeOverride` prop you can directly set/override the component theme variables declared in theme.js. It accepts an object or a function. The function has the component's theme and the currently active main theme as its parameter.
146-
*
147-
* See more about the overrides on the [Legacy theme overrides](/#legacy-theme-overrides) docs page.
148-
*
149-
* ```js-code
150-
* // ExampleComponent/theme.js
151-
* const generateComponentTheme = (theme) => {
152-
* const { colors } = theme
153-
*
154-
* const componentVariables = {
155-
* background: colors?.backgroundMedium,
156-
* color: colors?.textDarkest,
157-
*
158-
* hoverColor: colors?.textLightest,
159-
* hoverBackground: colors?.backgroundDarkest
160-
* }
161-
*
162-
* return componentVariables
163-
* }
164-
* export default generateComponentTheme
165-
* ```
166-
*
167-
* ```jsx-code
168-
* {// global theme override}
169-
* <InstUISettingsProvider theme={{
170-
* colors: { backgroundMedium: '#888' }
171-
* }}>
172-
* {// component theme override}
173-
* <ExampleComponent themeOverride={{ hoverColor: '#eee' }} />
174-
*
175-
* {// component theme override with function}
176-
* <ExampleComponent themeOverride={(componentTheme, currentTheme) => ({
177-
* hoverBackground: componentTheme.background,
178-
* activeBackground: currentTheme.colors.backgroundBrand
179-
* })} />
180-
* </InstUISettingsProvider>
181-
* ```
129+
* Override patterns (provider-scoped, per-component, function form) are
130+
* documented on the [Legacy theme overrides](/#legacy-theme-overrides) docs
131+
* page — `withStyleForDocs` follows the same model.
182132
*
183-
* @module withStyleNew
133+
* @module withStyleForDocs
184134
*
185-
* @param {function} generateStyle - The function that returns the component's style object
186-
* @param {function} generateComponentTheme - The function that returns the component's theme variables object
187-
* @returns {ReactElement} The decorated WithStyle Component
135+
* @param {function} generateStyle - Returns the component's style object
136+
* @param {function} generateComponentTheme - Returns the component's theme variables object
137+
* @returns {ReactElement} The decorated component
188138
*/
189139
const withStyleForDocs = decorator(
190140
(

packages/emotion/src/InstUISettingsProvider/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ ReactDOM.render(
6262

6363
#### Theme overrides
6464

65-
There are multiple ways to override themes in InstUI. You can read about how these work on the dedicated docs page: [Using theme overrides](/#using-theme-overrides).
65+
There are multiple ways to override themes in InstUI. You can read about how these work on the dedicated docs pages:
66+
67+
- [Legacy theme overrides](/#legacy-theme-overrides).
68+
- [New theme overrides](/#new-theme-overrides).
6669

6770
### Text direction management
6871

packages/emotion/src/withStyle.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ const defaultValues = {
9494
* ---
9595
* category: utilities/themes
9696
* ---
97-
* used for old (v11 and eariler) theming system
97+
* Legacy decorator for the pre-v11.7 theming system. New components should use
98+
* `withStyleNew` instead. Override patterns for components decorated with
99+
* `withStyle` are documented on the
100+
* [Legacy theme overrides](/#legacy-theme-overrides) docs page.
101+
*
98102
* TODO delete when the theme migration is complete
99103
*/
100104
const withStyle = decorator(

packages/emotion/src/withStyleNew.tsx

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,9 @@ const defaultValues = {
9898
* category: utilities/themes
9999
* ---
100100
*
101-
* A decorator or higher order component that makes a component themeable.
102-
*
103-
* It adds a `makeStyles` function and the generated `styles` object to the decorated Component's props. If it has an own theme, it also adds the `themeOverride` prop to the component.
104-
*
105-
* As a HOC:
101+
* Decorator (or HOC) that makes a component themeable using InstUI's new
102+
* theming system. Injects a `makeStyles` function and the
103+
* generated `styles` object as props.
106104
*
107105
* ```js-code
108106
* import { withStyleNew } from '@instructure/emotion'
@@ -111,42 +109,18 @@ const defaultValues = {
111109
* export default withStyleNew(generateStyle)(ExampleComponent)
112110
* ```
113111
*
114-
* Themeable components inject their themed styles into the document
115-
* when they are mounted.
116-
*
117-
* ### Applying themes
118-
*
119-
* A themeable component’s theme can be configured via wrapping it in an
120-
* [InstUISettingsProvider](InstUISettingsProvider) component, and/or set
121-
* explicitly via its `themeOverride` prop.
122-
*
123-
* InstUISettingsProvider provides a theme object (e.g. the [canvas theme](/#canvas)).
124-
* These variables are mapped to the component's own variables in `theme.js` (see [theming](theming-basics) for more info).
112+
* Optionally pass a `useTokensFrom` key as the second argument to consume
113+
* another component's tokens (e.g. `withStyleNew(generateStyle, 'BaseButton')`).
125114
*
126-
* With the `themeOverride` prop you can directly set/override the component theme variables declared in theme.js. It accepts an object or a function. The function has the component's theme and the currently active main theme as its parameter.
127-
*
128-
* See more about the overrides on the [Using theme overrides](/#using-theme-overrides) docs page.
129-
*
130-
* ```jsx-code
131-
* {// global theme override}
132-
* <InstUISettingsProvider theme={{
133-
* colors: { backgroundMedium: '#888' }
134-
* }}>
135-
* {// component theme override}
136-
* <ExampleComponent themeOverride={{ hoverColor: '#eee' }} />
137-
*
138-
* {// component theme override with function}
139-
* <ExampleComponent themeOverride={(componentTheme, currentTheme) => ({
140-
* hoverBackground: componentTheme.background,
141-
* activeBackground: currentTheme.colors.backgroundBrand
142-
* })} />
143-
* </InstUISettingsProvider>
144-
* ```
115+
* Override patterns (provider-scoped, per-component, primitives / semantics /
116+
* sharedTokens layers, priority rules) are documented on the
117+
* [New theme overrides](/#new-theme-overrides) docs page.
145118
*
146119
* @module withStyleNew
147120
*
148-
* @param {function} generateStyle - The function that returns the component's style object
149-
* @returns {ReactElement} The decorated WithStyle Component
121+
* @param {function} generateStyle - Returns the component's style object
122+
* @param {string} [useTokensFrom] - Key of another component whose tokens this one should consume
123+
* @returns {ReactElement} The decorated component
150124
*/
151125
const withStyleNew = decorator(
152126
(

packages/ui-link/src/Link/v1/README.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,9 @@ describes: Link
1010
---
1111
type: example
1212
---
13-
<div>
14-
<Text>The quick brown fox <Link href="https://instructure.github.io/instructure-ui/"
15-
themeOverride={{
16-
focusOutlineColor: 'pink'
17-
}}>jumps</Link> over the lazy dog.</Text>
18-
<Link color="link-inverse" href="https://instructure.github.io/instructure-ui/">jumps</Link>
19-
</div>
20-
```
21-
22-
```js
23-
---
24-
type: example
25-
---
26-
<View background="primary-inverse" as="div">
27-
<Text color="primary-inverse">The quick brown fox <Link color="link-inverse" href="https://instructure.github.io/instructure-ui/" themeOverride={{
28-
focusInverseIconOutlineColor: 'pink'
29-
}}>jumps</Link> over the lazy dog.</Text>
30-
</View>
13+
<Link href="https://instructure.github.io/instructure-ui/" target="_blank">
14+
Link text
15+
</Link>
3116
```
3217

3318
### Controlled navigation
@@ -164,7 +149,7 @@ type: example
164149

165150
### Theme overrides
166151

167-
Examples showing how theme overrides work for Link:
152+
Examples showing how [theme overrides](legacy-theme-overrides) work for Link:
168153

169154
```js
170155
---

packages/ui-link/src/Link/v2/README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,19 @@ type: example
168168

169169
### Theme overrides
170170

171-
Examples showing how [theme overrides](using-theme-overrides) work for Link:
171+
Examples showing how [theme overrides](new-theme-overrides) work for Link:
172172

173173
```js
174174
---
175175
type: example
176176
---
177177
<div>
178178
<InstUISettingsProvider
179-
theme={{
180-
newTheme: {
181-
sharedTokens: {
182-
focusOutline: {
183-
infoColor: 'pink',
184-
width: '0.5rem',
185-
}
179+
themeOverride={{
180+
sharedTokens: {
181+
focusOutline: {
182+
infoColor: 'pink',
183+
width: '0.5rem'
186184
}
187185
}
188186
}}

packages/ui-themes/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ ReactDOM.render(
3939
)
4040
```
4141

42-
> You can read more about how our theming system works and how to use it [here](/#using-theme-overrides)
42+
> You can read more about how our theming system works and how to use it:
43+
44+
- [Legacy theme overrides](/#legacy-theme-overrides).
45+
- [New theme overrides](/#new-theme-overrides).
4346

4447
[npm]: https://img.shields.io/npm/v/@instructure/ui-themes.svg
4548
[npm-url]: https://npmjs.com/package/@instructure/ui-themes

0 commit comments

Comments
 (0)