Skip to content
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

- `ConfirmDialog`: Add `__next40pxDefaultSize` to buttons ([#58421](https://github.com/WordPress/gutenberg/pull/58421)).
- `SnackbarList`: Allow limiting the number of maximum visible Snackbars ([#58559](https://github.com/WordPress/gutenberg/pull/58559)).

### Bug Fix

Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/snackbar/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ const SNACKBAR_VARIANTS = {
*/
export function SnackbarList( {
notices,
maxVisible,
className,
children,
onRemove,
}: WordPressComponentProps< SnackbarListProps, 'div' > ) {
const listRef = useRef< HTMLDivElement | null >( null );
const isReducedMotion = useReducedMotion();
const visibleNotices = maxVisible ? notices.slice( -maxVisible ) : notices;
className = classnames( 'components-snackbar-list', className );
const removeNotice =
( notice: SnackbarListProps[ 'notices' ][ number ] ) => () =>
Expand All @@ -76,7 +78,7 @@ export function SnackbarList( {
<div className={ className } tabIndex={ -1 } ref={ listRef }>
{ children }
<AnimatePresence>
{ notices.map( ( notice ) => {
{ visibleNotices.map( ( notice ) => {
const { content, ...restNotice } = notice;

return (
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/snackbar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type SnackbarListProps = {
content: string;
}
>;
maxVisible?: number;
onRemove: ( id: string ) => void;
children?: NoticeChildren | Array< NoticeChildren >;
};
1 change: 1 addition & 0 deletions packages/edit-widgets/src/components/notices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function Notices() {
/>
<SnackbarList
notices={ snackbarNotices }
maxVisible={ 3 }
className="edit-widgets-notices__snackbar"
onRemove={ removeNotice }
/>
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/editor-snackbars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function EditorSnackbars() {
return (
<SnackbarList
notices={ snackbarNotices }
maxVisible={ 3 }
className="components-editor-notices__snackbar"
onRemove={ removeNotice }
/>
Expand Down