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.

81 lines
2.3 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. public: { id: 'privacy.public.short', defaultMessage: 'Public' },
  14. unlisted: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
  15. private: { id: 'privacy.private.short', defaultMessage: 'Followers-only' },
  16. direct: { id: 'privacy.direct.short', defaultMessage: 'Direct' },
  17. });
  18. @injectIntl
  19. export default class StatusIcons extends React.PureComponent {
  20. static propTypes = {
  21. status: ImmutablePropTypes.map.isRequired,
  22. mediaIcon: PropTypes.string,
  23. collapsible: PropTypes.bool,
  24. collapsed: PropTypes.bool,
  25. setExpansion: PropTypes.func.isRequired,
  26. intl: PropTypes.object.isRequired,
  27. };
  28. // Handles clicks on collapsed button
  29. handleCollapsedClick = (e) => {
  30. const { collapsed, setExpansion } = this.props;
  31. if (e.button === 0) {
  32. setExpansion(collapsed ? null : false);
  33. e.preventDefault();
  34. }
  35. }
  36. // Rendering.
  37. render () {
  38. const {
  39. status,
  40. mediaIcon,
  41. collapsible,
  42. collapsed,
  43. intl,
  44. } = this.props;
  45. return (
  46. <div className='status__info__icons'>
  47. {mediaIcon ? (
  48. <i
  49. className={`fa fa-fw fa-${mediaIcon}`}
  50. aria-hidden='true'
  51. />
  52. ) : null}
  53. {(
  54. <VisibilityIcon visibility={status.get('visibility')} />
  55. )}
  56. {collapsible ? (
  57. <IconButton
  58. className='status__collapse-button'
  59. animate flip
  60. active={collapsed}
  61. title={
  62. collapsed ?
  63. intl.formatMessage(messages.uncollapse) :
  64. intl.formatMessage(messages.collapse)
  65. }
  66. icon='angle-double-up'
  67. onClick={this.handleCollapsedClick}
  68. />
  69. ) : null}
  70. </div>
  71. );
  72. }
  73. }