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.

68 lines
2.1 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import classNames from 'classnames';
  5. import IconButton from '../../../components/icon_button';
  6. import { changeComposeSensitivity } from '../../../actions/compose';
  7. import Motion from 'react-motion/lib/Motion';
  8. import spring from 'react-motion/lib/spring';
  9. import { injectIntl, defineMessages } from 'react-intl';
  10. const messages = defineMessages({
  11. title: { id: 'compose_form.sensitive', defaultMessage: 'Mark media as sensitive' },
  12. });
  13. const mapStateToProps = state => ({
  14. visible: state.getIn(['compose', 'media_attachments']).size > 0,
  15. active: state.getIn(['compose', 'sensitive']),
  16. });
  17. const mapDispatchToProps = dispatch => ({
  18. onClick () {
  19. dispatch(changeComposeSensitivity());
  20. },
  21. });
  22. class SensitiveButton extends React.PureComponent {
  23. static propTypes = {
  24. visible: PropTypes.bool,
  25. active: PropTypes.bool,
  26. onClick: PropTypes.func.isRequired,
  27. intl: PropTypes.object.isRequired,
  28. };
  29. render () {
  30. const { visible, active, onClick, intl } = this.props;
  31. return (
  32. <Motion defaultStyle={{ scale: 0.87 }} style={{ scale: spring(visible ? 1 : 0.87, { stiffness: 200, damping: 3 }) }}>
  33. {({ scale }) => {
  34. const icon = active ? 'eye-slash' : 'eye';
  35. const className = classNames('compose-form__sensitive-button', {
  36. 'compose-form__sensitive-button--visible': visible,
  37. });
  38. return (
  39. <div className={className} style={{ transform: `translateZ(0) scale(${scale})` }}>
  40. <IconButton
  41. className='compose-form__sensitive-button__icon'
  42. title={intl.formatMessage(messages.title)}
  43. icon={icon}
  44. onClick={onClick}
  45. size={18}
  46. active={active}
  47. style={{ lineHeight: null, height: null }}
  48. inverted
  49. />
  50. </div>
  51. );
  52. }}
  53. </Motion>
  54. );
  55. }
  56. }
  57. export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));