-
Notifications
You must be signed in to change notification settings - Fork 51
/
Paragraph.jsx
75 lines (66 loc) · 1.8 KB
/
Paragraph.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import * as typography from '@tds/shared-typography'
import { spacing } from '@tds/shared-styles'
import { safeRest } from '@tds/util-helpers'
const paragraphColor = ({ invert }) => (invert ? typography.invertedColor : typography.color)
const paragraphInheritColor = ({ inheritColor }) =>
inheritColor ? { color: 'inherit' } : undefined
const paragraphSize = ({ size }) => typography[size]
const paragraphBold = ({ bold, size }) => (bold ? typography.boldFont : typography[`${size}Font`])
const paragraphAlign = ({ align }) => ({
textAlign: align,
})
export const StyledParagraph = styled.p(
paragraphColor,
typography.wordBreak,
spacing.noSpacing,
paragraphInheritColor,
paragraphSize,
paragraphBold,
paragraphAlign,
{ sup: typography.sup }
)
/**
* Block text as an HTML `<p>` element.
*
* @version ./package.json
*/
const Paragraph = ({ children, ...rest }, context) => (
<StyledParagraph {...safeRest(rest)} inheritColor={context.inheritColor}>
{children}
</StyledParagraph>
)
Paragraph.propTypes = {
/**
* Embolden paragraph text without conveying any special importance or relevance.
*/
bold: PropTypes.bool,
/**
* The font size.
*/
size: PropTypes.oneOf(['small', 'medium', 'large']),
/**
* Content alignment.
*/
align: PropTypes.oneOf(['left', 'center', 'right']),
/**
* Invert the text color to appear light on dark backgrounds.
*/
invert: PropTypes.bool,
/**
* The content. Can be text, other components, or HTML elements.
*/
children: PropTypes.node.isRequired,
}
Paragraph.defaultProps = {
bold: false,
size: 'medium',
align: 'left',
invert: false,
}
Paragraph.contextTypes = {
inheritColor: PropTypes.bool,
}
export default Paragraph