summaryrefslogtreecommitdiff
path: root/app/client/common/buttonGrid.component.js
blob: 6c7c105fc887d1d063db61eb05486731f6a40603 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { h, Component } from 'preact'

export default class ButtonGrid extends Component {
  state = {
    x: 0, y: 0,
  }

  render() {
    const {
      x: _x,
      y: _y,
    } = this.state
    const {
      x: X,
      y: Y,
      max = Infinity,
      onClick,
      onHover,
    } = this.props
    return (
      <table className='buttonGrid'>
        <tr className='row'>
          <th>{" "}</th>
          {X.map(x => (
            <th className={x === _x && 'bold'}>{x}</th>
          ))}
        </tr>          
        {Y.map(y => (
          <tr className='row'>
            <th className={y === _y && 'bold'}>{y}</th>
            {X.map(x => (
              <td>
                {x * y > max ? " " :
                  <button
                    onClick={() => onClick(x, y)}
                    onMouseEnter={() => {
                      this.setState({ x, y })
                      onHover(x, y)
                    }}
                  >
                    {" "}
                  </button>
                }
              </td>
            ))}
          </tr>
        ))}
      </table>
    )
  }
}