Skip to content

Commit a691b78

Browse files
committed
feat(editor2): better appearance
1 parent d1775eb commit a691b78

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

src/components/editor/NumericInput2.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
NumericInputProps,
55
} from '@blueprintjs/core'
66

7+
import clsx from 'clsx'
78
import { clamp, noop } from 'lodash-es'
89
import {
910
WheelEventHandler,
@@ -31,6 +32,7 @@ export const NumericInput2 = ({
3132
onFocus,
3233
onWheelFocused,
3334
wheelStepSize,
35+
inputClassName,
3436
...props
3537
}: NumericInput2Props) => {
3638
const allowNegative = min === undefined || min < 0
@@ -79,6 +81,11 @@ export const NumericInput2 = ({
7981
min={min}
8082
max={max}
8183
minorStepSize={minorStepSize}
84+
inputClassName={clsx(
85+
(wheelStepSize !== undefined || onWheelFocused !== undefined) &&
86+
'focus:cursor-ns-resize',
87+
inputClassName,
88+
)}
8289
inputRef={inputRef}
8390
value={endsWithDot ? value + '.' : value}
8491
onFocus={(e) => {

src/components/editor2/EditorToolbar.tsx

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
Button,
3+
ButtonProps,
34
Callout,
45
H2,
56
Icon,
@@ -16,6 +17,7 @@ import { FC, useRef, useState } from 'react'
1617
import { i18n, useTranslation } from '../../i18n/i18n'
1718
import { formatError } from '../../utils/error'
1819
import { formatRelativeTime } from '../../utils/times'
20+
import { useCurrentSize } from '../../utils/useCurrenSize'
1921
import { RelativeTime } from '../RelativeTime'
2022
import { AppToaster } from '../Toaster'
2123
import { Settings } from './Settings'
@@ -40,8 +42,14 @@ export const EditorToolbar: FC<EditorToolbarProps> = ({
4042
onSubmit,
4143
}) => {
4244
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+
4351
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]">
4553
<Icon icon="properties" />
4654
<div className="ml-2 flex items-baseline">
4755
<H2 className="!text-base mb-0">
@@ -53,27 +61,32 @@ export const EditorToolbar: FC<EditorToolbarProps> = ({
5361
</span>
5462
)}
5563
</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">
5765
<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" />
6573
<SubmitButton submitAction={submitAction} onSubmit={onSubmit} />
6674
</div>
6775
</div>
6876
)
6977
}
7078

71-
interface SubmitButtonProps {
79+
interface SubmitButtonProps extends ButtonProps {
7280
submitAction: string
7381
onSubmit: () => Promise<void | false> | false | void
7482
}
7583

76-
const SubmitButton = ({ submitAction, onSubmit }: SubmitButtonProps) => {
84+
const SubmitButton = ({
85+
submitAction,
86+
onSubmit,
87+
className,
88+
...buttonProps
89+
}: SubmitButtonProps) => {
7790
const [submitting, setSubmitting] = useState(false)
7891
const [status, setStatus] = useState<'idle' | 'success' | 'error'>('idle')
7992
const statusResetTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
@@ -102,14 +115,15 @@ const SubmitButton = ({ submitAction, onSubmit }: SubmitButtonProps) => {
102115
return (
103116
<Button
104117
large
118+
{...buttonProps}
105119
intent={
106120
status === 'success'
107121
? 'success'
108122
: status === 'error'
109123
? 'danger'
110124
: 'primary'
111125
}
112-
className="w-40"
126+
className={clsx('w-40', className)}
113127
icon={status === 'success' ? 'tick' : 'upload'}
114128
loading={submitting}
115129
text={submitAction}
@@ -118,7 +132,7 @@ const SubmitButton = ({ submitAction, onSubmit }: SubmitButtonProps) => {
118132
)
119133
}
120134

121-
const AutoSaveButton = () => {
135+
const AutoSaveButton = (buttonProps: ButtonProps) => {
122136
const t = useTranslation()
123137
const edit = useEdit()
124138
const archive = useAtomValue(editorArchiveAtom)
@@ -141,7 +155,6 @@ const AutoSaveButton = () => {
141155
limit: AUTO_SAVE_LIMIT,
142156
})}
143157
<Button
144-
minimal
145158
icon="floppy-disk"
146159
intent="primary"
147160
className=""
@@ -195,33 +208,30 @@ const AutoSaveButton = () => {
195208
onClosed={() => setIsOpen(false)}
196209
>
197210
<Button
198-
minimal
199-
large
211+
{...buttonProps}
200212
icon="projects"
201213
title={t.components.editor2.EditorToolbar.auto_save}
202214
/>
203215
</Popover2>
204216
)
205217
}
206218

207-
const HistoryButtons = () => {
219+
const HistoryButtons = (buttonProps: ButtonProps) => {
208220
const t = useTranslation()
209221
const { history, canRedo, canUndo } = useHistoryValue(historyAtom)
210222
const { undo, redo, checkout } = useHistoryControls(historyAtom)
211223
const [isOpen, setIsOpen] = useState(false)
212224
return (
213225
<>
214226
<Button
215-
minimal
216-
large
227+
{...buttonProps}
217228
icon="undo"
218229
title={t.components.editor2.EditorToolbar.undo}
219230
disabled={!canUndo}
220231
onClick={undo}
221232
/>
222233
<Button
223-
minimal
224-
large
234+
{...buttonProps}
225235
icon="redo"
226236
title={t.components.editor2.EditorToolbar.redo}
227237
disabled={!canRedo}
@@ -274,7 +284,7 @@ const HistoryButtons = () => {
274284
onClosed={() => setIsOpen(false)}
275285
>
276286
<Button
277-
minimal
287+
{...buttonProps}
278288
icon="history"
279289
title={t.components.editor2.EditorToolbar.undo_history}
280290
text={history.index + 1 + '/' + history.stack.length}
@@ -284,7 +294,7 @@ const HistoryButtons = () => {
284294
)
285295
}
286296

287-
const ErrorButton = () => {
297+
const ErrorButton = (buttonProps: ButtonProps) => {
288298
const t = useTranslation()
289299
const globalErrors = useAtomValue(editorAtoms.globalErrors)
290300
const entityErrors = useAtomValue(editorAtoms.entityErrors)
@@ -317,8 +327,7 @@ const ErrorButton = () => {
317327
onInteraction={(isOpen) => setIsOpen(allErrors.length > 0 && isOpen)}
318328
>
319329
<Button
320-
minimal
321-
large
330+
{...buttonProps}
322331
icon={allErrors.length > 0 ? 'cross-circle' : 'tick-circle'}
323332
intent={allErrors.length > 0 ? 'danger' : 'success'}
324333
title={
@@ -332,13 +341,12 @@ const ErrorButton = () => {
332341
)
333342
}
334343

335-
const ErrorVisibleButton = () => {
344+
const ErrorVisibleButton = (buttonProps: ButtonProps) => {
336345
const t = useTranslation()
337346
const [visible, setVisible] = useAtom(editorAtoms.errorsVisible)
338347
return (
339348
<Button
340-
minimal
341-
large
349+
{...buttonProps}
342350
icon="eye-open"
343351
active={visible}
344352
onClick={() => setVisible(!visible)}

src/components/editor2/Settings.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
Button,
3+
ButtonProps,
34
Dialog,
45
DialogBody,
56
FormGroup,
@@ -13,7 +14,9 @@ import { useTranslation } from '../../i18n/i18n'
1314
import { NumericInput2 } from '../editor/NumericInput2'
1415
import { editorAtoms } from './editor-state'
1516

16-
export const Settings = () => {
17+
interface SettingsProps extends ButtonProps {}
18+
19+
export const Settings = (props: SettingsProps) => {
1720
const [isOpen, setIsOpen] = useState(false)
1821
const [config, setConfig] = useAtom(editorAtoms.config)
1922
const t = useTranslation()
@@ -22,7 +25,7 @@ export const Settings = () => {
2225
<>
2326
<Button
2427
icon="cog"
25-
minimal
28+
{...props}
2629
onClick={() => setIsOpen(true)}
2730
title={t.components.editor2.Settings.title}
2831
/>

src/components/editor2/action/ActionItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const ActionItem: FC<ActionItemProps> = memo(
110110
<Card
111111
className={clsx(
112112
className,
113-
'!p-0 !rounded-none',
113+
'!p-0 !rounded overflow-hidden',
114114
typeInfo.accentText,
115115
)}
116116
>

0 commit comments

Comments
 (0)