Skip to content

Commit 229d79a

Browse files
committed
docs: improve themening documentation
1 parent 317b0c1 commit 229d79a

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

docs/how_tos/theming.md

+58-12
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Overview
44

5-
This document serves as a guide to using `@openedx/frontend-platform` to support MFE theming with Paragon using theme CSS loaded externally (e.g., from a CDN).
5+
This document is a guide for using `@openedx/frontend-platform` to support MFE theming with Paragon loading the theme CSS externally (e.g., from a CDN).
66

7-
To do this, configured URLs pointing to relevant CSS files from `@openedx/paragon` and (optionally) `@openedx/brand-openedx` are loaded and injected to the HTML document at runtime. This differs than the consuming application importing the styles from `@openedx/paragon` and `@openedx/brand-openedx` directly, which includes these styles in the application's production assets.
7+
To do this, configured URLs pointing to relevant CSS files from `@openedx/paragon` and (optionally) `@openedx/brand-openedx` are loaded and injected to the HTML document at runtime. This differs from importing the styles from `@openedx/paragon` and `@openedx/brand-openedx` directly, which includes these styles in the application's production assets.
88

99
By serving CSS loaded externally, consuming applications of Paragon no longer need to be responsible for compiling the theme SCSS to CSS themselves and instead use a pre-compiled CSS file. In doing so, this allows making changes to the Paragon theme without needing to necessarily re-build and re-deploy all consuming applications.
1010

@@ -14,13 +14,13 @@ By serving CSS loaded externally, consuming applications of Paragon no longer ne
1414

1515
1. **Get theme preference from localStorage.** Supports persisting and loading the user's preference for their selected theme variant, until cleared.
1616
1. **Detect user system settings.** Rely on the `prefers-color-scheme` media query to detect if the user's system indicates a preference for dark mode. If so, use the default dark theme variant, if one is configured.
17-
1. **Use default theme variant as configured (see below).** Otherwise, load the default theme variant as configured by the `defaults` option described below.
17+
1. **Use the default theme variant as configured (see below).** Otherwise, load the default theme variant as configured by the `defaults` option described below.
1818

19-
Whenever the current theme variant changes, an attrivbute `data-paragon-theme-variant="*"` is updated on the `<html>` element. This attribute enables applications' both JS and CSS to have knowledge of the currently applied theme variant.
19+
Whenever the current theme variant changes, an attribute `data-paragon-theme-variant="*"` is updated on the `<html>` element. This attribute enables applications both JS and CSS to have knowledge of the currently applied theme variant.
2020

2121
### Supporting custom theme variants beyond `light` and `dark`
2222

23-
If your use case necessitates additional variants beyond the default supported `light` and `dark` theme variants, you may pass any number of custom theme variants. Custom theme variants will work the user's persisted localStorage setting (i.e., if a user switches to a custom theme variant, the MFE will continue to load the custom theme variant by default). By supporting custom theme variants, it also supports having multiple or alternative `light` and/or `dark` theme variants.
23+
If your use case requires additional variants beyond the default `light` and `dark` theme variants, you may pass any number of custom theme variants. Custom theme variants will work the user's persisted localStorage setting (i.e., if a user switches to a custom theme variant, the MFE will continue to load the custom theme variant by default). By supporting custom theme variants, it also supports having multiple or alternative `light` and/or `dark` theme variants. You can see the [Configuration options](#configuration-options) example for better understanding.
2424

2525
### Performance implications
2626

@@ -90,6 +90,52 @@ The `dark` theme variant options are optional.
9090
| `variants.dark.urls.default` | String | URL for the `dark.css` file from `@openedx/paragon`. |
9191
| `variants.dark.urls.brandOverride` | String | URL for the `dark.css` file from `@openedx/brand-openedx`. |
9292

93+
Understanding the different configuration options, a complex use case:
94+
95+
```js
96+
const config = {
97+
PARAGON_THEME_URLS: {
98+
{
99+
core: {
100+
urls: {
101+
default: 'https://cdn.jsdelivr.net/npm/@openedx/paragon@$paragonVersion/dist/core.min.css',
102+
brandOverride: 'https://cdn.jsdelivr.net/npm/@my-brand/brand-package@#brandVersion/dist/core.min.css',
103+
},
104+
},
105+
defaults: {
106+
light: 'light',
107+
dark: 'dark',
108+
},
109+
variants: {
110+
light: {
111+
urls: {
112+
default: 'https://cdn.jsdelivr.net/npm/@openedx/paragon@$paragonVersion/dist/light.min.css',
113+
brandOverride: 'https://cdn.jsdelivr.net/npm/@my-brand/brand-package@$brandVersion/dist/light.min.css',
114+
},
115+
},
116+
// Configure optional dark mode
117+
dark: {
118+
urls: {
119+
default: 'https://cdn.jsdelivr.net/npm/@openedx/paragon@$paragonVersion/dark/dark.min.css',
120+
brandOverride: 'https://cdn.jsdelivr.net/npm/@my-brand/brand-package@$brandVersion/dist/dark.min.css',
121+
},
122+
},
123+
// Configure any extra theme using a custom @openedx/brand-openedx package
124+
green: {
125+
url: 'https://cdn.jsdelivr.net/npm/@my-brand/brand-package@$brandVersion/dist/green.min.css',
126+
},
127+
red: {
128+
url: 'https://cdn.jsdelivr.net/npm/@my-brand/brand-package@$brandVersion/dist/red.min.css',
129+
},
130+
'high-contrast-dark': {
131+
url: 'https://cdn.jsdelivr.net/npm/@my-brand/brand-package@$brandVersion/dist/high-contrast-dark.min.css',
132+
},
133+
},
134+
}
135+
}
136+
}
137+
```
138+
93139
### JavaScript-based configuration
94140

95141
One approach to configuring the `PARAGON_THEME_URLS` is to create a `env.config.js` file in the root of the repository. The configuration is defined as a JavaScript file, which affords consumers to use more complex data types, amongst other benefits.
@@ -145,7 +191,7 @@ MFE_CONFIG_OVERRIDES = {
145191
}
146192
```
147193

148-
### Locally installed `@openedx/paragon`
194+
### Reference the locally installed `@openedx/paragon` version
149195

150196
If you would like to use the same version of the Paragon CSS urls as the locally installed `@openedx/paragon`, the configuration for the Paragon CSS urls may contain a wildcard `$paragonVersion` which gets replaced with the locally installed version of `@openedx/paragon` in the consuming application, e.g.:
151197

@@ -158,9 +204,9 @@ In the event the other Paragon CSS urls are configured via one of the other docu
158204

159205
## Usage with `@openedx/brand-openedx`
160206

161-
The core Paragon design tokens and styles may be optionally overriden by utilizing `@openedx/brand-openedx`, which allows theme authors to customize the default Paragon theme to match the look and feel of their custom brand.
207+
The core Paragon design tokens and styles may be optionally overridden by utilizing `@openedx/brand-openedx`, which allows theme authors to customize the default Paragon theme to match the look and feel of their custom brand.
162208

163-
This override mechanism works by compiling the design tokens defined in `@openedx/brand-openedx` with the the core Paragon tokens to generate overrides to Paragon's default CSS variables, and then compiling the output CSS with any SCSS theme customizations not possible through a design token override.
209+
This override mechanism works by compiling the design tokens defined in `@openedx/brand-openedx` with the core Paragon tokens to generate overrides to Paragon's default CSS variables and then compiling the output CSS with any SCSS theme customizations not possible through a design token override.
164210

165211
The CSS urls for `@openedx/brand-openedx` overrides will be applied after the core Paragon theme urls load, thus overriding any previously set CSS variables and/or styles.
166212

@@ -172,7 +218,7 @@ const config = {
172218
core: {
173219
urls: {
174220
default: 'https://cdn.jsdelivr.net/npm/@openedx/paragon@$paragonVersion/dist/core.min.css',
175-
brandOverride: 'https://cdn.jsdelivr.net/npm/@openedx/brand-openedx-edx.org@#brandVersion/dist/core.min.css',
221+
brandOverride: 'https://cdn.jsdelivr.net/npm/@openedx/brand-openedx@#brandVersion/dist/core.min.css',
176222
},
177223
},
178224
defaults: {
@@ -182,7 +228,7 @@ const config = {
182228
light: {
183229
urls: {
184230
default: 'https://cdn.jsdelivr.net/npm/@openedx/paragon@$paragonVersion/dist/light.min.css',
185-
brandOverride: 'https://cdn.jsdelivr.net/npm/@openedx/brand-openedx-edx.org@$brandVersion/dist/light.min.css',
231+
brandOverride: 'https://cdn.jsdelivr.net/npm/@openedx/brand-openedx@$brandVersion/dist/light.min.css',
186232
},
187233
},
188234
},
@@ -192,9 +238,9 @@ const config = {
192238
export default config;
193239
```
194240

195-
### Locally installed `@openedx/brand-openedx`
241+
### Reference the locally installed `@openedx/brand-openedx` version
196242

197-
If you would like to use the same version of the brand override CSS urls as the locally installed `@openedx/brand-openedx`, the configuration for the brand override CSS urls may contain a wildcard `$brandVersion` which gets replaced with the locally installed version of `@openedx/brand-openedx` in the consuming application, e.g.:
243+
If you would like to use the same version of the brand overrides CSS urls as the locally installed `@openedx/brand-openedx`, the configuration for the brand override CSS urls may contain a wildcard `$brandVersion` which gets replaced with the locally installed version of `@openedx/brand-openedx` in the consuming application, e.g.:
198244

199245
```shell
200246
https://cdn.jsdelivr.net/npm/@openedx/brand-openedx@$brandVersion/dist/core.min.css

src/react/AppProvider.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { SELECTED_THEME_VARIANT_KEY } from './constants';
4545
* - Optionally a redux `Provider`. Will only be included if a `store` property is passed to
4646
* `AppProvider`.
4747
* - A `Router` for react-router.
48+
* - A theme manager for Paragon.
4849
*
4950
* @param {Object} props
5051
* @param {Object} [props.store] A redux store.

0 commit comments

Comments
 (0)