aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/dropdowns/components/menu.js
blob: f6d8a139e776c5f4fa51640f317231c1ce1a862e (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
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')

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

Menu.prototype.render = function () {
  const { className = '', children, isShowing } = this.props
  return isShowing
    ? h('div', { className: `menu ${className}` }, children)
    : h('noscript')
}

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

Item.prototype.render = function () {
  const {
    icon,
    children,
    text,
    className = '',
    onClick,
  } = this.props
  const itemClassName = `menu__item ${className} ${onClick ? 'menu__item--clickable' : ''}`
  const iconComponent = icon ? h('div.menu__item__icon', [icon]) : null
  const textComponent = text ? h('div.menu__item__text', text) : null

  return children
    ? h('div', { className: itemClassName, onClick }, children)
    : h('div.menu__item', { className: itemClassName, onClick }, [ iconComponent, textComponent ]
      .filter(d => Boolean(d))
    )
}

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

Divider.prototype.render = function () {
  return h('div.menu__divider')
}

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

CloseArea.prototype.render = function () {
  return h('div.menu__close-area', { onClick: this.props.onClick })
}

module.exports = { Menu, Item, Divider, CloseArea }