Angular Common - Utils - ui - themes

An object that serves as a namespace for the methods that work with DevExtreme CSS Themes.

import ui.themes from "devextreme-angular/ui/themes"

current()

Gets the current theme's name.

Return Value:

String

The current theme's name.

current(themeName)

Switches the active theme.

Parameters:
themeName:

String

The theme name.

current(themeName) switches between themes that you link in the <head> element. Add a <link rel="dx-theme"> element for each theme:

index.html
<link rel="dx-theme" data-theme="fluent-next.blue.dark" href="css/dx.fluent-next.blue.dark.css" data-active="true">
<link rel="dx-theme" data-theme="fluent-next.blue.light" href="css/dx.fluent-next.blue.light.css" data-active="false">

Pass a data-theme attribute value to current(themeName) to switch the active theme. This method updates DevExtreme styles automatically. To ensure that specific components apply the new styles, call their repaint() methods (if available) in a callback function passed to ready(callback). If you applied an inverted dark/light mode to specific containers while using a Fluent Next theme, call refreshMode() to apply updated modes to open overlays.

Callback functions passed to ready(callback) run only once, so call ready(callback) before each current(themeName) call:

jQuery
index.js
function switchToLightTheme() {
    DevExpress.ui.themes.ready(() => {
        dataGridInstance.repaint();
        DevExpress.ui.themes.refreshMode();
    });
    DevExpress.ui.themes.current('fluent-next.blue.light');
}
Angular
app.component.ts
import themes from "devextreme/ui/themes";

// ...
export class AppComponent {
    switchToLightTheme() {
        themes.ready(() => {
            dataGridInstance.repaint();
            themes.refreshMode();
        });
        themes.current('fluent-next.blue.light');
    }
}
Vue
App.vue
<script setup lang="ts">
import themes from "devextreme/ui/themes";

function switchToLightTheme() {
    themes.ready(() => {
        dataGridInstance.repaint();
        themes.refreshMode();
    });
    themes.current('fluent-next.blue.light');
}
</script>
React
App.tsx
import { useCallback } from 'react';
import themes from "devextreme/ui/themes";

export default function App() {
    const switchToLightTheme = useCallback(() => {
        themes.ready(() => {
            dataGridInstance.repaint();
            themes.refreshMode();
        });
        themes.current('fluent-next.blue.light');
    }, []);

    // ...
}
See Also

customAccentColor()

Gets the custom accent color (primary color) applied to the active Fluent Next stylesheet.

Return Value:

String

The custom accent color or an empty string if no custom accent color is defined.

customAccentColor() returns the --dx-accent-color value defined in the :root scope. The returned value retains the format you specify (for instance, "SlateBlue" or "#6A5ACD").

See Also

customAccentColor(color)

Applies a custom accent color (primary color) to the active Fluent Next stylesheet.

Parameters:
color:

String

| null

A CSS color value. Pass null or an empty string to remove the custom accent color.

This method defines the --dx-accent-color CSS variable in the :root scope. Fluent Next stylesheets calculate primary color shades from this variable, and DevExtreme components update their colors immediately. If you define a --dx-accent-color value in your stylesheets, customAccentColor(color) overrides this value.

customAccentColor(color) accepts the following CSS color values:

  • Color names (for instance, "SlateBlue")
  • Hexadecimal values
  • rgb(), hsl(), and oklch() color functions
  • References to CSS variables (for instance, "var(--my-brand-color)")

The accent color does not change if you pass an invalid value to this method.

After you remove a custom accent color that you specified with this method, components use the --dx-accent-color value from your stylesheets. If you do not define this value, components use the predefined accent color.

NOTE
Only Fluent Next themes support custom accent colors. If another theme is active when you call customAccentColor(color), the method defines the --dx-accent-color variable but logs a warning and does not change application appearance. The --dx-accent-color value takes effect when you switch to a Fluent Next theme.
See Also

initialized(callback)

Specifies a function to be executed after a theme is loaded.

Parameters:
callback:

Function

The function.

In some situations, UI components may apply their configuration or calculate their sizes before a theme is loaded. If you encounter issues with component appearance, use initialized(callback) to ensure that all styles are applied:

Angular
main.ts
import themes from 'devextreme/ui/themes';
// ...
themes.initialized(() => {
    platformBrowserDynamic().bootstrapModule(AppModule)
        .catch(err => console.error(err));
});
Vue
index.js
import { createApp } from "vue";
import App from "./App.vue";

import themes from "devextreme/ui/themes";

themes.initialized(() => createApp(App).mount("#app"));
React
index.js
import React from "react";
import ReactDOM from "react-dom";
import App from "./App.js";

import themes from "devextreme/ui/themes";

themes.initialized(() =>
    ReactDOM.render(<App />, document.getElementById("app"))
);

mode(element)

Gets the theme mode applied to an element.

Parameters:
element:

Element

|

jQuery

The element for which to retrieve the theme mode.

Return Value:

String

The element's theme mode ("light" or "dark").

mode(element) returns a calculated theme mode, not the mode class assigned to the passed element. The calculated theme mode for a dx-theme-mode-inverted container depends on the nearest enclosing theme mode. Refer to the following help topic for additional information: Container-Specific Theme Modes.

You can call this method under any DevExtreme theme and for any element (including elements outside theme mode containers). If no container specifies a mode for the element, mode(element) returns the active theme's mode ("light" or "dark").

If you change theme mode classes at runtime, mode(element) returns the updated value immediately.

ready(callback)

Specifies a function to be executed once, the next time a theme is applied.

Parameters:
callback:

Function

The function.

Refer to the current(themeName) description for a code example.

refreshMode()

Updates theme modes in open overlays.

When a container's theme mode changes at runtime, DevExtreme styles in this container update automatically. DevExtreme component overlays (for instance, popups and drop-down lists) render at the viewport level by default and do not update automatically.

If a theme mode container includes DevExtreme components that display overlays, call refreshMode() in the following scenarios:

  • When you change the container's theme mode class
  • When you call current(themeName) to switch between Fluent Next stylesheets (if the container uses the dx-theme-mode-inverted class)
NOTE
  • refreshMode() preserves focus in open overlays.
  • Closed overlays apply the current theme mode when they open. refreshMode() does nothing if no overlays are open.
  • Call refreshMode() in a callback function passed to ready(callback) to update open overlays after you switch between Fluent Next stylesheets. Callback functions passed to ready(callback) run only once, so call ready(callback) before each current(themeName) call.
See Also