Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
feat(TitledCopy): allow change of title rank h1-h6
Browse files Browse the repository at this point in the history
  • Loading branch information
CanRau committed Oct 6, 2018
1 parent 8558679 commit af102a1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/TitledCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Container = styled.div(props => ({
},
}))

const H2 = styled.h2(props => ({
const Title = styled.h2(props => ({
fontSize: `2.7rem`,
textAlign: props.centeredTitle && `center`,
}))
Expand All @@ -34,6 +34,7 @@ const ContentWrapper = styled.div(props => ({

const TitledCopy = ({
title,
rank,
paragraphs,
centered,
centeredTitle,
Expand All @@ -57,14 +58,16 @@ const TitledCopy = ({
spoilerOpen: !state.spoilerOpen,
})

const Tag = Title.withComponent(rank ? (rank > 6 ? `h6` : `h${rank}`) : `h2`)

return (
<Container centered={centered} full={full} {...props}>
{title && (
<H2 id={slugifiedId} centeredTitle={centeredTitle}>
<Tag id={slugifiedId} centeredTitle={centeredTitle}>
{Array.isArray(title)
? title.map((x, i) => <div key={i}>{x}</div>)
: title}
</H2>
</Tag>
)}

{content && (
Expand Down Expand Up @@ -93,6 +96,7 @@ const TitledCopy = ({
TitledCopy.propTypes = {
title: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
paragraphs: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
rank: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
centered: PropTypes.bool,
centeredTitle: PropTypes.bool,
centeredCopy: PropTypes.bool,
Expand Down

0 comments on commit af102a1

Please sign in to comment.