WIP themeprovider

This commit is contained in:
Ezekiel Aquino
2018-11-30 16:25:37 +01:00
parent 46422ff783
commit 5c12e664a9
4 changed files with 66 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
import * as React from 'react';
import styled from 'styled-components';
import styled, { ThemeProvider } from 'styled-components';
import { Footer } from 'ts/@next/components/footer';
import { Header } from 'ts/@next/components/header';
@@ -9,23 +9,54 @@ import { GlobalStyles } from 'ts/@next/constants/globalStyle';
// Note(ez): We'll define the theme and provide it via a prop
// e.g. theme dark/light/etc.
interface Props {
theme?: 'dark' | 'light' | 'gray';
children: any;
}
interface GlobalThemes {
[key: string]: {
bgColor: string;
textColor: string;
}
}
const GLOBAL_THEMES: GlobalThemes = {
dark: {
bgColor: '#000000',
textColor: '#FFFFFF',
},
light: {
bgColor: '#FFFFFF',
textColor: '#FFFFFF',
},
gray: {
bgColor: '#e0e0e0',
textColor: '#FFFFFF',
},
}
export const SiteWrap: React.StatelessComponent<Props> = props => {
const { children } = props;
const {
children,
theme = 'dark',
} = props;
const currentTheme = GLOBAL_THEMES[theme];
return (
<>
{/* GlobalStyles will be exposed the theme via provider,
same is true for all children of SiteWrap
*/}
<GlobalStyles />
<Header />
<Main>
{children}
</Main>
<Footer/>
</>
);
return (
<>
<ThemeProvider theme={currentTheme}>
<>
<GlobalStyles />
<Header />
<Main>
{ children }
</Main>
<Footer/>
</>
</ThemeProvider>
</>
);
};

View File

@@ -1,5 +1,5 @@
import * as React from 'react';
import styled from 'styled-components';
import styled, { withTheme } from 'styled-components';
import { colors } from 'ts/style/colors';
interface HeadingProps {
@@ -47,7 +47,7 @@ const PARAGRAPH_SIZES: ParagraphSizes = {
};
const StyledHeading = styled.h1<HeadingProps>`
color: ${props => props.color || colors.white};
color: ${props => props.color || props.theme.textColor};
font-size: ${props => HEADING_SIZES[props.size || 'default']};
font-weight: 300;
margin-bottom: ${props => !props.noMargin && '30px'};
@@ -60,7 +60,6 @@ export const Heading: React.StatelessComponent<HeadingProps> = props => {
children,
} = props;
const Component = StyledHeading.withComponent(asElement);
return <Component {...props}>{children}</Component>;
};
@@ -69,6 +68,7 @@ export const Paragraph = styled.p<ParagraphProps>`
font-size: ${props => PARAGRAPH_SIZES[props.size || 'default']};
margin-bottom: ${props => !props.noMargin && '30px'};
line-height: 1.4;
color: ${props => `rgba(255, 255, 255, ${props.muted || 0.75})`};
color: ${props => props.color || props.theme.textColor};
opacity: ${props => props.muted || 0.75};
text-align: ${props => props.center && 'center'};
`;

View File

@@ -1,11 +1,16 @@
import {createGlobalStyle} from 'styled-components';
import { withTheme, createGlobalStyle } from 'styled-components';
import {cssReset} from 'ts/@next/constants/cssReset';
import {colors} from 'ts/style/colors';
// Not sure if cssReset is already imported into index.tsx Also: currently
// createglobalStyle from styled-components is throwing a warning about how
// there's not typing exported from styled-comps
const GlobalStyles = createGlobalStyle `
interface GlobalStyle {
theme: {
bgColor: string;
textColor: string;
}
}
const GlobalStyles = withTheme(createGlobalStyle<GlobalStyle> `
${cssReset};
@font-face {
@@ -24,13 +29,13 @@ const GlobalStyles = createGlobalStyle `
html {
font-size: 18px;
background-color: ${colors.backgroundBlack};
background-color: ${props => props.theme.bgColor};
}
body {
font-family: 'Formular', sans-serif !important;
-webkit-font-smoothing: antialiased;
color: ${colors.white};
color: ${props => props.theme.textColor};
}
.visuallyHidden {
@@ -58,6 +63,6 @@ const GlobalStyles = createGlobalStyle `
color: inherit;
text-decoration: none;
}
`;
`);
export {GlobalStyles};
export { GlobalStyles };

View File

@@ -25,8 +25,8 @@ import SupportIcon from 'ts/@next/icons/illustrations/support.svg';
</SiteWrap>
*/
export const NextLanding = () => (
<SiteWrap>
export const NextLanding: React.StatelessComponent<{}> = () => (
<SiteWrap theme="dark">
<Section>
<Wrap>
<Column colWidth="1/2">