2019-07-14 21:43:49 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
export default
|
|
|
|
class Spoilers extends React.PureComponent {
|
2023-02-03 20:52:07 +01:00
|
|
|
|
2019-07-14 21:43:49 +02:00
|
|
|
static propTypes = {
|
|
|
|
spoilerText: PropTypes.string,
|
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
hidden: true,
|
2023-02-03 20:52:07 +01:00
|
|
|
};
|
2019-07-14 21:43:49 +02:00
|
|
|
|
|
|
|
handleSpoilerClick = () => {
|
|
|
|
this.setState({ hidden: !this.state.hidden });
|
2023-02-03 20:52:07 +01:00
|
|
|
};
|
2019-07-14 21:43:49 +02:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { spoilerText, children } = this.props;
|
|
|
|
const { hidden } = this.state;
|
|
|
|
|
2023-02-03 20:52:07 +01:00
|
|
|
const toggleText = hidden ?
|
|
|
|
(<FormattedMessage
|
|
|
|
id='status.show_more'
|
|
|
|
defaultMessage='Show more'
|
|
|
|
key='0'
|
|
|
|
/>) :
|
|
|
|
(<FormattedMessage
|
|
|
|
id='status.show_less'
|
|
|
|
defaultMessage='Show less'
|
|
|
|
key='0'
|
|
|
|
/>);
|
2019-07-14 21:43:49 +02:00
|
|
|
|
|
|
|
return ([
|
|
|
|
<p className='spoiler__text'>
|
|
|
|
{spoilerText}
|
|
|
|
{' '}
|
2023-04-04 16:33:44 +02:00
|
|
|
<button tabIndex={0} className='status__content__spoiler-link' onClick={this.handleSpoilerClick}>
|
2019-07-14 21:43:49 +02:00
|
|
|
{toggleText}
|
|
|
|
</button>
|
|
|
|
</p>,
|
|
|
|
<div className={`status__content__spoiler ${!hidden ? 'status__content__spoiler--visible' : ''}`}>
|
|
|
|
{children}
|
2023-02-03 20:52:07 +01:00
|
|
|
</div>,
|
2019-07-14 21:43:49 +02:00
|
|
|
]);
|
|
|
|
}
|
2023-02-03 20:52:07 +01:00
|
|
|
|
2019-07-14 21:43:49 +02:00
|
|
|
}
|
|
|
|
|