From 6f46e54e382bf3f535f27ebead18c2bdf4628e49 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sat, 15 Jan 2022 23:08:25 +0100 Subject: chore(comments): handle comment reply --- src/components/CommentForm/CommentForm.module.scss | 13 ++++++++ src/components/CommentForm/CommentForm.tsx | 35 +++++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) (limited to 'src/components/CommentForm') diff --git a/src/components/CommentForm/CommentForm.module.scss b/src/components/CommentForm/CommentForm.module.scss index 2330ca2..922923a 100644 --- a/src/components/CommentForm/CommentForm.module.scss +++ b/src/components/CommentForm/CommentForm.module.scss @@ -3,6 +3,19 @@ .wrapper { width: min(calc(100vw - (var(--spacing-md) * 2)), fun.convert-px(500)); margin: auto; + + &--reply { + width: 100%; + margin-top: var(--spacing-sm); + padding: var(--spacing-md); + position: relative; + background: var(--color-bg); + border: fun.convert-px(1) solid var(--color-border-light); + box-shadow: fun.convert-px(3) fun.convert-px(3) 0 0 + var(--color-shadow-lighter), + fun.convert-px(4) fun.convert-px(4) fun.convert-px(3) fun.convert-px(-2) + var(--color-shadow-light); + } } .title { diff --git a/src/components/CommentForm/CommentForm.tsx b/src/components/CommentForm/CommentForm.tsx index ea02306..1ed219c 100644 --- a/src/components/CommentForm/CommentForm.tsx +++ b/src/components/CommentForm/CommentForm.tsx @@ -3,16 +3,21 @@ import { Form, FormItem, Input, TextArea } from '@components/Form'; import Notice from '@components/Notice/Notice'; import { t } from '@lingui/macro'; import { createComment } from '@services/graphql/mutations'; -import { useState } from 'react'; +import { ForwardedRef, forwardRef, useState } from 'react'; import styles from './CommentForm.module.scss'; -const CommentForm = ({ - articleId, - parentId = 0, -}: { - articleId: number; - parentId?: number; -}) => { +const CommentForm = ( + { + articleId, + parentId = 0, + isReply = false, + }: { + articleId: number; + parentId?: number; + isReply?: boolean; + }, + ref: ForwardedRef +) => { const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [website, setWebsite] = useState(''); @@ -57,10 +62,17 @@ const CommentForm = ({ } }; + const wrapperClasses = `${styles.wrapper} ${ + isReply ? styles['wrapper--reply'] : '' + }`; + return ( -
+

{t`Leave a comment`}

-
+ @@ -111,4 +124,4 @@ const CommentForm = ({ ); }; -export default CommentForm; +export default forwardRef(CommentForm); -- cgit v1.2.3