ghost-portal/packages/apps/src/Root.tsx
Jaco Greeff 2bf88c5860
Use theme via css vars (#4789)
* Extract global CSS vars (non-theme specific)

* Use theme via css vars

* All text colors

* Additional

* All vars (excluding name...)

* Additional

* linting

* css linting

* Update Card css
2021-03-10 11:04:14 +01:00

67 lines
1.8 KiB
TypeScript

// Copyright 2017-2021 @polkadot/apps authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ThemeDef } from '@polkadot/react-components/types';
import type { KeyringStore } from '@polkadot/ui-keyring/types';
import React, { Suspense, useEffect, useState } from 'react';
import { HashRouter } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';
import { Api } from '@polkadot/react-api';
import Queue from '@polkadot/react-components/Status/Queue';
import { BlockAuthors, Events } from '@polkadot/react-query';
import { settings } from '@polkadot/ui-settings';
import Apps from './Apps';
import { darkTheme, lightTheme } from './themes';
import WindowDimensions from './WindowDimensions';
interface Props {
store?: KeyringStore;
}
function createTheme ({ uiTheme }: { uiTheme: string }): ThemeDef {
const validTheme = uiTheme === 'dark' ? 'dark' : 'light';
document && document.documentElement &&
document.documentElement.setAttribute('data-theme', validTheme);
return uiTheme === 'dark'
? darkTheme
: lightTheme;
}
function Root ({ store }: Props): React.ReactElement<Props> {
const [theme, setTheme] = useState(() => createTheme(settings));
useEffect((): void => {
settings.on('change', (settings) => setTheme(createTheme(settings)));
}, []);
return (
<Suspense fallback='...'>
<ThemeProvider theme={theme}>
<Queue>
<Api
store={store}
url={settings.apiUrl}
>
<BlockAuthors>
<Events>
<HashRouter>
<WindowDimensions>
<Apps />
</WindowDimensions>
</HashRouter>
</Events>
</BlockAuthors>
</Api>
</Queue>
</ThemeProvider>
</Suspense>
);
}
export default React.memo(Root);