diff --git a/client/coral-embed-stream/src/components/EditableCommentContent.js b/client/coral-embed-stream/src/components/EditableCommentContent.js index 3116ec96b..b408c1b1a 100644 --- a/client/coral-embed-stream/src/components/EditableCommentContent.js +++ b/client/coral-embed-stream/src/components/EditableCommentContent.js @@ -1,5 +1,6 @@ import React, {PropTypes} from 'react'; -import {notifyForNewCommentStatus, CommentForm} from 'coral-plugin-commentbox/CommentBox'; +import {notifyForNewCommentStatus} from 'coral-plugin-commentbox/CommentBox'; +import {CommentForm} from 'coral-plugin-commentbox/CommentForm'; import styles from './Comment.css'; import {Icon} from 'coral-ui'; diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index 57ff7cf49..da5f8c5cd 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -1,12 +1,11 @@ import React, {PropTypes} from 'react'; -import {Button} from 'coral-ui'; import {I18n} from '../coral-framework'; import translations from './translations.json'; import Slot from 'coral-framework/components/Slot'; import {connect} from 'react-redux'; -import classnames from 'classnames'; +import {CommentForm} from './CommentForm'; -const name = 'coral-plugin-commentbox'; +export const name = 'coral-plugin-commentbox'; // Given a newly posted comment's status, show a notification to the user // if needed @@ -18,133 +17,6 @@ export const notifyForNewCommentStatus = (addNotification, status) => { } }; -/** - * Common UI for Creating or Editing a Comment - */ -export class CommentForm extends React.Component { - static propTypes = { - - // Initial value for underlying comment body textarea - defaultValue: PropTypes.string, - charCountEnable: PropTypes.bool.isRequired, - maxCharCount: PropTypes.number, - cancelButtonClicked: PropTypes.func, - - // Save the comment in the form. - // Will be passed { body: String } - saveComment: PropTypes.func.isRequired, - - // DOM ID for form input that edits comment body - bodyInputId: PropTypes.string, - - // screen reader label for input that edits comment body - bodyLabel: PropTypes.string, - - // Placeholder for input that edits comment body - bodyPlaceholder: PropTypes.string, - - // render at start of button container (useful for extra buttons) - buttonContainerStart: PropTypes.node, - - // render inside submit button - submitText: PropTypes.node, - - styles: PropTypes.shape({ - textarea: PropTypes.string - }), - - // cStyle for enabled save - saveButtonCStyle: PropTypes.string, - - // return whether the save button should be enabled for the provided - // comment ({ body }) (for reasons other than charCount) - saveCommentEnabled: PropTypes.func, - - // className to add to buttons - buttonClass: PropTypes.string, - } - static get defaultProps() { - return { - bodyLabel: lang.t('comment'), - bodyPlaceholder: lang.t('comment'), - submitText: lang.t('post'), - saveButtonCStyle: 'darkGrey', - saveCommentEnabled: () => true, - }; - } - constructor(props) { - super(props); - this.onBodyChange = this.onBodyChange.bind(this); - this.onClickSubmit = this.onClickSubmit.bind(this); - this.state = { - body: props.defaultValue || '' - }; - } - onBodyChange(e) { - this.setState({body: e.target.value}); - } - onClickSubmit(e) { - e.preventDefault(); - const {saveComment} = this.props; - const {body} = this.state; - saveComment({body}); - } - render() { - const {maxCharCount, styles, saveCommentEnabled, buttonClass, charCountEnable} = this.props; - - const body = this.state.body; - const length = body.length; - const isNotValidLength = (length) => !length || (maxCharCount && length > maxCharCount); - const disablePostComment = (charCountEnable && isNotValidLength(length)) || ! saveCommentEnabled({body}); - - return
-
- -