);
}
/**
* Render the form heading based on showTitle prop
* @private
* @returns {Void|DOMElement} - The heading or an empty element
*/
_renderHeading() {
const { showTitle } = this.props;
if (showTitle) {
return (
{ I18n.t("components.add_comment_form.title") }
);
}
return null;
}
/**
* Render a message telling the user to sign in or sign up to leave a comment.
* @private
* @returns {Void|DOMElement} - The message or an empty element.
*/
_renderAccountMessage() {
const { session } = this.props;
if (!session) {
return (
);
}
return null;
}
/**
* Render the add comment form if session is present.
* @private
* @returns {Void|DOMElement} - The add comment form on an empty element.
*/
_renderForm() {
const { session, submitButtonClassName, commentable: { id, type } } = this.props;
const { disabled } = this.state;
if (session) {
return (
);
}
return null;
}
/**
* Render the form heading based on showTitle prop
* @private
* @returns {Void|DOMElement} - The heading or an empty element
*/
_renderTextArea() {
const { commentable: { id, type }, autoFocus, maxLength } = this.props;
const { error } = this.state;
const className = classnames({ 'is-invalid-input': error });
let textAreaProps = {
ref: (textarea) => {this.bodyTextArea = textarea},
id: `add-comment-${type}-${id}`,
className,
rows: "4",
maxLength,
required: "required",
pattern: `^(.){0,${maxLength}}$`,
placeholder: I18n.t("components.add_comment_form.form.body.placeholder"),
onChange: (evt) => this._checkCommentBody(evt.target.value)
};
if (autoFocus) {
textAreaProps.autoFocus = 'autoFocus';
}
return (
);
}
/**
* Render the text area form error if state has an error
* @private
* @returns {Void|DOMElement} - The error or an empty element
*/
_renderTextAreaError() {
const { maxLength } = this.props;
const { error } = this.state;
if (error) {
return (
{ I18n.t("components.add_comment_form.form.form_error", { length: maxLength }) }
);
}
return null;
}
/**
* Render opinion buttons or not based on the arguable prop
* @private
* @returns {Void|DOMElement} - Returns nothing or a wrapper with buttons
*/
_renderOpinionButtons() {
const { session, arguable } = this.props;
const { alignment } = this.state;
const buttonClassName = classnames('button', 'tiny', 'button--muted');
const okButtonClassName = classnames(buttonClassName, 'opinion-toggle--ok', {
'is-active': alignment === 1
});
const koButtonClassName = classnames(buttonClassName, 'opinion-toggle--ko', {
'is-active': alignment === -1
});
const neutralButtonClassName = classnames(buttonClassName, 'opinion-toggle--meh', {
'is-active': alignment === 0
});
if (session && arguable) {
return (
);
}
return null;
}
/**
* Render a select with an option for each user's verified group
* @private
* @returns {Void|DOMElement} - Returns nothing or a form field.
*/
_renderCommentAs() {
const { session, commentable: { id, type } } = this.props;
const { user, verifiedUserGroups } = session;
if (verifiedUserGroups.length > 0) {
return (