Skip to content

Commit 759c1e6

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 ced0fb5 commit 759c1e6

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
@@ -57,22 +57,41 @@ class Theme extends Component<ThemeProps, ThemeState> {
5757

5858
state: ThemeState = { showColors: false }
5959

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

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

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

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

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

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)