Back to Devexpress

Themes and Styles for a Blazor WebAssembly Application

dashboard-403817-web-dashboard-integrate-dashboard-component-dashboard-component-for-blazor-blazor-webassembly-themes-and-styles.md

latest15.2 KB
Original Source

Themes and Styles for a Blazor WebAssembly Application

  • Mar 16, 2023
  • 7 minutes to read

Supported Themes

You can apply two types of themes to a Web Dashboard:

Predefined themesYou can find the complete list in the table below. All the listed options are different modifications of the Generic, Generic Compact, and Material Design Compact DevExtreme themes.Custom themesYou can modify Generic and Generic Compact DevExtreme themes. This topic includes step-by-step instructions on theme customization.

Each theme is a collection of CSS files (stylesheets).

Generic Themes

ImageDemoCSS File (Generic)CSS File (Generic Compact)
Lightdx.light.css
dx-analytics.light.css
dx-dashboard.light.cssdx.light.compact.css
dx-analytics.light.compact.css
dx-dashboard.light.compact.css
Darkdx.dark.css
dx-analytics.dark.css
dx-dashboard.dark.cssdx.dark.compact.css
dx-analytics.dark.compact.css
dx-dashboard.dark.compact.css
Carminedx.carmine.css
dx-analytics.carmine.css
dx-dashboard.carmine.cssdx.carmine.compact.css
dx-analytics.carmine.compact.css
dx-dashboard.carmine.compact.css
Soft Bluedx.softblue.css
dx-analytics.softblue.css
dx-dashboard.softblue.cssdx.softblue.compact.css
dx-analytics.softblue.compact.css
dx-dashboard.softblue.compact.css
Green Mistdx.greenmist.css
dx-analytics.greenmist.css
dx-dashboard.greenmist.cssdx.greenmist.compact.css
dx-analytics.greenmist.compact.css
dx-dashboard.greenmist.compact.css
Dark Moondx.darkmoon.css
dx-analytics.darkmoon.css
dx-dashboard.darkmoon.cssdx.darkmoon.compact.css
dx-analytics.darkmoon.compact.css
dx-dashboard.darkmoon.compact.css
Dark Violetdx.darkviolet.css
dx-analytics.darkviolet.css
dx-dashboard.darkviolet.cssdx.darkviolet.compact.css
dx-analytics.darkviolet.compact.css
dx-dashboard.darkviolet.compact.css

Material Design Themes

ImageDemoCSS File (Material Design Compact)
Blue Lightdx.material.blue.light.compact.css
dx-analytics.material.blue.light.compact.css
dx-dashboard.material.blue.light.compact.css
Lime Lightdx.material.lime.light.compact.css
dx-analytics.material.lime.light.compact.css
dx-dashboard.material.lime.light.compact.css
Orange Lightdx.material.orange.light.compact.css
dx-analytics.material.orange.light.compact.css
dx-dashboard.material.orange.light.compact.css
Purple Lightdx.material.purple.light.compact.css
dx-analytics.material.purple.light.compact.css
dx-dashboard.material.purple.light.compact.css
Teal Lightdx.material.teal.light.compact.css
dx-analytics.material.teal.light.compact.css
dx-dashboard.material.teal.light.compact.css
Blue Darkdx.material.blue.dark.compact.css
dx-analytics.material.blue.dark.compact.css
dx-dashboard.material.blue.dark.compact.css
Lime Darkdx.material.lime.dark.compact.css
dx-analytics.material.lime.dark.compact.css
dx-dashboard.material.lime.dark.compact.css
Orange Darkdx.material.orange.dark.compact.css
dx-analytics.material.orange.dark.compact.css
dx-dashboard.material.orange.dark.compact.css
Purple Darkdx.material.purple.dark.compact.css
dx-analytics.material.purple.dark.compact.css
dx-dashboard.material.purple.dark.compact.css
Teal Darkdx.material.teal.dark.compact.css
dx-analytics.material.teal.dark.compact.css
dx-dashboard.material.teal.dark.compact.css

Apply a Built-in Theme

In the wwwroot folder, open the index.html file and reference the corresponding stylesheets. The code snippet below shows how to apply the Carmine theme:

html
<head>
<!-- ... -->
    <link href="_content/DevExpress.Blazor.Dashboard/ace.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/ace-theme-dreamweaver.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/ace-theme-ambiance.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx.carmine.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx-analytics.common.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx-analytics.carmine.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx-querybuilder.css" rel="stylesheet" />
    <link href="_content/DevExpress.Blazor.Dashboard/dx-dashboard.carmine.css" rel="stylesheet" />
</head>

Optional: Bundle Resources

You can bundle and minimize the CSS files with the BuildBundlerMinifier NuGet package, Gulp, or any other third-party tool. To bundle resources with the BuildBundlerMinifier, do the following:

  1. Install the BuildBundlerMinifier NuGet package.

  2. Create a bundleconfig.json file with the content and then add the file into project:

  3. In the wwwroot folder, open the index.html file and reference the CSS bundle instead of CSS stylesheets:

  4. Rebuild your application.

Customize Themes

Warning

Customization is available only for Generic and Generic Compact themes.

The DevExpress Dashboard CLI is used with the DevExtreme ThemeBuilder to create a custom theme for the Web Dashboard.

Theme customization involves the following basic steps:

  1. Use the DevExtreme ThemeBuilder tool to customize an existing theme and export the results.
  2. Add Dashboard-specific settings to the generated resource files.
  3. Use the DevExpress Dashboard CLI to convert the customized resource files into a Web Dashboard theme.
  4. Register the new theme in your application.

Create a Custom Theme

  1. Make sure you have Node.js and npm installed on your machine.

  2. Open the ThemeBuilder. Create a custom theme based on Generic themes. For instance, you can use the Light theme as a base and change its accent color from blue (#337ab7) to yellow (#fdb400).

  3. Set the color scheme name (for example, “light-yellow”) and use the Export MetadataDownload Metadata File button to export metadata in a JSON format.

  4. Copy the downloaded JSON file ( dx.generic.light-yellow.json ) to an empty folder.

  5. Edit dx.generic.light-yellow.json and add the dashboardItems property to override the accent colors at the dashboard level:

  6. In the folder you created in Step 4, execute the command that installs the devexpress-dashboard-cli package and builds the CSS files for your custom JSON file. Use the same version of the devexpress-dashboard-cli package as the version of DevExpress packages that you use in your application:

Color Constants

The Web Dashboard uses color constants to paint the control’s elements. The colors of the color constants listed in the table below can be customized. Changes to specific dashboard elements’ colors do not affect the basic DevExtreme colors.

Show Table

Color ConstantDescription
@dashboard-surface-bgThe background color of the dashboard surface.
@dashboard-item-selected-bgThe background color of the selected element in a dashboard item.
@dashboard-item-hover-bgThe background color applied to elements in a dashboard item when you hover over them.
@dashboard-overlay-shader-bgThe shading background color.
@dashboard-border-colorA more contrast border color.
@dashboard-border-sub-colorA less contrast border color.
@dashboard-shadowThe color of the shadow used for the control’s elements (for example, when you hover over icons in the Toolbox).
@dashboard-shadow-border-colorThe color of the border that appears with the shadow.
@dashboard-tab-hover-bgThe background color of the inactive hovered tab page’s header.
@dashboard-tab-inactive-bgThe background color of the inactive tab page.
@dashboard-info-toast-bgThe background color of the information notification toast.
@dashboard-info-toast-colorThe text color of the information notification toast.
@dashboard-errorThe background color of the error notification toast.
@dashboard-successThe background color of the success notification toast.
@dashboard-item-menu-bgThe background color of the dashboard item menu.
@dashboard-item-menu-icon-colorThe primary color of the dashboard item menu’s icons.
@dashboard-item-menu-icon-sub-colorThe additional color of the dashboard item menu’s icons.
@dashboard-item-menu-remove-icon-colorThe color of the dashboard item menu’s Delete icon.
@dashboard-item-menu-separator-colorThe color of the dashboard item menu’s separator.
@dashboard-item-menu-item-border-colorThe border color of a dashboard item. The border appears when you hover or select a dashboard item in the [Designer]> (xref:119283#designer-and-viewer-modes) mode.
@dashboard-item-binding-menu-bgThe background color of the dashboard item’s Binding menu.
@dashboard-item-binding-menu-filter-section-bgThe background color of the Binding menu’s Filter section.
@dashboard-menu-bgThe dashboard menu‘s background color.
@dashboard-menu-colorThe dashboard menu’s basic color.
@dashboard-menu-header-bgThe background color of the dashboard menu’s header.
@dashboard-menu-header-colorThe primary color of the dashboard menu’s header.
@dashboard-menu-icon-colorThe color of the dashboard menu’s icons (for example, the X icon used to close the menu).
@dashboard-menu-selected-bgThe background color of the selected element in the dashboard’s menu.
@dashboard-menu-selected-colorThe color of the selected dashboard menu’s element.
@dashboard-menu-hover-bgThe background color applied to elements in a dashboard menu when you hover over them.
@dashboard-menu-hover-colorThe primary color applied to elements in a dashboard menu when you hover over them.
@dashboard-toolbar-colorThe text color of the dashboard item caption and dashboard title.

Apply a Custom Theme

A custom theme’s icons should be in the same folder as the theme’s CSS files. You can download icons as follows:

  1. In a command line interface, install the devextreme package. The icons folder is located at node_modules/devextreme/dist/css/icons.
  2. Copy the icons folder next to the theme’s CSS files.

To apply the custom theme you created, register the generated CSS files instead of the default styles:

  1. Create the wwwroot | custom-themes folder in the project and place the generated CSS files in this folder.

  2. Attach the generated CSS files instead of corresponding existing CSS files:

  3. Rebuild your application.

The image below shows the Web Dashboard with a custom Light Yellow theme: