Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Dark mode.
Mike Caoaa265d1d4263
diff --git a/components/common/Button.module.css b/components/common/Button.module.cssindex faae656bb..351f5ecc4 100644--- a/components/common/Button.module.css+++ b/components/common/Button.module.css@@ -3,6 +3,7 @@justify-content: center;align-items: center;font-size: var(--font-size-normal);+ color: var(--gray900);background: var(--gray100);padding: 8px 16px;border-radius: 4px;@@ -18,7 +19,7 @@}.button:active {- color: initial;+ color: var(--gray700);}.large {diff --git a/components/common/ButtonGroup.module.css b/components/common/ButtonGroup.module.cssindex d18a8e9c0..bc60f8d36 100644--- a/components/common/ButtonGroup.module.css+++ b/components/common/ButtonGroup.module.css@@ -7,6 +7,7 @@.group .button {border-radius: 0;+ color: var(--gray800);background: var(--gray50);border-left: 1px solid var(--gray500);padding: 4px 8px;@@ -24,6 +25,7 @@margin: 0;}-.selected {+.group .button.selected {+ color: var(--gray900);font-weight: 600;}diff --git a/components/common/Dropdown.module.css b/components/common/Dropdown.module.cssindex 250e6c293..4b94f58ff 100644--- a/components/common/Dropdown.module.css+++ b/components/common/Dropdown.module.css@@ -20,5 +20,5 @@}.icon {- padding-left: 10px;+ padding-left: 20px;}diff --git a/components/common/Link.module.css b/components/common/Link.module.cssindex d6dc0536f..24d8f84cd 100644--- a/components/common/Link.module.css+++ b/components/common/Link.module.css@@ -2,7 +2,7 @@ a.link,a.link:active,a.link:visited {position: relative;- color: #2c2c2c;+ color: var(--gray900);text-decoration: none;}@@ -12,7 +12,7 @@ a.link:before {bottom: -2px;width: 0;height: 2px;- background: #2680eb;+ background: var(--primary400);opacity: 0.5;transition: width 100ms;}diff --git a/components/common/Menu.module.css b/components/common/Menu.module.cssindex 9bcd642f0..655518374 100644--- a/components/common/Menu.module.css+++ b/components/common/Menu.module.css@@ -8,14 +8,14 @@.option {font-size: var(--font-size-small);font-weight: normal;- background: #fff;+ background: var(--gray50);padding: 4px 16px;cursor: pointer;white-space: nowrap;}.option:hover {- background: #f5f5f5;+ background: var(--gray100);}.float {diff --git a/components/common/Modal.module.css b/components/common/Modal.module.cssindex 3702e7740..bf2491c71 100644--- a/components/common/Modal.module.css+++ b/components/common/Modal.module.css@@ -16,8 +16,8 @@right: 0;bottom: 0;margin: auto;- background: var(--gray900);- opacity: 0.1;+ background: #000;+ opacity: 0.5;}.content {diff --git a/components/common/NavMenu.module.css b/components/common/NavMenu.module.cssindex c5d6c9db9..7be739737 100644--- a/components/common/NavMenu.module.css+++ b/components/common/NavMenu.module.css@@ -1,4 +1,5 @@.menu {+ color: var(--gray800);border: 1px solid var(--gray500);border-radius: 4px;overflow: hidden;@@ -16,5 +17,6 @@}.selected {+ color: var(--gray900);font-weight: 600;}diff --git a/components/common/Toast.module.css b/components/common/Toast.module.cssindex bfcd26bba..a65abfd18 100644--- a/components/common/Toast.module.css+++ b/components/common/Toast.module.css@@ -9,7 +9,7 @@justify-content: space-between;align-items: center;padding: 8px 16px;- color: var(--gray50);+ color: var(--msgColor);background: var(--green400);margin: auto;z-index: 2;diff --git a/components/common/WorldMap.js b/components/common/WorldMap.jsindex f10dd5425..f6eec8d67 100644--- a/components/common/WorldMap.js+++ b/components/common/WorldMap.js@@ -1,44 +1,57 @@-import React, { useState } from 'react';+import React, { useState, useMemo } from 'react';import ReactTooltip from 'react-tooltip';+import { ComposableMap, Geographies, Geography, ZoomableGroup } from 'react-simple-maps';import classNames from 'classnames';import tinycolor from 'tinycolor2';-import { ComposableMap, Geographies, Geography, ZoomableGroup } from 'react-simple-maps';+import useTheme from 'hooks/useTheme';+import { THEME_COLORS } from 'lib/constants';import styles from './WorldMap.module.css';const geoUrl = '/world-110m.json';-export default function WorldMap({- data,- className,- baseColor = '#e9f3fd',- fillColor = '#f5f5f5',- strokeColor = '#2680eb',- hoverColor = '#2680eb',-}) {+export default function WorldMap({ data, className }) {const [tooltip, setTooltip] = useState();+ const [theme] = useTheme();+ const colors = useMemo(+ () => ({+ baseColor: THEME_COLORS[theme].primary,+ fillColor: THEME_COLORS[theme].gray100,+ strokeColor: THEME_COLORS[theme].primary,+ hoverColor: THEME_COLORS[theme].primary,+ }),+ [theme],+ );function getFillColor(code) {- if (code === 'AQ') return '#ffffff';+ if (code === 'AQ') return;const country = data?.find(({ x }) => x === code);- return country ? tinycolor(baseColor).darken(country.z) : fillColor;- }- function getStrokeColor(code) {- return code === 'AQ' ? '#ffffff' : strokeColor;+ if (!country) {+ return colors.fillColor;+ }++ return tinycolor(colors.baseColor)[theme === 'light' ? 'lighten' : 'darken'](+ 40 * (1.0 - country.z / 100),+ );}- function getHoverColor(code) {- return code === 'AQ' ? '#ffffff' : hoverColor;+ function getOpacity(code) {+ return code === 'AQ' ? 0 : 1;}function handleHover({ ISO_A2: code, NAME: name }) {+ if (code === 'AQ') return;const country = data?.find(({ x }) => x === code);setTooltip(`${name}: ${country?.y || 0} visitors`);}return (- <div className={classNames(styles.container, className)}>- <ComposableMap data-tip="" projection="geoMercator">+ <div+ className={classNames(styles.container, className)}+ data-tip=""+ data-for="world-map-tooltip"+ >+ <ComposableMap projection="geoMercator"><ZoomableGroup zoom={0.8} minZoom={0.7} center={[0, 40]}><Geographies geography={geoUrl}>{({ geographies }) => {@@ -50,10 +63,11 @@ export default function WorldMap({key={geo.rsmKey}geography={geo}fill={getFillColor(code)}- stroke={getStrokeColor(code)}+ stroke={colors.strokeColor}+ opacity={getOpacity(code)}style={{default: { outline: 'none' },- hover: { outline: 'none', fill: getHoverColor(code) },+ hover: { outline: 'none', fill: colors.hoverColor },pressed: { outline: 'none' },}}onMouseOver={() => handleHover(geo.properties)}@@ -65,7 +79,7 @@ export default function WorldMap({</Geographies></ZoomableGroup></ComposableMap>- <ReactTooltip>{tooltip}</ReactTooltip>+ <ReactTooltip id="world-map-tooltip">{tooltip}</ReactTooltip></div>);}diff --git a/components/common/WorldMap.module.css b/components/common/WorldMap.module.cssindex bf84d6970..c25280382 100644--- a/components/common/WorldMap.module.css+++ b/components/common/WorldMap.module.css@@ -1,5 +1,4 @@.container {overflow: hidden;position: relative;- background: #fff;}diff --git a/components/forms/DatePickerForm.js b/components/forms/DatePickerForm.jsindex f8b6416eb..673cd7bd8 100644--- a/components/forms/DatePickerForm.js+++ b/components/forms/DatePickerForm.js@@ -6,7 +6,7 @@ import Button from 'components/common/Button';import { FormButtons } from 'components/layout/FormLayout';import { getDateRangeValues } from 'lib/date';import styles from './DatePickerForm.module.css';-import ButtonGroup from '../common/ButtonGroup';+import ButtonGroup from 'components/common/ButtonGroup';const FILTER_DAY = 0;const FILTER_RANGE = 1;diff --git a/components/layout/FormLayout.module.css b/components/layout/FormLayout.module.cssindex 0b82ee7c8..90e1b8c27 100644--- a/components/layout/FormLayout.module.css+++ b/components/layout/FormLayout.module.css@@ -39,7 +39,7 @@}.msg {- color: var(--gray50);+ color: var(--msgColor);background: var(--red400);font-size: var(--font-size-small);padding: 4px 8px;diff --git a/components/layout/Header.js b/components/layout/Header.jsindex f275bda3b..46c9b3e4b 100644--- a/components/layout/Header.js+++ b/components/layout/Header.js@@ -3,11 +3,12 @@ import { FormattedMessage } from 'react-intl';import { useSelector } from 'react-redux';import classNames from 'classnames';import Link from 'components/common/Link';-import UserButton from '../common/UserButton';-import Icon from '../common/Icon';+import UserButton from 'components/common/UserButton';+import Icon from 'components/common/Icon';+import LanguageButton from 'components/settings/LanguageButton';+import ThemeButton from 'components/settings/ThemeButton';import Logo from 'assets/logo.svg';import styles from './Header.module.css';-import LanguageButton from '../common/LanguageButton';export default function Header() {const user = useSelector(state => state.user);@@ -32,10 +33,14 @@ export default function Header() {<FormattedMessage id="label.settings" defaultMessage="Settings" /></Link><LanguageButton menuAlign="right" />+ <ThemeButton /><UserButton /></>) : (- <LanguageButton menuAlign="right" />+ <>+ <LanguageButton menuAlign="right" />+ <ThemeButton />+ </>)}</div></div>diff --git a/components/layout/Layout.js b/components/layout/Layout.jsindex 021745cc9..b16a07170 100644--- a/components/layout/Layout.js+++ b/components/layout/Layout.js@@ -16,8 +16,8 @@ export default function Layout({ title, children, header = true, footer = true }</Head>{header && <Header />}<main className="container">{children}</main>- <div id="__modals" />{footer && <Footer />}+ <div id="__modals" /></>);}diff --git a/components/layout/Layout.module.css b/components/layout/Layout.module.cssnew file mode 100644index 000000000..90b6c876f--- /dev/null+++ b/components/layout/Layout.module.css@@ -0,0 +1,6 @@+.layout {+ display: flex;+ flex-direction: column;+ width: 100%;+ height: 100%;+}diff --git a/components/metrics/BarChart.js b/components/metrics/BarChart.jsindex 1c66504dd..5b81c7691 100644--- a/components/metrics/BarChart.js+++ b/components/metrics/BarChart.js@@ -6,6 +6,8 @@ import { formatLongNumber } from 'lib/format';import { dateFormat } from 'lib/lang';import useLocale from 'hooks/useLocale';import styles from './BarChart.module.css';+import useTheme from 'hooks/useTheme';+import { THEME_COLORS } from 'lib/constants';export default function BarChart({chartId,@@ -23,6 +25,12 @@ export default function BarChart({const chart = useRef();const [tooltip, setTooltip] = useState({});const [locale] = useLocale();+ const [theme] = useTheme();+ const colors = {+ text: THEME_COLORS[theme].gray700,+ line: THEME_COLORS[theme].gray200,+ zeroLine: THEME_COLORS[theme].gray500,+ };function renderXLabel(label, index, values) {const d = new Date(values[index].value);@@ -97,6 +105,11 @@ export default function BarChart({responsive: true,responsiveAnimationDuration: 0,maintainAspectRatio: false,+ legend: {+ labels: {+ fontColor: colors.text,+ },+ },scales: {xAxes: [{@@ -110,6 +123,7 @@ export default function BarChart({callback: renderXLabel,minRotation: 0,maxRotation: 0,+ fontColor: colors.text,},gridLines: {display: false,@@ -123,6 +137,11 @@ export default function BarChart({ticks: {callback: renderYLabel,beginAtZero: true,+ fontColor: colors.text,+ },+ gridLines: {+ color: colors.line,+ zeroLineColor: colors.zeroLine,},stacked,},@@ -144,8 +163,13 @@ export default function BarChart({function updateChart() {const { options } = chart.current;+ options.legend.labels.fontColor = colors.text;options.scales.xAxes[0].time.unit = unit;options.scales.xAxes[0].ticks.callback = renderXLabel;+ options.scales.xAxes[0].ticks.fontColor = colors.text;+ options.scales.yAxes[0].ticks.fontColor = colors.text;+ options.scales.yAxes[0].gridLines.color = colors.line;+ options.scales.yAxes[0].gridLines.zeroLineColor = colors.zeroLine;options.animation.duration = animationDuration;options.tooltips.custom = renderTooltip;@@ -161,7 +185,7 @@ export default function BarChart({updateChart();}}- }, [datasets, unit, animationDuration, locale]);+ }, [datasets, unit, animationDuration, locale, theme]);return (<>diff --git a/components/metrics/BarChart.module.css b/components/metrics/BarChart.module.cssindex 88b785cad..cd26d3afe 100644--- a/components/metrics/BarChart.module.css+++ b/components/metrics/BarChart.module.css@@ -3,6 +3,7 @@}.tooltip {+ color: var(--msgColor);pointer-events: none;z-index: 1;}@@ -12,7 +13,6 @@flex-direction: column;justify-content: center;align-items: center;- color: var(--gray50);text-align: center;}diff --git a/components/metrics/MetricsTable.module.css b/components/metrics/MetricsTable.module.cssindex 656806345..814351f03 100644--- a/components/metrics/MetricsTable.module.css+++ b/components/metrics/MetricsTable.module.css@@ -74,7 +74,7 @@position: relative;width: 50px;color: #6e6e6e;- border-left: 1px solid var(--gray600);+ border-left: 1px solid var(--gray500);padding-left: 10px;z-index: 1;}diff --git a/components/common/LanguageButton.js b/components/settings/LanguageButton.jssimilarity index 95%rename from components/common/LanguageButton.jsrename to components/settings/LanguageButton.jsindex fae904157..953204f4d 100644--- a/components/common/LanguageButton.js+++ b/components/settings/LanguageButton.js@@ -1,7 +1,7 @@import React, { useState, useRef } from 'react';import Head from 'next/head';-import Menu from './Menu';-import Button from './Button';+import Menu from 'components/common/Menu';+import Button from 'components/common/Button';import { menuOptions } from 'lib/lang';import useLocale from 'hooks/useLocale';import useDocumentClick from 'hooks/useDocumentClick';diff --git a/components/common/LanguageButton.module.css b/components/settings/LanguageButton.module.csssimilarity index 100%rename from components/common/LanguageButton.module.cssrename to components/settings/LanguageButton.module.cssdiff --git a/components/settings/ThemeButton.js b/components/settings/ThemeButton.jsnew file mode 100644index 000000000..b16f39706--- /dev/null+++ b/components/settings/ThemeButton.js@@ -0,0 +1,13 @@+import React from 'react';+import Button from 'components/common/Button';+import useTheme from 'hooks/useTheme';++export default function ThemeButton() {+ const [theme, setTheme] = useTheme();++ function handleClick() {+ setTheme(theme === 'light' ? 'dark' : 'light');+ }++ return <Button onClick={handleClick}>{theme}</Button>;+}diff --git a/components/settings/TimezoneSetting.js b/components/settings/TimezoneSetting.jsindex 54751a452..b1ed09607 100644--- a/components/settings/TimezoneSetting.js+++ b/components/settings/TimezoneSetting.js@@ -1,8 +1,8 @@import React from 'react';import { FormattedMessage } from 'react-intl';import { listTimeZones } from 'timezone-support';-import DropDown from '../common/DropDown';-import Button from '../common/Button';+import DropDown from 'components/common/DropDown';+import Button from 'components/common/Button';import useTimezone from 'hooks/useTimezone';import { getTimezone } from 'lib/date';import styles from './TimezoneSetting.module.css';diff --git a/hooks/useLocale.js b/hooks/useLocale.jsindex 788b9b28c..6c7ed2a37 100644--- a/hooks/useLocale.js+++ b/hooks/useLocale.js@@ -1,5 +1,5 @@import { useDispatch, useSelector } from 'react-redux';-import { updateApp } from 'redux/actions/app';+import { setLocale } from 'redux/actions/app';import { setItem } from 'lib/web';import { LOCALE_CONFIG } from 'lib/constants';@@ -7,10 +7,10 @@ export default function useLocale() {const locale = useSelector(state => state.app.locale);const dispatch = useDispatch();- function setLocale(value) {+ function saveLocale(value) {setItem(LOCALE_CONFIG, value);- dispatch(updateApp({ locale: value }));+ dispatch(setLocale(value));}- return [locale, setLocale];+ return [locale, saveLocale];}diff --git a/hooks/useTheme.js b/hooks/useTheme.jsnew file mode 100644index 000000000..7ce158b72--- /dev/null+++ b/hooks/useTheme.js@@ -0,0 +1,21 @@+import { useDispatch, useSelector } from 'react-redux';+import { setTheme } from 'redux/actions/app';+import { getItem, setItem } from 'lib/web';+import { THEME_CONFIG } from 'lib/constants';+import { useEffect } from 'react';++export default function useLocale() {+ const theme = useSelector(state => state.app.theme || getItem(THEME_CONFIG) || 'light');+ const dispatch = useDispatch();++ function saveTheme(value) {+ setItem(THEME_CONFIG, value);+ dispatch(setTheme(value));+ }++ useEffect(() => {+ document.body.setAttribute('data-theme', theme);+ }, [theme]);++ return [theme, saveTheme];+}diff --git a/lib/constants.js b/lib/constants.jsindex 0e2468ab3..9bb29933d 100644--- a/lib/constants.js+++ b/lib/constants.js@@ -2,6 +2,38 @@ export const AUTH_COOKIE_NAME = 'umami.auth';export const LOCALE_CONFIG = 'umami.locale';export const TIMEZONE_CONFIG = 'umami.timezone';export const DATE_RANGE_CONFIG = 'umami.date-range';+export const THEME_CONFIG = 'umami.theme';++export const THEME_COLORS = {+ light: {+ primary: '#2680eb',+ gray50: '#ffffff',+ gray75: '#fafafa',+ gray100: '#f5f5f5',+ gray200: '#eaeaea',+ gray300: '#e1e1e1',+ gray400: '#cacaca',+ gray500: '#b3b3b3',+ gray600: '#8e8e8e',+ gray700: '#6e6e6e',+ gray800: '#4b4b4b',+ gray900: '#2c2c2c',+ },+ dark: {+ primary: '#2680eb',+ gray50: '#252525',+ gray75: '#2f2f2f',+ gray100: '#323232',+ gray200: '#3e3e3e',+ gray300: '#4a4a4a',+ gray400: '#5a5a5a',+ gray500: '#6e6e6e',+ gray600: '#909090',+ gray700: '#b9b9b9',+ gray800: '#e3e3e3',+ gray900: '#ffffff',+ },+};export const DEFAULT_DATE_RANGE = '24hour';diff --git a/package.json b/package.jsonindex 547537f39..ec47c63c3 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "umami",- "version": "0.42.0",+ "version": "0.43.0","description": "A simple, fast, website analytics alternative to Google Analytics. ","author": "Mike Cao <[email protected]>","license": "MIT",diff --git a/redux/actions/app.js b/redux/actions/app.jsindex cbb8285b0..6bcba2f00 100644--- a/redux/actions/app.js+++ b/redux/actions/app.js@@ -1,18 +1,25 @@import { createSlice } from '@reduxjs/toolkit';import { getItem } from 'lib/web';-import { LOCALE_CONFIG } from 'lib/constants';+import { LOCALE_CONFIG, THEME_CONFIG } from 'lib/constants';const app = createSlice({name: 'app',- initialState: { locale: getItem(LOCALE_CONFIG) || 'en-US' },+ initialState: {+ locale: getItem(LOCALE_CONFIG) || 'en-US',+ theme: getItem(THEME_CONFIG) || 'light',+ },reducers: {- updateApp(state, action) {- state = action.payload;+ setLocale(state, action) {+ state.locale = action.payload;+ return state;+ },+ setTheme(state, action) {+ state.theme = action.payload;return state;},},});-export const { updateApp } = app.actions;+export const { setLocale, setTheme } = app.actions;export default app.reducer;diff --git a/styles/index.css b/styles/index.cssindex c305f70f2..1a73afb75 100644--- a/styles/index.css+++ b/styles/index.css@@ -1,14 +1,17 @@html,body {font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;- font-size: var(--font-size-normal);font-weight: 400;line-height: 1.8;padding: 0;margin: 0;- width: 100%;height: 100%;+ overflow: auto;box-sizing: border-box;+ display: flex;+ flex-direction: column;++ font-size: var(--font-size-normal);color: var(--gray900);background: var(--gray75);}@@ -51,6 +54,8 @@ a:visited {input[type='text'],input[type='password'],textarea {+ color: var(--gray900);+ background: var(--gray50);padding: 4px 8px;font-size: var(--font-size-normal);line-height: 1.8;@@ -92,6 +97,7 @@ main {flex-direction: column;width: 100%;height: 100%;+ flex: 1;}#__modals {diff --git a/styles/variables.css b/styles/variables.cssindex ba504a198..02e5392f6 100644--- a/styles/variables.css+++ b/styles/variables.css@@ -36,4 +36,33 @@--green500: #268e6c;--green600: #12805c;--green700: #107154;++ --msgColor: #ffffff;+}++[data-theme='dark'] {+ /*+ --gray50: #080808;+ --gray75: #1a1a1a;+ --gray100: #1e1e1e;+ --gray200: #2c2c2c;+ --gray300: #393939;+ --gray400: #494949;+ --gray500: #5c5c5c;+ --gray600: #7c7c7c;+ --gray700: #6e6e6e;+ --gray800: #a2a2a2;+ --gray900: #efefef;+ */+ --gray50: #252525;+ --gray75: #2f2f2f;+ --gray100: #323232;+ --gray200: #3e3e3e;+ --gray300: #4a4a4a;+ --gray400: #5a5a5a;+ --gray500: #6e6e6e;+ --gray600: #909090;+ --gray700: #b9b9b9;+ --gray800: #e3e3e3;+ --gray900: #ffffff;}