Skip to content

Instantly share code, notes, and snippets.

@ZwaarContrast
Last active January 30, 2017 15:00
Show Gist options
  • Save ZwaarContrast/c0e344b201379601b0664d60fac0d6e9 to your computer and use it in GitHub Desktop.
Save ZwaarContrast/c0e344b201379601b0664d60fac0d6e9 to your computer and use it in GitHub Desktop.
import React, {PropTypes} from 'react';
import styled, {css} from 'styled-components';
const HeadingCSS = styled( Heading )`
font-weight: 700;
/* more styling */
`;
const StyledH1 = styled.h1`${ HeadingCSS }`;
const StyledH2 = styled.h2`${ HeadingCSS }`;
/* etc */
const Heading = ( {children, tag} ) => {
switch ( tag ) {
case 'h2':
return (
<StyledH2>
{children}
</StyledH2>
);
case 'h1':
return (
<StyledH1>
{children}
</StyledH1>
);
}
};
Heading.propTypes = {
/**
* The tag to use to render the elment
*/
tag: PropTypes.oneOf( ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] ),
};
Heading.defaultProps = {
tag: 'h1',
};
Heading.displayName = 'Heading';
export default ( Heading );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment