You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document gives an overview on how you can customize Instructure UI components by tweaking their theme variables.
10
10
While this gives you a level of flexibility on the look and feel of the components you should be aware of 2 things:
11
11
12
-
- The default theme variables are tested to have high enough contrast ratios for WCAG 2.1 conformance. If you are making changes, please make sure that your app stays WCAG conformant.
12
+
- The default theme variables are tested to have high enough contrast ratios for WCAG 2.1 AA conformance. If you are making changes, please make sure that your app stays WCAG conformant.
13
13
- The look of components is only customisable to a certain degree. This is intentional, because Instructure UI is a design system geared towards the Canvas "look and feel", not a generic UI component library.
14
14
15
15
```js
@@ -25,63 +25,32 @@ type: embed
25
25
</ToggleBlockquote>
26
26
```
27
27
28
-
### How theming works in InstUI
28
+
### Using a different theme for a DOM subtree
29
29
30
-
The theming system in InstUI has these levels:
31
-
32
-
**The application level theme**
33
-
34
-
On the broader level, there is the main theme object that contains the color, spacing, typography etc. variables available in the theme (e.g.: [canvas theme](/#canvas)). The application level theme can be set via the [InstUISettingsProvider](/#InstUISettingsProvider) component.
30
+
By nesting the `InstUISettingsProvider` you can apply different themes to some sections of you app.
35
31
36
-
```jsx
32
+
```js
37
33
---
38
-
type:code
34
+
type:example
39
35
---
40
-
// app/component root sets the app theme
41
36
<InstUISettingsProvider theme={canvas}>
42
-
<ExampleComponent />
43
-
</InstUISettingsProvider>
44
-
```
45
-
46
-
**The component's own theme**
47
-
48
-
Every themeable component has its own "theme map". This map defines the components own theme variables (used by this component only), and maps them to values in the global theme object. These local variables are then passed to the component and used in the styles object.
49
-
50
-
See the [emotion](/#emotion), [built-in themes](/#ui-themes) and [InstUISettingsProvider](/#InstUISettingsProvider) docs pages for more info and examples.
51
-
52
-
Either you set up the themes globally, or you use the `InstUISettingsProvider` to set up themes, the component's `theme.js` will map it to theme variables:
monospace font family set via override only if the parent theme is 'canvas'.
101
+
</Heading>
102
+
</InstUISettingsProvider>
103
+
</div>
104
+
</InstUISettingsProvider>
105
+
```
106
+
107
+
### Overriding theme for a specific component in a subtree
108
+
109
+
You can override the theme variables of specific components too with the `componentOverrides` key. You can do this for every theme or for just a given theme.
110
+
111
+
**Important:** these variables are the components own theme variables set in the `theme.js` of the component.
My icon background and border should be dark blue in any theme.
135
+
</Alert>
136
+
</InstUISettingsProvider>
137
+
138
+
<InstUISettingsProvider
139
+
theme={{
140
+
themeOverrides: {
141
+
canvas: {
142
+
componentOverrides: {
143
+
Alert: {
144
+
warningIconBackground:"deeppink",
145
+
warningBorderColor:"deeppink"
146
+
}
147
+
}
148
+
}
149
+
}
150
+
}}
151
+
>
152
+
<Alert variant="warning" margin="small">
153
+
My border and icon background should be deep pink just if the 'canvas' theme is active.
121
154
</Alert>
122
155
</InstUISettingsProvider>
123
156
</div>
124
157
</InstUISettingsProvider>
125
158
```
126
159
127
-
#### Partial theme overrides
160
+
For child components both the displayName (`'InlineList.Item'`) and the componentId (`List.Item.componentId`) can be used as keys in `componentOverrides`.
128
161
129
-
When providing a partial theme object, you can override any theme variable inside that provider.
162
+
```jsx
163
+
---
164
+
type: code
165
+
---
166
+
<InstUISettingsProvider
167
+
theme={{
168
+
componentOverrides: {
169
+
'InlineList.Item': {
170
+
color:'blue'
171
+
},
172
+
[List.Item.componentId]: {
173
+
color:'red'
174
+
}
175
+
}
176
+
}}
177
+
>
178
+
{/* ... */}
179
+
</InstUISettingsProvider>
180
+
```
181
+
182
+
### Overriding theme for a single component
183
+
184
+
Themeable components (that implement the [withStyle](#withStyle) decorator) accept a `themeOverride` prop. This prop let's you override the component's own theme. It accepts an object or a function.
185
+
186
+
The available theme variables are always displayed at the bottom of the component's page (e.g.: [Button component theme variables](/#Button/#ButtonTheme)).
You can access and use any global theme variable via the second parameter (e.g. the [canvas theme](/#canvas)). When changing themes, these variables will update too.
Every themeable component has its own "theme map". This map defines the components own theme variables (used by this component only), and maps them to values in the global theme object. These local variables are then passed to the component and used in the styles object.
286
+
287
+
See the [emotion](/#emotion), [built-in themes](/#ui-themes) and [InstUISettingsProvider](/#InstUISettingsProvider) docs pages for more info and examples.
288
+
289
+
Either you set up the themes globally, or you use the `InstUISettingsProvider` to set up themes, the component's `theme.js` will map it to theme variables:
0 commit comments