2017-05-03 00:04:16 +00:00
|
|
|
import React from 'react';
|
2017-03-24 23:01:43 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-04-21 18:05:35 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-20 17:43:09 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import IconButton from '../../../components/icon_button';
|
2017-03-24 23:01:43 +00:00
|
|
|
import { changeComposeSensitivity } from '../../../actions/compose';
|
2017-10-16 07:36:15 +00:00
|
|
|
import Motion from '../../ui/util/optional_motion';
|
2017-05-20 12:58:13 +00:00
|
|
|
import spring from 'react-motion/lib/spring';
|
2017-03-24 23:01:43 +00:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
2017-05-20 15:31:47 +00:00
|
|
|
title: { id: 'compose_form.sensitive', defaultMessage: 'Mark media as sensitive' },
|
2017-03-24 23:01:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
visible: state.getIn(['compose', 'media_attachments']).size > 0,
|
2017-05-20 15:31:47 +00:00
|
|
|
active: state.getIn(['compose', 'sensitive']),
|
2017-07-31 03:06:56 +00:00
|
|
|
disabled: state.getIn(['compose', 'spoiler']),
|
2017-03-24 23:01:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
|
|
|
|
onClick () {
|
|
|
|
dispatch(changeComposeSensitivity());
|
2017-05-20 15:31:47 +00:00
|
|
|
},
|
2017-03-24 23:01:43 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
class SensitiveButton extends React.PureComponent {
|
2017-03-24 23:01:43 +00:00
|
|
|
|
2017-05-12 12:44:10 +00:00
|
|
|
static propTypes = {
|
|
|
|
visible: PropTypes.bool,
|
|
|
|
active: PropTypes.bool,
|
2017-07-31 03:06:56 +00:00
|
|
|
disabled: PropTypes.bool,
|
2017-05-12 12:44:10 +00:00
|
|
|
onClick: PropTypes.func.isRequired,
|
2017-05-20 15:31:47 +00:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 12:44:10 +00:00
|
|
|
};
|
|
|
|
|
2017-03-24 23:01:43 +00:00
|
|
|
render () {
|
2017-07-31 03:06:56 +00:00
|
|
|
const { visible, active, disabled, onClick, intl } = this.props;
|
2017-03-24 23:01:43 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Motion defaultStyle={{ scale: 0.87 }} style={{ scale: spring(visible ? 1 : 0.87, { stiffness: 200, damping: 3 }) }}>
|
2017-06-20 17:43:09 +00:00
|
|
|
{({ scale }) => {
|
|
|
|
const icon = active ? 'eye-slash' : 'eye';
|
|
|
|
const className = classNames('compose-form__sensitive-button', {
|
|
|
|
'compose-form__sensitive-button--visible': visible,
|
|
|
|
});
|
|
|
|
return (
|
2017-10-19 16:27:55 +00:00
|
|
|
<div className={className} style={{ transform: `scale(${scale})` }}>
|
2017-06-20 17:43:09 +00:00
|
|
|
<IconButton
|
|
|
|
className='compose-form__sensitive-button__icon'
|
|
|
|
title={intl.formatMessage(messages.title)}
|
|
|
|
icon={icon}
|
|
|
|
onClick={onClick}
|
|
|
|
size={18}
|
|
|
|
active={active}
|
2017-07-31 03:06:56 +00:00
|
|
|
disabled={disabled}
|
2017-06-20 17:43:09 +00:00
|
|
|
style={{ lineHeight: null, height: null }}
|
|
|
|
inverted
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
2017-03-24 23:01:43 +00:00
|
|
|
</Motion>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-24 23:01:43 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));
|