-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfontProperties.js
More file actions
88 lines (84 loc) · 2.28 KB
/
fontProperties.js
File metadata and controls
88 lines (84 loc) · 2.28 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
import PropTypes from 'prop-types'
import Plugin from './Plugin'
import propTypes from './propTypes'
const getFontSize = (fontSize, {options, registry, config}) => {
if (fontSize && typeof(fontSize) === 'string') {
// TODO: throw error on missing size or fall through to style validation?
const sizes = options.sizes || registry.sizes || config.sizes || {}
fontSize = sizes[fontSize] || 16
}
return fontSize
}
export default [
new Plugin(
'color',
({prop, options}) => {
if (options.supportsText) {
return {color: prop}
}
},
{propType: propTypes.color}
),
new Plugin(
'size',
({prop, options, registry, config}) => {
if (options.supportsText) {
return {fontSize: getFontSize(prop, {options, registry, config})}
}
},
{propType: propTypes.fontSize}
),
new Plugin(
'align',
({options, prop}) => {
if (options.supportsText) {
return {textAlign: prop}
}
},
{propType: PropTypes.oneOf(['left', 'center', 'right'])}
),
// Bold, does not currently support multiple weight, boolean only
new Plugin(
'bold',
({options, registry, propName}) => {
if (options.supportsText) {
if (registry.has(propName)) {
return registry.resolve(propName)
}
return {fontWeight: 'bold'}
}
},
{propType: PropTypes.bool}
),
// Font object support
new Plugin(
'font',
({context, prop, colors, sizes, options, registry, config}) => {
if (options.supportsText) {
const fontShapeColors = propTypes.fontShapeColors
const fontShapeMap = propTypes.fontShapeMap
// Inherited from the parent context
if (!prop && context) {
prop = context.font
} else {
prop = Object.assign({}, context.font, prop)
}
const style = {}
for (let k in prop) {
if (prop[k] !== undefined) {
let val = prop[k]
if (~fontShapeColors.indexOf(k)) {
val = colors[val] || val
}
style[fontShapeMap[k]] = val
}
}
if (style.fontSize) {
style.fontSize = getFontSize(style.fontSize, {options, registry, config})
}
return style
}
},
{propType: propTypes.font}
)
]