Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

feat: add optional theme switch toggle (#3620)

Igor Dykhtaa0bee767270c
diff --git a/docs/api-reference/custom-theme/README.md b/docs/api-reference/custom-theme/README.md
index b81e60728..9a3800fce 100644
--- a/docs/api-reference/custom-theme/README.md
+++ b/docs/api-reference/custom-theme/README.md
@@ -23,3 +23,23 @@ const Map = props => (
| `dark` (default) | ![Screen Shot 2020-03-11 at 2 11 45 PM](https://user-images.githubusercontent.com/3605556/76464370-78c13080-63a2-11ea-977e-9678a25580f9.png) |
| `light` | ![Screen Shot 2020-03-11 at 2 10 15 PM](https://user-images.githubusercontent.com/3605556/76464360-74951300-63a2-11ea-82fe-3d055dc0b8dd.png) |
| `base` | ![Screen Shot 2020-03-11 at 2 10 49 PM](https://user-images.githubusercontent.com/3605556/76464366-78289a00-63a2-11ea-944b-e5a9208bacde.png) |
+
+### Theme Toggle Control
+
+To show a map control that lets users switch between light and dark themes at runtime, enable it via application config:
+
+```js
+import {initApplicationConfig} from '@kepler.gl/utils';
+
+initApplicationConfig({enableThemeToggle: true});
+```
+
+When enabled, the active theme is stored in `uiState.theme` (`'light'` | `'dark'`) and can be initialized through `keplerGlReducer.initialState`:
+
+```js
+keplerGlReducer.initialState({
+ uiState: {
+ theme: 'light'
+ }
+});
+```
diff --git a/examples/custom-theme/src/app.js b/examples/custom-theme/src/app.js
index 6f75d0143..bf7a35319 100644
--- a/examples/custom-theme/src/app.js
+++ b/examples/custom-theme/src/app.js
@@ -23,7 +23,17 @@ const theme = {
secondaryInputBgd: '#f7f7F7',
secondaryInputBgdActive: '#f7f7F7',
secondaryInputBgdHover: '#ffffff',
- panelActiveBg: '#f7f7F7'
+ panelActiveBg: '#f7f7F7',
+ // Map control buttons (top-right) use floatingBtn* tokens
+ floatingBtnBgd: '#F7F7F7',
+ floatingBtnActBgd: '#F7F7F7',
+ floatingBtnBgdHover: '#F7F7F7',
+ floatingBtnColor: '#6A7485',
+ floatingBtnActColor: '#2473bd',
+ mapPanelBackgroundColor: '#FFFFFF',
+ mapPanelHeaderBackgroundColor: '#F7F7F7',
+ toolbarItemBgdHover: '#F7F7F7',
+ toolbarItemIconHover: '#2473bd'
};
const emptyTheme = {};
diff --git a/src/actions/src/action-types.ts b/src/actions/src/action-types.ts
index fd033a1aa..5d19c35f6 100644
--- a/src/actions/src/action-types.ts
+++ b/src/actions/src/action-types.ts
@@ -164,6 +164,7 @@ export const ActionTypes = {
ADD_NOTIFICATION: `${ACTION_PREFIX}ADD_NOTIFICATION`,
REMOVE_NOTIFICATION: `${ACTION_PREFIX}REMOVE_NOTIFICATION`,
SET_LOCALE: `${ACTION_PREFIX}SET_LOCALE`,
+ SET_THEME: `${ACTION_PREFIX}SET_THEME`,
LAYER_FILTERED_ITEMS_CHANGE: `${ACTION_PREFIX}LAYER_FILTERED_ITEMS_CHANGE`,
WMS_FEATURE_INFO: `${ACTION_PREFIX}WMS_FEATURE_INFO`,
SYNC_TIME_FILTER_WITH_LAYER_TIMELINE: `${ACTION_PREFIX}SYNC_TIME_FILTER_WITH_LAYER_TIMELINE`,
diff --git a/src/actions/src/ui-state-actions.ts b/src/actions/src/ui-state-actions.ts
index 47b02af2a..5eebf6352 100644
--- a/src/actions/src/ui-state-actions.ts
+++ b/src/actions/src/ui-state-actions.ts
@@ -475,6 +475,27 @@ export const setLocale: (
})
);
+/** SET_THEME */
+export type SetThemeUpdaterAction = {
+ payload: {theme: string};
+};
+/**
+ * Set UI `theme` value (`light` or `dark`)
+ * @memberof uiStateActions
+ * @param theme - theme of the UI
+ * @public
+ */
+export const setTheme: (
+ theme: SetThemeUpdaterAction['payload']['theme']
+) => Merge<SetThemeUpdaterAction, {type: typeof ActionTypes.SET_THEME}> = createAction(
+ ActionTypes.SET_THEME,
+ (theme: SetThemeUpdaterAction['payload']['theme']) => ({
+ payload: {
+ theme
+ }
+ })
+);
+
/** TOGGLE_PANEL_LIST_VIEW */
export type TogglePanelListViewAction = {
payload: {
diff --git a/src/components/src/index.ts b/src/components/src/index.ts
index a25a53325..035d13d56 100644
--- a/src/components/src/index.ts
+++ b/src/components/src/index.ts
@@ -159,6 +159,7 @@ export {default as CoordinateInfoFactory} from './map/coordinate-info';
export {default as LayerHoverInfoFactory} from './map/layer-hover-info';
export {default as LazyTippy} from './map/lazy-tippy';
export {default as LocalePanelFactory} from './map/locale-panel';
+export {default as ThemeToggleButtonFactory} from './map/theme-toggle-button';
export {default as MapControlFactory} from './map/map-control';
export {default as MapNavigationControlFactory} from './map/map-navigation-control';
export {default as MapScaleFactory} from './map/map-scale';
diff --git a/src/components/src/kepler-gl.tsx b/src/components/src/kepler-gl.tsx
index 27cba1998..a822d5377 100644
--- a/src/components/src/kepler-gl.tsx
+++ b/src/components/src/kepler-gl.tsx
@@ -188,6 +188,7 @@ export const mapFieldsSelector = (props: KeplerGLProps, index = 0) => {
mapControls: props.uiState.mapControls,
readOnly: props.uiState.readOnly,
locale: props.uiState.locale,
+ uiTheme: props.uiState.theme,
isLoadingIndicatorVisible: Number(props.visState.loadingIndicatorValue) > 0,
sidePanelWidth: props.sidePanelWidth ? props.sidePanelWidth : DEFAULT_KEPLER_GL_PROPS.width,
@@ -546,17 +547,31 @@ function KeplerGlFactory(
/* selectors */
themeSelector = props => props.theme;
- availableThemeSelector = createSelector(this.themeSelector, theme =>
- typeof theme === 'object'
- ? {
+ uiThemeSelector = props => props.uiState?.theme;
+ availableThemeSelector = createSelector(
+ this.themeSelector,
+ this.uiThemeSelector,
+ (theme, uiTheme) => {
+ // When theme toggle is enabled, uiState.theme drives light/dark switching.
+ const themeInput = getApplicationConfig().enableThemeToggle
+ ? uiTheme || THEME.dark
+ : theme;
+
+ if (typeof themeInput === 'object' && themeInput !== null) {
+ return {
...basicTheme,
- ...theme
- }
- : theme === THEME.light
- ? themeLT
- : theme === THEME.base
- ? themeBS
- : theme
+ ...themeInput
+ };
+ }
+ if (themeInput === THEME.light) {
+ return themeLT;
+ }
+ if (themeInput === THEME.base) {
+ return themeBS;
+ }
+ // THEME.dark and unknown values fall back to the default dark theme
+ return basicTheme;
+ }
);
datasetsSelector = props => props.visState.datasets;
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index 58e5ddca8..86ceca616 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -238,6 +238,7 @@ export interface MapContainerProps {
sidePanelWidth?: number;
locale?: any;
+ uiTheme?: string;
theme?: any;
editor?: any;
MapComponent?: typeof MapboxLegacyMap | typeof MaplibreMap;
@@ -1323,6 +1324,7 @@ export default function MapContainerFactory(
mapControls,
isExport,
locale,
+ uiTheme,
uiStateActions,
visStateActions,
index,
@@ -1438,6 +1440,7 @@ export default function MapContainerFactory(
}
editor={editor}
locale={locale}
+ themeName={uiTheme}
onTogglePerspective={mapStateActions.togglePerspective}
onSetMapViewMode={mapStateActions.setMapViewMode}
mapViewMode={mapState.mapViewMode}
@@ -1447,6 +1450,7 @@ export default function MapContainerFactory(
onToggleSplitMapViewport={mapStateActions.toggleSplitMapViewport}
onSetEditorMode={visStateActions.setEditorMode}
onSetLocale={uiStateActions.setLocale}
+ onSetTheme={uiStateActions.setTheme}
onToggleEditorVisibility={visStateActions.toggleEditorVisibility}
onLayerVisConfigChange={visStateActions.layerVisConfigChange}
onToggleLayerVisibility={this._handleToggleLayerVisibility}
diff --git a/src/components/src/map/map-control.tsx b/src/components/src/map/map-control.tsx
index a9547c3a7..e17ff1070 100644
--- a/src/components/src/map/map-control.tsx
+++ b/src/components/src/map/map-control.tsx
@@ -11,6 +11,7 @@ import Toggle3dButtonFactory from './toggle-3d-button';
import MapLegendPanelFactory from './map-legend-panel';
import MapDrawPanelFactory from './map-draw-panel';
import LocalePanelFactory from './locale-panel';
+import ThemeToggleButtonFactory from './theme-toggle-button';
import MapNavigationControlFactory from './map-navigation-control';
import {Layer} from '@kepler.gl/layers';
import {Editor, LayerVisConfig, LayerOrder, MapControls, MapState} from '@kepler.gl/types';
@@ -73,8 +74,10 @@ export type MapControlProps = {
onToggleLayerVisibility?: (layer: Layer) => void;
top: number;
onSetLocale: typeof UIStateActions.setLocale;
+ onSetTheme: typeof UIStateActions.setTheme;
availableLocales: string[];
locale: string;
+ themeName?: string;
logoComponent?: React.FC | React.ReactNode;
isExport?: boolean;
@@ -100,6 +103,7 @@ MapControlFactory.deps = [
MapLegendPanelFactory,
MapDrawPanelFactory,
LocalePanelFactory,
+ ThemeToggleButtonFactory,
AnnotationControlFactory,
MapNavigationControlFactory
];
@@ -110,6 +114,7 @@ function MapControlFactory(
MapLegendPanel: ReturnType<typeof MapLegendPanelFactory>,
MapDrawPanel: ReturnType<typeof MapDrawPanelFactory>,
LocalePanel: ReturnType<typeof LocalePanelFactory>,
+ ThemeToggleButton: ReturnType<typeof ThemeToggleButtonFactory>,
AnnotationControl: ReturnType<typeof AnnotationControlFactory>,
MapNavigationControl: ReturnType<typeof MapNavigationControlFactory>
) {
@@ -119,6 +124,7 @@ function MapControlFactory(
MapDrawPanel,
AnnotationControl,
LocalePanel,
+ ThemeToggleButton,
MapLegendPanel
];
@@ -132,6 +138,8 @@ function MapControlFactory(
logoComponent = LegendLogo,
mapState,
mapStateActions,
+ themeName,
+ onSetTheme,
...restProps
}) => {
const actionComponentProps = {
@@ -142,7 +150,9 @@ function MapControlFactory(
onSetMapSplitMode: getApplicationConfig().enableSwipeMode
? mapStateActions?.setMapSplitMode
: undefined,
- ...restProps
+ ...restProps,
+ themeName,
+ onSetTheme
};
return (
<StyledMapControl className="map-control" $top={top}>
diff --git a/src/components/src/map/theme-toggle-button.tsx b/src/components/src/map/theme-toggle-button.tsx
new file mode 100644
index 000000000..cf490d105
--- /dev/null
+++ b/src/components/src/map/theme-toggle-button.tsx
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import React, {ComponentType, useCallback} from 'react';
+import classnames from 'classnames';
+
+import {THEME} from '@kepler.gl/constants';
+import {MapControls} from '@kepler.gl/types';
+import {getApplicationConfig} from '@kepler.gl/utils';
+
+import {Moon, Sun} from '../common/icons';
+import {MapControlButton} from '../common/styled-components';
+import MapControlTooltipFactory from './map-control-tooltip';
+
+interface ThemeToggleButtonIcons {
+ sun: ComponentType<any>;
+ moon: ComponentType<any>;
+}
+
+export type ThemeToggleButtonProps = {
+ themeName?: string;
+ onSetTheme: (theme: string) => void;
+ mapControls: MapControls;
+ actionIcons?: ThemeToggleButtonIcons;
+};
+
+ThemeToggleButtonFactory.deps = [MapControlTooltipFactory];
+
+function ThemeToggleButtonFactory(
+ MapControlTooltip: ReturnType<typeof MapControlTooltipFactory>
+) {
+ const defaultActionIcons = {
+ sun: Sun,
+ moon: Moon
+ };
+
+ const ThemeToggleButton: React.FC<ThemeToggleButtonProps> = ({
+ themeName = THEME.dark,
+ onSetTheme,
+ mapControls,
+ actionIcons = defaultActionIcons
+ }) => {
+ const isLight = themeName === THEME.light;
+
+ const onClick = useCallback(
+ event => {
+ event.preventDefault();
+ onSetTheme(isLight ? THEME.dark : THEME.light);
+ },
+ [isLight, onSetTheme]
+ );
+
+ if (!getApplicationConfig().enableThemeToggle) {
+ return null;
+ }
+
+ const showControl = mapControls?.mapTheme?.show;
+ if (!showControl) {
+ return null;
+ }
+
+ const Icon = isLight ? actionIcons.moon : actionIcons.sun;
+
+ return (
+ <MapControlTooltip
+ id="toggle-theme"
+ message={isLight ? 'tooltip.switchToDarkTheme' : 'tooltip.switchToLightTheme'}
+ >
+ <MapControlButton
+ className={classnames('map-control-button', 'toggle-theme', {light: isLight})}
+ onClick={onClick}
+ active={isLight}
+ >
+ <Icon height="18px" />
+ </MapControlButton>
+ </MapControlTooltip>
+ );
+ };
+
+ ThemeToggleButton.displayName = 'ThemeToggleButton';
+ return React.memo(ThemeToggleButton);
+}
+
+export default ThemeToggleButtonFactory;
diff --git a/src/constants/src/default-settings.ts b/src/constants/src/default-settings.ts
index c63597394..cb08777b8 100644
--- a/src/constants/src/default-settings.ts
+++ b/src/constants/src/default-settings.ts
@@ -1339,6 +1339,7 @@ export const MAP_CONTROLS = keyMirror({
splitMap: null,
mapDraw: null,
mapLocale: null,
+ mapTheme: null,
effect: null,
annotation: null,
aiAssistant: null
diff --git a/src/localization/src/translations/ca.ts b/src/localization/src/translations/ca.ts
index d1a6e53b6..75fc077cf 100644
--- a/src/localization/src/translations/ca.ts
+++ b/src/localization/src/translations/ca.ts
@@ -321,6 +321,8 @@ export default {
disable3DMap: 'Desactiva mapa 3D',
DrawOnMap: 'Dibuixa al mapa',
selectLocale: 'Selecciona configuració regional',
+ switchToLightTheme: 'Canvia al tema clar',
+ switchToDarkTheme: 'Canvia al tema fosc',
showAiAssistantPanel: 'Mostra el tauler de AI Assistant',
hideAiAssistantPanel: 'Oculta el tauler de AI Assistant',
hideLayerPanel: 'Oculta el tauler de capes',
diff --git a/src/localization/src/translations/cn.ts b/src/localization/src/translations/cn.ts
index ec47b2541..4ebfcfc72 100644
--- a/src/localization/src/translations/cn.ts
+++ b/src/localization/src/translations/cn.ts
@@ -308,6 +308,8 @@ export default {
disable3DMap: '禁用 3D 地图',
DrawOnMap: '在地图上绘制',
selectLocale: '选择语言',
+ switchToLightTheme: '切换到浅色主题',
+ switchToDarkTheme: '切换到深色主题',
showAiAssistantPanel: '显示 AI 助手面板',
hideAiAssistantPanel: '隐藏 AI 助手面板',
hideLayerPanel: '隐藏图层面板',
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index abd484561..febdeb81c 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -370,6 +370,8 @@ export default {
top: 'Top',
DrawOnMap: 'Draw on map',
selectLocale: 'Select locale',
+ switchToLightTheme: 'Switch to light theme',
+ switchToDarkTheme: 'Switch to dark theme',
showAiAssistantPanel: 'Show AI Assistant',
hideAiAssistantPanel: 'Hide AI Assistant',
hideLayerPanel: 'Hide layer panel',
diff --git a/src/localization/src/translations/es.ts b/src/localization/src/translations/es.ts
index f3b915522..d6a0b75fe 100644
--- a/src/localization/src/translations/es.ts
+++ b/src/localization/src/translations/es.ts
@@ -322,6 +322,8 @@ export default {
disable3DMap: 'Desactivar mapa 3D',
DrawOnMap: 'Dibujar en el mapa',
selectLocale: 'Seleccionar configuración regional',
+ switchToLightTheme: 'Cambiar a tema claro',
+ switchToDarkTheme: 'Cambiar a tema oscuro',
showAiAssistantPanel: 'Mostrar el panel de AI Assistant',
hideAiAssistantPanel: 'Ocultar el panel de AI Assistant',
hideLayerPanel: 'Ocultar la tabla de capas',
diff --git a/src/localization/src/translations/fi.ts b/src/localization/src/translations/fi.ts
index 05c7dbe8f..6bebf44ae 100644
--- a/src/localization/src/translations/fi.ts
+++ b/src/localization/src/translations/fi.ts
@@ -320,6 +320,8 @@ export default {
disable3DMap: 'Poistu 3D-näkymästä',
DrawOnMap: 'Piirrä kartalle',
selectLocale: 'Valitse kielisyys',
+ switchToLightTheme: 'Vaihda vaaleaan teemaan',
+ switchToDarkTheme: 'Vaihda tummaan teemaan',
showAiAssistantPanel: 'Näytä AI-apuohjelman paneeli',
hideAiAssistantPanel: 'Piilota AI-apuohjelman paneeli',
hideLayerPanel: 'Piilota tasopaneeli',
diff --git a/src/localization/src/translations/ja.ts b/src/localization/src/translations/ja.ts
index ede08a010..4094a2e2b 100644
--- a/src/localization/src/translations/ja.ts
+++ b/src/localization/src/translations/ja.ts
@@ -317,6 +317,8 @@ export default {
disable3DMap: '3D地図を無効化',
DrawOnMap: '地図上に図形を描画',
selectLocale: '言語設定',
+ switchToLightTheme: 'ライトテーマに切り替え',
+ switchToDarkTheme: 'ダークテーマに切り替え',
showAiAssistantPanel: 'AI 助手パネルを表示',
hideAiAssistantPanel: 'AI 助手パネルを非表示',
hideLayerPanel: 'レイヤパネルを非表示',
diff --git a/src/localization/src/translations/pt.ts b/src/localization/src/translations/pt.ts
index dd87a35dd..babaee6dd 100644
--- a/src/localization/src/translations/pt.ts
+++ b/src/localization/src/translations/pt.ts
@@ -322,6 +322,8 @@ export default {
disable3DMap: 'Desabilitar Mapa 3D',
DrawOnMap: 'Desenhar no mapa',
selectLocale: 'Selecionar língua',
+ switchToLightTheme: 'Mudar para tema claro',
+ switchToDarkTheme: 'Mudar para tema escuro',
showAiAssistantPanel: 'Mostrar painel de AI Assistant',
hideAiAssistantPanel: 'Esconder painel de AI Assistant',
hideLayerPanel: 'Esconder painel de camada',
diff --git a/src/localization/src/translations/ru.ts b/src/localization/src/translations/ru.ts
index 067559845..034a8af6b 100644
--- a/src/localization/src/translations/ru.ts
+++ b/src/localization/src/translations/ru.ts
@@ -319,6 +319,8 @@ export default {
disable3DMap: 'Отключить 3D Карту',
DrawOnMap: 'Рисовать на карте',
selectLocale: 'Выберите регион',
+ switchToLightTheme: 'Переключить на светлую тему',
+ switchToDarkTheme: 'Переключить на тёмную тему',
showAiAssistantPanel: 'Показать панель AI Assistant',
hideAiAssistantPanel: 'Скрыть панель AI Assistant',
hideLayerPanel: 'Скрыть панель слоев',
diff --git a/src/reducers/src/ui-state-updaters.ts b/src/reducers/src/ui-state-updaters.ts
index 877e45e90..ebfa74a4f 100644
--- a/src/reducers/src/ui-state-updaters.ts
+++ b/src/reducers/src/ui-state-updaters.ts
@@ -11,7 +11,8 @@ import {
EXPORT_IMG_RATIOS,
EXPORT_MAP_FORMATS,
RESOLUTIONS,
- MAP_CONTROLS
+ MAP_CONTROLS,
+ THEME
} from '@kepler.gl/constants';
import {LOCALE_CODES} from '@kepler.gl/localization';
import {
@@ -106,7 +107,8 @@ const DEFAULT_MAP_LEGEND_CONTROL = {
* @property toggle3d Default: `{show: true}`
* @property splitMap Default: `{show: true}`
* @property mapDraw Default: `{show: true, active: false}`
- * @property mapLocale Default: `{show: false, active: false}`
+ * @property mapLocale Default: `{show: true, active: false}`
+ * @property mapTheme Default: `{show: true, active: false}`
* @public
*/
export const DEFAULT_MAP_CONTROLS: MapControls = (
@@ -262,6 +264,8 @@ export const DEFAULT_EXPORT_VIDEO: ExportVideo = {
* @property notifications Default: `[]`
* @property notifications Default: `[]`
* @property loadFiles
+ * @property locale Default: `'en'`
+ * @property theme Default: `'dark'`
* @property isSidePanelCloseButtonVisible Default: `true`
* @public
*/
@@ -287,6 +291,8 @@ export const INITIAL_UI_STATE: UiState = {
loadFiles: DEFAULT_LOAD_FILES,
// Locale of the UI
locale: LOCALE_CODES.en,
+ // Theme of the UI (used when enableThemeToggle is on)
+ theme: THEME.dark,
layerPanelListView: 'list',
filterPanelListView: 'list',
isSidePanelCloseButtonVisible: true
@@ -956,6 +962,24 @@ export const setLocaleUpdater = (
locale
});
+/**
+ * Set the theme of the UI
+ * @memberof uiStateUpdaters
+ * @param state `uiState`
+ * @param action
+ * @param action.payload
+ * @param action.payload.theme theme
+ * @returns nextState
+ * @public
+ */
+export const setThemeUpdater = (
+ state: UiState,
+ {payload: {theme}}: UIStateActions.SetThemeUpdaterAction
+): UiState => ({
+ ...state,
+ theme
+});
+
/**
* Toggle layer panel list view
* @memberof uiStateUpdaters
@@ -1037,5 +1061,11 @@ export const receiveMapConfigUpdater = (
} as UIStateActions.SetLocaleUpdaterAction);
}
+ if (uiState.theme) {
+ newState = setThemeUpdater(newState, {
+ payload: {theme: uiState.theme}
+ } as UIStateActions.SetThemeUpdaterAction);
+ }
+
return newState;
};
diff --git a/src/reducers/src/ui-state.ts b/src/reducers/src/ui-state.ts
index b2193c00c..7a33b9a24 100644
--- a/src/reducers/src/ui-state.ts
+++ b/src/reducers/src/ui-state.ts
@@ -46,6 +46,7 @@ const actionHandler = {
[ActionTypes.TOGGLE_SPLIT_MAP]: uiStateUpdaters.toggleSplitMapUpdater,
[ActionTypes.SHOW_DATASET_TABLE]: uiStateUpdaters.showDatasetTableUpdater,
[ActionTypes.SET_LOCALE]: uiStateUpdaters.setLocaleUpdater,
+ [ActionTypes.SET_THEME]: uiStateUpdaters.setThemeUpdater,
[ActionTypes.TOGGLE_PANEL_LIST_VIEW]: uiStateUpdaters.togglePanelListViewUpdater,
[ActionTypes.RECEIVE_MAP_CONFIG]: uiStateUpdaters.receiveMapConfigUpdater
};
diff --git a/src/schemas/src/ui-state-schema.ts b/src/schemas/src/ui-state-schema.ts
index 683c6c613..51a577091 100644
--- a/src/schemas/src/ui-state-schema.ts
+++ b/src/schemas/src/ui-state-schema.ts
@@ -26,7 +26,8 @@ export const propertiesV1 = {
},
key: 'mapControls'
}),
- locale: null
+ locale: null,
+ theme: null
};
const uiStateSchema = {
diff --git a/src/types/reducers.d.ts b/src/types/reducers.d.ts
index 9f2184820..ceb3b5530 100644
--- a/src/types/reducers.d.ts
+++ b/src/types/reducers.d.ts
@@ -508,6 +508,7 @@ export type MapControls = {
splitMap?: MapControlItem;
mapDraw?: MapControlItem;
mapLocale?: MapControlItem;
+ mapTheme?: MapControlItem;
effect?: MapControlItem;
annotation?: MapControlItem;
aiAssistant?: MapControlItem;
@@ -528,6 +529,8 @@ export type Notifications = {
export type Locale = string;
+export type UiTheme = string;
+
export type PanelListView = string;
export type UiState = {
@@ -552,6 +555,8 @@ export type UiState = {
loadFiles: LoadFiles;
// Locale of the UI
locale: Locale;
+ // Theme of the UI (`light` | `dark`), used when enableThemeToggle is on
+ theme: UiTheme;
// view layers by list or dataset
layerPanelListView: PanelListView;
// view filters by list or dataset
diff --git a/src/types/schemas.d.ts b/src/types/schemas.d.ts
index 0e0fce7ce..11c92cb96 100644
--- a/src/types/schemas.d.ts
+++ b/src/types/schemas.d.ts
@@ -152,6 +152,7 @@ export type ParsedUiState = {
};
};
locale?: string;
+ theme?: string;
};
export type SavedMapState = {
diff --git a/src/utils/src/application-config.ts b/src/utils/src/application-config.ts
index d33326c23..6f2671f2b 100644
--- a/src/utils/src/application-config.ts
+++ b/src/utils/src/application-config.ts
@@ -162,7 +162,10 @@ export type KeplerApplicationConfig = {
/** Whether to enable the layer groups feature. Enabled by default. */
enableLayerGroups?: boolean;
-
+
+ /** Whether to show a map control to toggle between light and dark UI themes. Disabled by default. */
+ enableThemeToggle?: boolean;
+
/**
* Custom SVG icons to be made available in the icon layer.
* These icons will be merged with the default icons fetched from CDN.
@@ -281,11 +284,13 @@ const DEFAULT_APPLICATION_CONFIG: Required<KeplerApplicationConfig> = {
enableLayerGroups: true,
+ enableThemeToggle: false,
+
customIcons: [],
customIconUrl: '',
- reduxLogLevel: 1
+ reduxLogLevel: 1,
};
const applicationConfig: Required<KeplerApplicationConfig> = DEFAULT_APPLICATION_CONFIG;
diff --git a/test/browser/components/map/map-control-test.js b/test/browser/components/map/map-control-test.js
index 759dfa5ee..9eaeb80c5 100644
--- a/test/browser/components/map/map-control-test.js
+++ b/test/browser/components/map/map-control-test.js
@@ -79,7 +79,7 @@ test('MapControlFactory - display all options', t => {
</MapViewStateContextProvider>
</IntlWrapper>
);
- t.equal($.find('.map-control-action').length, 7, 'Should show 7 action panels');
+ t.equal($.find('.map-control-action').length, 8, 'Should show 8 action panels');
t.end();
});
diff --git a/test/node/schemas/ui-state-schema-test.js b/test/node/schemas/ui-state-schema-test.js
index 757ae11ce..c28b3189b 100644
--- a/test/node/schemas/ui-state-schema-test.js
+++ b/test/node/schemas/ui-state-schema-test.js
@@ -15,11 +15,12 @@ test('#uiStateSchema -> v1 -> save load uiState', t => {
t.deepEqual(
Object.keys(uiToSave).sort(),
- ['locale', 'mapControls'].sort(),
- 'saved uiState should have mapControls and locale'
+ ['locale', 'mapControls', 'theme'].sort(),
+ 'saved uiState should have mapControls, locale and theme'
);
t.equal(uiToSave.locale, 'en', 'default locale should be en');
+ t.equal(uiToSave.theme, 'dark', 'default theme should be dark');
t.deepEqual(
uiToSave.mapControls,
{mapLegend: {active: false}},