aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/custom-radio-list.js
blob: a4c5253969b543f98d998a816d0d9b88d84e32d8 (plain) (blame)
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
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits

module.exports = RadioList

inherits(RadioList, Component)
function RadioList () {
  Component.call(this)
}

RadioList.prototype.render = function () {
  const props = this.props
  const activeClass = '.custom-radio-selected'
  const inactiveClass = '.custom-radio-inactive'
  const {
    labels,
    defaultFocus,
  } = props


  return (
    h('.flex-row', {
      style: {
        fontSize: '12px',
      },
    }, [
      h('.flex-column.custom-radios', {
        style: {
          marginRight: '5px',
        },
      },
        labels.map((lable, i) => {
          let isSelcted = (this.state !== null)
          isSelcted = isSelcted ? (this.state.selected === lable) : (defaultFocus === lable)
          return h(isSelcted ? activeClass : inactiveClass, {
            title: lable,
            onClick: (event) => {
              this.setState({selected: event.target.title})
              props.onClick(event)
            },
          })
        })
      ),
      h('.text', {},
        labels.map((lable) => {
          if (props.subtext) {
            return h('.flex-row', {}, [
              h('.radio-titles', lable),
              h('.radio-titles-subtext', `- ${props.subtext[lable]}`),
            ])
          } else {
            return h('.radio-titles', lable)
          }
        })
      ),
    ])
  )
}