Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Editor: Extract snackbars into a separate component
Editor snackbars are no rendered in the InterfaceSkeleton footer to avoid z-index context issues.
  • Loading branch information
Mamaduka committed Jul 14, 2021
commit 0facff431df619fa333882639f900048fe2ab0ff
24 changes: 15 additions & 9 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
UnsavedChangesWarning,
EditorNotices,
EditorKeyboardShortcutsRegister,
EditorSnackbars,
store as editorStore,
} from '@wordpress/editor';
import { AsyncModeProvider, useSelect, useDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -246,15 +247,20 @@ function Layout( { styles } ) {
</>
}
footer={
! hasReducedUI &&
showBlockBreadcrumbs &&
! isMobileViewport &&
isRichEditingEnabled &&
mode === 'visual' && (
<div className="edit-post-layout__footer">
<BlockBreadcrumb rootLabelText={ documentLabel } />
</div>
)
<>
<EditorSnackbars />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this breaks the UI a bit in "reduced interface mode" (and a couple other modes too). Basically the "footer" is not considered empty any more and an "empty" white area is shown.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should move it to the actions section?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the implications, it could be worth a try 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Works as expected actions area also has z-index, so stacking context is good for us. And If I understand correctly other elements rendered here are also popovers.

{ ! hasReducedUI &&
showBlockBreadcrumbs &&
! isMobileViewport &&
isRichEditingEnabled &&
mode === 'visual' && (
<div className="edit-post-layout__footer">
<BlockBreadcrumb
rootLabelText={ documentLabel }
/>
</div>
) }
</>
}
actions={
<ActionsPanel
Expand Down
8 changes: 7 additions & 1 deletion packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@wordpress/interface';
import {
EditorNotices,
EditorSnackbars,
EntitiesSavedStates,
UnsavedChangesWarning,
store as editorStore,
Expand Down Expand Up @@ -268,7 +269,12 @@ function Editor( { initialSettings } ) {
) }
</>
}
footer={ <BlockBreadcrumb /> }
footer={
<>
<EditorSnackbars />
<BlockBreadcrumb />
</>
}
/>
<Popover.Slot />
<PluginArea />
Expand Down
10 changes: 1 addition & 9 deletions packages/editor/src/components/editor-notices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { filter } from 'lodash';
/**
* WordPress dependencies
*/
import { NoticeList, SnackbarList } from '@wordpress/components';
import { NoticeList } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { store as noticesStore } from '@wordpress/notices';
Expand All @@ -25,9 +25,6 @@ export function EditorNotices( { notices, onRemove } ) {
isDismissible: false,
type: 'default',
} );
const snackbarNotices = filter( notices, {
type: 'snackbar',
} );

return (
<>
Expand All @@ -42,11 +39,6 @@ export function EditorNotices( { notices, onRemove } ) {
>
<TemplateValidationNotice />
</NoticeList>
<SnackbarList
notices={ snackbarNotices }
className="components-editor-notices__snackbar"
onRemove={ onRemove }
/>
</>
);
}
Expand Down
30 changes: 30 additions & 0 deletions packages/editor/src/components/editor-snackbars/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* External dependencies
*/
import { filter } from 'lodash';

/**
* WordPress dependencies
*/
import { SnackbarList } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';

export default function EditorSnackbars() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it should be EditorSnackbarNotices (I'm not great with naming, just asking :) )

Copy link
Member Author

@Mamaduka Mamaduka Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not great with naming, just asking :)

Same here 😄

Since "Snackbars" or "Toasts" are notice types themself, I don't think there's a need for the Notices suffix IMO.

const notices = useSelect(
( select ) => select( noticesStore ).getNotices(),
[]
);
const { removeNotice } = useDispatch( noticesStore );
const snackbarNotices = filter( notices, {
type: 'snackbar',
} );

return (
<SnackbarList
notices={ snackbarNotices }
className="components-editor-notices__snackbar"
onRemove={ removeNotice }
/>
);
}
1 change: 1 addition & 0 deletions packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { default as EditorKeyboardShortcutsRegister } from './global-keyboard-sh
export { default as EditorHistoryRedo } from './editor-history/redo';
export { default as EditorHistoryUndo } from './editor-history/undo';
export { default as EditorNotices } from './editor-notices';
export { default as EditorSnackbars } from './editor-snackbars';
export { default as EntitiesSavedStates } from './entities-saved-states';
export { default as ErrorBoundary } from './error-boundary';
export { default as LocalAutosaveMonitor } from './local-autosave-monitor';
Expand Down