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.

52 lines
1.6 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import TextIconButton from '../components/text_icon_button';
  5. import { changeComposeSensitivity } from '../../../actions/compose';
  6. import Motion from 'react-motion/lib/Motion';
  7. import spring from 'react-motion/lib/spring';
  8. import { injectIntl, defineMessages } from 'react-intl';
  9. const messages = defineMessages({
  10. title: { id: 'compose_form.sensitive', defaultMessage: 'Mark media as sensitive' },
  11. });
  12. const mapStateToProps = state => ({
  13. visible: state.getIn(['compose', 'media_attachments']).size > 0,
  14. active: state.getIn(['compose', 'sensitive']),
  15. });
  16. const mapDispatchToProps = dispatch => ({
  17. onClick () {
  18. dispatch(changeComposeSensitivity());
  19. },
  20. });
  21. class SensitiveButton extends React.PureComponent {
  22. static propTypes = {
  23. visible: PropTypes.bool,
  24. active: PropTypes.bool,
  25. onClick: PropTypes.func.isRequired,
  26. intl: PropTypes.object.isRequired,
  27. };
  28. render () {
  29. const { visible, active, onClick, intl } = this.props;
  30. return (
  31. <Motion defaultStyle={{ scale: 0.87 }} style={{ scale: spring(visible ? 1 : 0.87, { stiffness: 200, damping: 3 }) }}>
  32. {({ scale }) =>
  33. <div style={{ display: visible ? 'block' : 'none', transform: `translateZ(0) scale(${scale})` }}>
  34. <TextIconButton onClick={onClick} label='NSFW' title={intl.formatMessage(messages.title)} active={active} />
  35. </div>
  36. }
  37. </Motion>
  38. );
  39. }
  40. }
  41. export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));