material 0.7.0 → 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.
Files changed (65) hide show
  1. package/form.js +27 -0
  2. package/index.js +59 -58
  3. package/list.js +35 -0
  4. package/package.json +5 -1
  5. package/src/appbar.js +7 -204
  6. package/src/badge.js +27 -0
  7. package/src/button.js +155 -155
  8. package/src/calendar.js +0 -2
  9. package/src/card.js +0 -2
  10. package/src/checkbox.js +0 -2
  11. package/src/component.js +0 -2
  12. package/src/container.js +0 -2
  13. package/src/datehour.js +38 -0
  14. package/src/dialog.js +105 -152
  15. package/src/divider.js +0 -2
  16. package/src/drawer.js +0 -2
  17. package/src/{control/file.js → file.js} +15 -45
  18. package/src/form/verify.js +2 -2
  19. package/src/form.js +0 -2
  20. package/src/icon.js +0 -2
  21. package/src/image.js +39 -106
  22. package/src/item.js +0 -2
  23. package/src/{control/link.js → link.js} +13 -32
  24. package/src/list/build.js +2 -2
  25. package/src/list/collection.js +1 -1
  26. package/src/list/filter.js +2 -2
  27. package/src/list/request.js +1 -1
  28. package/src/list/search.js +5 -5
  29. package/src/list.js +29 -217
  30. package/src/loading.js +73 -0
  31. package/src/menu.js +60 -116
  32. package/src/mixin/display.js +0 -1
  33. package/src/mixin/insert.js +2 -24
  34. package/src/{control/module → module}/attributes.js +2 -2
  35. package/src/module/build.js +8 -5
  36. package/src/navigation.js +19 -0
  37. package/src/progress.js +0 -2
  38. package/src/search.js +71 -0
  39. package/src/select.js +57 -272
  40. package/src/{control/selecter.js → selecter.js} +5 -5
  41. package/src/skin/material/component/navigation.sass +1 -0
  42. package/src/skin/material/control/button.sass +10 -0
  43. package/src/slider.js +0 -2
  44. package/src/snackbar.js +72 -51
  45. package/src/switch.js +111 -103
  46. package/src/{control/switcher.js → switcher.js} +17 -20
  47. package/src/text.js +25 -74
  48. package/src/textfield.js +96 -233
  49. package/src/banner.js +0 -231
  50. package/src/control/button.js +0 -239
  51. package/src/control/button.new.js +0 -190
  52. package/src/control/datehour.js +0 -65
  53. package/src/control/dialog.js +0 -175
  54. package/src/control/image.js +0 -92
  55. package/src/control/list.js +0 -67
  56. package/src/control/loading.js +0 -128
  57. package/src/control/menu.js +0 -85
  58. package/src/control/search.js +0 -98
  59. package/src/control/select.js +0 -130
  60. package/src/control/snackbar.js +0 -91
  61. package/src/control/switch.js +0 -272
  62. package/src/control/text.js +0 -70
  63. package/src/control/textfield.js +0 -177
  64. package/src/tabs/setup.js +0 -0
  65. /package/src/{control/module → module}/addclass.js +0 -0
@@ -1,6 +1,6 @@
1
1
  const special = ['required', 'disabled', 'multiple', 'checked']
2
2
 
3
- function setAttributes (element, o) {
3
+ function attributes (element, o) {
4
4
  // console.log('attributes', o.attributes, element)
5
5
 
6
6
  if (!element) return
@@ -18,4 +18,4 @@ function setAttributes (element, o) {
18
18
  }
19
19
  }
20
20
 
21
- export default setAttributes
21
+ export default attributes
@@ -4,12 +4,12 @@ import Layout from '../layout'
4
4
  export default {
5
5
  build () {
6
6
  this.element = document.createElement(this.options.tag || 'div')
7
- // for backward compatibility
8
- this.element = this.element
9
7
 
10
8
  const defaults = this.constructor.defaults || {}
11
9
 
12
- this.element.classList.add(defaults.class)
10
+ if (defaults.base) this.element.classList.add(defaults.base)
11
+
12
+ if (defaults.class) this.element.classList.add(defaults.class)
13
13
 
14
14
  if (this.options.class !== defaults.class) {
15
15
  this.addClass(this.options.class)
@@ -19,7 +19,11 @@ export default {
19
19
  dataset(this.element, this.options.data)
20
20
  }
21
21
 
22
- this.container = this.options.container
22
+ if (this.options.base === 'view') {
23
+ this.container = this.options.container || document.body
24
+ } else {
25
+ this.container = this.options.container
26
+ }
23
27
 
24
28
  if (this.container) this.appendTo(this.container)
25
29
 
@@ -40,5 +44,4 @@ export default {
40
44
  const list = c.split(' ')
41
45
  list.forEach(item => this.element.classList.add(item))
42
46
  }
43
-
44
47
  }
@@ -0,0 +1,19 @@
1
+ import build from './module/build'
2
+
3
+ class Navigation {
4
+ static defaults = {
5
+ class: 'navigation'
6
+ }
7
+
8
+ constructor (options) {
9
+ this.init(options)
10
+ this.build()
11
+ }
12
+
13
+ init (options) {
14
+ this.options = Object.assign({}, Navigation.defaults, options || {})
15
+ Object.assign(this, build)
16
+ }
17
+ }
18
+
19
+ export default Navigation
package/src/progress.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  // import Component from './component';
4
2
  import create from './element/create'
5
3
  import classify from './module/classify'
package/src/search.js ADDED
@@ -0,0 +1,71 @@
1
+ import EventEmitter from './mixin/emitter'
2
+
3
+ import build from './module/build'
4
+ import bindEvents from './module/events'
5
+
6
+ import Button from './button'
7
+ import cancel from './skin/material/icon/cancel.svg'
8
+
9
+ class Search extends EventEmitter {
10
+ static defaults = {
11
+ class: 'search-input',
12
+ minChar: 4,
13
+ iconCancel: cancel,
14
+ timeout: 200,
15
+ events: [
16
+ ['input.input', 'onInput'],
17
+ ['input.cancel', 'onCancel']
18
+ ]
19
+ }
20
+
21
+ constructor (options) {
22
+ super()
23
+
24
+ this.init(options)
25
+ this.build()
26
+ this.buildSearch()
27
+ this.bindEvents()
28
+ }
29
+
30
+ init(options) {
31
+ this.options = Object.assign({}, Search.defaults, options || {})
32
+ Object.assign(this, build, bindEvents)
33
+ }
34
+
35
+ buildSearch () {
36
+ if (this.options.icon) {
37
+ this.icon = document.createElement('i')
38
+ this.icon.classList.add('icon')
39
+ this.icon.innerHTML = this.options.icon
40
+ this.element.appendChild(this.icon)
41
+ }
42
+
43
+ this.input = document.createElement('input')
44
+ this.input.classList.add('input')
45
+ this.element.appendChild(this.input)
46
+
47
+ this.cancel = new Button({
48
+ container: this.element,
49
+ class: 'clear',
50
+ icon: this.options.iconCancel
51
+ })
52
+ }
53
+
54
+ onInput () {
55
+ if (this.input.value.length < this.options.minChar) return
56
+
57
+ clearTimeout(this.timeout)
58
+
59
+ this.timeout = setTimeout(() => {
60
+ this.emit('change', this.input.value)
61
+ }, this.options.timeout)
62
+ }
63
+
64
+ onCancel () {
65
+ this.input.value = ''
66
+ this.input.focus()
67
+ this.emit('cancel')
68
+ }
69
+ }
70
+
71
+ export default Search
package/src/select.js CHANGED
@@ -1,323 +1,108 @@
1
- 'use strict'
1
+ import EventEmitter from './mixin/emitter'
2
2
 
3
- import emitter from './module/emitter'
3
+ import build from './module/build'
4
4
  import attach from './module/attach'
5
+ import attributes from './module/attributes'
6
+ import dataset from './view/dataset'
5
7
 
6
- var defaults = {
7
- prefix: 'material',
8
- class: 'textfield',
9
- type: 'control',
10
- tag: 'div',
11
- events: [
12
- ['input.change', '_onChange'],
13
- ['input.focus', 'focus'],
14
- ['input.blur', 'blur'],
15
- // ['input.keypress', '_handleInputKeyPress',
16
- ['input.keyup', '_handleInputKeyPress']
17
- // ['input.mouseover', 'mouseover']
18
- // ['input.change', '_onChange']
19
- // 'input.keydown': '_handleInputKeyPress'
20
-
21
- ]
22
- }
8
+ class Select extends EventEmitter {
9
+ static defaults = {
10
+ type: 'list',
11
+ class: 'select',
12
+ first: null,
13
+ attributes: ['type', 'name', 'autocomplete', 'required']
14
+ }
23
15
 
24
- /**
25
- * Textfield class
26
- * @class
27
- */
28
- class Select {
29
- /**
30
- * Constructor
31
- * @param {Object} options - Component options
32
- * @return {Object} Class instance
33
- */
34
16
  constructor (options) {
35
- this.options = Object.assign({}, defaults, options || {})
17
+ super()
36
18
 
37
- this.init()
19
+ this.init(options)
38
20
  this.build()
39
- this.attach()
40
-
41
- return this
42
- }
43
-
44
- /**
45
- * init
46
- * @param {Object} options The class options
47
- * @return {Object} The class instance
48
- */
49
- init () {
50
- Object.assign(this, emitter, attach)
51
-
52
- this.value = this.options.value
53
-
54
- return this
55
- }
56
-
57
- mouseover () {
58
- // console.log('mouseover')
59
- }
60
-
61
- /**
62
- * [build description]
63
- * @return {Object} The class instance
64
- */
65
- build () {
66
- // create a new div as input element
67
- var tag = this.options.tag || 'div'
68
- this.element = document.createElement(tag)
69
- this.element.classList.add(this.options.prefix + '-' + this.options.class)
70
-
71
21
  this.buildLabel()
72
22
  this.buildInput()
73
- this.buildUnderline()
74
-
75
- if (this.disabled) {
76
- css.add(this.element, 'is-disabled')
77
- }
23
+ this.attach()
24
+ }
78
25
 
79
- // insert if container this.options is given
80
- if (this.options.container) {
81
- // console.log(this.name, opts.container);
82
- insert(this.element, this.options.container)
83
- }
26
+ init(options) {
27
+ this.options = Object.assign({}, Select.defaults, options || {})
28
+ Object.assign(this, build, attach, dataset)
84
29
  }
85
30
 
86
31
  buildLabel () {
87
- this.label = document.createElement('label')
88
- this.label.classList.add(this.options.class + '-label')
89
- this.element.appendChild(this.label)
90
-
91
- if (this.options.label !== false) {
92
- this.setLabel()
32
+ if (this.options.label) {
33
+ this.label = document.createElement('span')
34
+ this.label.classList.add('label')
35
+ this.label.innerHTML = this.options.label
36
+ this.element.appendChild(this.label)
93
37
  }
94
38
  }
95
39
 
96
- /**
97
- * [_initInput description]
98
- * @return {Object} The class instance
99
- */
100
40
  buildInput () {
101
41
  this.input = document.createElement('select')
102
- this.input.classList.add(this.options.class + '-input')
103
- // this.input.setAttribute('type', 'text')
42
+ this.input.classList.add('input')
104
43
  this.element.appendChild(this.input)
105
44
 
106
- if (this.options.options) {
107
- this.setOptions(this.options.options)
45
+ this.input.addEventListener('change', () => {
46
+ // console.log('change', this.input[this.input.selectedIndex].value)
47
+ this.emit('change', this.input[this.input.selectedIndex].value)
48
+ })
49
+
50
+ if (this.options.data) {
51
+ dataset(this.data, this.options.data)
108
52
  }
109
53
 
110
- // if (!this.options.value) {
111
- // this.element.classList.add('is-empty')
112
- // }
54
+ attributes(this.input, this.options)
113
55
 
114
- if (this.readonly) {
115
- this.input.setAttribute('readonly', 'readonly')
116
- this.input.setAttribute('tabindex', '-1')
56
+ if (this.options.options) {
57
+ this.setOptions(this.options.options)
117
58
  }
118
-
119
- return this.input
120
59
  }
121
60
 
122
61
  setOptions (options) {
123
- for (var i = 0; i < options.length; i++) {
124
- this.add(options[i], options[i])
125
- }
126
- }
62
+ // console.log('buildCountry', this.input)
127
63
 
128
- /**
129
- * _initUnderline
130
- * @return {Object} The class instance
131
- */
132
- buildUnderline () {
133
- this.underline = document.createElement('span')
134
- this.underline.classList.add(this.options.class + '-underline')
135
- this.element.appendChild(this.underline)
136
- }
64
+ var first = this.options.first
137
65
 
138
- /**
139
- * Setter
140
- * @param {string} prop
141
- * @param {string} value
142
- */
143
- set (prop, value) {
144
- switch (prop) {
145
- case 'value':
146
- this.setValue(value)
147
- break
148
- case 'label':
149
- this.setLabel(value)
150
- break
151
- case 'disabled':
152
- if (value === true) {
153
- this.disable()
154
- } else if (value === false) {
155
- this.enable()
156
- }
157
- break
158
- default:
159
- this.setValue(prop)
66
+ if (first && first[0] && first[1]) {
67
+ this.input.options[0] = new Option(first[1], first[0])
160
68
  }
161
69
 
162
- return this
163
- }
164
-
165
- /**
166
- * [buildLabel description]
167
- * @return {Object} The class instance
168
- */
169
- setLabel (label) {
170
- label = label || this.options.label
171
- var text
172
-
173
- if (label === null || label === false) {
174
- text = ''
175
- } else if (this.options.label) {
176
- text = label
177
- } else {
178
- text = this.options.name
70
+ for (var i = 0; i < options.length; i++) {
71
+ this.addOption(options[i][1], options[i][0])
179
72
  }
180
-
181
- this.label.textContent = text
182
73
  }
183
74
 
184
- disable () {
185
- this.disabled = true
186
-
187
- this.input.setAttribute('disabled', 'disabled')
188
- this.element.classList.add('is-disabled')
189
- return this
75
+ addOption (name, value) {
76
+ // console.log('addOption', name, value)
77
+ this.input.options[this.input.options.length] = new Option(name, value)
190
78
  }
191
79
 
192
- enable () {
193
- this.disabled = false
80
+ set (value) {
81
+ // console.log('set', value)
82
+ this.input.value = value
194
83
 
195
- this.element.input.removeAttribute('disabled')
196
- this.element.classList.remove('is-disabled')
197
84
  return this
198
85
  }
199
86
 
200
- /**
201
- * Getter
202
- * @param {string} prop
203
- * @param {string} value
204
- */
205
- get (prop) {
206
- var value
207
-
208
- switch (prop) {
209
- case 'value':
210
- value = this.getValue()
211
- break
212
- case 'name':
213
- value = this.name
214
- break
215
- default:
216
- return this.getValue()
87
+ setLabel (value) {
88
+ // console.log('setLabel', value)
89
+ if (this.label) {
90
+ this.label.innerHTML = value
217
91
  }
218
-
219
- return value
220
- }
221
-
222
- /**
223
- * [getValue description]
224
- * @return {Object} The class instance
225
- */
226
- getValue () {
227
- // console.log('getValue', this);
228
- return this.input.value
229
- }
230
-
231
- /**
232
- * [setValue description]
233
- * @param {string} value [description]
234
- */
235
- setValue (value) {
236
- // console.log('setValue', this.options.name, value)
237
- this.input.value = value
238
-
239
- if (value) {
240
- this.element.classList.remove('is-empty')
241
- } else {
242
- this.element.classList.add('is-empty')
243
- }
244
-
245
- this.emit('change', value)
246
92
  }
247
93
 
248
- _onChange (ev) {
249
- // console.log('change', ev)
250
-
251
- this.emit('change', ev.target.value)
252
- }
253
-
254
- /**
255
- * [_initValue description]
256
- * @return {Object} The class instance
257
- */
258
- _initValue () {
259
- var opts = this.options
260
-
261
- // create a new div as input element
262
- if (opts.value) {
263
- this.setValue(opts.value)
264
- }
94
+ setText (value) {
95
+ this.setLabel(value)
265
96
  }
266
97
 
267
- /**
268
- * [_onFocus description]
269
- * @return {Object} The class instance
270
- */
271
- _handleInputKeyPress (e) {
272
- // console.log('_handleInputKeyPress', e);
98
+ get () {
99
+ var value = null
273
100
 
274
- if (this.get('value') === '') {
275
- this.element.classList.add('is-empty')
276
- } else {
277
- this.element.classList.remove('is-empty')
101
+ if (this.input[this.input.selectedIndex]) {
102
+ value = this.input[this.input.selectedIndex].value
278
103
  }
279
104
 
280
- this.emit('change', this.getValue())
281
- }
282
-
283
- add (key, value, selected) {
284
- selected = selected || false
285
- var select = this.input
286
- select.options[select.options.length] = new Option(value, key, selected, selected)
287
- }
288
-
289
- /**
290
- * focus method
291
- * @return {?} [description]
292
- */
293
- focus () {
294
- if (this.disabled === true) return this
295
-
296
- this.element.classList.add('is-focused')
297
- if (this.input !== document.activeElement) { this.input.focus() }
298
- return this
299
- }
300
-
301
- /**
302
- * blur method
303
- * @return {?} [description]
304
- */
305
- blur () {
306
- this.element.classList.remove('is-focused')
307
- return this
308
- }
309
- /**
310
- * [setError description]
311
- * @param {string} error Error description
312
- */
313
- setError (error) {
314
- if (error) {
315
- this.addClass('field-error')
316
- if (this.error) { this.error.set('html', error) }
317
- } else {
318
- if (this.error) { this.removeClass('field-error') }
319
- if (this.error) { this.error.set('html', '') }
320
- }
105
+ return value
321
106
  }
322
107
  }
323
108
 
@@ -1,12 +1,12 @@
1
- import emitter from '..//module/emitter'
2
- import attach from '../module/attach'
3
- import dataset from '../view/dataset'
1
+ import emitter from './module/emitter'
2
+ import attach from './module/attach'
3
+ import dataset from './view/dataset'
4
4
  import attributes from './module/attributes'
5
5
  import addClass from './module/addclass'
6
6
 
7
7
  // ui
8
- import Layout from '../layout'
9
- import Element from '../element'
8
+ import Layout from './layout'
9
+ import Element from './element'
10
10
  import Button from './button'
11
11
 
12
12
  const defaults = {
@@ -0,0 +1 @@
1
+ .navigation
@@ -123,3 +123,13 @@
123
123
  background-color: rgba(0, 0, 0, .1)
124
124
  &:focus
125
125
  background-color: rgba(0, 0, 0, .1)
126
+
127
+ .ripple
128
+ opacity: 1
129
+ pointer-events: none
130
+ z-index: 1
131
+ position: absolute
132
+ background-color: rgba(255, 255, 255, 0.1)
133
+ height: 5px
134
+ width: 5px
135
+ border-radius: 50%
package/src/slider.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  import init from './mixin/init'
4
2
  import build from './element/build'
5
3
  import control from './mixin/control'