2017-12-24 06:16:45 +00:00
|
|
|
// Package imports.
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { defineMessages, FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
// Components.
|
|
|
|
import Collapsable from 'flavours/glitch/components/collapsable';
|
|
|
|
|
|
|
|
// Utils.
|
|
|
|
import {
|
|
|
|
assignHandlers,
|
|
|
|
hiddenComponent,
|
|
|
|
} from 'flavours/glitch/util/react_helpers';
|
|
|
|
|
|
|
|
// Messages.
|
|
|
|
const messages = defineMessages({
|
|
|
|
placeholder: {
|
|
|
|
defaultMessage: 'Write your warning here',
|
|
|
|
id: 'compose_form.spoiler_placeholder',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handlers.
|
|
|
|
const handlers = {
|
|
|
|
|
|
|
|
// Handles a keypress.
|
2018-01-03 20:36:21 +00:00
|
|
|
handleKeyDown ({
|
2017-12-24 06:16:45 +00:00
|
|
|
ctrlKey,
|
|
|
|
keyCode,
|
|
|
|
metaKey,
|
|
|
|
}) {
|
|
|
|
const { onSubmit } = this.props;
|
|
|
|
|
|
|
|
// We submit the status on control/meta + enter.
|
|
|
|
if (onSubmit && keyCode === 13 && (ctrlKey || metaKey)) {
|
|
|
|
onSubmit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// The component.
|
|
|
|
export default class ComposerSpoiler extends React.PureComponent {
|
|
|
|
|
|
|
|
// Constructor.
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
assignHandlers(this, handlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rendering.
|
|
|
|
render () {
|
2018-01-03 20:36:21 +00:00
|
|
|
const { handleKeyDown } = this.handlers;
|
2017-12-24 06:16:45 +00:00
|
|
|
const {
|
|
|
|
hidden,
|
|
|
|
intl,
|
|
|
|
onChange,
|
|
|
|
text,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
// The result.
|
|
|
|
return (
|
|
|
|
<Collapsable
|
|
|
|
isVisible={!hidden}
|
|
|
|
fullHeight={50}
|
|
|
|
>
|
|
|
|
<label className='composer--spoiler'>
|
|
|
|
<span {...hiddenComponent}>
|
|
|
|
<FormattedMessage {...messages.placeholder} />
|
|
|
|
</span>
|
|
|
|
<input
|
|
|
|
id='glitch.composer.spoiler.input'
|
|
|
|
onChange={onChange}
|
2018-01-03 20:36:21 +00:00
|
|
|
onKeyDown={handleKeyDown}
|
2017-12-24 06:16:45 +00:00
|
|
|
placeholder={intl.formatMessage(messages.placeholder)}
|
|
|
|
type='text'
|
|
|
|
value={text}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
</Collapsable>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Props.
|
|
|
|
ComposerSpoiler.propTypes = {
|
|
|
|
hidden: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
onSubmit: PropTypes.func,
|
|
|
|
text: PropTypes.string,
|
|
|
|
};
|