Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bootstrap Text & Heading components
- Loading branch information
1 parent
9d56cf4
commit 1014512
Showing
8 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { FC, HTMLAttributes } from 'react' | ||
import styled from '@emotion/styled' | ||
import { css } from '@emotion/react' | ||
|
||
import { theme } from '../theme' | ||
|
||
export const Heading: FC<HeadingProps> = ({ children, ...props }) => { | ||
const _className = props.className | ||
? `avocado-heading ${props.className}` | ||
: `avocado-heading` | ||
|
||
switch (props.level) { | ||
case 'h1': | ||
return ( | ||
<StyledH1 {...props} className={_className}> | ||
{children} | ||
</StyledH1> | ||
) | ||
case 'h2': | ||
return ( | ||
<StyledH2 {...props} className={_className}> | ||
{children} | ||
</StyledH2> | ||
) | ||
case 'h3': | ||
return ( | ||
<StyledH3 {...props} className={_className}> | ||
{children} | ||
</StyledH3> | ||
) | ||
case 'h4': | ||
return ( | ||
<StyledH4 {...props} className={_className}> | ||
{children} | ||
</StyledH4> | ||
) | ||
case 'h5': | ||
return ( | ||
<StyledH5 {...props} className={_className}> | ||
{children} | ||
</StyledH5> | ||
) | ||
case 'h6': | ||
return ( | ||
<StyledH6 {...props} className={_className}> | ||
{children} | ||
</StyledH6> | ||
) | ||
default: | ||
throw new Error('Please pass a heading level') | ||
} | ||
} | ||
|
||
const StyledHeadingBase = css` | ||
margin-top: 0; | ||
margin-bottom: 0.5em; | ||
line-height: 1; | ||
` | ||
|
||
const StyledH1 = styled.h1` | ||
font-size: ${theme.typography['6xl']}; | ||
${StyledHeadingBase}; | ||
` | ||
const StyledH2 = styled.h2` | ||
font-size: ${theme.typography['5xl']}; | ||
${StyledHeadingBase}; | ||
` | ||
const StyledH3 = styled.h3` | ||
font-size: ${theme.typography['4xl']}; | ||
${StyledHeadingBase}; | ||
` | ||
const StyledH4 = styled.h4` | ||
font-size: ${theme.typography['3xl']}; | ||
${StyledHeadingBase}; | ||
` | ||
const StyledH5 = styled.h5` | ||
font-size: ${theme.typography['2xl']}; | ||
${StyledHeadingBase}; | ||
` | ||
const StyledH6 = styled.h6` | ||
font-size: ${theme.typography.xl}; | ||
${StyledHeadingBase}; | ||
` | ||
|
||
interface HeadingProps extends HTMLAttributes<HTMLHeadingElement> { | ||
level: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './heading' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './text' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { FC, HTMLAttributes } from 'react' | ||
import styled from '@emotion/styled' | ||
|
||
const Text: FC<TextProps> = ({ children, ...props }) => { | ||
return <StyledText {...props}>{children}</StyledText> | ||
} | ||
|
||
const StyledText = styled.p` | ||
margin-top: 0; | ||
` | ||
|
||
interface TextProps extends HTMLAttributes<HTMLParagraphElement> {} | ||
|
||
export { Text } |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const typography = { | ||
xs: '0.75rem', | ||
ms: '0.875rem', | ||
sm: '1rem', | ||
lg: '1.125rem', | ||
xl: '1.25rem', | ||
'2xl': '1.5rem', | ||
'3xl': '1.75rem', | ||
'4xl': '2rem', | ||
'5xl': '2.5rem', | ||
'6xl': '3rem', | ||
'7xl': '4rem' | ||
} | ||
|
||
export default typography | ||
export type Typography = typeof typography |