aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/button/button.component.js
blob: 7769e487562cd73d07898f935f9255c629f4a1a7 (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
const { Component } = require('react')
const h = require('react-hyperscript')
const PropTypes = require('prop-types')
const classnames = require('classnames')

const SECONDARY = 'secondary'
const CLASSNAME_PRIMARY = 'btn-primary'
const CLASSNAME_PRIMARY_LARGE = 'btn-primary--lg'
const CLASSNAME_SECONDARY = 'btn-secondary'
const CLASSNAME_SECONDARY_LARGE = 'btn-secondary--lg'

const getClassName = (type, large = false) => {
  let output = type === SECONDARY ? CLASSNAME_SECONDARY : CLASSNAME_PRIMARY

  if (large) {
    output += ` ${type === SECONDARY ? CLASSNAME_SECONDARY_LARGE : CLASSNAME_PRIMARY_LARGE}`
  }

  return output
}

class Button extends Component {
  render () {
    const { type, large, className, ...buttonProps } = this.props

    return (
      h('button', {
        className: classnames(getClassName(type, large), className),
        ...buttonProps,
      }, this.props.children)
    )
  }
}

Button.propTypes = {
  type: PropTypes.string,
  large: PropTypes.bool,
  className: PropTypes.string,
  children: PropTypes.string,
}

module.exports = Button