-
Notifications
You must be signed in to change notification settings - Fork 51
/
Text.jsx
64 lines (56 loc) · 1.68 KB
/
Text.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
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import * as typography from '@tds/shared-typography'
import { safeRest } from '@tds/util-helpers'
const textColor = ({ invert }) => (invert ? typography.invertedColor : typography.color)
const textInheritColor = ({ inheritColor }) => (inheritColor ? { color: 'inherit' } : undefined)
const textSize = ({ size }) => typography[size]
const textBold = ({ bold, size }) => (bold ? typography.boldFont : typography[`${size}Font`])
const textBlock = ({ block }) => (block ? typography.blockText : undefined)
export const StyledText = styled.span(textColor, textInheritColor, textSize, textBold, textBlock, {
sup: typography.sup,
})
/**
* Inline text usually as an HTML `<span>` element.
*
* @version ./package.json
*/
const Text = ({ children, ...rest }, context) => (
<StyledText {...safeRest(rest)} inheritColor={context.inheritColor}>
{children}
</StyledText>
)
Text.propTypes = {
/**
* If true, renders a block level element.
* Otherwise, renders an inline element.
*/
block: PropTypes.bool,
/**
* Embolden text without conveying any special importance or relevance.
*/
bold: PropTypes.bool,
/**
* The font size.
*/
size: PropTypes.oneOf(['base', 'small', 'medium', 'large']),
/**
* 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,
}
Text.defaultProps = {
block: false,
bold: false,
size: 'base',
invert: false,
}
Text.contextTypes = {
inheritColor: PropTypes.bool,
}
export default Text