glitchier-soc/app/javascript/mastodon/features/compose/containers/sensitive_button_container.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

import React from 'react';
2017-03-25 01:01:43 +02:00
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import IconButton from '../../../components/icon_button';
2017-03-25 01:01:43 +02:00
import { changeComposeSensitivity } from '../../../actions/compose';
import Motion from '../../ui/util/optional_motion';
import spring from 'react-motion/lib/spring';
2017-03-25 01:01:43 +02:00
import { injectIntl, defineMessages } from 'react-intl';
const messages = defineMessages({
marked: { id: 'compose_form.sensitive.marked', defaultMessage: 'Media is marked as sensitive' },
unmarked: { id: 'compose_form.sensitive.unmarked', defaultMessage: 'Media is not marked as sensitive' },
2017-03-25 01:01:43 +02:00
});
const mapStateToProps = state => ({
visible: state.getIn(['compose', 'media_attachments']).size > 0,
active: state.getIn(['compose', 'sensitive']),
disabled: state.getIn(['compose', 'spoiler']),
2017-03-25 01:01:43 +02:00
});
const mapDispatchToProps = dispatch => ({
onClick () {
dispatch(changeComposeSensitivity());
},
2017-03-25 01:01:43 +02:00
});
class SensitiveButton extends React.PureComponent {
2017-03-25 01:01:43 +02:00
static propTypes = {
visible: PropTypes.bool,
active: PropTypes.bool,
disabled: PropTypes.bool,
onClick: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};
2017-03-25 01:01:43 +02:00
render () {
const { visible, active, disabled, onClick, intl } = this.props;
2017-03-25 01:01:43 +02:00
return (
<Motion defaultStyle={{ scale: 0.87 }} style={{ scale: spring(visible ? 1 : 0.87, { stiffness: 200, damping: 3 }) }}>
{({ scale }) => {
const icon = active ? 'eye-slash' : 'eye';
const className = classNames('compose-form__sensitive-button', {
'compose-form__sensitive-button--visible': visible,
});
return (
<div className={className} style={{ transform: `scale(${scale})` }}>
<IconButton
className='compose-form__sensitive-button__icon'
title={intl.formatMessage(active ? messages.marked : messages.unmarked)}
icon={icon}
onClick={onClick}
size={18}
active={active}
disabled={disabled}
style={{ lineHeight: null, height: null }}
inverted
/>
</div>
);
}}
2017-03-25 01:01:43 +02:00
</Motion>
);
}
}
2017-03-25 01:01:43 +02:00
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));