You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB

  1. import React from 'react';
  2. import IconButton from '../../../components/icon_button';
  3. import PropTypes from 'prop-types';
  4. import { defineMessages, injectIntl } from 'react-intl';
  5. const messages = defineMessages({
  6. add_poll: { id: 'poll_button.add_poll', defaultMessage: 'Add a poll' },
  7. remove_poll: { id: 'poll_button.remove_poll', defaultMessage: 'Remove poll' },
  8. });
  9. const iconStyle = {
  10. height: null,
  11. lineHeight: '27px',
  12. };
  13. class PollButton extends React.PureComponent {
  14. static propTypes = {
  15. disabled: PropTypes.bool,
  16. unavailable: PropTypes.bool,
  17. active: PropTypes.bool,
  18. onClick: PropTypes.func.isRequired,
  19. intl: PropTypes.object.isRequired,
  20. };
  21. handleClick = () => {
  22. this.props.onClick();
  23. };
  24. render () {
  25. const { intl, active, unavailable, disabled } = this.props;
  26. if (unavailable) {
  27. return null;
  28. }
  29. return (
  30. <div className='compose-form__poll-button'>
  31. <IconButton
  32. icon='tasks'
  33. title={intl.formatMessage(active ? messages.remove_poll : messages.add_poll)}
  34. disabled={disabled}
  35. onClick={this.handleClick}
  36. className={`compose-form__poll-button-icon ${active ? 'active' : ''}`}
  37. size={18}
  38. inverted
  39. style={iconStyle}
  40. />
  41. </div>
  42. );
  43. }
  44. }
  45. export default injectIntl(PollButton);