Last active
November 14, 2018 06:47
-
-
Save kotarella1110/cfa1db2e1c78b73cf124ca7132fabbd6 to your computer and use it in GitHub Desktop.
Title component example - TypeScript + React + styled-components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import * as ReactDOM from 'react-dom'; | |
import Title from './Title'; | |
interface Props { | |
compiler: string; | |
framework: string; | |
} | |
const App: React.SFC<Props> = () => <Title isActive />; | |
ReactDOM.render( | |
<ThemeProvider theme={theme}> | |
<Title compiler="TypeScript" framework="React" /> | |
</ThemeProvider>, | |
document.getElementById('app') as HTMLElement | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as styledComponents from 'styled-components'; | |
import { ThemeInterface } from './theme'; | |
const { | |
default: styled, | |
css, | |
createGlobalStyle, | |
keyframes, | |
ThemeProvider | |
} = styledComponents as styledComponents.ThemedStyledComponentsModule< | |
ThemeInterface | |
>; | |
export { css, createGlobalStyle, keyframes, ThemeProvider }; | |
export default styled; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface ThemeInterface { | |
primaryColor: string; | |
primaryColorInverted: string; | |
} | |
export default const theme = { | |
primaryColor: '#e9e9eb' | |
primaryColorInverted: '161614'; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import styled from './styled-components'; | |
const Title = styled<{ isActive: boolean }, 'h1'>('h1')` | |
color: ${props => props.isActive ? props.theme.primaryColor : props.theme.primaryColorInverted} | |
` | |
export default Title; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment