Skip to content

Commit c00a058

Browse files
committed
chore: tidy-up for house style
1 parent d25237b commit c00a058

File tree

2 files changed

+31
-50
lines changed

2 files changed

+31
-50
lines changed

packages/components/src/CreateComment/CreateComment.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ describe('CreateComment Component', () => {
3737
onChange={mockOnChange}
3838
/>,
3939
)
40-
expect(screen.getByText('Login')).toBeInTheDocument()
40+
expect(
41+
screen.getByText('Hi there! Login to leave a comment'),
42+
).toBeInTheDocument()
4143
expect(
4244
screen.queryByPlaceholderText('Leave your questions or feedback...'),
4345
).toBeNull()

packages/components/src/CreateComment/CreateComment.tsx

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@ export const CreateComment = (props: Props) => {
3030
const placeholder = props.placeholder || 'Leave your questions or feedback...'
3131
const buttonLabel = props.buttonLabel ?? 'Leave a comment'
3232

33-
const onChange = (textAreaElement: HTMLTextAreaElement) => {
34-
;(textAreaElement.parentNode! as HTMLDivElement).dataset.replicatedValue =
35-
textAreaElement.value
36-
props.onChange && props?.onChange(textAreaElement.value)
33+
const onChange = ({ parentNode, value }: HTMLTextAreaElement) => {
34+
;(parentNode! as HTMLDivElement).dataset.replicatedValue = value
35+
props?.onChange(value)
36+
}
37+
38+
const commentIsActive = comment.length > 0 || textareaIsFocussed
39+
const onClick = () => {
40+
!isLoading && onSubmit(comment)
3741
}
3842

3943
return (
40-
<Flex sx={{ flexDirection: 'column', gap: 3 }}>
41-
<Flex data-target="create-comment-container">
44+
<Flex sx={{ flexDirection: 'column' }}>
45+
<Flex data-target="create-comment-container" sx={{ gap: 2 }}>
4246
<Box
4347
sx={{
4448
lineHeight: 0,
45-
marginTop: 2,
4649
display: ['none', 'block'],
4750
flexShrink: 0,
4851
}}
@@ -53,8 +56,8 @@ export const CreateComment = (props: Props) => {
5356
sx={{
5457
display: 'block',
5558
background: 'white',
56-
flexGrow: 1,
57-
marginLeft: [2, 5],
59+
flex: 1,
60+
marginLeft: [0, 3],
5861
borderRadius: 1,
5962
position: 'relative',
6063
width: 'min-content',
@@ -69,16 +72,11 @@ export const CreateComment = (props: Props) => {
6972
},
7073
}}
7174
>
72-
{!isLoggedIn ? (
73-
<LoginPrompt />
74-
) : (
75-
<>
76-
<div
77-
className={
78-
comment.length > 0 || textareaIsFocussed
79-
? 'grow-wrap value-set'
80-
: 'grow-wrap'
81-
}
75+
{!isLoggedIn && <LoginPrompt />}
76+
{isLoggedIn && (
77+
<Flex sx={{ flexDirection: 'column' }}>
78+
<Box
79+
className={`grow-wrap ${commentIsActive ? 'value-set' : ''}`}
8280
>
8381
<Textarea
8482
value={comment}
@@ -93,60 +91,43 @@ export const CreateComment = (props: Props) => {
9391
onFocus={() => setTextareaIsFocussed(true)}
9492
onBlur={() => setTextareaIsFocussed(false)}
9593
/>
96-
</div>
94+
</Box>
9795
<Text
9896
sx={{
9997
fontSize: 1,
100-
display:
101-
comment.length > 0 || textareaIsFocussed ? 'block' : 'none',
102-
position: 'absolute',
103-
right: 0,
104-
bottom: 0,
105-
pointerEvents: 'none',
106-
padding: 1,
98+
display: commentIsActive ? 'flex' : 'none',
99+
alignSelf: 'flex-end',
100+
padding: 2,
107101
}}
108102
>
109103
{comment.length}/{maxLength}
110104
</Text>
111-
</>
105+
</Flex>
112106
)}
113107
</Box>
114108
<Flex
115109
sx={{
116110
alignSelf: 'flex-end',
117111
height: ['40px', '52px'],
118112
width: ['40px', 'auto'],
119-
marginLeft: 3,
120113
}}
121114
>
122115
<Button
123116
data-cy={isReply ? 'reply-submit' : 'comment-submit'}
124117
data-testid="send-comment-button"
125118
disabled={!comment.trim() || !isLoggedIn || isLoading}
126119
variant="primary"
127-
onClick={() => {
128-
if (!isLoading) {
129-
onSubmit(comment)
130-
}
131-
}}
120+
onClick={onClick}
132121
sx={{
133-
marginTop: isLoggedIn ? 0 : 0,
134122
height: ['40px', '100%'],
135123
width: ['40px', 'auto'],
136124
padding: [0, 1],
137125
}}
138126
>
139-
{isLoading ? (
140-
'Loading...'
141-
) : (
127+
{isLoading && 'Loading...'}
128+
{!isLoading && (
142129
<>
143-
<Text
144-
sx={{
145-
display: ['none', 'block'],
146-
}}
147-
>
148-
{buttonLabel}
149-
</Text>
130+
<Text sx={{ display: ['none', 'block'] }}>{buttonLabel}</Text>
150131
<Image
151132
src={sendMobile}
152133
sx={{
@@ -168,17 +149,15 @@ const LoginPrompt = () => {
168149
return (
169150
<Box sx={{ padding: [3, 4] }}>
170151
<Text data-cy="comments-login-prompt">
171-
Hi there!{' '}
172152
<Link
173153
to="/sign-in"
174154
style={{
175155
textDecoration: 'underline',
176156
color: 'inherit',
177157
}}
178158
>
179-
Login
180-
</Link>{' '}
181-
to leave a comment
159+
Hi there! Login to leave a comment
160+
</Link>
182161
</Text>
183162
</Box>
184163
)

0 commit comments

Comments
 (0)