Skip to content

Commit 568dc8d

Browse files
authored
refactored chassis-select
1 parent 97ba4c8 commit 568dc8d

File tree

18 files changed

+1553
-0
lines changed

18 files changed

+1553
-0
lines changed

author-optgroup-label/styles.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:host {
2+
contain: content;
3+
display: flex;
4+
max-width: 100%;
5+
}
6+
7+
:host *,
8+
:host *:before,
9+
:host *:after {
10+
box-sizing: border-box;
11+
}

author-optgroup-label/tag.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class AuthorOptgroupLabelElement extends HTMLElement {
2+
constructor () {
3+
super()
4+
}
5+
}
6+
7+
customElements.define('author-optgroup-label', AuthorOptgroupLabelElement)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<slot name="afterbegin"></slot>
2+
3+
<slot name="beforelabel"></slot>
4+
<slot></slot>
5+
<slot name="afterlabel"></slot>
6+
7+
<slot name="beforeend"></slot>

author-optgroup/styles.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
:host {
2+
contain: content;
3+
display: flex;
4+
flex-direction: column;
5+
max-width: 100%;
6+
}
7+
8+
:host *,
9+
:host *:before,
10+
:host *:after {
11+
box-sizing: border-box;
12+
}

author-optgroup/tag.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class AuthorOptgroupElement extends HTMLElement {
2+
constructor () {
3+
super()
4+
5+
this.UTIL.definePrivateMethods({
6+
optionSelectionHandler: evt => this.emit('option.selected', evt.detail, this.parentNode),
7+
parentStateChangeHandler: evt => this.emit('state.change', evt.detail)
8+
})
9+
10+
this.UTIL.registerListeners(this, {
11+
connected: () => {
12+
this.parentNode.on('state.change', this.PRIVATE.parentStateChangeHandler)
13+
},
14+
15+
disconnected: () => {
16+
this.parentNode.off('state.change', this.PRIVATE.parentStateChangeHandler)
17+
},
18+
19+
'option.selected': this.PRIVATE.optionSelectionHandler
20+
})
21+
}
22+
23+
get options () {
24+
return this.parentNode.options
25+
}
26+
27+
get multiple () {
28+
return this.parentNode.multiple
29+
}
30+
}
31+
32+
customElements.define('author-optgroup', AuthorOptgroupElement)

author-optgroup/template.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<slot name="afterbegin"></slot>
2+
3+
<slot name="beforeoptgroup"></slot>
4+
<slot></slot>
5+
<slot name="afteroptgroup"></slot>
6+
7+
<slot name="beforeend"></slot>

author-option/styles.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
:host {
2+
contain: content;
3+
display: flex;
4+
flex-direction: column;
5+
max-width: 100%;
6+
}
7+
8+
:host *,
9+
:host *:before,
10+
:host *:after {
11+
box-sizing: border-box;
12+
}

author-option/tag.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
class AuthorOptionElement extends HTMLElement {
2+
constructor () {
3+
super()
4+
5+
this.UTIL.defineAttributes({
6+
disabled: false,
7+
hover: false,
8+
id: '',
9+
label: '',
10+
selected: false,
11+
value: ''
12+
})
13+
14+
this.UTIL.defineProperties({
15+
defaultSelected: false,
16+
17+
form: {
18+
readonly: true,
19+
private: true
20+
},
21+
22+
index: {
23+
readonly: true,
24+
get: () => this.parentNode.options.findIndex(option => option.displayElement === this)
25+
}
26+
})
27+
28+
this.UTIL.definePrivateMethods({
29+
mouseButtonDown: evt => {
30+
let code = evt.buttons !== undefined ? evt.buttons : evt.nativeEvent.which
31+
return code >= 1
32+
},
33+
34+
mousemoveHandler: evt => this.emit('option.hovered', this.index),
35+
36+
mouseoutHandler: evt => this.hover = false,
37+
38+
mouseoverHandler: evt => {
39+
let mousedown = this.PRIVATE.mouseButtonDown(evt)
40+
41+
if (!(this.parentNode.multiple && mousedown)) {
42+
this.hover = true
43+
return
44+
}
45+
46+
let { shiftKey, metaKey, ctrlKey } = evt
47+
this.PRIVATE.select(shiftKey, metaKey, ctrlKey, mousedown)
48+
},
49+
50+
parentStateChangeHandler: evt => {
51+
let { name, value } = evt.detail
52+
53+
switch (name) {
54+
case 'multiple':
55+
if (value) {
56+
this.removeEventListener('mouseup', this.PRIVATE.selectionHandler)
57+
this.addEventListener('mousedown', this.PRIVATE.selectionHandler)
58+
} else {
59+
this.addEventListener('mouseup', this.PRIVATE.selectionHandler)
60+
this.removeEventListener('mousedown', this.PRIVATE.selectionHandler)
61+
}
62+
break
63+
}
64+
},
65+
66+
select: (shiftKey = false, metaKey = false, ctrlKey = false, mousedown = false) => {
67+
let { index } = this
68+
this.emit('option.selected', {index, shiftKey, metaKey, ctrlKey, mousedown}, this.parentNode)
69+
},
70+
71+
selectionHandler: evt => {
72+
let { shiftKey, metaKey, ctrlKey } = evt
73+
this.PRIVATE.select(shiftKey, metaKey, ctrlKey)
74+
}
75+
})
76+
77+
this.UTIL.registerListeners(this, {
78+
connected: () => {
79+
this.parentNode.on('state.change', this.PRIVATE.parentStateChangeHandler)
80+
},
81+
82+
disconnected: () => {
83+
this.off('mousedown', this.PRIVATE.selectionHandler)
84+
this.parentNode.off('state.change', this.PRIVATE.parentStateChangeHandler)
85+
},
86+
87+
mouseover: this.PRIVATE.mouseoverHandler,
88+
mousemove: this.PRIVATE.mousemoveHandler,
89+
mouseout: this.PRIVATE.mouseoutHandler,
90+
mouseup: this.PRIVATE.selectionHandler
91+
})
92+
}
93+
94+
static get observedAttributes () {
95+
return ['disabled', 'hover', 'label', 'selected', 'value']
96+
}
97+
98+
get text () {
99+
return this.innerHTML
100+
}
101+
102+
set text (content) {
103+
this.innerHTML = content
104+
}
105+
106+
/**
107+
* @method remove
108+
* Remove this option from the DOM.
109+
* @override
110+
*/
111+
remove () {
112+
this.parentNode.options.splice(this.index, 1)
113+
super.remove()
114+
}
115+
}
116+
117+
customElements.define('author-option', AuthorOptionElement)

author-option/template.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<slot name="afterbegin"></slot>
2+
3+
<slot name="beforeoption"></slot>
4+
<slot></slot>
5+
<slot name="afteroption"></slot>
6+
7+
<slot name="beforeend"></slot>

author-options/styles.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
:host {
2+
display: block;
3+
width: 100%;
4+
}
5+
6+
:host *,
7+
:host *:before,
8+
:host *:after {
9+
box-sizing: border-box;
10+
}

0 commit comments

Comments
 (0)