aboutsummaryrefslogtreecommitdiff
path: root/src/view/sequencer/block.ts
blob: ff8d2dbb0d17c3b2f4e1629aca2285b0baf39386 (plain)
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
import h, { classNames } from 'lib/h'

interface Params {
  checked: boolean,
  onCheck: (checked: boolean) => void
}

export function column(xs: Array<Params>) {
  return h('ol',
    { className: 'g-Sequencer__Column' },
    ...xs.map(params => h('li', {}, block(params)))
  )
}

function block({ checked, onCheck }: Params) {
  return h('div', 
    { className: classNames({
        'g-Sequencer__Block': true,
        'g-Sequencer__Block--Checked': checked
      }),
      onclick: (e: Event) => {
        checked = !checked
        onCheck(checked)
        let target = e.target as HTMLElement
        if (target !== undefined) {
          if (checked) {
            target.classList.add('g-Sequencer__Block--Checked')
          } else {
            target.classList.remove('g-Sequencer__Block--Checked')
          }
        }
      }
    }
  )
}