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.

77 lines
2.0 KiB

  1. // Package imports.
  2. import React from 'react';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { defineMessages, injectIntl } from 'react-intl';
  6. // Mastodon imports.
  7. import IconButton from './icon_button';
  8. import VisibilityIcon from './status_visibility_icon';
  9. // Messages for use with internationalization stuff.
  10. const messages = defineMessages({
  11. collapse: { id: 'status.collapse', defaultMessage: 'Collapse' },
  12. uncollapse: { id: 'status.uncollapse', defaultMessage: 'Uncollapse' },
  13. });
  14. @injectIntl
  15. export default class StatusIcons extends React.PureComponent {
  16. static propTypes = {
  17. status: ImmutablePropTypes.map.isRequired,
  18. mediaIcon: PropTypes.string,
  19. collapsible: PropTypes.bool,
  20. collapsed: PropTypes.bool,
  21. setCollapsed: PropTypes.func.isRequired,
  22. intl: PropTypes.object.isRequired,
  23. };
  24. // Handles clicks on collapsed button
  25. handleCollapsedClick = (e) => {
  26. const { collapsed, setCollapsed } = this.props;
  27. if (e.button === 0) {
  28. setCollapsed(!collapsed);
  29. e.preventDefault();
  30. }
  31. }
  32. // Rendering.
  33. render () {
  34. const {
  35. status,
  36. mediaIcon,
  37. collapsible,
  38. collapsed,
  39. intl,
  40. } = this.props;
  41. return (
  42. <div className='status__info__icons'>
  43. {mediaIcon ? (
  44. <i
  45. className={`fa fa-fw fa-${mediaIcon}`}
  46. aria-hidden='true'
  47. />
  48. ) : null}
  49. {(
  50. <VisibilityIcon visibility={status.get('visibility')} />
  51. )}
  52. {collapsible ? (
  53. <IconButton
  54. className='status__collapse-button'
  55. animate flip
  56. active={collapsed}
  57. title={
  58. collapsed ?
  59. intl.formatMessage(messages.uncollapse) :
  60. intl.formatMessage(messages.collapse)
  61. }
  62. icon='angle-double-up'
  63. onClick={this.handleCollapsedClick}
  64. />
  65. ) : null}
  66. </div>
  67. );
  68. }
  69. }