material 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/form.js +27 -0
- package/index.js +61 -51
- package/list.js +35 -0
- package/package.json +5 -1
- package/src/appbar.js +7 -204
- package/src/badge.js +27 -0
- package/src/button.js +160 -161
- package/src/calendar.js +8 -10
- package/src/card.js +4 -6
- package/src/checkbox.js +8 -10
- package/src/component.js +4 -6
- package/src/container.js +4 -6
- package/src/datehour.js +38 -0
- package/src/dialog.js +106 -153
- package/src/divider.js +4 -6
- package/src/drawer.js +11 -13
- package/src/field/email.js +5 -5
- package/src/field/image.js +4 -4
- package/src/{control/file.js → file.js} +18 -48
- package/src/form/build.js +7 -7
- package/src/form/verify.js +2 -2
- package/src/form.js +6 -8
- package/src/icon.js +8 -10
- package/src/image.js +39 -106
- package/src/item.js +7 -9
- package/src/layout.js +10 -10
- package/src/link.js +50 -0
- package/src/list/add.js +1 -1
- package/src/list/build.js +9 -9
- package/src/list/collection.js +1 -1
- package/src/list/display.js +10 -10
- package/src/list/filter.js +2 -2
- package/src/list/request.js +1 -1
- package/src/list/search.js +7 -7
- package/src/list.js +29 -217
- package/src/loading.js +73 -0
- package/src/map/build.js +6 -6
- package/src/map/display.js +8 -8
- package/src/menu.js +60 -116
- package/src/{component → mixin}/control.js +10 -10
- package/src/{component → mixin}/create.js +1 -1
- package/src/{module → mixin}/display.js +9 -22
- package/src/{component → mixin}/events.js +2 -2
- package/src/{component → mixin}/focus.js +2 -3
- package/src/{component → mixin}/insert.js +3 -25
- package/src/{control/module → module}/attributes.js +2 -2
- package/src/module/build.js +11 -7
- package/src/{component → module}/classify.js +0 -13
- package/src/module/dom.js +1 -57
- package/src/module/events.js +4 -2
- package/src/{component → module}/ripple.js +15 -42
- package/src/navigation.js +19 -0
- package/src/progress.js +7 -9
- package/src/search.js +71 -0
- package/src/select.js +58 -273
- package/src/{control/selecter.js → selecter.js} +20 -20
- package/src/selector.js +32 -32
- package/src/skin/material/component/navigation.sass +1 -0
- package/src/skin/material/control/button.sass +10 -0
- package/src/slider.js +32 -34
- package/src/snackbar.js +72 -51
- package/src/switch.js +115 -107
- package/src/{control/switcher.js → switcher.js} +33 -36
- package/src/tabs.js +8 -8
- package/src/tabview.js +8 -8
- package/src/text.js +25 -74
- package/src/textfield.js +97 -234
- package/src/toolbar.js +28 -28
- package/src/tooltip.js +11 -11
- package/src/tree.js +12 -16
- package/src/view/build.js +6 -6
- package/src/view/display.js +16 -16
- package/src/view.js +5 -5
- package/src/banner.js +0 -231
- package/src/component/click.js +0 -17
- package/src/control/button.js +0 -267
- package/src/control/button.new.js +0 -190
- package/src/control/datehour.js +0 -65
- package/src/control/dialog.js +0 -175
- package/src/control/image.js +0 -92
- package/src/control/link.js +0 -69
- package/src/control/list.js +0 -67
- package/src/control/loading.js +0 -128
- package/src/control/menu.js +0 -85
- package/src/control/search.js +0 -98
- package/src/control/select.js +0 -130
- package/src/control/snackbar.js +0 -89
- package/src/control/switch.js +0 -272
- package/src/control/text.js +0 -70
- package/src/control/textfield.js +0 -177
- /package/src/{component → mixin}/controller.js +0 -0
- /package/src/{component → mixin}/emitter.js +0 -0
- /package/src/{component → mixin}/icon.js +0 -0
- /package/src/{component → mixin}/init.js +0 -0
- /package/src/{component → mixin}/label.js +0 -0
- /package/src/{component → mixin}/settings.js +0 -0
- /package/src/{control/module → module}/addclass.js +0 -0
- /package/src/{tabs/setup.js → module/last.js} +0 -0
package/src/control/snackbar.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// base class
|
|
2
|
-
import EventEmitter from '../component/emitter'
|
|
3
|
-
// related modules
|
|
4
|
-
import build from '../module/build'
|
|
5
|
-
import bindEvents from '../module/events'
|
|
6
|
-
import display from '../module/display'
|
|
7
|
-
// ui element
|
|
8
|
-
import Text from './text'
|
|
9
|
-
import Button from './button'
|
|
10
|
-
|
|
11
|
-
class Snackbar extends EventEmitter {
|
|
12
|
-
static defaults = {
|
|
13
|
-
class: 'snackbar',
|
|
14
|
-
transition: 225,
|
|
15
|
-
duration: 4000,
|
|
16
|
-
close: false,
|
|
17
|
-
layout: [
|
|
18
|
-
[Text, 'text', { tag: 'span', class: 'text' }],
|
|
19
|
-
[Button, 'action', { class: 'action', type: 'link' }],
|
|
20
|
-
[Button, 'close', { class: 'close', type: 'action' }]
|
|
21
|
-
],
|
|
22
|
-
events: [
|
|
23
|
-
['ui.action.click', 'action'],
|
|
24
|
-
['ui.close.click', 'destroy']
|
|
25
|
-
]
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
constructor (options) {
|
|
29
|
-
super()
|
|
30
|
-
|
|
31
|
-
this.init(options)
|
|
32
|
-
this.build(this.constructor)
|
|
33
|
-
this.render()
|
|
34
|
-
this.bindEvents()
|
|
35
|
-
this.show()
|
|
36
|
-
|
|
37
|
-
if (this.options.duration)
|
|
38
|
-
setTimeout(()=>{
|
|
39
|
-
this.destroy()
|
|
40
|
-
}, this.options.duration)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
init(options) {
|
|
44
|
-
this.options = Object.assign({}, Snackbar.defaults, options || {})
|
|
45
|
-
Object.assign(this, build, bindEvents, display)
|
|
46
|
-
|
|
47
|
-
this.buildSnackbarContainer(this.options.container)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
buildSnackbarContainer (container = document.body) {
|
|
51
|
-
console.log('buildSnackbarContainer', container)
|
|
52
|
-
|
|
53
|
-
let snackbarContainer = container.querySelector('.snackbars')
|
|
54
|
-
|
|
55
|
-
console.log('snackbarContainer', snackbarContainer)
|
|
56
|
-
|
|
57
|
-
if (!snackbarContainer) {
|
|
58
|
-
this.options.container = document.createElement('div')
|
|
59
|
-
this.options.container.classList.add('snackbars')
|
|
60
|
-
container.appendChild(this.options.container)
|
|
61
|
-
} else {
|
|
62
|
-
this.options.container = snackbarContainer
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
render () {
|
|
67
|
-
this.ui.text.set(this.options.text)
|
|
68
|
-
if (this.options.action) {
|
|
69
|
-
this.ui.action.set(this.options.action)
|
|
70
|
-
this.ui.action.element.classList.add('show')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (this.options.close) this.ui.close.element.classList.add('show')
|
|
74
|
-
|
|
75
|
-
return this
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
action () {
|
|
79
|
-
this.emit('action')
|
|
80
|
-
this.destroy()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
close() {
|
|
84
|
-
// console.log('close')
|
|
85
|
-
this.destroy()
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export default Snackbar
|
package/src/control/switch.js
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
// module
|
|
2
|
-
import dataset from '../view/dataset'
|
|
3
|
-
import attach from '../module/attach'
|
|
4
|
-
import emitter from '../module/emitter'
|
|
5
|
-
import attributes from './module/attributes'
|
|
6
|
-
import addClass from './module/addclass'
|
|
7
|
-
|
|
8
|
-
// ui
|
|
9
|
-
import Layout from '../layout'
|
|
10
|
-
import Element from '../element'
|
|
11
|
-
|
|
12
|
-
let defaults = {
|
|
13
|
-
class: 'switch',
|
|
14
|
-
attributes: ['type', 'name', 'required', 'checked'],
|
|
15
|
-
layout: [
|
|
16
|
-
[Element, 'input', { class: 'input', type: 'checkbox' }],
|
|
17
|
-
[Element, 'control', { class: 'control' },
|
|
18
|
-
[Element, 'track', { class: 'track' },
|
|
19
|
-
[Element, 'knob', { class: 'knob' }]
|
|
20
|
-
]
|
|
21
|
-
]
|
|
22
|
-
],
|
|
23
|
-
events: [
|
|
24
|
-
['ui.control.click', 'toggle'],
|
|
25
|
-
// ['ui.label.click', 'toggle'],
|
|
26
|
-
// for accessibility purpose
|
|
27
|
-
['ui.input.click', 'toggle'],
|
|
28
|
-
['ui.input.focus', 'focus'],
|
|
29
|
-
['ui.input.blur', 'blur']
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
class Switch {
|
|
34
|
-
constructor (options) {
|
|
35
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
36
|
-
Object.assign(this, emitter, attach, dataset)
|
|
37
|
-
|
|
38
|
-
this.value = this.options.value
|
|
39
|
-
|
|
40
|
-
this.build()
|
|
41
|
-
this.setup()
|
|
42
|
-
this.attach()
|
|
43
|
-
|
|
44
|
-
return this
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* build method
|
|
49
|
-
* @return {Object} The class instance
|
|
50
|
-
*/
|
|
51
|
-
build () {
|
|
52
|
-
var tag = this.options.tag || 'span'
|
|
53
|
-
this.root = document.createElement(tag)
|
|
54
|
-
this.root.classList.add('switch')
|
|
55
|
-
|
|
56
|
-
if (this.options.class !== 'switch') {
|
|
57
|
-
addClass(this.root, this.options.class)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.layout = new Layout(this.options.layout, this.root)
|
|
61
|
-
this.ui = this.layout.component
|
|
62
|
-
|
|
63
|
-
// console.log('ui', this.ui)
|
|
64
|
-
|
|
65
|
-
this.styleAttributes()
|
|
66
|
-
|
|
67
|
-
this.buildIcon()
|
|
68
|
-
this.buildLabel()
|
|
69
|
-
|
|
70
|
-
if (this.options.container) {
|
|
71
|
-
this.options.container.appendChild(this.root)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setup () {
|
|
76
|
-
if (this.options.data) {
|
|
77
|
-
dataset(this.root, this.options.data)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// console.log('attribute', this.ui.input, this.options)
|
|
81
|
-
attributes(this.ui.input, this.options)
|
|
82
|
-
|
|
83
|
-
if (this.options.checked) {
|
|
84
|
-
this.check(true)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (this.value) {
|
|
88
|
-
this.element.input.setAttribute('checked', 'checked')
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (this.options.tooltip) {
|
|
92
|
-
this.root.setAttribute('data-tooltip', this.options.tooltip)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this.ui.input.setAttribute('aria-label', this.options.name)
|
|
96
|
-
|
|
97
|
-
if (this.options.case) {
|
|
98
|
-
this.root.classList.add(this.options.case + '-case')
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
buildLabel () {
|
|
103
|
-
// console.log('buildLabel', this.options.label)
|
|
104
|
-
if (!this.options.label) return
|
|
105
|
-
|
|
106
|
-
this.ui.label = document.createElement('label')
|
|
107
|
-
this.ui.label.classList.add('label')
|
|
108
|
-
this.ui.label.innerHTML = this.options.label
|
|
109
|
-
|
|
110
|
-
if (this.options.name) {
|
|
111
|
-
this.ui.label.setAttribute('for', this.options.name)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
this.root.insertBefore(this.ui.label, this.ui.input)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
buildIcon () {
|
|
118
|
-
if (!this.options.icon) return
|
|
119
|
-
|
|
120
|
-
this.ui.icon = document.createElement('i')
|
|
121
|
-
this.ui.icon.classList.add('icon')
|
|
122
|
-
this.ui.icon.innerHTML = this.options.icon
|
|
123
|
-
|
|
124
|
-
this.root.insertBefore(this.ui.icon, this.ui.input)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
styleAttributes () {
|
|
128
|
-
if (this.options.style) {
|
|
129
|
-
this.root.classList.add('style-' + this.options.style)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (this.options.size) {
|
|
133
|
-
this.root.classList.add(this.options.size + '-size')
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (this.options.color) {
|
|
137
|
-
this.root.classList.add('color-' + this.options.color)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (this.options.bold) {
|
|
141
|
-
this.root.classList.add('bold')
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Setter
|
|
147
|
-
* @param {string} prop
|
|
148
|
-
* @param {string} value
|
|
149
|
-
* @return {Object} The class instance
|
|
150
|
-
*/
|
|
151
|
-
set (prop, value, silent) {
|
|
152
|
-
switch (prop) {
|
|
153
|
-
case 'value':
|
|
154
|
-
this.setValue(value, silent)
|
|
155
|
-
break
|
|
156
|
-
case 'text':
|
|
157
|
-
this.setValue(value)
|
|
158
|
-
break
|
|
159
|
-
case 'disabled':
|
|
160
|
-
if (value === true) {
|
|
161
|
-
this.disable()
|
|
162
|
-
} else if (value === false) {
|
|
163
|
-
this.enable()
|
|
164
|
-
}
|
|
165
|
-
break
|
|
166
|
-
default:
|
|
167
|
-
this.setValue(prop, value)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return this
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
setLabel (value) {
|
|
174
|
-
// console.log('setLabel', value)
|
|
175
|
-
if (this.ui.label) {
|
|
176
|
-
this.ui.label.innerHTML = value
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
setText (value) {
|
|
181
|
-
this.setLabel(value)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
get () {
|
|
185
|
-
return this.value
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* set switch value
|
|
190
|
-
* @param {boolean} value [description]
|
|
191
|
-
*/
|
|
192
|
-
getValue () {
|
|
193
|
-
return this.value
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* set switch value
|
|
198
|
-
* @param {boolean} value [description]
|
|
199
|
-
*/
|
|
200
|
-
setValue (value, silent) {
|
|
201
|
-
// console.log('setValue', value, typeof silent, silent)
|
|
202
|
-
this.check(value, silent)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* [toggle description]
|
|
207
|
-
* @return {Object} The class instance
|
|
208
|
-
*/
|
|
209
|
-
toggle () {
|
|
210
|
-
// console.log('toggle')
|
|
211
|
-
if (this.disabled) return
|
|
212
|
-
|
|
213
|
-
this.focus()
|
|
214
|
-
|
|
215
|
-
if (this.checked) {
|
|
216
|
-
this.check(false)
|
|
217
|
-
} else {
|
|
218
|
-
this.check(true)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return this
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Set checkbox value
|
|
226
|
-
* @param {boolean} value [description]
|
|
227
|
-
*/
|
|
228
|
-
check (checked, silent) {
|
|
229
|
-
// console.log('check', checked, silent)
|
|
230
|
-
if (checked === true) {
|
|
231
|
-
this.root.classList.add('is-checked')
|
|
232
|
-
this.ui.input.checked = true
|
|
233
|
-
this.checked = true
|
|
234
|
-
this.value = true
|
|
235
|
-
if (!silent) {
|
|
236
|
-
this.emit('change', this.checked)
|
|
237
|
-
}
|
|
238
|
-
} else {
|
|
239
|
-
this.root.classList.remove('is-checked')
|
|
240
|
-
this.ui.input.checked = false
|
|
241
|
-
this.checked = false
|
|
242
|
-
this.value = false
|
|
243
|
-
if (!silent) {
|
|
244
|
-
this.emit('change', this.checked)
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return this
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* [_onInputFocus description]
|
|
252
|
-
* @return {?} [description]
|
|
253
|
-
*/
|
|
254
|
-
focus () {
|
|
255
|
-
if (this.disabled === true) return this
|
|
256
|
-
|
|
257
|
-
this.root.classList.add('is-focused')
|
|
258
|
-
if (this.ui.input !== document.activeElement) { this.ui.input.focus() }
|
|
259
|
-
return this
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* [_onInputBlur description]
|
|
264
|
-
* @return {?} [description]
|
|
265
|
-
*/
|
|
266
|
-
blur () {
|
|
267
|
-
this.root.classList.remove('is-focused')
|
|
268
|
-
return this
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export default Switch
|
package/src/control/text.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import addClass from './module/addclass'
|
|
2
|
-
|
|
3
|
-
const defaults = {
|
|
4
|
-
class: 'text',
|
|
5
|
-
tag: 'span'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class Text {
|
|
9
|
-
/**
|
|
10
|
-
* Constructor
|
|
11
|
-
* @param {Object} options - Component options
|
|
12
|
-
* @return {Object} Class instance
|
|
13
|
-
*/
|
|
14
|
-
constructor (options) {
|
|
15
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
16
|
-
|
|
17
|
-
// console.log('options', this.options)
|
|
18
|
-
|
|
19
|
-
this.build()
|
|
20
|
-
|
|
21
|
-
return this
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Build Method
|
|
26
|
-
* @return {Object} This class instance
|
|
27
|
-
*/
|
|
28
|
-
build () {
|
|
29
|
-
this.root = document.createElement(this.options.tag)
|
|
30
|
-
addClass(this.root, this.options.class)
|
|
31
|
-
|
|
32
|
-
if (this.options.class !== 'text') {
|
|
33
|
-
this.root.classList.add('text')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (this.options.text) {
|
|
37
|
-
this.set(this.options.text)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (this.options.container) {
|
|
41
|
-
this.options.container.appendChild(this.root)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return this
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
set (text) {
|
|
48
|
-
// console.log('set', text)
|
|
49
|
-
if (text === undefined) return
|
|
50
|
-
|
|
51
|
-
var label = this.options.label || ''
|
|
52
|
-
|
|
53
|
-
if (this.options.textFirst) {
|
|
54
|
-
this.root.innerHTML = text + label
|
|
55
|
-
} else {
|
|
56
|
-
this.root.innerHTML = label + text
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (this.options.spaceAfter) {
|
|
60
|
-
this.root.innerHTML = this.root.innerHTML + ' '
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setText (text) {
|
|
65
|
-
// console.log('setText', text)
|
|
66
|
-
this.root.innerHTML = text
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default Text
|
package/src/control/textfield.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import emitter from '../module/emitter'
|
|
3
|
-
import attach from '../module/attach'
|
|
4
|
-
import dataset from '../view/dataset'
|
|
5
|
-
import attributes from './module/attributes'
|
|
6
|
-
|
|
7
|
-
const defaults = {
|
|
8
|
-
class: 'textfield',
|
|
9
|
-
attributes: ['type', 'name', 'title', 'maxlength', 'pattern', 'min', 'max', 'placeholder', 'readonly', 'autocomplete', 'required', 'disabled'],
|
|
10
|
-
events: [
|
|
11
|
-
['input.input', 'onInput'],
|
|
12
|
-
['input.focus', 'onFocus'],
|
|
13
|
-
['input.blur', 'onBlur'],
|
|
14
|
-
['input.click', 'onClick']
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class Text {
|
|
19
|
-
static isComponent () {
|
|
20
|
-
return true
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Constructor
|
|
24
|
-
* @param {Object} options - Component options
|
|
25
|
-
* @return {Object} Class instance
|
|
26
|
-
*/
|
|
27
|
-
constructor (options) {
|
|
28
|
-
this.options = Object.assign({}, defaults, options || {})
|
|
29
|
-
Object.assign(this, emitter, attach, dataset)
|
|
30
|
-
// console.log('options', options)
|
|
31
|
-
|
|
32
|
-
this.build()
|
|
33
|
-
this.attach()
|
|
34
|
-
|
|
35
|
-
return this
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Build Method
|
|
40
|
-
* @return {Object} This class instance
|
|
41
|
-
*/
|
|
42
|
-
build () {
|
|
43
|
-
var tag = this.options.tag || 'div'
|
|
44
|
-
|
|
45
|
-
this.root = document.createElement(tag)
|
|
46
|
-
this.root.classList.add('textfield')
|
|
47
|
-
|
|
48
|
-
if (this.options.class !== 'textfield') {
|
|
49
|
-
this.root.classList.add(this.options.class)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.buildLabel()
|
|
53
|
-
this.buildInput()
|
|
54
|
-
|
|
55
|
-
if (this.options.value) {
|
|
56
|
-
this.set(this.options.value)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (this.options.data) {
|
|
60
|
-
dataset(this.root, this.options.data)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (this.container) {
|
|
64
|
-
this.container.appendChild(this.root)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return this
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
buildLabel () {
|
|
71
|
-
if (this.options.label) {
|
|
72
|
-
this.label = document.createElement('label')
|
|
73
|
-
this.label.classList.add('label')
|
|
74
|
-
this.label.innerHTML = this.options.label
|
|
75
|
-
this.root.appendChild(this.label)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
buildInput () {
|
|
80
|
-
let tag = 'input'
|
|
81
|
-
if (this.options.type === 'multiline') {
|
|
82
|
-
tag = 'textarea'
|
|
83
|
-
}
|
|
84
|
-
this.input = document.createElement(tag)
|
|
85
|
-
this.input.classList.add('input')
|
|
86
|
-
this.root.appendChild(this.input)
|
|
87
|
-
|
|
88
|
-
attributes(this.input, this.options)
|
|
89
|
-
|
|
90
|
-
if (this.options.focus) {
|
|
91
|
-
this.input.focus()
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
onInput (ev) {
|
|
96
|
-
// console.log('onInput', this.value, this.input.value)
|
|
97
|
-
|
|
98
|
-
this.emit('change', ev)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
onFocus (ev) {
|
|
102
|
-
this.root.classList.add('focused')
|
|
103
|
-
this.emit('focus', ev)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
onBlur (ev) {
|
|
107
|
-
this.root.classList.remove('focused')
|
|
108
|
-
this.emit('blur', ev)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
onClick (ev) {
|
|
112
|
-
// console.log('click')
|
|
113
|
-
this.emit('click', ev)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Setter
|
|
118
|
-
* @param {string} prop
|
|
119
|
-
* @param {string} value
|
|
120
|
-
* @return {Object} The class instance
|
|
121
|
-
*/
|
|
122
|
-
set (prop, value) {
|
|
123
|
-
// console.log('set', this.root, prop, value)
|
|
124
|
-
switch (prop) {
|
|
125
|
-
case 'value':
|
|
126
|
-
this.setValue(value)
|
|
127
|
-
break
|
|
128
|
-
case 'label':
|
|
129
|
-
this.setLabel(value)
|
|
130
|
-
break
|
|
131
|
-
default:
|
|
132
|
-
// console.log('prop', prop)
|
|
133
|
-
this.setValue(prop)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return this
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
setValue (value) {
|
|
140
|
-
// console.log('set', typeof value, value)
|
|
141
|
-
if (value && value !== 'undefined') {
|
|
142
|
-
this.value = value
|
|
143
|
-
this.input.value = value
|
|
144
|
-
} else {
|
|
145
|
-
this.input.value = ''
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
setLabel (value) {
|
|
150
|
-
// console.log('setLabel', value)
|
|
151
|
-
if (this.label) {
|
|
152
|
-
this.label.innerHTML = value
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
setText (value) {
|
|
157
|
-
this.setLabel(value)
|
|
158
|
-
|
|
159
|
-
if (this.options.placeholder) {
|
|
160
|
-
this.input.placeholder = value
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
hide () {
|
|
165
|
-
this.root.classList.add('hide')
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
show () {
|
|
169
|
-
this.root.classList.remove('hide')
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
get () {
|
|
173
|
-
return this.input.value
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export default Text
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|