gab-social/app/javascript/gabsocial/features/compose/components/spoiler_button.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-02-08 06:12:01 +00:00
import { injectIntl, defineMessages } from 'react-intl'
import { changeComposeSpoilerness } from '../../../actions/compose'
import ComposeExtraButton from './compose_extra_button'
const messages = defineMessages({
marked: { id: 'compose_form.spoiler.marked', defaultMessage: 'Text is hidden behind warning' },
unmarked: { id: 'compose_form.spoiler.unmarked', defaultMessage: 'Text is not hidden' },
title: { id: 'compose_form.spoiler.title', defaultMessage: 'Warning' },
})
const mapStateToProps = (state) => ({
active: state.getIn(['compose', 'spoiler']),
})
2020-04-11 23:29:19 +01:00
const mapDispatchToProps = (dispatch) => ({
2020-02-08 06:12:01 +00:00
onClick () {
dispatch(changeComposeSpoilerness())
},
})
export default
@injectIntl
@connect(mapStateToProps, mapDispatchToProps)
class SpoilerButton extends PureComponent {
static propTypes = {
active: PropTypes.bool,
2020-03-24 04:39:12 +00:00
intl: PropTypes.object.isRequired,
2020-02-28 15:20:47 +00:00
small: PropTypes.bool,
2020-02-08 06:12:01 +00:00
}
handleClick = (e) => {
e.preventDefault()
this.props.onClick()
}
render () {
2020-02-28 15:20:47 +00:00
const { active, intl, small } = this.props
2020-02-08 06:12:01 +00:00
return (
<ComposeExtraButton
title={intl.formatMessage(messages.title)}
icon='warning'
onClick={this.handleClick}
2020-02-28 15:20:47 +00:00
small={small}
2020-03-07 04:53:28 +00:00
active={active}
2020-02-08 06:12:01 +00:00
/>
)
}
}