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

55 lines
1.4 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
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'
class SpoilerButton extends React.PureComponent {
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
/>
)
}
}
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']),
})
const mapDispatchToProps = (dispatch) => ({
onClick () {
dispatch(changeComposeSpoilerness())
},
})
SpoilerButton.propTypes = {
active: PropTypes.bool,
intl: PropTypes.object.isRequired,
small: PropTypes.bool,
}
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(SpoilerButton))