Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 69fc27a

Browse files
authored
fix: discard on mobile (#1107)
1 parent 79a6fc5 commit 69fc27a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

packages/core/src/components/entry-editor/EditorToolbar.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
lg:!hidden;
2323
}
2424

25+
.CMS_EditorToolbar_discard-button {
26+
@apply flex
27+
lg:!hidden;
28+
}
29+
2530
.CMS_EditorToolbar_delete-button {
2631
@apply flex
2732
lg:!hidden;

packages/core/src/components/entry-editor/EditorToolbar.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import MenuGroup from '../common/menu/MenuGroup';
2929
import MenuItemButton from '../common/menu/MenuItemButton';
3030
import EditorWorkflowToolbarButtons from './EditorWorkflowToolbarButtons';
3131

32-
import type { WorkflowStatus } from '@staticcms/core/constants/publishModes';
3332
import type { CollectionWithDefaults, EditorPersistOptions } from '@staticcms/core';
33+
import type { WorkflowStatus } from '@staticcms/core/constants/publishModes';
3434
import type { FC, MouseEventHandler } from 'react';
3535

3636
import './EditorToolbar.css';
@@ -41,6 +41,7 @@ export const classes = generateClassNames('EditorToolbar', [
4141
'more-menu-button',
4242
'more-menu-label-icon',
4343
'preview-toggle',
44+
'discard-button',
4445
'delete-button',
4546
'publish-button',
4647
'publish-button-icon',
@@ -419,14 +420,34 @@ const EditorToolbar: FC<EditorToolbarProps> = ({
419420
disabled={disabled}
420421
/>
421422
) : null}
422-
{canDelete ? (
423+
{hasChanged ? (
424+
<IconButton
425+
icon={TrashIcon}
426+
key="discard-button"
427+
title={t('editor.editorToolbar.discardChanges')}
428+
color="warning"
429+
variant="text"
430+
onClick={handleDiscardDraft}
431+
rootClassName={classes['discard-button']}
432+
aria-label="discard chnages"
433+
disabled={disabled}
434+
/>
435+
) : canDelete &&
436+
(!useOpenAuthoring || hasUnpublishedChanges) &&
437+
(!useWorkflow || workflowDeleteLabel) ? (
423438
<IconButton
424439
icon={TrashIcon}
425440
key="delete-button"
426-
title={t('editor.editorToolbar.deleteEntry')}
441+
title={useWorkflow ? t(workflowDeleteLabel!) : t('editor.editorToolbar.deleteEntry')}
427442
color="error"
428443
variant="text"
429-
onClick={onDelete}
444+
onClick={
445+
useWorkflow &&
446+
workflowDeleteLabel &&
447+
workflowDeleteLabel !== 'editor.editorToolbar.deletePublishedEntry'
448+
? onDeleteUnpublishedChanges
449+
: onDelete
450+
}
430451
rootClassName={classes['delete-button']}
431452
aria-label="delete"
432453
disabled={disabled}

0 commit comments

Comments
 (0)