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.

48 lines
1.3 KiB

  1. // Package imports //
  2. import React from 'react';
  3. import PropTypes from 'prop-types';
  4. import { defineMessages, injectIntl } from 'react-intl';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. const messages = defineMessages({
  7. public: { id: 'privacy.public.short', defaultMessage: 'Public' },
  8. unlisted: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
  9. private: { id: 'privacy.private.short', defaultMessage: 'Followers-only' },
  10. direct: { id: 'privacy.direct.short', defaultMessage: 'Direct' },
  11. });
  12. @injectIntl
  13. export default class VisibilityIcon extends ImmutablePureComponent {
  14. static propTypes = {
  15. visibility: PropTypes.string,
  16. intl: PropTypes.object.isRequired,
  17. withLabel: PropTypes.bool,
  18. };
  19. render() {
  20. const { withLabel, visibility, intl } = this.props;
  21. const visibilityClass = {
  22. public: 'globe',
  23. unlisted: 'unlock-alt',
  24. private: 'lock',
  25. direct: 'envelope',
  26. }[visibility];
  27. const label = intl.formatMessage(messages[visibility]);
  28. const icon = (<i
  29. className={`status__visibility-icon fa fa-fw fa-${visibilityClass}`}
  30. title={label}
  31. aria-hidden='true'
  32. />);
  33. if (withLabel) {
  34. return (<span style={{ whiteSpace: 'nowrap' }}>{icon} {label}</span>);
  35. } else {
  36. return icon;
  37. }
  38. }
  39. }