1
1
import {
2
2
Button ,
3
+ ButtonProps ,
3
4
Callout ,
4
5
H2 ,
5
6
Icon ,
@@ -16,6 +17,7 @@ import { FC, useRef, useState } from 'react'
16
17
import { i18n , useTranslation } from '../../i18n/i18n'
17
18
import { formatError } from '../../utils/error'
18
19
import { formatRelativeTime } from '../../utils/times'
20
+ import { useCurrentSize } from '../../utils/useCurrenSize'
19
21
import { RelativeTime } from '../RelativeTime'
20
22
import { AppToaster } from '../Toaster'
21
23
import { Settings } from './Settings'
@@ -40,8 +42,14 @@ export const EditorToolbar: FC<EditorToolbarProps> = ({
40
42
onSubmit,
41
43
} ) => {
42
44
const t = useTranslation ( )
45
+ const { isLG } = useCurrentSize ( )
46
+ const buttonProps = {
47
+ minimal : true ,
48
+ className : isLG ? undefined : 'min-w-10 h-10' ,
49
+ } satisfies ButtonProps
50
+
43
51
return (
44
- < div className = "px-4 md:px-8 flex items-center flex-wrap bg-white dark:bg-[#383e47]" >
52
+ < div className = "px-4 md:px-8 flex items-center flex-wrap [&_.bp4-button-text]:leading-none bg-white dark:bg-[#383e47]" >
45
53
< Icon icon = "properties" />
46
54
< div className = "ml-2 flex items-baseline" >
47
55
< H2 className = "!text-base mb-0" >
@@ -53,27 +61,32 @@ export const EditorToolbar: FC<EditorToolbarProps> = ({
53
61
</ span >
54
62
) }
55
63
</ div >
56
- < div className = "grow py-2 flex flex-wrap items-center" >
64
+ < div className = "grow py-1 flex flex-wrap items-center justify-end " >
57
65
< span className = "grow" />
58
- < Settings />
59
- < AutoSaveButton />
60
- < HistoryButtons />
61
- < ErrorVisibleButton />
62
- < ErrorButton />
63
- < SourceEditorButton minimal />
64
- < span className = "grow max-w-6 " />
66
+ < Settings { ... buttonProps } />
67
+ < AutoSaveButton { ... buttonProps } />
68
+ < HistoryButtons { ... buttonProps } />
69
+ < ErrorVisibleButton { ... buttonProps } />
70
+ < ErrorButton { ... buttonProps } />
71
+ < SourceEditorButton { ... buttonProps } />
72
+ < span className = "grow max-w-4 " />
65
73
< SubmitButton submitAction = { submitAction } onSubmit = { onSubmit } />
66
74
</ div >
67
75
</ div >
68
76
)
69
77
}
70
78
71
- interface SubmitButtonProps {
79
+ interface SubmitButtonProps extends ButtonProps {
72
80
submitAction : string
73
81
onSubmit : ( ) => Promise < void | false > | false | void
74
82
}
75
83
76
- const SubmitButton = ( { submitAction, onSubmit } : SubmitButtonProps ) => {
84
+ const SubmitButton = ( {
85
+ submitAction,
86
+ onSubmit,
87
+ className,
88
+ ...buttonProps
89
+ } : SubmitButtonProps ) => {
77
90
const [ submitting , setSubmitting ] = useState ( false )
78
91
const [ status , setStatus ] = useState < 'idle' | 'success' | 'error' > ( 'idle' )
79
92
const statusResetTimer = useRef < ReturnType < typeof setTimeout > | null > ( null )
@@ -102,14 +115,15 @@ const SubmitButton = ({ submitAction, onSubmit }: SubmitButtonProps) => {
102
115
return (
103
116
< Button
104
117
large
118
+ { ...buttonProps }
105
119
intent = {
106
120
status === 'success'
107
121
? 'success'
108
122
: status === 'error'
109
123
? 'danger'
110
124
: 'primary'
111
125
}
112
- className = " w-40"
126
+ className = { clsx ( ' w-40' , className ) }
113
127
icon = { status === 'success' ? 'tick' : 'upload' }
114
128
loading = { submitting }
115
129
text = { submitAction }
@@ -118,7 +132,7 @@ const SubmitButton = ({ submitAction, onSubmit }: SubmitButtonProps) => {
118
132
)
119
133
}
120
134
121
- const AutoSaveButton = ( ) => {
135
+ const AutoSaveButton = ( buttonProps : ButtonProps ) => {
122
136
const t = useTranslation ( )
123
137
const edit = useEdit ( )
124
138
const archive = useAtomValue ( editorArchiveAtom )
@@ -141,7 +155,6 @@ const AutoSaveButton = () => {
141
155
limit : AUTO_SAVE_LIMIT ,
142
156
} ) }
143
157
< Button
144
- minimal
145
158
icon = "floppy-disk"
146
159
intent = "primary"
147
160
className = ""
@@ -195,33 +208,30 @@ const AutoSaveButton = () => {
195
208
onClosed = { ( ) => setIsOpen ( false ) }
196
209
>
197
210
< Button
198
- minimal
199
- large
211
+ { ...buttonProps }
200
212
icon = "projects"
201
213
title = { t . components . editor2 . EditorToolbar . auto_save }
202
214
/>
203
215
</ Popover2 >
204
216
)
205
217
}
206
218
207
- const HistoryButtons = ( ) => {
219
+ const HistoryButtons = ( buttonProps : ButtonProps ) => {
208
220
const t = useTranslation ( )
209
221
const { history, canRedo, canUndo } = useHistoryValue ( historyAtom )
210
222
const { undo, redo, checkout } = useHistoryControls ( historyAtom )
211
223
const [ isOpen , setIsOpen ] = useState ( false )
212
224
return (
213
225
< >
214
226
< Button
215
- minimal
216
- large
227
+ { ...buttonProps }
217
228
icon = "undo"
218
229
title = { t . components . editor2 . EditorToolbar . undo }
219
230
disabled = { ! canUndo }
220
231
onClick = { undo }
221
232
/>
222
233
< Button
223
- minimal
224
- large
234
+ { ...buttonProps }
225
235
icon = "redo"
226
236
title = { t . components . editor2 . EditorToolbar . redo }
227
237
disabled = { ! canRedo }
@@ -274,7 +284,7 @@ const HistoryButtons = () => {
274
284
onClosed = { ( ) => setIsOpen ( false ) }
275
285
>
276
286
< Button
277
- minimal
287
+ { ... buttonProps }
278
288
icon = "history"
279
289
title = { t . components . editor2 . EditorToolbar . undo_history }
280
290
text = { history . index + 1 + '/' + history . stack . length }
@@ -284,7 +294,7 @@ const HistoryButtons = () => {
284
294
)
285
295
}
286
296
287
- const ErrorButton = ( ) => {
297
+ const ErrorButton = ( buttonProps : ButtonProps ) => {
288
298
const t = useTranslation ( )
289
299
const globalErrors = useAtomValue ( editorAtoms . globalErrors )
290
300
const entityErrors = useAtomValue ( editorAtoms . entityErrors )
@@ -317,8 +327,7 @@ const ErrorButton = () => {
317
327
onInteraction = { ( isOpen ) => setIsOpen ( allErrors . length > 0 && isOpen ) }
318
328
>
319
329
< Button
320
- minimal
321
- large
330
+ { ...buttonProps }
322
331
icon = { allErrors . length > 0 ? 'cross-circle' : 'tick-circle' }
323
332
intent = { allErrors . length > 0 ? 'danger' : 'success' }
324
333
title = {
@@ -332,13 +341,12 @@ const ErrorButton = () => {
332
341
)
333
342
}
334
343
335
- const ErrorVisibleButton = ( ) => {
344
+ const ErrorVisibleButton = ( buttonProps : ButtonProps ) => {
336
345
const t = useTranslation ( )
337
346
const [ visible , setVisible ] = useAtom ( editorAtoms . errorsVisible )
338
347
return (
339
348
< Button
340
- minimal
341
- large
349
+ { ...buttonProps }
342
350
icon = "eye-open"
343
351
active = { visible }
344
352
onClick = { ( ) => setVisible ( ! visible ) }
0 commit comments