-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example usage: ```jsx <Heading level="1">Heading Level 1</Heading> <Heading level="1" weight="weak">Heading Level 1 (Weak)</Heading> <Heading level="2">Heading Level 2</Heading> <Heading level="2" weight="weak">Heading Level 2 (Weak)</Heading> <Heading level="3">Heading Level 3</Heading> <Heading level="3" weight="weak">Heading Level 3 (Weak)</Heading> ```
- Loading branch information
1 parent
7cd69a6
commit 9b21dc7
Showing
29 changed files
with
605 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import Heading from './Heading'; | ||
import { ComponentDocs } from '../../../docs/src/types'; | ||
|
||
const docs: ComponentDocs = { | ||
examples: [ | ||
{ | ||
label: 'Level 1', | ||
render: () => <Heading level="1">Heading Level 1</Heading> | ||
}, | ||
{ | ||
label: 'Level 1 Weak', | ||
render: () => ( | ||
<Heading level="1" weight="weak"> | ||
Heading Level 1 Weak | ||
</Heading> | ||
) | ||
}, | ||
{ | ||
label: 'Level 2', | ||
render: () => <Heading level="2">Heading Level 2</Heading> | ||
}, | ||
{ | ||
label: 'Level 2 Weak', | ||
render: () => ( | ||
<Heading level="2" weight="weak"> | ||
Heading Level 2 Weak | ||
</Heading> | ||
) | ||
}, | ||
{ | ||
label: 'Level 3', | ||
render: () => <Heading level="3">Heading Level 3</Heading> | ||
}, | ||
{ | ||
label: 'Level 3 Weak', | ||
render: () => ( | ||
<Heading level="3" weight="weak"> | ||
Heading Level 3 Weak | ||
</Heading> | ||
) | ||
} | ||
] | ||
}; | ||
|
||
export default docs; |
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,94 @@ | ||
import React, { Component, ReactNode } from 'react'; | ||
import classnames from 'classnames'; | ||
import ThemeConsumer from '../ThemeConsumer/ThemeConsumer'; | ||
import Box, { BoxProps } from '../Box/Box'; | ||
import { | ||
HeadingSize, | ||
TransformVariant, | ||
FontWeightVariants, | ||
Tokens | ||
} from 'lib/themes/theme'; | ||
|
||
type HeadingLevel = '1' | '2' | '3'; | ||
type HeadingWeight = 'regular' | 'weak'; | ||
|
||
const resolveComponent = ( | ||
component: BoxProps['component'], | ||
level: HeadingLevel | ||
): BoxProps['component'] => (component ? component : `h${level}`); | ||
|
||
interface HeadingAtoms { | ||
fontSize: HeadingSize; | ||
transform: TransformVariant; | ||
fontWeight: FontWeightVariants; | ||
} | ||
const resolveHeadingAtoms = ( | ||
level: HeadingLevel, | ||
weight: HeadingWeight, | ||
tokens: Tokens | ||
): HeadingAtoms => { | ||
if (level === '1') { | ||
return { | ||
fontSize: 'level1', | ||
transform: 'level1Heading', | ||
fontWeight: tokens.heading.level1[weight] | ||
}; | ||
} | ||
if (level === '2') { | ||
return { | ||
fontSize: 'level2', | ||
transform: 'level2Heading', | ||
fontWeight: tokens.heading.level2[weight] | ||
}; | ||
} | ||
if (level === '3') { | ||
return { | ||
fontSize: 'level3', | ||
transform: 'level3Heading', | ||
fontWeight: tokens.heading.level3[weight] | ||
}; | ||
} | ||
throw new Error('No valid heading level provided'); | ||
}; | ||
|
||
export interface HeadingProps { | ||
children: ReactNode; | ||
level: HeadingLevel; | ||
weight?: HeadingWeight; | ||
component?: BoxProps['component']; | ||
} | ||
|
||
export default class Heading extends Component<HeadingProps> { | ||
static displayName = 'Heading'; | ||
|
||
render() { | ||
const { level, weight = 'regular', component, children } = this.props; | ||
|
||
return ( | ||
<ThemeConsumer> | ||
{theme => { | ||
const { transform, fontSize, fontWeight } = resolveHeadingAtoms( | ||
level, | ||
weight, | ||
theme.tokens | ||
); | ||
|
||
return ( | ||
<Box | ||
component={resolveComponent(component, level)} | ||
className={classnames( | ||
theme.atoms.fontFamily.text, | ||
theme.atoms.color.neutral, | ||
theme.atoms.fontSize[fontSize], | ||
theme.atoms.fontWeight[fontWeight], | ||
theme.atoms.transform[transform] | ||
)} | ||
> | ||
{children} | ||
</Box> | ||
); | ||
}} | ||
</ThemeConsumer> | ||
); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'.regular': { fontWeight: '400' }, | ||
'.medium': { fontWeight: '500' }, | ||
'.strong': { fontWeight: '600' } | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
export const medium: string; | ||
export const regular: string; | ||
export const strong: string; |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
export const largeText: string; | ||
export const level1Heading: string; | ||
export const level2Heading: string; | ||
export const level3Heading: string; | ||
export const standardText: string; |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'.regular': { fontWeight: '400' }, | ||
'.medium': { fontWeight: '500' }, | ||
'.strong': { fontWeight: '600' } | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
export const medium: string; | ||
export const regular: string; | ||
export const strong: string; |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
export const largeText: string; | ||
export const level1Heading: string; | ||
export const level2Heading: string; | ||
export const level3Heading: string; | ||
export const standardText: string; |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
'.regular': { fontWeight: '400' }, | ||
'.medium': { fontWeight: '500' }, | ||
'.strong': { fontWeight: '700' } | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
export const medium: string; | ||
export const regular: string; | ||
export const strong: string; |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
export const largeText: string; | ||
export const level1Heading: string; | ||
export const level2Heading: string; | ||
export const level3Heading: string; | ||
export const standardText: string; |
Oops, something went wrong.