Skip to content

Commit 149db9c

Browse files
committed
Implement PostCommentWrite presentational
1 parent 3a0c535 commit 149db9c

File tree

10 files changed

+91
-41
lines changed

10 files changed

+91
-41
lines changed

src/components/common/Button.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ const Button: React.SFC<ButtonProps> = ({
4848
}) => {
4949
const htmlProps = rest as any;
5050
return (
51-
<ButtonBlock color={color} inline={inline} {...htmlProps}>
51+
<ButtonBlock
52+
color={color}
53+
inline={inline}
54+
{...htmlProps}
55+
onClick={e => {
56+
if (htmlProps.onClick) {
57+
htmlProps.onClick(e);
58+
}
59+
(e.target as HTMLButtonElement).blur();
60+
}}
61+
>
5262
{children}
5363
</ButtonBlock>
5464
);

src/components/common/Typography.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const TypographyBlock = styled.div`
99
letter-spacing: -0.02em;
1010
word-break: keep-all;
1111
word-wrap: break-word;
12-
font-family: 'Spoqa Han Sans';
12+
font-family: 'Spoqa Han Sans', -apple-system, BlinkMacSystemFont,
13+
-apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Apple SD Gothic Neo',
14+
arial, 나눔고딕, 'Nanum Gothic', 돋움;
1315
1416
a {
1517
color: ${palette.teal7};

src/components/post/PostCommentsWrite.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,53 @@ import * as React from 'react';
22
import styled from 'styled-components';
33
import TextareaAutosize from 'react-textarea-autosize';
44
import Button from '../common/Button';
5+
import palette from '../../lib/styles/palette';
6+
import { customFont } from '../../lib/styles/utils';
57

68
const PostCommentsWriteBlock = styled.div`
79
> .buttons-wrapper {
810
display: flex;
911
justify-content: flex-end;
1012
}
1113
`;
12-
const StyledTextarea = styled(TextareaAutosize)``;
14+
const StyledTextarea = styled(TextareaAutosize)`
15+
resize: none;
16+
padding: 1rem;
17+
outline: none;
18+
border: 1px solid ${palette.gray2};
19+
margin-bottom: 1.5rem;
20+
width: 100%;
21+
border-radius: 4px;
22+
min-height: 5.625rem;
23+
font-size: 1rem;
24+
${customFont};
25+
color: ${palette.gray9};
26+
&::placeholder {
27+
color: ${palette.gray5};
28+
}
29+
line-height: 1.75;
30+
`;
1331

14-
export interface PostCommentsWriteProps {}
32+
export interface PostCommentsWriteProps {
33+
comment: string;
34+
onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
35+
onWrite: () => void;
36+
}
1537

16-
const PostCommentsWrite: React.FC<PostCommentsWriteProps> = props => {
38+
const PostCommentsWrite: React.FC<PostCommentsWriteProps> = ({
39+
comment,
40+
onChange,
41+
onWrite,
42+
}) => {
1743
return (
1844
<PostCommentsWriteBlock>
19-
<StyledTextarea placeholder="댓글을 작성하세요" />
45+
<StyledTextarea
46+
placeholder="댓글을 작성하세요"
47+
value={comment}
48+
onChange={onChange}
49+
/>
2050
<div className="buttons-wrapper">
21-
<Button>댓글 작성</Button>
51+
<Button onClick={onWrite}>댓글 작성</Button>
2252
</div>
2353
</PostCommentsWriteBlock>
2454
);

src/components/post/__tests__/PostCommentsWrite.test.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import * as React from 'react';
2-
import { render } from 'react-testing-library';
2+
import { render, fireEvent } from 'react-testing-library';
33
import PostCommentsWrite, {
44
PostCommentsWriteProps,
55
} from '../PostCommentsWrite';
66

77
describe('PostCommentsWrite', () => {
88
const setup = (props: Partial<PostCommentsWriteProps> = {}) => {
9-
const initialProps: PostCommentsWriteProps = {};
9+
const initialProps: PostCommentsWriteProps = {
10+
comment: 'hello world',
11+
onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => {},
12+
onWrite: () => {},
13+
};
1014
const utils = render(<PostCommentsWrite {...initialProps} {...props} />);
1115

12-
const textarea = utils.getByPlaceholderText('댓글을 작성하세요');
16+
const textarea = utils.getByPlaceholderText(
17+
'댓글을 작성하세요',
18+
) as HTMLTextAreaElement;
1319
const writeButton = utils.getByText('댓글 작성');
1420
return {
1521
textarea,
@@ -22,4 +28,27 @@ describe('PostCommentsWrite', () => {
2228
expect(textarea).toBeVisible();
2329
expect(writeButton).toBeVisible();
2430
});
31+
it('shows value on textarea', () => {
32+
const { textarea } = setup();
33+
expect(textarea.value).toBe('hello world');
34+
});
35+
it('calls onChange and onWrite functions', () => {
36+
const onChange = jest.fn();
37+
const onWrite = jest.fn();
38+
const { textarea, writeButton } = setup({ onChange, onWrite });
39+
40+
const changeEvent = {
41+
target: {
42+
value: 'hello world!',
43+
},
44+
};
45+
46+
fireEvent.change(textarea, changeEvent);
47+
48+
expect(onChange).toBeCalled();
49+
50+
fireEvent.click(writeButton);
51+
52+
expect(onWrite).toBeCalled();
53+
});
2554
});

src/components/post/__tests__/PostCommentsWrite.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/components/write/__tests__/__snapshots__/MarkdownPreview.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports[`MarkdownPreview matches snapshot 1`] = `
99
class="sc-bxivhb cFXJHm"
1010
/>
1111
<div
12-
class="sc-bdVaJa eJgOOc"
12+
class="sc-bdVaJa ckqNDH"
1313
>
1414
<div
1515
class="atom-one-light sc-bwzfXH duSwWC"

src/components/write/__tests__/__snapshots__/QuillEditor.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ exports[`QuillEditor matches snapshot 1`] = `
249249
class="sc-cSHVUG cvxfxn"
250250
>
251251
<div
252-
class="sc-VigVT fvLanP"
252+
class="sc-VigVT jwbwQF"
253253
>
254254
<div
255255
tabindex="2"

src/containers/write/__tests__/__snapshots__/ActiveEditor.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ exports[`ActiveEditor matches snapshot 1`] = `
267267
class="sc-jWBwVP boWCkI"
268268
>
269269
<div
270-
class="sc-hMqMXs eaqQgC"
270+
class="sc-hMqMXs cRFXMV"
271271
>
272272
<div
273273
tabindex="2"

src/index.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
body {
22
margin: 0;
33
padding: 0;
4-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
5-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
6-
sans-serif;
4+
font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Apple SD Gothic Neo", arial, 나눔고딕, "Nanum Gothic", 돋움, Dotum, Tahoma, Geneva, sans-serif;
75
-webkit-font-smoothing: antialiased;
86
-moz-osx-font-smoothing: grayscale;
97
color: #212529;

src/lib/styles/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ export const ellipsis = css`
55
white-space: nowrap;
66
overflow-x: hidden;
77
`;
8+
9+
export const customFont = css`
10+
font-family: 'Spoqa Han Sans', -apple-system, BlinkMacSystemFont,
11+
-apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Apple SD Gothic Neo',
12+
arial, 나눔고딕, 'Nanum Gothic', 돋움;
13+
`;

0 commit comments

Comments
 (0)