Skip to content

Instantly share code, notes, and snippets.

@LukeSmetham
Last active January 20, 2020 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukeSmetham/fa938f04d2dd834643b49cdc6d490dcc to your computer and use it in GitHub Desktop.
Save LukeSmetham/fa938f04d2dd834643b49cdc6d490dcc to your computer and use it in GitHub Desktop.
import React from 'react';
import styled from 'styled-components';
// By default, the Text component will render
// to the dom as a <p> tag.
const Text = styled.p`
color: ${({ color, theme }) => theme.color[color]};
font-size: ${({ size }) => size}px;
font-weight: ${({ weight }) => weight};
line-height: ${({ lineHeight, size }) => lineHeight || size + 8}px;
`;
Text.defaultProps = {
color: 'text',
size: 16,
weight: '500',
};
// Below we pass "h1" to render the Text as a
// heading, whilst maintaining the style definition.
// Under the hood, styled-components just passes
// the generated className prop to the `as` element.
// This means you can also pass in a react component
// like so <Text as={MyOtherTextComponent} />.
export default () => {
return (
<div>
<Text color="primary" as="h1" size={24}>Title</Text>
<Text>Paragraph</Text>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment