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.

71 lines
2.2 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 '../../ui/util/optional_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. disabled: state.getIn(['compose', 'spoiler']),
  17. });
  18. const mapDispatchToProps = dispatch => ({
  19. onClick () {
  20. dispatch(changeComposeSensitivity());
  21. },
  22. });
  23. class SensitiveButton extends React.PureComponent {
  24. static propTypes = {
  25. visible: PropTypes.bool,
  26. active: PropTypes.bool,
  27. disabled: PropTypes.bool,
  28. onClick: PropTypes.func.isRequired,
  29. intl: PropTypes.object.isRequired,
  30. };
  31. render () {
  32. const { visible, active, disabled, onClick, intl } = this.props;
  33. return (
  34. <Motion defaultStyle={{ scale: 0.87 }} style={{ scale: spring(visible ? 1 : 0.87, { stiffness: 200, damping: 3 }) }}>
  35. {({ scale }) => {
  36. const icon = active ? 'eye-slash' : 'eye';
  37. const className = classNames('compose-form__sensitive-button', {
  38. 'compose-form__sensitive-button--visible': visible,
  39. });
  40. return (
  41. <div className={className} style={{ transform: `scale(${scale})` }}>
  42. <IconButton
  43. className='compose-form__sensitive-button__icon'
  44. title={intl.formatMessage(messages.title)}
  45. icon={icon}
  46. onClick={onClick}
  47. size={18}
  48. active={active}
  49. disabled={disabled}
  50. style={{ lineHeight: null, height: null }}
  51. inverted
  52. />
  53. </div>
  54. );
  55. }}
  56. </Motion>
  57. );
  58. }
  59. }
  60. export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));