You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.1 KiB
53 lines
1.1 KiB
5 years ago
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import { FormattedMessage } from 'react-intl';
|
||
|
|
||
|
export default
|
||
|
class Spoilers extends React.PureComponent {
|
||
2 years ago
|
|
||
5 years ago
|
static propTypes = {
|
||
|
spoilerText: PropTypes.string,
|
||
|
children: PropTypes.node,
|
||
|
};
|
||
|
|
||
|
state = {
|
||
|
hidden: true,
|
||
2 years ago
|
};
|
||
5 years ago
|
|
||
|
handleSpoilerClick = () => {
|
||
|
this.setState({ hidden: !this.state.hidden });
|
||
2 years ago
|
};
|
||
5 years ago
|
|
||
|
render () {
|
||
|
const { spoilerText, children } = this.props;
|
||
|
const { hidden } = this.state;
|
||
|
|
||
2 years ago
|
const toggleText = hidden ?
|
||
|
(<FormattedMessage
|
||
|
id='status.show_more'
|
||
|
defaultMessage='Show more'
|
||
|
key='0'
|
||
|
/>) :
|
||
|
(<FormattedMessage
|
||
|
id='status.show_less'
|
||
|
defaultMessage='Show less'
|
||
|
key='0'
|
||
|
/>);
|
||
5 years ago
|
|
||
|
return ([
|
||
|
<p className='spoiler__text'>
|
||
|
{spoilerText}
|
||
|
{' '}
|
||
|
<button tabIndex='0' className='status__content__spoiler-link' onClick={this.handleSpoilerClick}>
|
||
|
{toggleText}
|
||
|
</button>
|
||
|
</p>,
|
||
|
<div className={`status__content__spoiler ${!hidden ? 'status__content__spoiler--visible' : ''}`}>
|
||
|
{children}
|
||
2 years ago
|
</div>,
|
||
5 years ago
|
]);
|
||
|
}
|
||
2 years ago
|
|
||
5 years ago
|
}
|
||
|
|