material 0.9.6 → 0.9.8

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/index.js CHANGED
@@ -37,6 +37,7 @@ import attributes from './src/module/attributes'
37
37
  import EventEmitter from './src/mixin/emitter'
38
38
  import display from './src/mixin/display'
39
39
  import build from './src/mixin/build'
40
+ import position from './src/mixin/position'
40
41
  // modules
41
42
  import clone from './src/module/clone'
42
43
  import dataset from './src/module/dataset'
@@ -51,6 +52,7 @@ import observer from './src/module/observer'
51
52
  import request from './src/module/request'
52
53
  import ripple from './src/module/ripple'
53
54
  import smoothscroll from './src/module/smoothscroll'
55
+ import touch from './src/module/touch'
54
56
 
55
57
  export {
56
58
  // classes
@@ -62,5 +64,5 @@ export {
62
64
  // mixins and modules
63
65
  EventEmitter,
64
66
  attributes, build, clone, create, dataset, device, display, events, emitter, jsonToHTML, mediator, merge,
65
- observer, request, ripple, smoothscroll
67
+ observer, position, request, ripple, smoothscroll, touch
66
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "material",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "A lightweight implementation of Material Design Components for the web - ES6",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/card.js CHANGED
@@ -1,28 +1,21 @@
1
- import build from './mixin/build'
2
- import display from './mixin/display'
1
+ import {
2
+ Component,
3
+ display
4
+ } from '../'
5
+
3
6
  import position from './mixin/position'
4
7
 
5
- class Card {
8
+ class Card extends Component {
6
9
  static defaults = {
7
10
  class: 'card',
11
+ mixins: [display, position],
8
12
  position: {
9
13
  align: 'center',
10
14
  vAlign: 'dynamic',
11
15
  offsetX: 10,
12
16
  offsetY: 10
13
17
  },
14
- close: true,
15
- layout: []
16
- }
17
-
18
- constructor (options) {
19
- this.init(options)
20
- this.build()
21
- }
22
-
23
- init (options) {
24
- this.options = { ...Card.defaults, ...options }
25
- Object.assign(this, build, display, position)
18
+ close: true
26
19
  }
27
20
  }
28
21
 
package/src/checkbox.js CHANGED
@@ -1,13 +1,9 @@
1
- import EventEmitter from './mixin/events'
2
- // import control from './mixin/control'
3
- import build from './mixin/build'
4
- import events from './module/events'
5
- import * as css from './module/css'
1
+ import Control from './class/control'
6
2
 
7
3
  import icon from './skin/material/icon/checkbox.svg'
8
4
  import Element from './element'
9
5
 
10
- class Checkbox {
6
+ class Checkbox extends Control {
11
7
  static defaults = {
12
8
  class: 'checkbox',
13
9
  layout: [
@@ -17,7 +13,7 @@ class Checkbox {
17
13
  ],
18
14
  events: [
19
15
  ['ui.control.click', 'click'],
20
- ['ui.label.click', 'toggle'],
16
+ ['ui.label.click', 'check'],
21
17
  // for accessibility purpose
22
18
  // ['element.input.click', 'toggle'],
23
19
  ['ui.input.focus', 'focus'],
@@ -27,20 +23,11 @@ class Checkbox {
27
23
  }
28
24
 
29
25
  constructor (options) {
30
- this.init(options)
31
- this.build()
26
+ super(options)
32
27
  this.setup()
33
28
  }
34
29
 
35
- init (options) {
36
- this.options = { ...Checkbox.defaults, ...options }
37
- Object.assign(this, build, attach)
38
- }
39
-
40
30
  setup () {
41
- this.element = build(this.options.build)
42
- this.element = this.element.root
43
-
44
31
  this.ui.control.innerHTML = icon
45
32
 
46
33
  const text = this.options.text || this.options.label
@@ -58,7 +45,7 @@ class Checkbox {
58
45
  if (this.options.disabled) {
59
46
  this.disabled = this.options.disabled
60
47
  this.ui.input.setAttribute('disabled', 'disabled')
61
- css.add(this.element, 'is-disabled')
48
+ this.element.classList.add('is-disabled')
62
49
  }
63
50
 
64
51
  if (this.options.checked) {
@@ -68,8 +55,6 @@ class Checkbox {
68
55
  if (this.options.value) {
69
56
  this.set('value', this.value)
70
57
  }
71
-
72
- events.attach(this.options.events, this)
73
58
  }
74
59
 
75
60
  set (prop, value) {
@@ -90,24 +75,32 @@ class Checkbox {
90
75
  return this
91
76
  }
92
77
 
93
- check (checked) {
94
- if (checked === true) {
95
- css.add(this.element, 'is-checked')
78
+ get () {
79
+ return this.value
80
+ }
81
+
82
+ check (value) {
83
+ if (value === true) {
84
+ this.element.classList.add('is-checked')
96
85
  this.ui.input.checked = true
97
- this.checked = true
98
- this.emit('change', this.checked)
86
+ this.value = true
87
+ this.emit('change', this.value)
99
88
  } else {
100
- css.remove(this.element, 'is-checked')
89
+ this.element.classList.remove('is-checked')
101
90
  this.ui.input.checked = false
102
- this.checked = false
103
- this.emit('change', this.checked)
91
+ this.value = false
92
+ this.emit('change', this.value)
104
93
  }
105
94
  return this
106
95
  }
107
96
 
108
- click (e) {
109
- this.toggle(e)
97
+ onClick (e) {
110
98
  this.ui.input.focus()
99
+ if (this.element.classList.add('is-checked')) {
100
+ this.check(false)
101
+ } else {
102
+ this.check(true)
103
+ }
111
104
 
112
105
  return this
113
106
  }
package/src/datehour.js CHANGED
@@ -1,21 +1,11 @@
1
- import build from './mixin/build'
1
+ import Component from './class/component'
2
2
 
3
- class DateHour {
3
+ class DateHour extends Component {
4
4
  static defaults = {
5
5
  class: 'date',
6
6
  tag: 'span'
7
7
  }
8
8
 
9
- constructor (options) {
10
- this.init(options)
11
- this.build()
12
- }
13
-
14
- init (options) {
15
- this.options = { ...DateHour.defaults, ...options }
16
- Object.assign(this, build)
17
- }
18
-
19
9
  set (date) {
20
10
  // console.log('set', src)
21
11
  const d = new Date(date)
package/src/menu.js CHANGED
@@ -1,15 +1,14 @@
1
- import EventEmitter from './mixin/emitter'
2
- // menu related modules
3
- import build from './mixin/build'
4
- import events from './module/events'
5
- import display from './mixin/display'
6
- import position from './mixin/position'
1
+ import {
2
+ Control, Element, display
3
+ } from '../index'
7
4
 
8
- import Element from './element'
5
+ import position from './mixin/position'
9
6
 
10
- class Menu extends EventEmitter {
7
+ class Menu extends Control {
11
8
  static defaults = {
12
9
  class: 'menu',
10
+ mixins: [display, position],
11
+ underlay: true,
13
12
  modal: false,
14
13
  position: {
15
14
  align: 'right',
@@ -28,37 +27,15 @@ class Menu extends EventEmitter {
28
27
  }
29
28
 
30
29
  constructor (options) {
31
- super()
30
+ super(options)
32
31
 
33
- this.init(options)
34
- this.build(this.constructor)
35
- this.buildUnderlay()
36
32
  this.setup()
37
33
 
38
34
  this.render(this.options.items)
39
-
40
- return this
41
- }
42
-
43
- init (options) {
44
- this.options = { ...Menu.defaults, ...options }
45
- Object.assign(this, build, display, position)
46
-
47
- this.menus = []
48
- }
49
-
50
- buildUnderlay () {
51
- if (!this.options.parentName) {
52
- this.underlay = new Element({
53
- class: 'menu-underlay'
54
- })
55
-
56
- this.options.container.appendChild(this.underlay)
57
- }
58
35
  }
59
36
 
60
37
  setup () {
61
- events.attach(this.options.events, this)
38
+ this.menus = []
62
39
  this.closeTimeout = null
63
40
 
64
41
  document.addEventListener('click', this.handleDocumentClick)
@@ -100,6 +77,7 @@ class Menu extends EventEmitter {
100
77
  class: 'floating',
101
78
  target: item,
102
79
  container: this.options.container,
80
+ underlay: false,
103
81
  parentName: obj.name,
104
82
  items: obj.items
105
83
  }).position(item, {
@@ -132,7 +110,6 @@ class Menu extends EventEmitter {
132
110
  }
133
111
 
134
112
  destroyMenu (menu) {
135
- // Trouver l'index de menuToDestroy dans this.menus
136
113
  const index = this.menus.indexOf(menu)
137
114
 
138
115
  // Si trouvé, supprimer le menu du tableau
@@ -140,7 +117,6 @@ class Menu extends EventEmitter {
140
117
  this.menus.splice(index, 1)
141
118
  }
142
119
 
143
- // Appeler la méthode destroy sur le menuToDestroy
144
120
  menu.destroy()
145
121
  }
146
122
 
@@ -1,14 +1,15 @@
1
1
  export default {
2
2
  position (target, position) {
3
+ // console.log('position', target)
3
4
  target = target || this.options.target
4
5
  position = position || this.options.position
5
6
  const { offsetX = 0, offsetY = 0, align = 'center', vAlign = 'middle' } = position
6
7
 
7
- const name = this.constructor.name
8
+ if (!target) return this
8
9
 
9
- if (!target) return
10
+ // console.log('--- target', target)
10
11
 
11
- // console.log('container', this.options.container)
12
+ this.options.container = this.options.container || this.element.parentNode
12
13
 
13
14
  const caller = target.getBoundingClientRect()
14
15
  const screen = this.options.container.getBoundingClientRect()
@@ -8,13 +8,9 @@ import { create } from '../module/layout'
8
8
  */
9
9
  const build = (instance) => {
10
10
  // console.log('name', instance.constructor.defaults)
11
- const { tag = 'div', class: customClass, data, base, container, layout, icon, label, show } = instance.options
11
+ const { tag = 'div', class: customClass, data, base, container, underlay, layout, icon, label, show } = instance.options
12
12
  const { defaults = {} } = instance.constructor
13
13
 
14
- if (instance.constructor?.defaults.class === 'length') {
15
- console.log('---', instance.constructor.defaults)
16
- }
17
-
18
14
  instance.element = document.createElement(tag)
19
15
 
20
16
  if (defaults.base) css.add(instance.element, defaults.base)
@@ -36,8 +32,9 @@ const build = (instance) => {
36
32
 
37
33
  instance.ui = instance.ui || {}
38
34
 
39
- if (icon) buildIcon(instance)
40
- if (label) buildLabel(instance)
35
+ if (instance.options.underlay) buildUnderlay(instance, defaults.class)
36
+ if (icon && !instance.ui.icon) buildIcon(instance)
37
+ if (label && !instance.ui.label) buildLabel(instance)
41
38
 
42
39
  if (show === true && instance.show) instance.show()
43
40
  }
@@ -50,9 +47,13 @@ const setupContainer = (instance, base, container) => {
50
47
  const setupLayout = (instance, layout) => {
51
48
  instance.layout = create(layout, instance.element)
52
49
  instance.ui = instance.layout.component
50
+ }
53
51
 
54
- if (instance.constructor.name === 'Length') {
55
- console.log(instance.ui)
52
+ function buildUnderlay (instance, name) {
53
+ if (instance.options.underlay) {
54
+ instance.underlay = document.createElement('div')
55
+ instance.underlay.classList.add(name + '-underlay')
56
+ instance.options.container.appendChild(instance.underlay)
56
57
  }
57
58
  }
58
59
 
@@ -19,13 +19,17 @@ function e (instance, ev) {
19
19
 
20
20
  const keys = ev.split('.')
21
21
 
22
- for (let i = 0, l = keys.length; i <= l; i++) {
23
- const key = keys[i]
24
- iteration = iteration || instance
25
- iteration = iteration[key]
22
+ if (keys[0] === 'window') {
23
+ element = window
24
+ } else {
25
+ for (let i = 0, l = keys.length; i <= l; i++) {
26
+ const key = keys[i]
27
+ iteration = iteration || instance
28
+ iteration = iteration[key]
26
29
 
27
- if (i === keys.length - 2) {
28
- element = iteration
30
+ if (i === keys.length - 2) {
31
+ element = iteration
32
+ }
29
33
  }
30
34
  }
31
35
 
@@ -1,5 +1,4 @@
1
- export default `
2
1
  <svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
3
2
  <path d="M0 0h24v24H0z" fill="none" />
4
3
  <path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z" />
5
- </svg>`;
4
+ </svg>
@@ -1,4 +1,3 @@
1
- export default `
2
1
  <svg width="18px" height="18px" class="checkbox-icon" viewBox="0 0 18 18">
3
2
  <polygon class="checkbox-check" points="7 14.42 2 9.42 3.41 8.01 7 11.59 14.59 4 16 5.42"></polygon>
4
- </svg>`;
3
+ </svg>
@@ -1,5 +1,4 @@
1
- export default `
2
1
  <svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
3
2
  <path d="M0 0h24v24H0z" fill="none" />
4
3
  <path d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z" />
5
- </svg>`;
4
+ </svg>
@@ -1,4 +1,3 @@
1
- export default `
2
1
  <svg width="24px" class="slider-pin" height="32px" viewBox="0 0 24 32">
3
2
  <path d="M12.4799395,31.9994146 C12.4799395,31.9994146 24,18.0312233 24,11.6159251 C24,5.2006268 18.627417,0 12,0 C5.372583,0 0,5.2006268 0,11.6159251 C0,18.0312233 12.4799395,31.9994146 12.4799395,31.9994146 Z"></path>
4
- </svg>`;
3
+ </svg>
package/src/text.js CHANGED
@@ -1,22 +1,16 @@
1
- import build from './mixin/build'
1
+ import Component from './class/component'
2
2
 
3
- class Text {
3
+ class Text extends Component {
4
4
  static defaults = {
5
5
  class: 'text',
6
6
  tag: 'span'
7
7
  }
8
8
 
9
9
  constructor (options) {
10
- this.init(options)
11
- this.build()
10
+ super(options)
12
11
  this.setup()
13
12
  }
14
13
 
15
- init (options) {
16
- this.options = { ...Text.defaults, ...options }
17
- Object.assign(this, build)
18
- }
19
-
20
14
  setup () {
21
15
  if (this.options.text) {
22
16
  this.set(this.options.text)
package/src/tooltip.js CHANGED
@@ -1,59 +1,33 @@
1
+ import Component from './class/component'
2
+ import Element from './element'
3
+ import position from './mixin/position'
1
4
  import touch from './module/touch'
2
5
 
3
- class Tooltip {
6
+ class Tooltip extends Component {
4
7
  static defaults = {
8
+ base: 'component',
9
+ class: 'tooltip',
10
+ tag: 'span',
11
+ mixins: [position],
5
12
  targets: '[data-tooltip]',
6
13
  offset: {
7
14
  top: 60
8
15
  },
9
- disabled: false
10
- }
11
-
12
- /**
13
- * The init method of the Button class
14
- * @param {Object} The element attributes
15
- * @private
16
- * @return {DOMElement} The dom element
17
- */
18
- constructor (options) {
19
- // console.log('constructor')
20
-
21
- this.init(options)
22
- this.build()
23
- this.bindEvents()
24
-
25
- return this
26
- }
27
-
28
- init (options) {
29
- this.options = { ...Tooltip.defaults, ...options }
30
- }
31
-
32
- build () {
33
- const container = this.options.container || document.body
34
-
35
- this.element = document.createElement('span')
36
- this.element.classList.add('tooltip')
37
- this.element.classList.add('control')
38
-
39
- this.pointer = document.createElement('span')
40
- this.pointer.classList.add('pointer')
41
- this.element.appendChild(this.pointer)
42
-
43
- this.label = document.createElement('span')
44
- this.label.classList.add('label')
45
- this.element.appendChild(this.label)
46
-
47
- container.appendChild(this.element)
16
+ position: {
17
+ align: 'center',
18
+ vAlign: 'bottom'
19
+ },
20
+ disabled: false,
21
+ layout: [
22
+ [Element, { tag: 'span', class: 'pointer' }],
23
+ [Element, 'label', { tag: 'span', class: 'label' }]
24
+ ]
48
25
  }
49
26
 
50
- bindEvents () {
51
- // console.log('attach', this.options.targets)
27
+ bindTargets () {
52
28
  const targets = document.querySelectorAll(this.options.targets)
53
-
54
29
  for (let i = 0; i < targets.length; i++) {
55
30
  targets[i].addEventListener('mouseover', (e) => {
56
- // console.log('tooltip', touch(), this.disabled)
57
31
  if (touch()) return
58
32
 
59
33
  if (this.disabled === true) {
@@ -66,16 +40,18 @@ class Tooltip {
66
40
  return
67
41
  }
68
42
 
69
- this.label.innerHTML = e.currentTarget.dataset.tooltip
43
+ this.ui.label.innerHTML = e.currentTarget.dataset.tooltip
70
44
  const coord = this.offset(e.currentTarget)
71
45
 
72
46
  this.show()
73
- this.element.style.top = (coord.top + this.options.offset.top) + 'px'
74
- this.element.style.left = coord.left - (this.element.offsetWidth / 2) + (e.currentTarget.offsetWidth / 2) + 'px'
47
+ // this.element.style.top = (coord.top + this.options.offset.top) + 'px'
48
+ // this.element.style.left = coord.left - (this.element.offsetWidth / 2) + (e.currentTarget.offsetWidth / 2) + 'px'
49
+
50
+ this.position(e.currentTarget)
75
51
  })
76
52
 
77
53
  targets[i].addEventListener('mouseleave', (e) => {
78
- this.label.innerHTML = ''
54
+ this.ui.label.innerHTML = ''
79
55
  this.hide()
80
56
  })
81
57
  }
package/src/view.js CHANGED
@@ -1,22 +1,8 @@
1
- import EventEmitter from './mixin/emitter'
2
- import build from './mixin/build'
1
+ import Control from './class/control'
3
2
 
4
- class View extends EventEmitter {
3
+ class View extends Control {
5
4
  static defaults = {
6
- class: 'view',
7
- type: null
8
- }
9
-
10
- constructor (options) {
11
- super()
12
-
13
- this.init(options)
14
- this.build()
15
- }
16
-
17
- init (options) {
18
- this.options = { ...View.defaults, ...options }
19
- Object.assign(this, build)
5
+ class: 'view'
20
6
  }
21
7
  }
22
8
 
package/src/component.js DELETED
@@ -1,38 +0,0 @@
1
- import create from './mixin/create'
2
- import events from './mixin/events'
3
- import insert from './mixin/insert'
4
-
5
- import emitter from './module/emitter'
6
-
7
- // Depracted
8
-
9
- class Component {
10
- static defaults = {
11
- prefix: 'material',
12
- class: 'component',
13
- tag: 'span'
14
- }
15
-
16
- constructor (options) {
17
- this.init(options)
18
- this.build()
19
- }
20
-
21
- init (options) {
22
- this.options = { ...Component.defaults, ...options }
23
-
24
- Object.assign(this, emitter, events, insert)
25
- }
26
-
27
- build () {
28
- this.element = create(this.options)
29
-
30
- if (this.options.container) {
31
- this.insert(this.options.container)
32
- }
33
-
34
- return this
35
- }
36
- }
37
-
38
- export default Component