-
Notifications
You must be signed in to change notification settings - Fork 6
/
Select.js
110 lines (95 loc) · 2.64 KB
/
Select.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import CustomElement from '../core/CustomElement.js';
import ControlMixin from '../mixins/ControlMixin.js';
import StateMixin from '../mixins/StateMixin.js';
import TextFieldMixin from '../mixins/TextFieldMixin.js';
import ThemableMixin from '../mixins/ThemableMixin.js';
/* @implements {HTMLSelectElement} */
export default CustomElement
.extend()
.mixin(ThemableMixin)
.mixin(StateMixin)
.mixin(ControlMixin)
.mixin(TextFieldMixin)
.observe({
trailingIcon: { empty: 'arrow_drop_down' },
})
.overrides({
controlTagName: 'select',
controlVoidElement: false,
type: 'select-one',
})
.define({
_select() {
return /** @type {HTMLSelectElement} */ (this.refs.control);
},
/** Readonly values */
multiple: { value: false },
size: { value: 1 },
})
.html`<slot id=slot></slot>`
.childEvents({
slot: {
/** @param {Event & {currentTarget:HTMLSlotElement}} event */
slotchange(event) {
const select = this._select;
select.replaceChildren(
...event.currentTarget.assignedNodes()
.map((child) => child.cloneNode(true)),
);
this._value = select.value;
},
},
})
.recompose(({ template, refs: { slot, prefix, suffix, control } }) => {
control.setAttribute('icon', '{icon}');
template.append(slot);
prefix.remove();
suffix.remove();
})
.on({
_formResetChanged(oldValue, newValue) {
if (!newValue) return;
this._select.value = this.querySelector('option[selected]')?.value ?? '';
},
})
.css`
#slot {
display: none;
}
#shape {
padding: 0;
cursor: pointer;
}
#shape[disabled] {
cursor: not-allowed;
}
#icon {
position: absolute;
/* padding-inline-start: 12px; */
}
#trailing-icon {
position: absolute;
inset-inline-end: 16px;
}
#control {
padding-inline-start: 16px;
padding-inline-end: calc(16px + 24px + 16px);
accent-color: rgb(var(--mdw-ink));
cursor: inherit;
}
#control[icon] {
margin-inline-start: calc(16px + 24px);
padding-inline-start: 0;
}
option {
accent-color: rgb(var(--mdw-ink));
min-block-size: var(--mdw-typescale__label-large__line-height);
appearance: none;
background-color: rgb(var(--mdw-color__surface)) !important;
border-radius: 0;
color: rgb(var(--mdw-color__on-surface)) !important;
font: var(--mdw-typescale__label-large__font);
letter-spacing: var(--mdw-typescale__label-large__letter-spacing);
}
`
.autoRegister('mdw-select');