From 1d2db41e9239965cc9c300b6abff956467df5f43 Mon Sep 17 00:00:00 2001 From: sam-keen Date: Fri, 25 Mar 2022 16:47:28 +0000 Subject: [PATCH] Added new shared theme switcher into stats project --- apps/stats/src/app.tsx | 34 +++++++++---------- apps/stats/src/components/header/header.tsx | 27 +++++---------- .../components/images/dark-mode-toggle.tsx | 18 ---------- apps/stats/src/components/images/index.ts | 2 -- .../components/images/light-mode-toggle.tsx | 10 ------ apps/stats/src/config/types.ts | 4 --- apps/stats/src/index.html | 16 ++------- apps/stats/tailwind.config.js | 1 + .../src}/hooks/use-theme-switcher.ts | 2 +- 9 files changed, 28 insertions(+), 86 deletions(-) delete mode 100644 apps/stats/src/components/images/dark-mode-toggle.tsx delete mode 100644 apps/stats/src/components/images/index.ts delete mode 100644 apps/stats/src/components/images/light-mode-toggle.tsx delete mode 100644 apps/stats/src/config/types.ts rename {apps/trading => libs/react-helpers/src}/hooks/use-theme-switcher.ts (94%) diff --git a/apps/stats/src/app.tsx b/apps/stats/src/app.tsx index 3f01d7596..8fbdfafa5 100644 --- a/apps/stats/src/app.tsx +++ b/apps/stats/src/app.tsx @@ -1,7 +1,9 @@ -import React, { useState } from 'react'; +import React from 'react'; import { DATA_SOURCES } from './config'; import { Header } from './components/header'; import { StatsManager } from '@vegaprotocol/network-stats'; +import { ThemeContext } from '@vegaprotocol/react-helpers'; +import { useThemeSwitcher } from '@vegaprotocol/react-helpers'; const envName = DATA_SOURCES.envName; const restEndpoint = DATA_SOURCES.restEndpoint; @@ -9,26 +11,22 @@ const statsEndpoint = `${restEndpoint}/statistics`; const nodesEndpoint = `${restEndpoint}/nodes-data`; function App() { - const [darkMode, setDarkMode] = useState( - document.documentElement.classList.contains('dark-mode-preferred') - ); + const [theme, toggleTheme] = useThemeSwitcher(); return ( -
-
-
- + +
+
+
+ +
-
+ ); } diff --git a/apps/stats/src/components/header/header.tsx b/apps/stats/src/components/header/header.tsx index acbfcf2e8..cbbb148d1 100644 --- a/apps/stats/src/components/header/header.tsx +++ b/apps/stats/src/components/header/header.tsx @@ -1,30 +1,19 @@ -import { VegaLogo } from '@vegaprotocol/ui-toolkit'; -import { LightModeToggle, DarkModeToggle } from '../images'; +import { VegaLogo, ThemeSwitcher } from '@vegaprotocol/ui-toolkit'; import { VegaBackgroundVideo } from '../videos'; -import { DarkModeState } from '../../config/types'; -export const Header = ({ darkMode, setDarkMode }: DarkModeState) => { +interface ThemeToggleProps { + toggleTheme: () => void; +} + +export const Header = ({ toggleTheme }: ThemeToggleProps) => { return (
-
+
- - +
diff --git a/apps/stats/src/components/images/dark-mode-toggle.tsx b/apps/stats/src/components/images/dark-mode-toggle.tsx deleted file mode 100644 index 42a7ac3b2..000000000 --- a/apps/stats/src/components/images/dark-mode-toggle.tsx +++ /dev/null @@ -1,18 +0,0 @@ -export const DarkModeToggle = () => { - return ( - - - - - - - ); -}; diff --git a/apps/stats/src/components/images/index.ts b/apps/stats/src/components/images/index.ts deleted file mode 100644 index fd1bfea32..000000000 --- a/apps/stats/src/components/images/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { DarkModeToggle } from './dark-mode-toggle'; -export { LightModeToggle } from './light-mode-toggle'; diff --git a/apps/stats/src/components/images/light-mode-toggle.tsx b/apps/stats/src/components/images/light-mode-toggle.tsx deleted file mode 100644 index f71b5eb9d..000000000 --- a/apps/stats/src/components/images/light-mode-toggle.tsx +++ /dev/null @@ -1,10 +0,0 @@ -export const LightModeToggle = () => { - return ( - - - - ); -}; diff --git a/apps/stats/src/config/types.ts b/apps/stats/src/config/types.ts deleted file mode 100644 index ebab4ed91..000000000 --- a/apps/stats/src/config/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface DarkModeState { - darkMode: boolean; - setDarkMode: (arg0: boolean) => void; -} diff --git a/apps/stats/src/index.html b/apps/stats/src/index.html index 4476c74cc..6cac04c63 100644 --- a/apps/stats/src/index.html +++ b/apps/stats/src/index.html @@ -5,7 +5,7 @@ - + - Vega Mainnet Stats - + Vega Network Stats diff --git a/apps/stats/tailwind.config.js b/apps/stats/tailwind.config.js index 739782864..1dd947e87 100644 --- a/apps/stats/tailwind.config.js +++ b/apps/stats/tailwind.config.js @@ -7,6 +7,7 @@ module.exports = { join(__dirname, 'src/**/*.{js,ts,jsx,tsx}'), ...createGlobPatternsForDependencies(__dirname), ], + darkMode: 'class', theme, plugins: [], }; diff --git a/apps/trading/hooks/use-theme-switcher.ts b/libs/react-helpers/src/hooks/use-theme-switcher.ts similarity index 94% rename from apps/trading/hooks/use-theme-switcher.ts rename to libs/react-helpers/src/hooks/use-theme-switcher.ts index a5069ca33..b0415c917 100644 --- a/apps/trading/hooks/use-theme-switcher.ts +++ b/libs/react-helpers/src/hooks/use-theme-switcher.ts @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react'; -import { LocalStorage } from '@vegaprotocol/react-helpers'; +import { LocalStorage } from '../lib/storage'; const darkTheme = 'dark'; const lightTheme = 'light';