@@ -15,8 +15,6 @@ import MarkdownRenderer from './MarkdownRenderer';
15
15
import { Box } from 'grommet/components/Box' ;
16
16
import { Text } from 'grommet/components/Text' ;
17
17
import { TextArea } from 'grommet/components/TextArea' ;
18
- import { Tabs } from 'grommet/components/Tabs' ;
19
- import { Tab } from 'grommet/components/Tab' ;
20
18
import { Button } from 'grommet/components/Button' ;
21
19
import { Stack } from 'grommet/components/Stack' ;
22
20
import Comment from './Comment' ;
@@ -66,6 +64,9 @@ function CommentInput({
66
64
67
65
const [ comment , setComment ] = React . useState ( '' ) ;
68
66
const [ saving , setSaving ] = React . useState ( false ) ;
67
+ const [ activeTab , setActiveTab ] = React . useState < 'write' | 'preview' > (
68
+ 'write' ,
69
+ ) ;
69
70
70
71
const onInputChange = React . useCallback (
71
72
( e ) => {
@@ -98,7 +99,7 @@ function CommentInput({
98
99
const count = post . getLinkedRecord ( 'comments' ) ?. getValue ( 'totalCount' ) ;
99
100
if ( Number . isInteger ( count ) ) {
100
101
// $FlowFixMe: count has been checked by isInteger
101
- const newCount = count + 1 ;
102
+ const newCount = count + 1 ;
102
103
// eslint-disable-next-line no-unused-expressions
103
104
post . getLinkedRecord ( 'comments' ) ?. setValue ( newCount , 'totalCount' ) ;
104
105
}
@@ -156,28 +157,59 @@ function CommentInput({
156
157
anchor = "center" >
157
158
< Box style = { { opacity : isLoggedIn ? 1 : 0.3 } } >
158
159
< Box height = { { min : 'small' } } >
159
- < Tabs justify = "start" >
160
- < Tab title = { < Text size = "small" > Write</ Text > } >
161
- < Box pad = "small" height = "small" >
162
- < TextArea
163
- focusIndicator = { false }
164
- disabled = { saving }
165
- placeholder = "Leave a comment (supports markdown)"
166
- value = { comment }
167
- style = { { height : '100%' , fontWeight : 'normal' } }
168
- onChange = { onInputChange }
169
- />
170
- </ Box >
171
- </ Tab >
172
- < Tab title = { < Text size = "small" > Preview</ Text > } >
173
- < Box pad = "small" height = { { min : 'small' } } >
174
- < MarkdownRenderer
175
- trustedInput = { false }
176
- source = { comment . trim ( ) ? comment : 'Nothing to preview.' }
177
- />
178
- </ Box >
179
- </ Tab >
180
- </ Tabs >
160
+ < Box pad = "small" direction = "row" gap = "medium" >
161
+ < Button
162
+ plain
163
+ focusIndicator = { false }
164
+ label = {
165
+ < Box
166
+ pad = { { bottom : 'xsmall' } }
167
+ border = { {
168
+ color : activeTab === 'write' ? 'black' : 'brand' ,
169
+ side : 'bottom' ,
170
+ size : 'small' ,
171
+ } } >
172
+ < Text size = "small" > Write</ Text >
173
+ </ Box >
174
+ }
175
+ onClick = { ( ) => setActiveTab ( 'write' ) }
176
+ />
177
+ < Button
178
+ plain
179
+ focusIndicator = { false }
180
+ label = {
181
+ < Box
182
+ pad = { { bottom : 'xsmall' } }
183
+ border = { {
184
+ color : activeTab === 'preview' ? 'black' : 'brand' ,
185
+ side : 'bottom' ,
186
+ size : 'small' ,
187
+ } } >
188
+ < Text size = "small" > Preview</ Text >
189
+ </ Box >
190
+ }
191
+ onClick = { ( ) => setActiveTab ( 'preview' ) }
192
+ />
193
+ </ Box >
194
+ { activeTab === 'write' ? (
195
+ < Box pad = "small" height = "small" >
196
+ < TextArea
197
+ focusIndicator = { false }
198
+ disabled = { saving }
199
+ placeholder = "Leave a comment (supports markdown)"
200
+ value = { comment }
201
+ style = { { height : '100%' , fontWeight : 'normal' } }
202
+ onChange = { onInputChange }
203
+ />
204
+ </ Box >
205
+ ) : (
206
+ < Box pad = "small" height = { { min : 'small' } } >
207
+ < MarkdownRenderer
208
+ trustedInput = { false }
209
+ source = { comment . trim ( ) ? comment : 'Nothing to preview.' }
210
+ />
211
+ </ Box >
212
+ ) }
181
213
</ Box >
182
214
< Box >
183
215
< Box pad = "small" align = "end" >
0 commit comments