logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

sensitive_button_container.js (2386B)


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