aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/custom-radio-list.js
blob: 201ec11dc622ffdbaa73f9d11acac53376453b6b (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
61
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
  let activeClass = '.custom-radio-selected'
  let inactiveClass = '.custom-radio-inactive'
  let {
    lables,
    defaultFocus,
    onClick,
  } = props


  return (
    h('.flex-row', {
      style: {
        fontSize: '12px',
      }
    }, [
        h('.flex-column.custom-radios', {
          style: {
            marginRight: '5px',
          }
        },
          lables.map((lable, i) => {
            let isSelcted = (this.state !== null )
            isSelcted = isSelcted ? (this.state.selected === lable) : (this.props.defaultFocus === lable)
            return h(isSelcted ? activeClass : inactiveClass, {
              title: lable,
              onClick: (event) => {
                this.setState({selected: event.target.title})
                props.onClick(event)
              }
            })
          }),
        ),
        h('.text', {},
          lables.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)
          }
        })
      )
    ])
  )
}