Newer
Older
import React, { useState, useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import styled, { css } from 'styled-components';
const Wrapper = styled.div`
background: #e2e2e2;
display: flex;
flex-direction: column;
padding: 8px 16px;
const ReplyTextArea = styled.textarea`
background: #e2e2e2;
box-sizing: border-box;
width: 100%;
const ActionWrapper = styled.div`
display: flex;
justify-content: flex-end;
margin-top: 4px;
const primary = css`
background: gray;
color: white;
const Button = styled.button`
border: 0;
border-radius: 5px;
cursor: pointer;
color: gray;
padding: 8px 16px;
${props => props.primary && primary}
${props => props.disabled && `cursor: not-allowed;`}
const ButtonGroup = styled.div`
> button:not(:last-of-type) {
margin-right: 8px;
}
const { className, isNewComment, onClickPost } = props;
const commentInput = useRef(null);
useEffect(() => {
setTimeout(() => {
if (isNewComment) commentInput.current.focus();
});
}, []);
setCommentValue('');
};
const onBlur = () => {
const {
current: { value },
} = commentInput;
if (value !== '') {
// Save into local storage
}
if (isNewComment === 0 && value === '') {
// resolveComment();
}
return (
<Wrapper className={className}>
<form onSubmit={handleSubmit}>
<TextWrapper>
<ReplyTextArea
placeholder={isNewComment ? 'Write comment...' : 'Reply...'}
onKeyDown={e => {
if (e.keyCode === 13 && !e.shiftKey) {
e.preventDefault();
<ActionWrapper>
<ButtonGroup>
Post
</Button>
Cancel
</Button>
</ButtonGroup>
</ActionWrapper>