Skip to content

Instantly share code, notes, and snippets.

@kotarella1110
Last active November 14, 2018 06:47
Show Gist options
  • Save kotarella1110/cfa1db2e1c78b73cf124ca7132fabbd6 to your computer and use it in GitHub Desktop.
Save kotarella1110/cfa1db2e1c78b73cf124ca7132fabbd6 to your computer and use it in GitHub Desktop.
Title component example - TypeScript + React + styled-components
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
);
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;
export interface ThemeInterface {
primaryColor: string;
primaryColorInverted: string;
}
export default const theme = {
primaryColor: '#e9e9eb'
primaryColorInverted: '161614';
};
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