ghost-keychain/packages/extension-ui/src/components/View.tsx
2022-01-01 09:26:35 +02:00

57 lines
1.3 KiB
TypeScript

// Copyright 2019-2022 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ThemeProps } from '../types';
import React, { useCallback, useState } from 'react';
import { createGlobalStyle, ThemeProvider } from 'styled-components';
// FIXME We should not import from index when this one is imported there as well
import { AvailableThemes, chooseTheme, Main, themes, ThemeSwitchContext } from '.';
interface Props {
children: React.ReactNode;
className?: string;
}
function View ({ children, className }: Props): React.ReactElement<Props> {
const [theme, setTheme] = useState(chooseTheme());
const switchTheme = useCallback(
(theme: AvailableThemes): void => {
localStorage.setItem('theme', theme);
setTheme(theme);
},
[]
);
const _theme = themes[theme];
return (
<ThemeSwitchContext.Provider value={switchTheme}>
<ThemeProvider theme={_theme}>
<BodyTheme theme={_theme} />
<Main className={className}>
{children}
</Main>
</ThemeProvider>
</ThemeSwitchContext.Provider>
);
}
const BodyTheme = createGlobalStyle<ThemeProps>`
body {
background-color: ${({ theme }: ThemeProps): string => theme.bodyColor};
}
html {
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
`;
export default View;