-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern-selector.js
30 lines (26 loc) · 929 Bytes
/
pattern-selector.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
export class PatternSelector extends EventTarget {
constructor(patterns) {
super();
this.patterns = patterns;
this.select = document.createElement('select');
this.select.addEventListener('change', function(event) {
// event.preventDefault();
this.dispatchEvent(new CustomEvent('patternselected', {
detail: event.target.value
}));
}.bind(this));
}
render(parent) {
this.patterns.forEach(pattern => {
const opt = document.createElement('option');
opt.value = opt.text = pattern;
this.select.add(opt);
});
const defaultOpt = document.createElement('option');
defaultOpt.text = 'Select pattern...';
defaultOpt.value = '';
this.select.add(defaultOpt, 0);
this.select.selectedIndex = 0;
parent.appendChild(this.select);
}
}