Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget Screen: Add default notices support #31578

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 27 additions & 7 deletions packages/edit-widgets/src/components/notices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,47 @@ import { filter } from 'lodash';
/**
* WordPress dependencies
*/
import { SnackbarList } from '@wordpress/components';
import { NoticeList, SnackbarList } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';

function Notices() {
const { removeNotice } = useDispatch( noticesStore );
const { notices } = useSelect( ( select ) => {
return {
notices: select( noticesStore ).getNotices(),
};
}, [] );

const dismissibleNotices = filter( notices, {
isDismissible: true,
type: 'default',
} );
const nonDismissibleNotices = filter( notices, {
isDismissible: false,
type: 'default',
} );
const snackbarNotices = filter( notices, {
type: 'snackbar',
} );
const { removeNotice } = useDispatch( noticesStore );

return (
<SnackbarList
notices={ snackbarNotices }
className="edit-widgets-notices__snackbar"
onRemove={ removeNotice }
/>
<>
<NoticeList
notices={ nonDismissibleNotices }
className="edit-widgets-notices__pinned"
/>
<NoticeList
notices={ dismissibleNotices }
className="edit-widgets-notices__dismissible"
onRemove={ removeNotice }
/>
<SnackbarList
notices={ snackbarNotices }
className="edit-widgets-notices__snackbar"
onRemove={ removeNotice }
/>
</>
);
}

Expand Down
18 changes: 18 additions & 0 deletions packages/edit-widgets/src/components/notices/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@
padding-right: 16px;
}
@include editor-left(".edit-widgets-notices__snackbar");

.edit-widgets-notices__dismissible,
.edit-widgets-notices__pinned {
.components-notice {
box-sizing: border-box;
margin: 0;
border-bottom: $border-width solid rgba(0, 0, 0, 0.2);
padding: 0 $grid-unit-15;

// Min-height matches the height of a single-line notice with an action button.
min-height: $header-height;

// Margins ensure that the dismiss button aligns to the center of the first line of text.
.components-notice__dismiss {
margin-top: $grid-unit-15;
}
}
}