Complete refactor (#123)

This commit is contained in:
Misode
2020-11-23 14:29:16 +01:00
committed by GitHub
parent 0ad33cd88f
commit 982b4728e7
45 changed files with 1162 additions and 1113 deletions

View File

@@ -0,0 +1,22 @@
import { Property } from '../state/Property';
import { View } from '../views/View';
import { Octicon } from './Octicon';
export const Dropdown = (view: View, icon: keyof typeof Octicon, entries: [string, string][], state: Property<string>, watcher?: (value: string) => void) => {
const dropdown = view.register(el => {
el.addEventListener('change', () => {
state.set((el as HTMLSelectElement).value)
})
state.watchRun(v => (el as HTMLSelectElement).value = v, 'dropdown')
watcher?.(state.get())
})
return `
<div class="dropdown">
<select data-id="${dropdown}">
${entries.map(e => `
<option value=${e[0]}>${e[1]}</option>
`).join('')}
</select>
${Octicon[icon]}
</div>`
}