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,123 @@
1
+ import emitter from '../module/emitter'
2
+ import dataset from '../view/dataset'
3
+ import attributes from './module/attributes'
4
+
5
+ const defaults = {
6
+ class: 'file',
7
+ attributes: ['name', 'accept', 'required', 'disabled', 'multiple']
8
+ }
9
+
10
+ class File {
11
+ /**
12
+ * Constructor
13
+ * @param {Object} options - Component options
14
+ * @return {Object} Class instance
15
+ */
16
+ constructor (options) {
17
+ this.options = Object.assign({}, defaults, options || {})
18
+ Object.assign(this, emitter)
19
+
20
+ this.build()
21
+ this.attach()
22
+
23
+ return this
24
+ }
25
+
26
+ /**
27
+ * Build Method
28
+ * @return {Object} This class instance
29
+ */
30
+ build () {
31
+ this.root = document.createElement('div')
32
+ this.root.classList.add('file')
33
+
34
+ if (this.options.class !== 'file') {
35
+ this.root.classList.add(this.options.class)
36
+ }
37
+
38
+ this.buildLabel()
39
+ this.buildInput()
40
+
41
+ if (this.options.data) {
42
+ dataset(this.root, this.options.data)
43
+ }
44
+
45
+ if (this.options.focus) {
46
+ this.input.focus()
47
+ }
48
+
49
+ if (this.options.container) {
50
+ this.options.container.appendChild(this.root)
51
+ }
52
+
53
+ return this
54
+ }
55
+
56
+ buildLabel () {
57
+ if (this.options.label) {
58
+ this.label = document.createElement('label')
59
+ this.label.classList.add('label')
60
+ this.label.innerHTML = this.options.label
61
+ this.root.appendChild(this.label)
62
+ }
63
+ }
64
+
65
+ buildInput () {
66
+ this.field = document.createElement('div')
67
+ this.field.classList.add('field')
68
+ this.root.appendChild(this.field)
69
+
70
+ this.input = document.createElement('input')
71
+ this.input.setAttribute('type', 'file')
72
+ this.root.appendChild(this.input)
73
+
74
+ attributes(this.input, this.options)
75
+
76
+ this.field.appendChild(this.input)
77
+
78
+ if (this.options.focus) {
79
+ this.input.focus()
80
+ }
81
+ }
82
+
83
+ attach () {
84
+ this.input.addEventListener('change', (e) => {
85
+ this.emit('change', e)
86
+ })
87
+ }
88
+
89
+ image (e) {
90
+ // console.log('image', e.target)
91
+ // if (input.files && input.files[0]) {
92
+ // var reader = new FileReader()
93
+
94
+ // reader.onload = (e) => {
95
+ // cover.style.backgroundImage = 'url("' + e.target.result + '")'
96
+ // }
97
+
98
+ // reader.readAsDataURL(input.files[0])
99
+ // }
100
+ }
101
+
102
+ reset () {
103
+ // console.log('reset')
104
+ this.input.value = ''
105
+ }
106
+
107
+ set (image) {
108
+ // console.log('set', image)
109
+ }
110
+
111
+ setLabel (value) {
112
+ // console.log('setLabel', value)
113
+ if (this.label) {
114
+ this.label.innerHTML = value
115
+ }
116
+ }
117
+
118
+ setText (value) {
119
+ this.setLabel(value)
120
+ }
121
+ }
122
+
123
+ export default File
@@ -0,0 +1,92 @@
1
+
2
+ const defaults = {
3
+ class: 'image',
4
+ tag: 'div',
5
+ format: 'thumb'
6
+ }
7
+
8
+ /**
9
+ * Class representing an image.
10
+ *
11
+ * @extends Image
12
+ * @return {parent} The class instance
13
+ * @example new Image({
14
+ * src: {
15
+ * filename: 'image.png',
16
+ * url: 'exmaple.com/image/'
17
+ * format: ['thumbs/', 'medium/', 'large/'],
18
+ * },
19
+ * container: document.body
20
+ * });
21
+ */
22
+ class Image {
23
+ /**
24
+ * Constructor
25
+ * @param {Object} options - Component options
26
+ * @return {Object} Class instance
27
+ */
28
+ constructor (options) {
29
+ this.options = Object.assign({}, defaults, options || {})
30
+
31
+ this.build()
32
+
33
+ return this
34
+ }
35
+
36
+ /**
37
+ * Build Method
38
+ * @return {Object} This class instance
39
+ */
40
+ build () {
41
+ this.root = document.createElement(this.options.tag)
42
+ this.root.classList.add(this.options.class)
43
+ if (this.options.class !== 'image') {
44
+ this.root.classList.add('image')
45
+ }
46
+
47
+ if (this.options.container) {
48
+ this.options.container.appendChild(this.root)
49
+ }
50
+
51
+ return this
52
+ }
53
+
54
+ set (src) {
55
+ // console.log('set', src)
56
+ if (!src) {
57
+ this.root.style.backgroundImage = ''
58
+ } else {
59
+ var url = null
60
+
61
+ if (src.format) {
62
+ var format = this.sanitize(src.format)
63
+
64
+ if (format.length > 0) {
65
+ var index = format.indexOf(this.options.format)
66
+ if (index === -1) {
67
+ format = src.format[0] + '/'
68
+ } else {
69
+ format = this.options.format + '/'
70
+ }
71
+ }
72
+
73
+ url = src.url + format
74
+ } else {
75
+ url = src.url
76
+ }
77
+
78
+ this.root.style.backgroundImage = 'url(' + url + src.filename + ')'
79
+ }
80
+ }
81
+
82
+ sanitize (formats) {
83
+ var a = []
84
+ for (var i = 0; i < formats.length; i++) {
85
+ var format = formats[i].replace(/\/$/, '')
86
+ a.push(format)
87
+ }
88
+ return a
89
+ }
90
+ }
91
+
92
+ export default Image
@@ -0,0 +1,61 @@
1
+ 'use strict'
2
+
3
+ const defaults = {
4
+ class: 'link',
5
+ tag: 'a'
6
+ }
7
+
8
+ class Link {
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
+ this.build()
18
+
19
+ return this
20
+ }
21
+
22
+ /**
23
+ * Build Method
24
+ * @return {Object} This class instance
25
+ */
26
+ build () {
27
+ this.root = document.createElement(this.options.tag)
28
+ this.root.classList.add(this.options.class)
29
+
30
+ if (this.options.class !== 'link') {
31
+ this.root.classList.add('link')
32
+ }
33
+
34
+ if (this.options.link) {
35
+ this.set(this.options.link)
36
+ }
37
+
38
+ if (this.options.target) {
39
+ this.root.target = this.options.target
40
+ }
41
+
42
+ if (this.options.container) {
43
+ this.options.container.appendChild(this.root)
44
+ }
45
+
46
+ if (this.options.text) {
47
+ this.root.innerHTML = this.options.text
48
+ }
49
+
50
+ return this
51
+ }
52
+
53
+ set (link) {
54
+ // console.log('set', text)
55
+ if (link === undefined) return
56
+
57
+ this.root.href = link
58
+ }
59
+ }
60
+
61
+ export default Link
@@ -0,0 +1,77 @@
1
+ import addClass from './module/addclass'
2
+
3
+ const defaults = {
4
+ class: 'text',
5
+ tag: 'span',
6
+ seprator: ' | '
7
+ }
8
+
9
+ class List {
10
+ /**
11
+ * Constructor
12
+ * @param {Object} options - Component options
13
+ * @return {Object} Class instance
14
+ */
15
+ constructor (options) {
16
+ this.options = Object.assign({}, defaults, options || {})
17
+
18
+ // console.log('options', this.options)
19
+
20
+ this.build()
21
+
22
+ return this
23
+ }
24
+
25
+ /**
26
+ * Build Method
27
+ * @return {Object} This class instance
28
+ */
29
+ build () {
30
+ this.root = document.createElement(this.options.tag)
31
+ addClass(this.root, this.options.class)
32
+
33
+ if (this.options.class !== 'text') {
34
+ this.root.classList.add('text')
35
+ }
36
+
37
+ if (this.options.list) {
38
+ this.set(this.options.list)
39
+ }
40
+
41
+ if (this.options.container) {
42
+ this.options.container.appendChild(this.root)
43
+ }
44
+
45
+ return this
46
+ }
47
+
48
+ set (list) {
49
+ var text = ''
50
+
51
+ for (var i = 0; i < list.length; i++) {
52
+ if (i < list.length - 1) {
53
+ text = text + list[i] + this.options.seprator
54
+ } else {
55
+ text = text + list[i]
56
+ }
57
+ }
58
+
59
+ // console.log('set', text)
60
+ if (text === undefined) return
61
+
62
+ var label = this.options.label || ''
63
+
64
+ this.root.innerHTML = label + text
65
+
66
+ if (this.options.spaceAfter) {
67
+ this.root.innerHTML = this.root.innerHTML + ' '
68
+ }
69
+ }
70
+
71
+ setText (text) {
72
+ // console.log('setText', text)
73
+ this.root.innerHTML = text
74
+ }
75
+ }
76
+
77
+ export default List
@@ -0,0 +1,128 @@
1
+ import emitter from '../module/emitter'
2
+ import attach from '../module/attach'
3
+
4
+ import dataset from '../view/dataset'
5
+
6
+ var defaults = {
7
+ class: 'loading',
8
+ tag: 'div',
9
+ delay: 1000,
10
+ type: 'indeterminate',
11
+ circular: `<svg class="progress" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
12
+ <circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
13
+ </svg>`
14
+ }
15
+
16
+ /**
17
+ * The class represents an item ie for list
18
+ *
19
+ * @class
20
+ * @return {Object} The class instance
21
+ * @example new Item(object);
22
+ */
23
+ class Loading {
24
+ static isComponent () {
25
+ return true
26
+ }
27
+
28
+ /**
29
+ * init
30
+ * @return {Object} The class options
31
+ */
32
+ constructor (options) {
33
+ this.options = Object.assign({}, defaults, options || {})
34
+ Object.assign(this, emitter, attach)
35
+ // console.log('options', options)
36
+
37
+ this.init()
38
+
39
+ return this
40
+ }
41
+
42
+ /**
43
+ * Setter
44
+ * @param {string} prop
45
+ * @param {string} value
46
+ * @return {Object} The class instance
47
+ */
48
+ init () {
49
+ this.build()
50
+ // this.setup()
51
+ // this.attach()
52
+
53
+ if (this.options.container) {
54
+ this.append(this.options.container)
55
+ }
56
+
57
+ return this
58
+ }
59
+
60
+ /**
61
+ * Build function for item
62
+ * @return {Object} This class instance
63
+ */
64
+ build (options) {
65
+ this.root = document.createElement(this.options.tag)
66
+ this.classify()
67
+
68
+ if (this.options.type === 'circular') {
69
+ this.root.innerHTML = this.options.circular
70
+ } if (this.options.type === 'indeterminate') {
71
+ this.bar = document.createElement(this.options.tag)
72
+ this.bar.classList.add('bar')
73
+ this.root.classList.add('type-indeterminate')
74
+ this.root.appendChild(this.bar)
75
+ }
76
+
77
+ return this
78
+ }
79
+
80
+ classify () {
81
+ if (this.options.class !== 'loading') {
82
+ this.root.setAttribute('class', this.options.class + ' ' + this.options.class)
83
+ } else {
84
+ this.root.classList.add(this.options.class)
85
+ }
86
+ }
87
+
88
+ append (container) {
89
+ container = container || this.options.container
90
+ if (this.options.container) {
91
+ container.appendChild(this.root)
92
+ }
93
+ }
94
+
95
+ set (progress) {
96
+ this.bar.setAttribute('style', 'width: ' + progress)
97
+ }
98
+
99
+ show (delay) {
100
+ delay = delay || this.options.delay
101
+
102
+ clearTimeout(this.showTimeout)
103
+ this.showTimeout = setTimeout(() => {
104
+ this.root.classList.add('show')
105
+ }, this.options.delay)
106
+
107
+ this.visible = true
108
+
109
+ return this
110
+ }
111
+
112
+ showNow () {
113
+ this.root.classList.add('show')
114
+
115
+ this.visible
116
+
117
+ return this
118
+ }
119
+
120
+ hide () {
121
+ clearTimeout(this.showTimeout)
122
+ this.root.classList.remove('show')
123
+ this.visible = false
124
+ return this
125
+ }
126
+ };
127
+
128
+ export default Loading
@@ -0,0 +1,16 @@
1
+
2
+ function setClass (element, className) {
3
+ // console.log('attributes', o.attributes, element)
4
+
5
+ if (!element || !className) return
6
+
7
+ let classNames = className.split(' ')
8
+
9
+ for (var i = 0; i < classNames.length; i++) {
10
+ var name = classNames[i]
11
+ element.classList.add(name)
12
+ }
13
+ return element
14
+ }
15
+
16
+ export default setClass
@@ -0,0 +1,21 @@
1
+ const special = ['required', 'disabled', 'multiple', 'checked']
2
+
3
+ function setAttributes (element, o) {
4
+ // console.log('attributes', o.attributes, element)
5
+
6
+ if (!element) return
7
+
8
+ for (var i = 0; i < o.attributes.length; i++) {
9
+ var attribute = o.attributes[i]
10
+
11
+ if (o[attribute] && o[attribute] !== 'undefined') {
12
+ if (special.indexOf(attribute) > -1) {
13
+ element.setAttribute(attribute, attribute)
14
+ } else {
15
+ element.setAttribute(attribute, o[attribute])
16
+ }
17
+ }
18
+ }
19
+ }
20
+
21
+ export default setAttributes
@@ -0,0 +1,98 @@
1
+ // search control
2
+
3
+ import emitter from '../module/emitter'
4
+ import Button from '../control/button'
5
+ import cancel from '../skin/material/icon/cancel.svg'
6
+
7
+ const defaults = {
8
+ class: 'search-input',
9
+ minChar: 4,
10
+ iconCancel: cancel,
11
+ timeout: 200
12
+ }
13
+
14
+ /**
15
+ * Class representing a search input
16
+ *
17
+ * @return {parent} The class instance
18
+ * @example new Search({
19
+ * container: document.body
20
+ * });
21
+ */
22
+ class Search {
23
+ /**
24
+ * Constructor
25
+ * @param {Object} options - Component options
26
+ * @return {Object} Class instance
27
+ */
28
+ constructor (options) {
29
+ this.options = Object.assign({}, defaults, options || {})
30
+ Object.assign(this, emitter)
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
+ this.root = document.createElement('div')
44
+ this.root.classList.add('search')
45
+
46
+ if (this.options.class !== 'search') {
47
+ this.root.classList.add(this.options.class)
48
+ }
49
+
50
+ if (this.options.icon) {
51
+ this.icon = document.createElement('i')
52
+ this.icon.classList.add('icon')
53
+ this.icon.innerHTML = this.options.icon
54
+ this.root.appendChild(this.icon)
55
+ }
56
+
57
+ this.input = document.createElement('input')
58
+ this.input.classList.add('input')
59
+ this.root.appendChild(this.input)
60
+
61
+ this.cancel = new Button({
62
+ container: this.root,
63
+ class: 'clear',
64
+ icon: this.options.iconCancel
65
+ })
66
+
67
+ if (this.options.container) {
68
+ this.options.container.appendChild(this.root)
69
+ }
70
+
71
+ return this
72
+ }
73
+
74
+ attach () {
75
+ this.input.addEventListener('input', () => {
76
+ if (this.input.value.length < this.options.minChar) return
77
+
78
+ clearTimeout(this.timeout)
79
+
80
+ this.timeout = setTimeout(() => {
81
+ this.emit('change', this.input.value)
82
+ }, this.options.timeout)
83
+ })
84
+
85
+ this.cancel.on('click', () => {
86
+ this.input.value = ''
87
+ this.input.focus()
88
+ this.emit('cancel')
89
+ })
90
+ }
91
+
92
+ set (email) {
93
+ this.root.innerHTML = email
94
+ this.root.setAttribute('href', 'mailto:' + email)
95
+ }
96
+ }
97
+
98
+ export default Search