-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathTypography.js
More file actions
64 lines (53 loc) · 1.67 KB
/
Copy pathTypography.js
File metadata and controls
64 lines (53 loc) · 1.67 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
import HEML, { createElement, transforms, cssGroups } from '@heml/utils' // eslint-disable-line no-unused-vars
import { merge } from 'lodash'
const {
margin, background, border, borderRadius, text, font
} = cssGroups
/**
* create mergable text element
* @param {String} name
* @param {Object} element
* @return {Object}
*/
function createTextElement (name, element = {}) {
let classToAdd = ''
const Tag = name
if (/^h\d$/i.test(name)) {
classToAdd = 'header'
} else {
classToAdd = 'text'
}
return createElement(name, merge({
attrs: true,
rules: {
root: [ '@default', { display: transforms.trueHide() }, margin, background, border, borderRadius, text, font ]
},
render (attrs, contents) {
const { rules, ...defaultAttrs } = attrs
return <Tag {...defaultAttrs} {...rule.root} class={classToAdd}>{contents}</Tag>
}
}, element))
}
const H1 = createTextElement('h1')
const H2 = createTextElement('h2')
const H3 = createTextElement('h3')
const H4 = createTextElement('h4')
const H5 = createTextElement('h5')
const H6 = createTextElement('h6')
const P = createTextElement('p')
const Ol = createTextElement('ol')
const Ul = createTextElement('ul')
const Li = createTextElement('li')
const A = createElement('a', {
attrs: true,
defaultAttrs: { href: '#' },
rules: {
root: [ '@default', { display: transforms.trueHide('inline') }, 'color', 'text-decoration' ],
text: [ 'color', 'text-decoration' ]
},
render (attrs, contents) {
const { rules, ...defaultAttrs } = attrs
return <a {...defaultAttrs} {...rules.root}><span {...rules.text}>{contents}</span></a>
}
})
export { H1, H2, H3, H4, H5, H6, P, Ol, Ul, Li, A }