Skip to content

Commit

Permalink
feat: add comment-placer-component (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroMiguelSS authored and satazor committed Feb 21, 2019
1 parent d94a90d commit dfe61d3
Show file tree
Hide file tree
Showing 24 changed files with 2,383 additions and 2,039 deletions.
3,721 changes: 1,865 additions & 1,856 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@
"prop-type-conditionals": "0.0.6",
"prop-types": "^15.6.2",
"proper-on-transition-end": "^0.3.0",
"react-animate-height": "^2.0.7",
"react-modal": "^3.5.1",
"react-popper": "^1.0.0",
"react-preload-image": "^1.0.4",
"react-time-ago": "^3.0.2",
"react-transition-group": "^2.4.0"
"react-transition-group": "^2.5.3"
},
"peerDepedencies": {
"react": "^16.6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/avatar/Avatar.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
left: 0;
width: 100%;
height: 100%;
object-fit: contain;
object-fit: cover;
}
}
9 changes: 6 additions & 3 deletions src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export default class Button extends Component {
feedback: 'none',
};

state = {};
state = {
feedback: null,
feedbackOutcome: null,
};

componentDidMount() {
this.maybeHandleFeedbackChange();
Expand Down Expand Up @@ -95,7 +98,7 @@ export default class Button extends Component {

handleProgressBarBegin = () => {
this.clearFeedbackOutcomeTimers();
this.setState({ feedbackOutcome: undefined });
this.setState({ feedbackOutcome: null });
};

handleProgressBarEnd = () => {
Expand All @@ -105,7 +108,7 @@ export default class Button extends Component {
this.setState({ feedbackOutcome: feedback }, () => {
this.clearFeedbackOutcomeTimers();
this.resetFeedbackOutcomeTimeoutId = setTimeout(() => {
this.setState({ feedbackOutcome: undefined });
this.setState({ feedbackOutcome: null });
}, FEEDBACK_OUTCOME_VISIBLE_DURATION);
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/comment-error/CommentError.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@import "../../styles/mixins/typography";

.commentError {
min-width: 35rem;
min-width: 30rem;

& .content {
position: relative;
Expand Down
2 changes: 1 addition & 1 deletion src/components/comment-input/CommentInput.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@import "../../styles/mixins/typography";

.commentInput {
min-width: 350px;
min-width: 30rem;

& .textarea {
width: 100%;
Expand Down
107 changes: 45 additions & 62 deletions src/components/comment-input/CommentInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import TextareaAutosize from '../textarea-autosize';
import TextButton from '../text-button';
import { ModalTrigger, ConfirmModal } from '../modal';
import { Author } from '../comment-common';
import FocusManager from './FocusManager';
import styles from './CommentInput.css';

const isBodyEmpty = (body) => !body || isWhitespace(body);
Expand All @@ -33,18 +32,12 @@ export default class CommentInput extends PureComponent {
type: PropTypes.oneOf(['reply', 'edit']),
author: PropTypes.object.isRequired,
body: PropTypes.string,
focusOnMount: PropTypes.bool,
preloadAvatarImage: PropTypes.bool,
onSubmit: PropTypes.func.isRequired,
onCancel: PropTypes.func.isRequired,
className: PropTypes.string,
};

static defaultProps = {
focusOnMount: true,
};

focusManagerRef = createRef();
textareaAutosizeRef = createRef();

constructor(props) {
Expand All @@ -57,76 +50,66 @@ export default class CommentInput extends PureComponent {
}

render() {
const { type, body, author, focusOnMount, preloadAvatarImage, onSubmit, onCancel, className, ...rest } = this.props;
const { type, body, author, preloadAvatarImage, onSubmit, onCancel, className, ...rest } = this.props;
const { empty, changed } = this.state;
const reply = type === 'reply';

const ConfirmCancelModal = reply ? ConfirmCancelReplyModal : ConfirmCancelEditModal;

return (
<FocusManager ref={ this.focusManagerRef } focusOnMount={ focusOnMount }>
<div { ...rest } className={ classNames(styles.commentInput, className) }>
<TextareaAutosize
placeholder={ reply ? 'Reply to this comment...' : '' }
ref={ this.textareaAutosizeRef }
defaultValue={ body }
rows={ reply ? 2 : 1 }
maxRows={ 10 }
submitOnEnter
onSubmit={ this.handleSubmitClick }
onChange={ this.handleTextareaChange }
onTransitionEnd={ this.handleTextareaTransitionEnd }
className={ styles.textarea } />

<div className={ styles.bottomBar }>
<Author
author={ author }
myself
preloadAvatarImage={ preloadAvatarImage }
className={ styles.author } />

<div className={ styles.actions }>
<TextButton
onMouseDown={ this.handleActionMouseDown }
onClick={ this.handleSubmitClick }
disabled={ empty }
className={ styles.button }>
{ reply ? 'Send' : 'Save' }
</TextButton>

<span className={ styles.separator } />

{ changed ? (
<ModalTrigger modal={ <ConfirmCancelModal onConfirm={ onCancel } /> }>
<TextButton
onMouseDown={ this.handleActionMouseDown }
className={ styles.button }>
Cancel
</TextButton>
</ModalTrigger>
) : (
<div { ...rest } className={ classNames(styles.commentInput, className) }>
<TextareaAutosize
placeholder={ reply ? 'Reply to this comment...' : '' }
ref={ this.textareaAutosizeRef }
defaultValue={ body }
rows={ 1 }
maxRows={ 10 }
submitOnEnter
onSubmit={ this.handleSubmitClick }
onChange={ this.handleTextareaChange }
onTransitionEnd={ this.handleTextareaTransitionEnd }
className={ styles.textarea } />

<div className={ styles.bottomBar }>
<Author
author={ author }
myself
preloadAvatarImage={ preloadAvatarImage }
className={ styles.author } />

<div className={ styles.actions }>
<TextButton
onMouseDown={ this.handleActionMouseDown }
onClick={ this.handleSubmitClick }
disabled={ empty }
className={ styles.button }>
{ reply ? 'Send' : 'Save' }
</TextButton>

<span className={ styles.separator } />

{ changed ? (
<ModalTrigger modal={ <ConfirmCancelModal onConfirm={ onCancel } /> }>
<TextButton
onMouseDown={ this.handleActionMouseDown }
onClick={ this.handleCancelClick }
className={ styles.button }>
Cancel
Cancel
</TextButton>
) }
</div>
</ModalTrigger>
) : (
<TextButton
onMouseDown={ this.handleActionMouseDown }
onClick={ this.handleCancelClick }
className={ styles.button }>
Cancel
</TextButton>
) }
</div>
</div>
</FocusManager>
</div>
);
}

isFocused() {
return this.focusManagerRef.current ? this.focusManagerRef.current.isFocused() : false;
}

focus() {
this.focusManagerRef.current && this.focusManagerRef.current.focus();
}

handleActionMouseDown = (event) => {
// Since the textarea animates, when the mouseup happens the mouse is no longer within the button
// Because of that we trigger click() manually after the animation ends
Expand Down
111 changes: 0 additions & 111 deletions src/components/comment-input/FocusManager.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/comment-placeholder/CommentPlaceholder.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}

.commentPlaceholder {
min-width: 35rem;
min-width: 30rem;
background-color: var(--color-white);

& .content {
Expand Down
Loading

0 comments on commit dfe61d3

Please sign in to comment.