Theme Configuration

By configuring a custom theme, you can do the following:

You can configure these features through a theme.json configuration file (1) in the theme folder:

filesystem

  1. frontend
  2. └── themes
  3. └── my-theme
  4. ├── components/
  5. └── styles.css
  6. └── theme.json (1)

Style Sheets From npm Packages

You can configure a custom theme to import style sheets from npm packages included as dependencies in the project by defining them in an importCss array in theme.json:

Sample theme.json for importing CSS from npm packages

  1. {
  2. "importCss": [
  3. "@fortawesome/fontawesome-free/css/regular.css",
  4. "@fortawesome/fontawesome-free/css/all.min.css"
  5. ]
  6. }

This loads the external style sheets as if they were imported as local style sheets through styles.css.

Note
npm packages must be added to the project
The importCss configuration does not import the npm packages themselves to the project. You need to do that by using the @NpmPackage annotation.

Similarly to the document root style sheet, style sheets can be forced to the document root for embedded Flow application or component use cases through a corresponding documentCss array, which can be useful for font-face declarations in npm packages:

The following example theme.json defines importing of CSS from npm packages into doc root:

theme.json

  1. {
  2. "documentCss": ["@fortawesome/fontawesome-free/css/all.min.css"]
  3. }

Other Assets From npm Packages

In addition to style sheets, other assets like fonts, images, and icons can also be included from npm packages added to the project, by mapping them from the dependency to local URIs in an assets block in theme.json.

Syntax for mapping assets from npm package to local URIs goes as follows:

theme.json

  1. {
  2. "assets": {
  3. "package-name": {
  4. "asset/glob/pattern": "local/target/path"
  5. }
  6. }
  7. }

For example, to use SVG icons from @fortawesome/fontawesome-free npm package, the SVG files should be mapped to some local path as follows:

Sample theme.json for mapping assets from npm packages.

  1. {
  2. "assets": {
  3. "@fortawesome/fontawesome-free": {
  4. "svgs/regular/**": "fontawesome/icons"
  5. }
  6. }
  7. }
Note
npm packages must be added to the project
The assets configuration does not import the npm packages themselves to the project. You need to do that by using the @NpmPackage annotation.

The SVG images mapped by the example above are now available on the path fontawesome/icons relative to the theme’s root folder, so they can be referenced in styles.css as follows:

styles.css usage of assets mapped from npm package

  1. .icon-snowflake {
  2. background-image: url('fontawesome/icons/snowflake.svg');
  3. }

The assets block supports multiple packages and multiple mappings per package.

Sample theme.json mapping multiple packages and assets per package

  1. {
  2. "assets": {
  3. "@fortawesome/fontawesome-free": {
  4. "svgs/regular/**": "fortawesome/icons",
  5. "webfonts/**": "webfonts"
  6. },
  7. "@fortawesome/free-solid-svg-icons": {
  8. "*.js": "solids"
  9. }
  10. }
  11. }

Extending Custom Themes

A custom theme can extend another custom theme by configuring a “parent theme” in theme.json. This can be useful for splitting your styles into a base theme shared by all applications, and multiple “sub-themes” for different applications or sub-brands. The parent theme can be in the same project as the sub-theme, or in a separate dependency.

Sample theme.json for parent theme configuration

  1. {
  2. "parent": "my-base-theme"
  3. }

With a parent and sub theme configuration like this, the CSS load order is as follows:

  1. Lumo styles

  2. Parent theme styles

  3. Sub-theme styles

  4. Manually loaded additional style sheets (for example, using @CssImport in Flow)