about summary refs log tree commit diff
path: root/app/javascript/mastodon/features/compose/components/text_icon_button.js
blob: bcfa2109090436e60b3e04d51392d1afd72ba473 (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
import React from 'react';
import PropTypes from 'prop-types';

class TextIconButton extends React.PureComponent {

  constructor (props, context) {
    super(props, context);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick (e) {
    e.preventDefault();
    this.props.onClick();
  }

  render () {
    const { label, title, active, ariaControls } = this.props;

    return (
      <button title={title} aria-label={title} className={`text-icon-button ${active ? 'active' : ''}`} aria-expanded={active} onClick={this.handleClick} aria-controls={ariaControls}>
        {label}
      </button>
    );
  }

}

TextIconButton.propTypes = {
  label: PropTypes.string.isRequired,
  title: PropTypes.string,
  active: PropTypes.bool,
  onClick: PropTypes.func.isRequired,
  ariaControls: PropTypes.string
};

export default TextIconButton;