/
Text.js
62 lines (56 loc) · 1.19 KB
/
Text.js
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
import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import map from './props'
const fontSizeMap = {
0: 6,
1: 5,
2: 4,
3: 3,
4: 2,
5: 1,
6: 0
}
const Text = props => {
const {
tag: Tag = 'span',
children,
className,
color,
fontSize,
fontWeight,
lineHeight,
mono,
nowrap
} = map(props)
const fontSizeClass = (fontSize in fontSizeMap)
? `f${fontSizeMap[fontSize]}`
: (typeof fontSize === 'string') ? `f${fontSize}` : null
return (
<Tag className={classnames(
className,
color && `text-${color}`,
fontSizeClass,
lineHeight && `lh-${lineHeight}`,
mono && 'text-mono',
nowrap && 'no-wrap',
)}>
{children}
</Tag>
)
}
Text.propTypes = {
tag: PropTypes.string,
// TODO: constrain with PropTypes.oneOf()
color: PropTypes.string,
// TODO constrain with PropTypes.oneOf()
fontSize: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string
]),
fontWeight: PropTypes.oneOf(['normal', 'bold']),
lineHeight: PropTypes.oneOf(['normal', 'condensed', 'condensed-ultra']),
mono: PropTypes.bool,
tag: PropTypes.string
}
export default Text