From d69bb9bb729fdd196d7430bdb2b90d91f29bb330 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sun, 11 Sep 2022 09:39:05 -0700 Subject: [PATCH] Invert QRcode foreground with dark/light themes --- frontend/src/components/App.js | 64 +++++++++++++++++++++------- frontend/src/components/OrderPage.js | 2 + frontend/src/components/TradeBox.js | 28 ++++++------ 3 files changed, 65 insertions(+), 29 deletions(-) diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js index fe9500d7..7da43b3e 100644 --- a/frontend/src/components/App.js +++ b/frontend/src/components/App.js @@ -21,23 +21,57 @@ export default class App extends Component { constructor(props) { super(props); this.state = { - dark: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches, expandedSettings: false, openLearn: false, - theme: { typography: { fontSize: 14 } }, + theme: createTheme({ + palette: { + mode: + window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches + ? 'dark' + : 'light', + background: { + default: + window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches + ? '#070707' + : '#fff', + }, + }, + }), }; } - lightTheme = createTheme({}); - - darkTheme = createTheme({ - palette: { - mode: 'dark', - background: { - default: '#070707', - }, - }, - }); + handleThemeChange = () => { + if (this.state.theme.palette.mode === 'light') { + this.setState(({ theme }) => ({ + theme: createTheme({ + typography: { + fontSize: theme.typography.fontSize, + }, + palette: { + mode: 'dark', + background: { + default: '#070707', + }, + }, + }), + })); + } + if (this.state.theme.palette.mode === 'dark') { + this.setState(({ theme }) => ({ + theme: createTheme({ + typography: { + fontSize: theme.typography.fontSize, + }, + palette: { + mode: 'light', + background: { + default: '#fff', + }, + }, + }), + })); + } + }; onSettingsClick = () => { this.setState({ @@ -62,7 +96,7 @@ export default class App extends Component { return ( - + this.setState({ dark: !this.state.dark })} + onClick={() => this.handleThemeChange()} > - {this.state.dark ? : } + {this.state.theme.palette.mode === 'dark' ? : }
- - - +