about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/local_settings/navigation/item/index.js
blob: a352d5fb2a7d170a4ade46d555b7dbd3d8dd32d3 (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
62
63
64
65
66
67
68
69
//  Package imports
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

//  Stylesheet imports
import './style.scss';

//  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

export default class LocalSettingsPage extends React.PureComponent {

  static propTypes = {
    active: PropTypes.bool,
    className: PropTypes.string,
    href: PropTypes.string,
    icon: PropTypes.string,
    index: PropTypes.number.isRequired,
    onNavigate: PropTypes.func,
    title: PropTypes.string,
  };

  handleClick = (e) => {
    const { index, onNavigate } = this.props;
    if (onNavigate) {
      onNavigate(index);
      e.preventDefault();
    }
  }

  render () {
    const { handleClick } = this;
    const {
      active,
      className,
      href,
      icon,
      onNavigate,
      title,
    } = this.props;

    const finalClassName = classNames('glitch', 'local-settings__navigation__item', {
      active,
    }, className);

    const iconElem = icon ? <i className={`fa fa-fw fa-${icon}`} /> : null;

    if (href) return (
      <a
        href={href}
        className={finalClassName}
      >
        {iconElem} {title}
      </a>
    );
    else if (onNavigate) return (
      <a
        onClick={handleClick}
        role='button'
        tabIndex='0'
        className={finalClassName}
      >
        {iconElem} {title}
      </a>
    );
    else return null;
  }

}