-
Notifications
You must be signed in to change notification settings - Fork 1
/
ux-input.js
40 lines (33 loc) · 896 Bytes
/
ux-input.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
export default function uxInput(state) {
var o = once(this)
, { label = '', value = '', focused = false, optional = false, name = '' } = state
, disabled = attr('disabled')(this)
o.classed('is-optional', optional)
.classed('is-focused', focused)
.classed('is-active' , value)
.property('value', value)
.attr('name', name)
o('input', 1)
.property('value', iff(d => is.str(value))(d => value))
.attr('disabled' , disabled)
.attr('placeholder', label)
.on('focus.focused', focus)
.on('keyup.value' , keyup)
.on('blur.focused' , blur)
o('label', 1)
.text(label)
function focus() {
if (focused) return
state.focused = true
o.draw()
}
function blur() {
if (!focused) return
state.focused = false
o.draw()
}
function keyup() {
o.emit('change', state.value = this.value)
.draw()
}
}