Skip to content

Commit

Permalink
Add standard notices to nav menu page (#22374)
Browse files Browse the repository at this point in the history
* Add notices to nav menu page

* Improve styles

* Handle breakpoints
  • Loading branch information
talldan committed May 15, 2020
1 parent 91a8966 commit 7427369
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
49 changes: 37 additions & 12 deletions packages/edit-navigation/src/components/notices/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
/**
* External dependencies
*/
import { filter } from 'lodash';

/**
* WordPress dependencies
*/
import { NoticeList, SnackbarList } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { SnackbarList } from '@wordpress/components';

export default function Notices() {
export default function EditNavigationNotices() {
const { removeNotice } = useDispatch( 'core/notices' );
const notices = useSelect(
( select ) =>
select( 'core/notices' )
.getNotices()
.filter( ( notice ) => notice.type === 'snackbar' ),
( select ) => select( 'core/notices' ).getNotices(),
[]
);
const { removeNotice } = useDispatch( 'core/notices' );
const dismissibleNotices = filter( notices, {
isDismissible: true,
type: 'default',
} );
const nonDismissibleNotices = filter( notices, {
isDismissible: false,
type: 'default',
} );
const snackbarNotices = filter( notices, {
type: 'snackbar',
} );

return (
<SnackbarList
className="edit-navigation-notices"
notices={ notices }
onRemove={ removeNotice }
/>
<>
<NoticeList
notices={ nonDismissibleNotices }
className="edit-navigation-notices__notice-list"
/>
<NoticeList
notices={ dismissibleNotices }
className="edit-navigation-notices__notice-list"
onRemove={ removeNotice }
/>
<SnackbarList
notices={ snackbarNotices }
className="edit-navigation-notices__snackbar-list"
onRemove={ removeNotice }
/>
</>
);
}
23 changes: 22 additions & 1 deletion packages/edit-navigation/src/components/notices/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
.components-snackbar-list.edit-navigation-notices {
.edit-navigation-notices__snackbar-list {
position: fixed;
bottom: 20px;
}

.edit-navigation-notices__notice-list {
// The page has a 10px left margin at narrower widths, reverse that so that the notice sits flush.
margin-left: -10px;

@include break-medium {
// The page has a 20px left margin at wider widths, reverse that so that the notice sits flush.
margin-left: -20px;
}

// Notices have some unusual margin and padding by default, reset that.
.components-notice {
margin: 0;
padding-right: 12px;

// Make sure the close button is centered.
.components-button {
align-self: initial;
}
}
}

0 comments on commit 7427369

Please sign in to comment.