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.
Files changed (98) hide show
  1. package/form.js +27 -0
  2. package/index.js +61 -51
  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 +160 -161
  8. package/src/calendar.js +8 -10
  9. package/src/card.js +4 -6
  10. package/src/checkbox.js +8 -10
  11. package/src/component.js +4 -6
  12. package/src/container.js +4 -6
  13. package/src/datehour.js +38 -0
  14. package/src/dialog.js +106 -153
  15. package/src/divider.js +4 -6
  16. package/src/drawer.js +11 -13
  17. package/src/field/email.js +5 -5
  18. package/src/field/image.js +4 -4
  19. package/src/{control/file.js → file.js} +18 -48
  20. package/src/form/build.js +7 -7
  21. package/src/form/verify.js +2 -2
  22. package/src/form.js +6 -8
  23. package/src/icon.js +8 -10
  24. package/src/image.js +39 -106
  25. package/src/item.js +7 -9
  26. package/src/layout.js +10 -10
  27. package/src/link.js +50 -0
  28. package/src/list/add.js +1 -1
  29. package/src/list/build.js +9 -9
  30. package/src/list/collection.js +1 -1
  31. package/src/list/display.js +10 -10
  32. package/src/list/filter.js +2 -2
  33. package/src/list/request.js +1 -1
  34. package/src/list/search.js +7 -7
  35. package/src/list.js +29 -217
  36. package/src/loading.js +73 -0
  37. package/src/map/build.js +6 -6
  38. package/src/map/display.js +8 -8
  39. package/src/menu.js +60 -116
  40. package/src/{component → mixin}/control.js +10 -10
  41. package/src/{component → mixin}/create.js +1 -1
  42. package/src/{module → mixin}/display.js +9 -22
  43. package/src/{component → mixin}/events.js +2 -2
  44. package/src/{component → mixin}/focus.js +2 -3
  45. package/src/{component → mixin}/insert.js +3 -25
  46. package/src/{control/module → module}/attributes.js +2 -2
  47. package/src/module/build.js +11 -7
  48. package/src/{component → module}/classify.js +0 -13
  49. package/src/module/dom.js +1 -57
  50. package/src/module/events.js +4 -2
  51. package/src/{component → module}/ripple.js +15 -42
  52. package/src/navigation.js +19 -0
  53. package/src/progress.js +7 -9
  54. package/src/search.js +71 -0
  55. package/src/select.js +58 -273
  56. package/src/{control/selecter.js → selecter.js} +20 -20
  57. package/src/selector.js +32 -32
  58. package/src/skin/material/component/navigation.sass +1 -0
  59. package/src/skin/material/control/button.sass +10 -0
  60. package/src/slider.js +32 -34
  61. package/src/snackbar.js +72 -51
  62. package/src/switch.js +115 -107
  63. package/src/{control/switcher.js → switcher.js} +33 -36
  64. package/src/tabs.js +8 -8
  65. package/src/tabview.js +8 -8
  66. package/src/text.js +25 -74
  67. package/src/textfield.js +97 -234
  68. package/src/toolbar.js +28 -28
  69. package/src/tooltip.js +11 -11
  70. package/src/tree.js +12 -16
  71. package/src/view/build.js +6 -6
  72. package/src/view/display.js +16 -16
  73. package/src/view.js +5 -5
  74. package/src/banner.js +0 -231
  75. package/src/component/click.js +0 -17
  76. package/src/control/button.js +0 -267
  77. package/src/control/button.new.js +0 -190
  78. package/src/control/datehour.js +0 -65
  79. package/src/control/dialog.js +0 -175
  80. package/src/control/image.js +0 -92
  81. package/src/control/link.js +0 -69
  82. package/src/control/list.js +0 -67
  83. package/src/control/loading.js +0 -128
  84. package/src/control/menu.js +0 -85
  85. package/src/control/search.js +0 -98
  86. package/src/control/select.js +0 -130
  87. package/src/control/snackbar.js +0 -89
  88. package/src/control/switch.js +0 -272
  89. package/src/control/text.js +0 -70
  90. package/src/control/textfield.js +0 -177
  91. /package/src/{component → mixin}/controller.js +0 -0
  92. /package/src/{component → mixin}/emitter.js +0 -0
  93. /package/src/{component → mixin}/icon.js +0 -0
  94. /package/src/{component → mixin}/init.js +0 -0
  95. /package/src/{component → mixin}/label.js +0 -0
  96. /package/src/{component → mixin}/settings.js +0 -0
  97. /package/src/{control/module → module}/addclass.js +0 -0
  98. /package/src/{tabs/setup.js → module/last.js} +0 -0
package/src/slider.js CHANGED
@@ -1,13 +1,11 @@
1
- 'use strict'
2
-
3
- import init from './component/init'
1
+ import init from './mixin/init'
4
2
  import build from './element/build'
5
- import control from './component/control'
3
+ import control from './mixin/control'
6
4
 
7
- import events from './component/events'
5
+ import events from './mixin/events'
8
6
  import insert from './element/insert'
9
7
  import offset from './element/offset'
10
- import classify from './component/classify'
8
+ import classify from './module/classify'
11
9
  // import control from './control';
12
10
  import attach from './module/attach'
13
11
  import css from './module/css'
@@ -15,7 +13,7 @@ import emitter from './module/emitter'
15
13
 
16
14
  import icon from './skin/material/icon/pin.svg'
17
15
 
18
- let defaults = {
16
+ const defaults = {
19
17
  prefix: 'material',
20
18
  class: 'slider',
21
19
  type: 'control',
@@ -84,19 +82,19 @@ class Slider {
84
82
  */
85
83
  build () {
86
84
  this.element = build(this.options.build)
87
- this.root = this.element.root
85
+ this.element = this.element.root
88
86
 
89
- classify(this.root, this.options)
87
+ classify(this.element, this.options)
90
88
 
91
89
  if (this.options.container) {
92
- insert(this.root, this.options.container)
90
+ insert(this.element, this.options.container)
93
91
  }
94
92
 
95
- var value = this.element.marker.innerHTML
93
+ const value = this.element.marker.innerHTML
96
94
  this.element.marker.innerHTML = icon + value
97
95
 
98
96
  if (this.options.type) {
99
- css.add(this.root, 'type-' + this.options.type)
97
+ css.add(this.element, 'type-' + this.options.type)
100
98
  }
101
99
 
102
100
  // init input
@@ -105,19 +103,19 @@ class Slider {
105
103
  }
106
104
 
107
105
  // if (this.options.name) {
108
- // this.root.dataset.name = name
106
+ // this.element.dataset.name = name
109
107
  // this.element.input.name = name
110
108
  // }
111
109
 
112
110
  // init text
113
- let text = this.options.label || this.options.text
111
+ const text = this.options.label || this.options.text
114
112
  this.element.label.textContent = text
115
113
 
116
114
  this.options.label = this.options.label || this.options.text
117
115
 
118
116
  this.initTrack()
119
117
 
120
- var delay = 50
118
+ const delay = 50
121
119
 
122
120
  setTimeout(() => {
123
121
  this.initCanvas()
@@ -133,13 +131,13 @@ class Slider {
133
131
  }
134
132
 
135
133
  drawCanvas () {
136
- var width = offset(this.element.track, 'width')
137
- var height = offset(this.element.track, 'height')
134
+ const width = offset(this.element.track, 'width')
135
+ const height = offset(this.element.track, 'height')
138
136
 
139
137
  this.element.canvas.width = width
140
138
  this.element.canvas.height = height
141
139
 
142
- var context = this.element.canvas.getContext('2d')
140
+ const context = this.element.canvas.getContext('2d')
143
141
  context.lineWidth = 2
144
142
  context.beginPath()
145
143
 
@@ -157,7 +155,7 @@ class Slider {
157
155
  this.element.track.addEventListener('mousedown', (ev) => {
158
156
  if (this.disabled === true) return
159
157
  this.initTrackSize()
160
- var position = ev.layerX
158
+ const position = ev.layerX
161
159
  this.update(position)
162
160
  })
163
161
 
@@ -167,7 +165,7 @@ class Slider {
167
165
 
168
166
  this.initDragging()
169
167
 
170
- var delay = 100
168
+ const delay = 100
171
169
 
172
170
  setTimeout(() => {
173
171
  this.setValue(this.options.value)
@@ -195,8 +193,8 @@ class Slider {
195
193
 
196
194
  css.add(this.element.control, 'dragging')
197
195
 
198
- var start = 0
199
- var position = 0
196
+ let start = 0
197
+ let position = 0
200
198
 
201
199
  if (e.pageX) start = e.pageX
202
200
  else if (e.clientX) start = e.clientX
@@ -207,7 +205,7 @@ class Slider {
207
205
  console.log('mousedown', this.disabled)
208
206
 
209
207
  e = e || window.event
210
- var end = 0
208
+ let end = 0
211
209
  if (e.pageX) end = e.pageX
212
210
  else if (e.clientX) end = e.clientX
213
211
 
@@ -218,7 +216,7 @@ class Slider {
218
216
  document.body.onmousemove = document.body.onmouseup = null
219
217
 
220
218
  e = e || window.event
221
- var end = 0
219
+ let end = 0
222
220
  if (e.pageX) end = e.pageX
223
221
  else if (e.clientX) end = e.clientX
224
222
 
@@ -230,8 +228,8 @@ class Slider {
230
228
  }
231
229
 
232
230
  update (position) {
233
- var size = this._tracksize
234
- var range = this.options.range[1] - this.options.range[0]
231
+ const size = this._tracksize
232
+ const range = this.options.range[1] - this.options.range[0]
235
233
 
236
234
  if (position > size) {
237
235
  position = size
@@ -241,8 +239,8 @@ class Slider {
241
239
  position = 0
242
240
  }
243
241
 
244
- var ratio = (size / position)
245
- var value = Math.round((range / ratio)) + this.options.range[0]
242
+ const ratio = (size / position)
243
+ const value = Math.round((range / ratio)) + this.options.range[0]
246
244
 
247
245
  if (position === 0) {
248
246
  css.remove(this.element.knob, 'notnull')
@@ -265,12 +263,12 @@ class Slider {
265
263
  updateValue (value) {
266
264
  this.initTrackSize()
267
265
 
268
- var size = offset(this.element.track, 'width')
266
+ let size = offset(this.element.track, 'width')
269
267
  size = parseInt(size)
270
268
 
271
- var range = this.options.range[1] - this.options.range[0]
272
- var ratio = value * 100 / range
273
- var position = Math.round(size * ratio / 100)
269
+ const range = this.options.range[1] - this.options.range[0]
270
+ const ratio = value * 100 / range
271
+ const position = Math.round(size * ratio / 100)
274
272
 
275
273
  this.update(position)
276
274
 
@@ -284,7 +282,7 @@ class Slider {
284
282
  * @return {?} [description]
285
283
  */
286
284
  insert (container, context) {
287
- insert(this.root, container, context)
285
+ insert(this.element, container, context)
288
286
  }
289
287
 
290
288
  /**
@@ -313,7 +311,7 @@ class Slider {
313
311
  * @param {string} value
314
312
  */
315
313
  get (prop) {
316
- var value
314
+ let value
317
315
 
318
316
  switch (prop) {
319
317
  case 'value':
package/src/snackbar.js CHANGED
@@ -1,69 +1,90 @@
1
- 'use strict'
2
-
3
- // import modules
4
- import init from './component/init'
5
- import create from './element/create'
6
- import insert from './component/insert'
7
- import classify from './component/classify'
8
- // import components
9
- import Layout from './layout'
10
-
11
- let defaults = {
12
- prefix: 'material',
13
- class: 'snackbar',
14
- delay: 2000,
15
- theme: 'dark'
16
- }
1
+ // base class
2
+ import EventEmitter from './mixin/emitter'
3
+ // related modules
4
+ import build from './module/build'
5
+ import bindEvents from './module/events'
6
+ import display from './mixin/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
+ };
17
27
 
18
- class Snackbar {
19
- /**
20
- * Constructor
21
- * @param {Object} options - Component options
22
- * @return {Object} Class instance
23
- */
24
28
  constructor (options) {
25
- this.options = Object.assign({}, defaults, options || {})
29
+ super()
26
30
 
27
- this.init()
28
- this.build()
31
+ this.init(options)
32
+ this.build(this.constructor)
33
+ this.render()
34
+ this.bindEvents()
29
35
  this.show()
36
+
37
+ if (this.options.duration)
38
+ setTimeout(()=>{
39
+ this.destroy()
40
+ }, this.options.duration)
30
41
  }
31
42
 
32
- init () {
33
- Object.assign(this, insert)
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)
34
48
  }
35
49
 
36
- /**
37
- * build the component using the super method
38
- * @return {Object} The class instance
39
- */
40
- build () {
41
- var tag = this.options.tag || 'div'
50
+ buildSnackbarContainer (container = document.body) {
51
+ // console.log('buildSnackbarContainer', container)
52
+
53
+ let snackbarContainer = container.querySelector('.snackbars')
42
54
 
43
- this.root = create(tag)
44
- classify(this.root, this.options)
55
+ // console.log('snackbarContainer', snackbarContainer)
45
56
 
46
- this.layout = new Layout(this.options.layout, this.root)
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
+ }
47
64
  }
48
65
 
49
- /**
50
- *
51
- * @return {[type]} [description]
52
- */
53
- show () {
54
- setTimeout(() => {
55
- this.root.classList.add('show')
56
- }, 10)
57
-
58
- if (this.options.delay) {
59
- setTimeout(() => {
60
- this.hide()
61
- }, this.options.delay)
66
+ render () {
67
+ this.ui.text.set(this.options.text)
68
+
69
+ if (this.options.action) {
70
+ this.ui.action.set(this.options.action)
71
+ this.ui.action.element.classList.add('show')
62
72
  }
73
+
74
+ if (this.options.close) this.ui.close.element.classList.add('show')
75
+
76
+ return this
77
+ }
78
+
79
+ action () {
80
+ // console.log('action')
81
+ this.emit('action')
82
+ this.destroy()
63
83
  }
64
84
 
65
- hide () {
66
- this.root.classList.remove('show')
85
+ close() {
86
+ // console.log('close')
87
+ this.destroy()
67
88
  }
68
89
  }
69
90
 
package/src/switch.js CHANGED
@@ -1,106 +1,125 @@
1
- 'use strict'
1
+ import EventEmitter from './mixin/emitter'
2
2
 
3
- // import control from '../control';
4
- // import control from './component/control'
5
- import build from './element/build'
6
- import emitter from './module/emitter'
7
- import insert from './component/insert'
3
+ // module
4
+ import build from './module/build'
5
+ import dataset from './module/dataset'
8
6
  import attach from './module/attach'
9
- import classify from './component/classify'
10
-
11
- let defaults = {
12
- prefix: 'material',
13
- class: 'switch',
14
- type: 'control',
15
- label: null,
16
- checked: false,
17
- error: false,
18
- value: false,
19
- disabled: false,
20
- build: ['$root.material-switch', {},
21
- ['input$input$switch-input', { type: 'checkbox' }],
22
- ['span$control.switch-control', {},
23
- ['span$track.switch-track', {},
24
- ['span$knob.switch-knob', {}]
7
+ import attributes from './module/attributes'
8
+
9
+ // ui
10
+ import Layout from './layout'
11
+ import Element from './element'
12
+
13
+ class Switch extends EventEmitter {
14
+ static defaults = {
15
+ class: 'switch',
16
+ attributes: ['type', 'name', 'required', 'checked'],
17
+ layout: [
18
+ [Element, 'input', { class: 'input', type: 'checkbox' }],
19
+ [Element, 'control', { class: 'control' },
20
+ [Element, 'track', { class: 'track' },
21
+ [Element, 'knob', { class: 'knob' }]
22
+ ]
25
23
  ]
26
24
  ],
27
- ['label$label.switch-label']
28
- ],
29
- events: [
30
- ['element.control.click', 'toggle'],
31
- // ['element.label.click', 'toggle'],
32
- // for accessibility purpose
33
- ['element.input.click', 'toggle'],
34
- ['element.input.focus', 'focus'],
35
- ['element.input.blur', 'blur']
36
- // ['element.input.keydown', 'keydown']
37
- ]
38
- }
25
+ events: [
26
+ ['ui.control.click', 'toggle'],
27
+ // ['ui.label.click', 'toggle'],
28
+ // for accessibility purpose
29
+ ['ui.input.click', 'toggle'],
30
+ ['ui.input.focus', 'focus'],
31
+ ['ui.input.blur', 'blur']
32
+ ]
33
+ }
39
34
 
40
- /**
41
- * Switch class
42
- * @class
43
- * @extends Control
44
- */
45
- class Switch {
46
- /**
47
- * Constructor
48
- * @param {Object} options
49
- - Component options
50
- * @return {Object} Class instance
51
- */
52
35
  constructor (options) {
36
+ super()
37
+
53
38
  this.init(options)
54
39
  this.build()
40
+ this.setup()
55
41
  this.attach()
56
-
57
- return this
58
42
  }
59
43
 
60
- /**
61
- * Constructor
62
- * @param {Object} options The class options
63
- * @return {Object} This class instance
64
- */
65
44
  init (options) {
66
- this.options = Object.assign({}, defaults, options || {})
67
- Object.assign(this, emitter, attach, insert)
45
+ this.options = Object.assign({}, Switch.defaults, options || {})
46
+ Object.assign(this, build, attach, dataset)
68
47
 
69
48
  this.value = this.options.value
70
-
71
- return this
72
49
  }
73
50
 
74
- /**
75
- * build method
76
- * @return {Object} The class instance
77
- */
78
- build () {
79
- this.element = build(this.options.build)
80
- this.root = this.element.root
51
+ setup () {
52
+ this.styleAttributes()
81
53
 
82
- classify(this.root, this.options)
54
+ this.buildIcon()
55
+ this.buildLabel()
83
56
 
84
- if (this.options.disabled) {
85
- this.disable()
57
+ if (this.options.data) {
58
+ dataset(this.root, this.options.data)
59
+ }
60
+
61
+ // console.log('attribute', this.ui.input, this.options)
62
+ attributes(this.ui.input, this.options)
63
+
64
+ if (this.options.checked) {
65
+ this.check(true)
86
66
  }
87
67
 
88
68
  if (this.value) {
89
69
  this.element.input.setAttribute('checked', 'checked')
90
70
  }
91
71
 
92
- this.element.input.setAttribute('aria-label', this.options.name)
72
+ if (this.options.tooltip) {
73
+ this.element.setAttribute('data-tooltip', this.options.tooltip)
74
+ }
93
75
 
94
- let text = this.options.label || this.options.text || ''
76
+ this.ui.input.setAttribute('aria-label', this.options.name)
95
77
 
96
- this.element.label.textContent = text
97
- this.element.label.setAttribute('for', this.options.name)
98
- if (this.options.checked) {
99
- this.check(true)
78
+ if (this.options.case) {
79
+ this.element.classList.add(this.options.case + '-case')
100
80
  }
81
+ }
82
+
83
+ buildLabel () {
84
+ // console.log('buildLabel', this.options.label)
85
+ if (!this.options.label) return
101
86
 
102
- if (this.options.container) {
103
- this.insert(this.options.container)
87
+ this.ui.label = document.createElement('label')
88
+ this.ui.label.classList.add('label')
89
+ this.ui.label.innerHTML = this.options.label
90
+
91
+ if (this.options.name) {
92
+ this.ui.label.setAttribute('for', this.options.name)
93
+ }
94
+
95
+ this.element.insertBefore(this.ui.label, this.ui.input)
96
+ }
97
+
98
+ buildIcon () {
99
+ if (!this.options.icon) return
100
+
101
+ this.ui.icon = document.createElement('i')
102
+ this.ui.icon.classList.add('icon')
103
+ this.ui.icon.innerHTML = this.options.icon
104
+
105
+ this.element.insertBefore(this.ui.icon, this.ui.input)
106
+ }
107
+
108
+ styleAttributes () {
109
+ if (this.options.style) {
110
+ this.element.classList.add('style-' + this.options.style)
111
+ }
112
+
113
+ if (this.options.size) {
114
+ this.element.classList.add(this.options.size + '-size')
115
+ }
116
+
117
+ if (this.options.color) {
118
+ this.element.classList.add('color-' + this.options.color)
119
+ }
120
+
121
+ if (this.options.bold) {
122
+ this.element.classList.add('bold')
104
123
  }
105
124
  }
106
125
 
@@ -115,6 +134,9 @@ class Switch {
115
134
  case 'value':
116
135
  this.setValue(value, silent)
117
136
  break
137
+ case 'text':
138
+ this.setValue(value)
139
+ break
118
140
  case 'disabled':
119
141
  if (value === true) {
120
142
  this.disable()
@@ -129,31 +151,29 @@ class Switch {
129
151
  return this
130
152
  }
131
153
 
154
+ setLabel (value) {
155
+ // console.log('setLabel', value)
156
+ if (this.ui.label) {
157
+ this.ui.label.innerHTML = value
158
+ }
159
+ }
160
+
161
+ setText (value) {
162
+ this.setLabel(value)
163
+ }
164
+
132
165
  get () {
133
166
  return this.value
134
167
  }
135
168
 
136
- /**
137
- * set switch value
138
- * @param {boolean} value [description]
139
- */
140
169
  getValue () {
141
170
  return this.value
142
171
  }
143
172
 
144
- /**
145
- * set switch value
146
- * @param {boolean} value [description]
147
- */
148
173
  setValue (value, silent) {
149
- // console.log('setValue', value)
150
174
  this.check(value, silent)
151
175
  }
152
176
 
153
- /**
154
- * [toggle description]
155
- * @return {Object} The class instance
156
- */
157
177
  toggle () {
158
178
  if (this.disabled) return
159
179
 
@@ -168,23 +188,19 @@ class Switch {
168
188
  return this
169
189
  }
170
190
 
171
- /**
172
- * Set checkbox value
173
- * @param {boolean} value [description]
174
- */
175
191
  check (checked, silent) {
176
192
  // console.log('check', checked, silent)
177
193
  if (checked === true) {
178
- this.root.classList.add('is-checked')
179
- this.element.input.checked = true
194
+ this.element.classList.add('is-checked')
195
+ this.ui.input.checked = true
180
196
  this.checked = true
181
197
  this.value = true
182
198
  if (!silent) {
183
199
  this.emit('change', this.checked)
184
200
  }
185
201
  } else {
186
- this.root.classList.remove('is-checked')
187
- this.element.input.checked = false
202
+ this.element.classList.remove('is-checked')
203
+ this.ui.input.checked = false
188
204
  this.checked = false
189
205
  this.value = false
190
206
  if (!silent) {
@@ -194,24 +210,16 @@ class Switch {
194
210
  return this
195
211
  }
196
212
 
197
- /**
198
- * [_onInputFocus description]
199
- * @return {?} [description]
200
- */
201
213
  focus () {
202
214
  if (this.disabled === true) return this
203
215
 
204
- this.root.classList.add('is-focused')
205
- if (this.element.input !== document.activeElement) { this.element.input.focus() }
216
+ this.element.classList.add('is-focused')
217
+ if (this.ui.input !== document.activeElement) { this.ui.input.focus() }
206
218
  return this
207
219
  }
208
220
 
209
- /**
210
- * [_onInputBlur description]
211
- * @return {?} [description]
212
- */
213
221
  blur () {
214
- this.root.classList.remove('is-focused')
222
+ this.element.classList.remove('is-focused')
215
223
  return this
216
224
  }
217
225
  }