Newer
Older
import React, { useState } 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 [value, setValue] = useState('');
return (
<Wrapper className={className}>
<form onSubmit={handleSubmit}>
<TextWrapper>
<ReplyTextArea
placeholder={isNewComment ? 'Write comment...' : 'Reply...'}
onKeyDown={e => {
if (e.keyCode === 13 && !e.shiftKey) {
e.preventDefault();
if (value) handleSubmit(e);
}
}}
<ActionWrapper>
<ButtonGroup>
<Button disabled={value.length === 0} primary type="submit">
Post
</Button>
<Button disabled={value.length === 0} onClick={resetValue}>
Cancel
</Button>
</ButtonGroup>
</ActionWrapper>