material 0.4.2 → 0.5.0

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 (168) hide show
  1. package/dist/tracks.svg +10 -0
  2. package/package.json +1 -1
  3. package/src/appbar.js +1 -2
  4. package/src/control/button.js +263 -0
  5. package/src/control/button.new.js +190 -0
  6. package/src/control/datehour.js +65 -0
  7. package/src/control/dialog.js +174 -0
  8. package/src/control/file.js +123 -0
  9. package/src/control/image.js +92 -0
  10. package/src/control/link.js +61 -0
  11. package/src/control/list.js +77 -0
  12. package/src/control/loading.js +128 -0
  13. package/src/control/module/addclass.js +16 -0
  14. package/src/control/module/attributes.js +21 -0
  15. package/src/control/search.js +98 -0
  16. package/src/control/select.js +130 -0
  17. package/src/control/selecter.js +246 -0
  18. package/src/control/switch.js +272 -0
  19. package/src/control/switcher.js +245 -0
  20. package/src/control/text.js +66 -0
  21. package/src/control/textfield.js +177 -0
  22. package/src/field/image.js +9 -3
  23. package/src/form/build.js +60 -6
  24. package/src/form/cancel.js +7 -3
  25. package/src/form/controller.js +90 -0
  26. package/src/form/create.js +12 -6
  27. package/src/form/data.js +82 -0
  28. package/src/form/delete.js +2 -1
  29. package/src/form/fetch.js +30 -0
  30. package/src/form/render.js +14 -19
  31. package/src/form/set.js +27 -12
  32. package/src/form/submit.js +24 -49
  33. package/src/form/update.js +46 -0
  34. package/src/layout.js +26 -22
  35. package/src/list/add.js +34 -0
  36. package/src/list/build.js +100 -6
  37. package/src/list/click.js +10 -5
  38. package/src/list/collection.js +187 -0
  39. package/src/list/create.js +21 -11
  40. package/src/list/display.js +78 -0
  41. package/src/list/empty.js +4 -1
  42. package/src/list/filter.js +114 -0
  43. package/src/list/load.js +2 -2
  44. package/src/list/remove.js +17 -4
  45. package/src/list/render.js +32 -9
  46. package/src/list/request.js +182 -0
  47. package/src/list/search.js +118 -35
  48. package/src/list/select.js +151 -30
  49. package/src/list/status.js +10 -3
  50. package/src/list/update.js +49 -8
  51. package/src/list/virtual.js +195 -127
  52. package/src/map/build.js +103 -0
  53. package/src/map/countries.js +114 -0
  54. package/src/map/display.js +135 -0
  55. package/src/map/focus.js +39 -0
  56. package/src/map/init.js +24 -0
  57. package/src/map/label.js +0 -0
  58. package/src/map/mode.js +44 -0
  59. package/src/map/mouse.js +65 -0
  60. package/src/map/select.js +68 -0
  61. package/src/map/set.js +71 -0
  62. package/src/map/viewport.js +46 -0
  63. package/src/map.js +71 -0
  64. package/src/module/attach.js +15 -16
  65. package/src/module/extract.js +35 -28
  66. package/src/module/mediator.js +56 -0
  67. package/src/module/object.js +17 -1
  68. package/src/module/observer.js +1 -1
  69. package/src/module/passive.js +17 -0
  70. package/src/module/remove.js +74 -0
  71. package/src/module/scrollbar.js +48 -0
  72. package/src/module/smoothscroll.js +20 -0
  73. package/src/module/viewport.js +20 -0
  74. package/src/selector.js +239 -0
  75. package/src/skin/material/base/body.sass +3 -0
  76. package/src/skin/material/button/file.sass +1 -1
  77. package/src/skin/material/container/container.sass +1 -1
  78. package/src/skin/material/container/dialog.sass +57 -1
  79. package/src/skin/material/container/drawer.sass +3 -3
  80. package/src/skin/material/control/button.sass +125 -0
  81. package/src/skin/material/control/dialog.sass +0 -0
  82. package/src/skin/material/control/progress.sass +136 -0
  83. package/src/skin/material/control/search.sass +40 -0
  84. package/src/skin/material/control/selecter.sass +131 -0
  85. package/src/skin/material/control/selector.sass +38 -0
  86. package/src/skin/material/control/slider.sass +2 -2
  87. package/src/skin/material/control/switch.sass +146 -3
  88. package/src/skin/material/control/switcher.sass +41 -0
  89. package/src/skin/material/control/textfield.sass +2 -1
  90. package/src/skin/material/icon/cancel.svg +1 -0
  91. package/src/skin/material/material.sass +3 -0
  92. package/src/skin/material/view/list.sass +81 -188
  93. package/src/skin/material/view/listview.sass +187 -96
  94. package/src/skin/material/view/tabview.sass +7 -5
  95. package/src/skin/material.bak/base/body.sass +52 -0
  96. package/src/skin/material.bak/base/elevation.sass +50 -0
  97. package/src/skin/material.bak/base/grid.sass +63 -0
  98. package/src/skin/material.bak/base/typo.sass +107 -0
  99. package/src/skin/material.bak/button/action.sass +89 -0
  100. package/src/skin/material.bak/button/button.sass +183 -0
  101. package/src/skin/material.bak/button/file.sass +24 -0
  102. package/src/skin/material.bak/button/floating.sass +113 -0
  103. package/src/skin/material.bak/button/raised.sass +101 -0
  104. package/src/skin/material.bak/button/stroked.sass +71 -0
  105. package/src/skin/material.bak/component/component.sass +7 -0
  106. package/src/skin/material.bak/component/divider.sass +17 -0
  107. package/src/skin/material.bak/component/image.sass +6 -0
  108. package/src/skin/material.bak/component/label.sass +2 -0
  109. package/src/skin/material.bak/component/progress.sass +138 -0
  110. package/src/skin/material.bak/component/subheader.sass +3 -0
  111. package/src/skin/material.bak/component/text.sass +85 -0
  112. package/src/skin/material.bak/container/appbar.sass +167 -0
  113. package/src/skin/material.bak/container/banner.sass +38 -0
  114. package/src/skin/material.bak/container/card.sass +18 -0
  115. package/src/skin/material.bak/container/container.sass +1 -0
  116. package/src/skin/material.bak/container/dialog.sass +184 -0
  117. package/src/skin/material.bak/container/drawer.sass +159 -0
  118. package/src/skin/material.bak/container/drawernew.sass +159 -0
  119. package/src/skin/material.bak/container/menu.sass +58 -0
  120. package/src/skin/material.bak/container/snackbar.sass +18 -0
  121. package/src/skin/material.bak/container/tabs.sass +75 -0
  122. package/src/skin/material.bak/container/toolbar.sass +161 -0
  123. package/src/skin/material.bak/control/button.sass +125 -0
  124. package/src/skin/material.bak/control/checkbox.sass +105 -0
  125. package/src/skin/material.bak/control/dialog.sass +0 -0
  126. package/src/skin/material.bak/control/search.sass +40 -0
  127. package/src/skin/material.bak/control/selecter.sass +128 -0
  128. package/src/skin/material.bak/control/slider.sass +181 -0
  129. package/src/skin/material.bak/control/switch.sass +284 -0
  130. package/src/skin/material.bak/control/switcher.sass +35 -0
  131. package/src/skin/material.bak/control/textfield.sass +126 -0
  132. package/src/skin/material.bak/control/tooltip.sass +36 -0
  133. package/src/skin/material.bak/icon/back.svg +5 -0
  134. package/src/skin/material.bak/icon/cancel.svg +1 -0
  135. package/src/skin/material.bak/icon/checkbox.svg +4 -0
  136. package/src/skin/material.bak/icon/forward.svg +5 -0
  137. package/src/skin/material.bak/icon/menu.svg +4 -0
  138. package/src/skin/material.bak/icon/pin.svg +4 -0
  139. package/src/skin/material.bak/layout/layout.sass +69 -0
  140. package/src/skin/material.bak/layout/resizer.sass +69 -0
  141. package/src/skin/material.bak/material.css +2042 -0
  142. package/src/skin/material.bak/material.css.map +7 -0
  143. package/src/skin/material.bak/material.sass +65 -0
  144. package/src/skin/material.bak/module/ripple.sass +9 -0
  145. package/src/skin/material.bak/theme/default.sass +50 -0
  146. package/src/skin/material.bak/theme/ocean.sass +29 -0
  147. package/src/skin/material.bak/theme/theme.sass +3 -0
  148. package/src/skin/material.bak/view/calendar.sass +193 -0
  149. package/src/skin/material.bak/view/form.sass +15 -0
  150. package/src/skin/material.bak/view/grid.sass +116 -0
  151. package/src/skin/material.bak/view/list.sass +89 -0
  152. package/src/skin/material.bak/view/listview.sass +195 -0
  153. package/src/skin/material.bak/view/map.sass +6 -0
  154. package/src/skin/material.bak/view/page.sass +4 -0
  155. package/src/skin/material.bak/view/tabview-bak.sass +40 -0
  156. package/src/skin/material.bak/view/tabview.sass +55 -0
  157. package/src/skin/material.bak/view/tree.sass +73 -0
  158. package/src/skin/material.bak/view/view.sass +7 -0
  159. package/src/switch.js +1 -1
  160. package/src/tabs/setup.js +0 -0
  161. package/src/tabview.js +64 -14
  162. package/src/tooltip.js +23 -5
  163. package/src/view/build.js +15 -3
  164. package/src/view/display.js +79 -7
  165. package/src/form/clean.js +0 -6
  166. package/src/form/mode.js +0 -16
  167. package/src/form/setup.js +0 -30
  168. package/src/list/fetch.js +0 -66
@@ -0,0 +1,130 @@
1
+ import emitter from '..//module/emitter'
2
+ import attach from '../module/attach'
3
+ import attributes from './module/attributes'
4
+ import dataset from '../view/dataset'
5
+
6
+ const defaults = {
7
+ type: 'list', // native
8
+ class: 'select',
9
+ first: null,
10
+ attributes: ['type', 'name', 'autocomplete', 'required']
11
+ }
12
+
13
+ class Select {
14
+ /**
15
+ * Constructor
16
+ * @param {Object} options - Component options
17
+ * @return {Object} Class instance
18
+ */
19
+ constructor (options) {
20
+ this.options = Object.assign({}, defaults, options || {})
21
+ Object.assign(this, emitter, attach, dataset)
22
+
23
+ this.build()
24
+ this.attach()
25
+
26
+ return this
27
+ }
28
+
29
+ /**
30
+ * Build Method
31
+ * @return {Object} This class instance
32
+ */
33
+ build () {
34
+ var tag = this.options.tag || 'span'
35
+ this.root = document.createElement(tag)
36
+ this.root.classList.add('select')
37
+
38
+ if (this.options.class !== 'select') {
39
+ this.root.classList.add(this.options.class)
40
+ }
41
+
42
+ this.buildLabel()
43
+ this.buildInput()
44
+
45
+ if (this.container) {
46
+ this.container.appendChild(this.root)
47
+ }
48
+
49
+ return this
50
+ }
51
+
52
+ buildLabel () {
53
+ if (this.options.label) {
54
+ this.label = document.createElement('span')
55
+ this.label.classList.add('label')
56
+ this.label.innerHTML = this.options.label
57
+ this.root.appendChild(this.label)
58
+ }
59
+ }
60
+
61
+ buildInput () {
62
+ this.input = document.createElement('select')
63
+ this.input.classList.add('input')
64
+ this.root.appendChild(this.input)
65
+
66
+ this.input.addEventListener('change', () => {
67
+ // console.log('change', this.input[this.input.selectedIndex].value)
68
+ this.emit('change', this.input[this.input.selectedIndex].value)
69
+ })
70
+
71
+ if (this.options.data) {
72
+ dataset(this.data, this.options.data)
73
+ }
74
+
75
+ attributes(this.input, this.options)
76
+
77
+ if (this.options.options) {
78
+ this.setOptions(this.options.options)
79
+ }
80
+ }
81
+
82
+ setOptions (options) {
83
+ // console.log('buildCountry', this.input)
84
+
85
+ var first = this.options.first
86
+
87
+ if (first && first[0] && first[1]) {
88
+ this.input.options[0] = new Option(first[1], first[0])
89
+ }
90
+
91
+ for (var i = 0; i < options.length; i++) {
92
+ this.addOption(options[i][1], options[i][0])
93
+ }
94
+ }
95
+
96
+ addOption (name, value) {
97
+ // console.log('addOption', name, value)
98
+ this.input.options[this.input.options.length] = new Option(name, value)
99
+ }
100
+
101
+ set (value) {
102
+ // console.log('set', value)
103
+ this.input.value = value
104
+
105
+ return this
106
+ }
107
+
108
+ setLabel (value) {
109
+ console.log('setLabel', value)
110
+ if (this.label) {
111
+ this.label.innerHTML = value
112
+ }
113
+ }
114
+
115
+ setText (value) {
116
+ this.setLabel(value)
117
+ }
118
+
119
+ get () {
120
+ var value = null
121
+
122
+ if (this.input[this.input.selectedIndex]) {
123
+ value = this.input[this.input.selectedIndex].value
124
+ }
125
+
126
+ return value
127
+ }
128
+ }
129
+
130
+ export default Select
@@ -0,0 +1,246 @@
1
+ import emitter from '..//module/emitter'
2
+ import attach from '../module/attach'
3
+ import dataset from '../view/dataset'
4
+ import attributes from './module/attributes'
5
+ import addClass from './module/addclass'
6
+
7
+ // ui
8
+ import Layout from '../layout'
9
+ import Element from '../element'
10
+ import Button from './button'
11
+
12
+ const defaults = {
13
+ class: 'selecter',
14
+ first: null,
15
+ attributes: ['type', 'name', 'autocomplete', 'required'],
16
+ layout: [
17
+ [Element, 'label', { tag: 'label', class: 'label' }],
18
+ [Element, 'value', { tag: 'value', class: 'value' }],
19
+ [Element, 'input', { tag: 'input', type: 'text', class: 'input' }],
20
+ [Element, 'list', { class: 'list' },
21
+ [Element, 'head', { class: 'head' },
22
+ [Element, 'title', { class: 'title' }],
23
+ [Button, 'close', { class: 'close' }]
24
+ ],
25
+ [Element, 'body', { class: 'body' }]
26
+ ]
27
+ ],
28
+ events: [
29
+ ['ui.value.click', 'showList'],
30
+ ['ui.list.click', 'select'],
31
+ ['ui.close.click', 'hideList']
32
+ ]
33
+ }
34
+
35
+ class Selecter {
36
+ /**
37
+ * Constructor
38
+ * @param {Object} options - Component options
39
+ * @return {Object} Class instance
40
+ */
41
+ constructor (options) {
42
+ this.options = Object.assign({}, defaults, options || {})
43
+ Object.assign(this, emitter, attach, dataset)
44
+
45
+ this.build()
46
+ this.setup()
47
+ this.attach()
48
+
49
+ return this
50
+ }
51
+
52
+ setup () {
53
+ if (this.options.data) {
54
+ dataset(this.root, this.options.data)
55
+ }
56
+
57
+ // console.log('attribute', this.ui.input, this.options)
58
+ attributes(this.ui.input, this.options)
59
+
60
+ if (this.value) {
61
+ this.element.input.setAttribute('checked', 'checked')
62
+ }
63
+
64
+ if (this.options.tooltip) {
65
+ this.root.setAttribute('data-tooltip', this.options.tooltip)
66
+ }
67
+
68
+ if (this.options.label) {
69
+ this.setLabel(this.options.label)
70
+ }
71
+
72
+ this.ui.input.setAttribute('aria-label', this.options.name)
73
+
74
+ if (this.options.case) {
75
+ this.root.classList.add(this.options.case + '-case')
76
+ }
77
+ }
78
+ /**
79
+ * build method
80
+ * @return {Object} The class instance
81
+ */
82
+ build () {
83
+ var tag = this.options.tag || 'span'
84
+ this.root = document.createElement(tag)
85
+ this.root.classList.add('selecter')
86
+
87
+ if (this.options.class !== 'selecter') {
88
+ addClass(this.root, this.options.class)
89
+ }
90
+
91
+ this.layout = new Layout(this.options.layout, this.root)
92
+ this.ui = this.layout.component
93
+
94
+ // console.log('ui', this.ui)
95
+
96
+ this.styleAttributes()
97
+
98
+ this.buildIcon(this.options.icon)
99
+ this.setList(this.options.list)
100
+
101
+ if (this.options.container) {
102
+ this.options.container.appendChild(this.root)
103
+ }
104
+ }
105
+
106
+ buildIcon (icon) {
107
+ if (!icon) return
108
+
109
+ this.ui.icon = document.createElement('i')
110
+ this.ui.icon.classList.add('icon')
111
+ this.ui.icon.innerHTML = this.options.icon
112
+
113
+ this.root.insertBefore(this.ui.icon, this.ui.input)
114
+ }
115
+
116
+ buildInput () {
117
+ this.input = document.createElement('select')
118
+ this.input.classList.add('input')
119
+ this.root.appendChild(this.input)
120
+
121
+ this.input.addEventListener('change', () => {
122
+ // console.log('change', this.input[this.input.selectedIndex].value)
123
+ this.emit('change', this.input[this.input.selectedIndex].value)
124
+ })
125
+
126
+ if (this.options.data) {
127
+ dataset(this.data, this.options.data)
128
+ }
129
+
130
+ attributes(this.input, this.options)
131
+ }
132
+
133
+ setList (list) {
134
+ // console.log('setList', list)
135
+ if (!list) return
136
+
137
+ this.values = {}
138
+
139
+ // console.log('list', list)
140
+
141
+ for (var i = 0; i < list.length; i++) {
142
+ // if (list.indexOf(list[i][0]) > -1) {
143
+ var item = document.createElement('div')
144
+ item.classList.add('item')
145
+ item.innerHTML = list[i][1]
146
+ item.dataset.value = list[i][0]
147
+
148
+ this.values[list[i][0]] = list[i][1]
149
+
150
+ this.ui.body.appendChild(item)
151
+ // }
152
+ }
153
+ }
154
+
155
+ styleAttributes () {
156
+ if (this.options.style) {
157
+ this.root.classList.add('style-' + this.options.style)
158
+ }
159
+
160
+ if (this.options.size) {
161
+ this.root.classList.add(this.options.size + '-size')
162
+ }
163
+
164
+ if (this.options.color) {
165
+ this.root.classList.add('color-' + this.options.color)
166
+ }
167
+
168
+ if (this.options.bold) {
169
+ this.root.classList.add('bold')
170
+ }
171
+ }
172
+ showList () {
173
+ // console.log('showList')
174
+
175
+ this.ui.list.classList.add('show')
176
+ }
177
+
178
+ hideList () {
179
+ // console.log('hideList')
180
+
181
+ this.ui.list.classList.remove('show')
182
+ }
183
+
184
+ select (e) {
185
+ // console.log('select', e.target)
186
+
187
+ e.preventDefault()
188
+
189
+ if (e && e.target && e.target.dataset.value) {
190
+ if (this.selected) {
191
+ this.selected.classList.remove('selected')
192
+ }
193
+ this.selected = e.target
194
+ this.selected.classList.add('selected')
195
+
196
+ this.value = e.target.dataset.value
197
+ // console.log('value', e.target.dataset.value)
198
+ this.ui.value.innerHTML = this.values[this.value]
199
+ this.emit('change', this.value)
200
+ }
201
+
202
+ if (this.options.type !== 'listonly') {
203
+ this.hideList()
204
+ }
205
+ }
206
+
207
+ addOption (name, value) {
208
+ this.input.options[this.input.options.length] = new Option(name, value)
209
+ }
210
+
211
+ set (value) {
212
+ // console.log('set', value, this.values)
213
+
214
+ this.ui.input.value = value
215
+ if (this.values) {
216
+ this.ui.value.innerHTML = this.values[value]
217
+ }
218
+
219
+ this.selected = this.root.querySelector('[data-value=' + value + ']')
220
+
221
+ // console.log('item', this.selected)
222
+ if (this.selected) {
223
+ this.selected.classList.add('selected')
224
+ }
225
+
226
+ return this
227
+ }
228
+
229
+ setLabel (value) {
230
+ // console.log('setLabel', value)
231
+ if (this.ui.label) {
232
+ this.ui.label.innerHTML = value
233
+ this.ui.title.innerHTML = value
234
+ }
235
+ }
236
+
237
+ setText (value) {
238
+ this.setLabel(value)
239
+ }
240
+
241
+ get () {
242
+ return this.value
243
+ }
244
+ }
245
+
246
+ export default Selecter
@@ -0,0 +1,272 @@
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