Skip to content

Commit 3e109be

Browse files
committed
refactor(emotion,theme-registry,ui-themes): docs, tests
1 parent 2a9488d commit 3e109be

File tree

10 files changed

+266
-83
lines changed

10 files changed

+266
-83
lines changed

docs/guides/using-theme-overrides.md

Lines changed: 89 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,7 @@ type: embed
2727

2828
### How theming works in InstUI
2929

30-
The theming system in InstUI has three levels:
31-
32-
**The global theme**
33-
34-
Global themes are useful when you have multiple React Application trees and you want to set up themes and overrides on a more global level than application level theming.
35-
This basically means you don't necessarily have to wrap each application tree with an [InstUISettingsProvider](/#InstUISettingsProvider) to use themes.
36-
InstUI leverages the [ThemeRegistry](/#ThemeRegistry) package to achieve global theming.
37-
38-
```jsx
39-
---
40-
type: code
41-
---
42-
// app/init sets the global theme
43-
import canvas from '@instructure/ui-themes'
44-
45-
canvas.use()
46-
```
30+
The theming system in InstUI has these levels:
4731

4832
**The application level theme**
4933

@@ -95,42 +79,28 @@ const generateStyle = (componentTheme) => {
9579
}
9680
```
9781
98-
### Global theme overrides
82+
### Application level theme overrides
9983
100-
In order to globally register and override themes, simply import the theme you wish to use and call `.use({ overrides })` on it:
84+
`<InstUISettingsProvider/>` accepts full theme objects and override objects too.
10185
10286
```js
10387
---
104-
type: code
88+
type: example
10589
---
106-
import ReactDOM from "react-dom"
107-
import { canvas } from "@instructure/ui-themes"
108-
109-
canvas.use({
110-
overrides: {
111-
colors: {
112-
primitives: {
113-
green45: "red"
114-
}
90+
<InstUISettingsProvider theme={{
91+
...canvas,
92+
...{
93+
typography: { fontFamily: 'monospace' }
11594
}
116-
}
117-
})
118-
119-
ReactDOM.render(
95+
}}>
12096
<div>
121-
...your application code goes here...
97+
<Heading level="h3" margin="small small">
98+
I should have monospace font family from the override
99+
</Heading>
122100
</div>
123-
)
101+
</InstUISettingsProvider>
124102
```
125103
126-
**Note**: globally overriding themes like this means that every InstUI component will use that theme, unless they are wrapped inside an `<InstUISettingsProvider/>`.
127-
128-
You can see more examples [here](/#using-theme-overrides/#using-theme-overrides-examples).
129-
130-
### Application level theme overrides
131-
132-
`<InstUISettingsProvider/>` accepts full theme objects and override objects too.
133-
134104
#### Full themes
135105
136106
By nesting the `InstUISettingsProvider` you can apply different themes to some sections of you app.
@@ -214,27 +184,27 @@ const Example = () => {
214184
return (
215185
<div>
216186
<h3>Common variables</h3>
217-
<Flex gap="small large">
218-
<Flex.Item size="50%">
187+
<Flex gap="small">
188+
<Flex.Item size="45%">
219189
<TextInput renderLabel="ic-brand-primary" value={icBrandPrimary} onChange={(e, v) => setIcBrandPrimary(v)}
220-
messages={[{text:'used for border/background/shadow/focus colors in many places',type:'hint'}]} />
190+
messages={[{text:'used for border/background/focus/shadow/.. colors in many places',type:'hint'}]} />
221191
</Flex.Item>
222-
<Flex.Item size="50%">
192+
<Flex.Item size="45%">
223193
<TextInput renderLabel="ic-brand-font-color-dark" value={icBrandFontColorDark} onChange={(e, v) => setIcBrandFontColorDark(v)}
224194
messages={[{text:'used in lots of places for text color',type:'hint'}]} />
225195
</Flex.Item>
226196
</Flex>
227197

228198
<h3><code>Button</code> branding</h3>
229-
<Flex gap="small large">
230-
<Flex.Item size="50%">
199+
<Flex gap="small">
200+
<Flex.Item size="45%">
231201
<TextInput renderLabel="ic-brand-button--primary-bgd" value={icBrandButtonPrimaryBgd} onChange={(e, v) => setIcBrandButtonPrimaryBgd(v)}
232202
messages={[{text:"Used by 'primary' color buttons for background",type:'hint'}]} />
233203
<br/>
234204
<TextInput renderLabel="ic-brand-button--primary-text" value={icBrandButtonPrimaryText} onChange={(e, v) => setIcBrandButtonPrimaryText(v)}
235205
messages={[{text:"Used by 'primary' color buttons for text color",type:'hint'}]} />
236206
</Flex.Item>
237-
<Flex.Item size="50%">
207+
<Flex.Item size="45%">
238208
<TextInput renderLabel="ic-brand-button--secondary-bgd" value={icBrandButtonSecondaryBgd} onChange={(e, v) => setIcBrandButtonSecondaryBgd(v)}
239209
messages={[{text:'Unused in InstUI',type:'hint'}]} />
240210
<br/>
@@ -260,13 +230,17 @@ const Example = () => {
260230
'ic-brand-global-nav-menu-item__text-color--active': icBrandGlobalNavMenuItemTextColorActive
261231
}}}>
262232
<hr style={{width:'100%'}}/>
263-
<Flex gap="small large">
264-
<Flex.Item size="50%">
265-
<Button color="primary">I'm a 'primary' color button</Button>
233+
<Flex gap="large">
234+
<Flex.Item size="45%">
235+
<Badge count={15} countUntil={100} margin="0 medium 0 0">
236+
<Button color="primary">I'm a 'primary' color button</Button>
237+
</Badge>
266238
<TextInput renderLabel="TextInput" placeholder="ic-brand-primary sets focus color"/>
267239
</Flex.Item>
268-
<Flex.Item size="50%">
269-
<Button color="secondary">I'm a 'secondary' color button</Button>
240+
<Flex.Item size="45%">
241+
<Badge count={15} countUntil={100} margin="0 medium 0 0">
242+
<Button color="secondary">I'm a 'secondary' color button</Button>
243+
</Badge>
270244
<TextArea label="TextArea" placeholder="ic-brand-primary sets focus color"/>
271245
</Flex.Item>
272246
</Flex>
@@ -280,18 +254,18 @@ const Example = () => {
280254

281255
<hr style={{width:'100%'}}/>
282256
<h3>Link colors used by <code>Link</code> and <code>Billboard</code>:</h3>
283-
<Flex gap="small large">
284-
<Flex.Item size="50%">
257+
<Flex gap="small">
258+
<Flex.Item size="45%">
285259
<TextInput renderLabel="ic-link-color" value={icLinkColor} onChange={(e, v) => setIcLinkColor(v)}
286260
messages={[{text:'Used for non-inverse Link and clickable Billboard',type:'hint'}]} />
287261
</Flex.Item>
288-
<Flex.Item size="50%">
262+
<Flex.Item size="45%">
289263
<TextInput renderLabel="ic-link-decoration" value={icLinkDecoration} onChange={(e, v) => setIcLinkDecoration(v)}
290264
messages={[{text:'Unused in InstUI',type:'hint'}]}/>
291265
</Flex.Item>
292266
</Flex>
293267
<hr style={{width:'100%'}}/>
294-
<Flex gap="small large">
268+
<Flex gap="small">
295269
<Flex.Item size="50%">
296270
<Link href="https://instructure.github.io/instructure-ui/">normal link</Link>
297271
</Flex.Item>
@@ -301,16 +275,16 @@ const Example = () => {
301275
</View>
302276
</Flex.Item>
303277
</Flex>
304-
<Flex gap="small large">
305-
<Flex.Item size="50%">
278+
<Flex gap="small">
279+
<Flex.Item size="40%">
306280
<Billboard
307281
margin="small"
308282
message="Billboard with link"
309283
href="http://instructure.com"
310284
hero={(size) => <IconGradebookLine size={size} />}
311285
/>
312286
</Flex.Item>
313-
<Flex.Item size="50%">
287+
<Flex.Item size="40%">
314288
<Billboard
315289
margin="small"
316290
message="Billboard without link"
@@ -321,13 +295,13 @@ const Example = () => {
321295

322296
<hr style={{width:'100%'}}/>
323297
<h3><code>SideNavBar</code> branding</h3>
324-
<Flex gap="small large">
325-
<Flex.Item size="50%">
298+
<Flex gap="large small">
299+
<Flex.Item size="45%">
326300
<TextInput renderLabel="ic-brand-global-nav-bgd" value={icBrandGlobalNavBgd} onChange={(e, v) => setIcBrandGlobalNavBgd(v)}/>
327301
<TextInput renderLabel="ic-global-nav-link-hover" value={icGlobalNavLinkHover} onChange={(e, v) => setIcGlobalNavLinkHover(v)}/>
328302
<TextInput renderLabel="ic-brand-global-nav-ic-icon-svg-fill" value={icBrandGlobalNavIcIconSvgFill} onChange={(e, v) => setIcBrandGlobalNavIcIconSvgFill(v)}/>
329303
</Flex.Item>
330-
<Flex.Item size="50%">
304+
<Flex.Item size="45%">
331305
<TextInput renderLabel="ic-brand-global-nav-menu-item__text-color" value={icBrandGlobalNavMenuItemTextColor} onChange={(e, v) => setIcBrandGlobalNavMenuItemTextColor(v)}/>
332306
<TextInput renderLabel="ic-brand-global-nav-menu-item__text-color--active" value={icBrandGlobalNavMenuItemTextColorActive} onChange={(e, v) => setIcBrandGlobalNavMenuItemTextColorActive(v)}/>
333307
<TextInput renderLabel="ic-brand-global-nav-ic-icon-svg-fill--active" value={icBrandGlobalNavIcIconSvgFillActive} onChange={(e, v) => setIcBrandGlobalNavIcIconSvgFillActive(v)}/>
@@ -386,3 +360,53 @@ const Example = () => {
386360

387361
render(<Example/>)
388362
```
363+
364+
### (DEPRECATED) Global (window-level) theming
365+
366+
**The global theme**
367+
368+
> This feature is deprecated because it needs to use the [global object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) that pierces application borders, so it causes issues with running multiple versions of InstUI in a single page.
369+
370+
Global themes are useful when you have multiple React Application trees, and you want to set up themes and overrides on a more global level than application level theming.
371+
This basically means you don't necessarily have to wrap each application tree with an [InstUISettingsProvider](/#InstUISettingsProvider) to use themes.
372+
InstUI leverages the [ThemeRegistry](/#ThemeRegistry) package to achieve global theming.
373+
374+
```jsx
375+
---
376+
type: code
377+
---
378+
// app/init sets the global theme
379+
import canvas from '@instructure/ui-themes'
380+
381+
canvas.use()
382+
```
383+
384+
### (DEPRECATED) Global theme overrides
385+
386+
In order to globally register and override themes, simply import the theme you wish to use and call `.use({ overrides })` on it:
387+
388+
```js
389+
---
390+
type: code
391+
---
392+
import ReactDOM from "react-dom"
393+
import { canvas } from "@instructure/ui-themes"
394+
395+
canvas.use({
396+
overrides: {
397+
colors: {
398+
primitives: {
399+
green45: "red"
400+
}
401+
}
402+
}
403+
})
404+
405+
ReactDOM.render(
406+
<div>
407+
...your application code goes here...
408+
</div>
409+
)
410+
```
411+
412+
**Note**: globally overriding themes like this means that every InstUI component will use that theme, unless they are wrapped inside an `<InstUISettingsProvider/>`.

packages/__docs__/components.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,9 @@ export { Drilldown } from '@instructure/ui-drilldown'
130130
export { SourceCodeEditor } from '@instructure/ui-source-code-editor'
131131
export { TopNavBar } from '@instructure/ui-top-nav-bar'
132132
export { TruncateList } from '@instructure/ui-truncate-list'
133-
export { canvas, canvasHighContrast, instructure } from '@instructure/ui-themes'
133+
export {
134+
canvas,
135+
canvasHighContrast,
136+
canvasThemeLocal,
137+
canvasHighContrastThemeLocal
138+
} from '@instructure/ui-themes'

packages/__docs__/src/Theme/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class Theme extends Component<ThemeProps> {
279279
id={`${themeKey}ApplicationUsage`}
280280
content={`
281281
### Usage (before mounting your application)
282-
##### Global theming
282+
##### (DEPRECATED) Global theming
283283
${'```javascript\n \
284284
---\n \
285285
type: code\n \

0 commit comments

Comments
 (0)