-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
index.js
78 lines (69 loc) · 1.73 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { define, WeElement } from 'omi'
import '../style/global/index.css'
import icon from '../style/global/_icon.scss'
import style from '../style/_button.scss'
define('el-button', class extends WeElement {
static pure = true
css() {
return icon + style
}
render(props, data) {
let classStr = 'el-button'
if (props.type) {
classStr += ` el-button--${props.type}`
}
if (props.plain) {
classStr += ' is-plain'
}
if (props.round) {
classStr += ' is-round'
}
if (props.circle) {
classStr += ' is-circle'
}
if (props.disabled) {
classStr += ' is-disabled'
}
if (typeof data.position === 'string') {
classStr += ' ' + data.position
}
if (props.size) {
classStr += ' el-button--' + props.size
}
if (props.iconRight) {
return (
<button style={props.style} onClick={this.onClick} class={classStr}>
<slot />
{props.icon && <i class={props.icon} />}
</button>
)
}
return (
<button style={props.style} onClick={this.onClick} class={classStr}>
{props.icon && <i class={props.icon} />}
<slot />
</button>
)
}
onClick = evt => {
if (this.props.disabled) {
evt.stopPropagation()
}
}
install() {
if (this.parentNode.nodeName === 'EL-BUTTON-GROUP') {
for (let i = 0, len = this.parentNode.childNodes.length; i < len; i++) {
if (this.parentNode.childNodes[i] === this) {
if (i === 0) {
this.data.position = 'first'
} else if (i === len - 1) {
this.data.position = 'last'
} else {
this.data.position = 'between'
}
break
}
}
}
}
})