docs/api-reference/widgets/styling.md
import {WidgetThemes} from '@site/src/doc-demos/widgets';
The deck.gl widget system provides support for themes. The primary goal of widget themes is to allow applications to select and switch between dark and light modes, so that widgets match the overall look of the application.
Themes are global for a deck instance, i.e they apply to all widgets in all views. Even though widgets can be placed in different views, it is not possible to specify different themes for different views.
Default themes are provided for dark and light mode, however themes can be customized to offer applications some additional control of styling, see below.
For applications that already implement theme switching in the non-deck parts of their UI, it is expected that deck.gl themes will be updated programmatically when the ambient UI theme is switched.
import {DarkTheme, LightTheme} from '@deck.gl/widgets';
new Deck({
style: mode === 'dark' ? DarkTheme : LightTheme
})
For minimal applications that don't implement a UI outside of deck.gl, a ThemeWidget is provided that let users switch between dark and light mode themes.
import {ThemeWidget} from '@deck.gl/widgets';
new Deck({
widgets=[new ThemeWidget()]
});
New themes can be defined programmatically or via CSS.
deck.gl uses CSS variables to define themes. This section provides guidance on how to theme and style widgets at different levels of specificity.
This lets application customize the appearance of widgets beyond the default light and dark mode themes.
import type {Theme} from '@deck.gl/widgets';
import {DarkTheme} from '@deck.gl/widgets';
const CustomTheme = {
...DarkTheme,
...
} satisfies Theme;
Apply to all widgets with the .deck-widget selector.
.deck-widget {
--button-size: 48px;
}
Note: While variables can be globally applied using the
:rootselector, ensuring their availability throughout the entire document, this method is not recommended. Applying variables globally can lead to naming conflicts, especially in larger projects or when integrating with other libraries.
The CSS variables for a specific type of widget using the .deck-widget-[type] selector.
.deck-widget-fullscreen {
--button-size: 48px;
}
Apply styles to a single instance of a widget using inline styles.
new FullscreenWidget({ style: {'--button-size': '48px'}})
To style hyphenated CSS properties (e.g. background-color, border-color, etc.), use the camelCase equivalent.
new FullscreenWidget({ style: {'backgroundColor': '#fff'}})
Define a custom class with your desired styles and apply it to a widget.
.my-class {
--button-size: 48px;
}
new FullscreenWidget({ className: 'my-class'})
We've provided a set of CSS variables to make styling UI Widgets more convenient. These variables allow for customization of widget sizes, colors, and other properties. Below is a list of these variables, their expected types, and default values.
Additionally, refer to each widget's API reference for variables specific to that widget.
| Name | Type | Default |
|---|---|---|
--button-size | Dimension | 28px |
--button-border-radius | Dimension | 8px |
--widget-margin | Dimension | 12px |
| Name | Type | Default |
|---|---|---|
--button-background | Color | #fff |
--button-stroke | Color | rgba(255, 255, 255, 0.3) |
--button-inner-stroke | Border | unset |
--button-shadow | Box Shadow | 0px 0px 8px 0px rgba(0, 0, 0, 0.25) |
--button-backdrop-filter | Backdrop Filter | unset |
--button-icon-idle | Color | rgba(97, 97, 102, 1) |
--button-icon-hover | Color | rgba(24, 24, 26, 1) |
--button-text-color | Color | rgba(24, 24, 26, 1) |
| Name | Type | Default |
|---|---|---|
--menu-gap | Dimension | 4px |
--menu-background | Color | #fff |
--menu-backdrop-filter | Backdrop Filter | unset |
--menu-border | Border | unset |
--menu-shadow | Box Shadow | 0px 0px 8px 0px rgba(0, 0, 0, 0.25) |
--menu-text | Color | rgb(24, 24, 26) |
--menu-item-hover | Color | rgba(0, 0, 0, 0.08) |
| Name | Type | Default |
|---|---|---|
--range-step-button-size | Dimension | 24px |
--range-track-size | Dimension | 16px |
--range-thumb-size | Dimension | 10px |
--range-track-color | Color | #888 |
--range-thumb-color | Color | #444 |
--range-decoration-active-color | Color | gold |
Refer to each widget's API reference for icon variable names.
Users can to customize icons to better align with their design preferences or branding. This section provides a step-by-step guide on how to replace and customize these icons.
--icon-fullscreen-enter, to replace the default icons with your customized ones.--button-icon-idle..deck-widget {
--icon-fullscreen-enter: url('path_to_your_svg_icon.svg');
--button-icon-idle: blue;
}
If possible, make the new icon re-colorable, resizable, and replaceable with CSS.
For consistency with the other icons in the core set, you can use Google Symbols.