@automattic/jetpack-components 0.53.0 → 0.53.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ### This is a list detailing changes for the Jetpack RNA Components package releases.
4
4
 
5
+ ## [0.53.1] - 2024-05-09
6
+ ### Added
7
+ - Added GlobalNotices component and useGlobalNotices hook [#37286]
8
+
5
9
  ## [0.53.0] - 2024-05-08
6
10
  ### Added
7
11
  - Social: Added add connection modal [#37211]
@@ -1019,6 +1023,7 @@
1019
1023
  ### Changed
1020
1024
  - Update node version requirement to 14.16.1
1021
1025
 
1026
+ [0.53.1]: https://github.com/Automattic/jetpack-components/compare/0.53.0...0.53.1
1022
1027
  [0.53.0]: https://github.com/Automattic/jetpack-components/compare/0.52.1...0.53.0
1023
1028
  [0.52.1]: https://github.com/Automattic/jetpack-components/compare/0.52.0...0.52.1
1024
1029
  [0.52.0]: https://github.com/Automattic/jetpack-components/compare/0.51.0...0.52.0
@@ -0,0 +1,31 @@
1
+ import { SnackbarList } from '@wordpress/components';
2
+ import styles from './styles.module.scss';
3
+ import { useGlobalNotices } from './use-global-notices';
4
+
5
+ export type GlobalNoticesProps = {
6
+ maxVisibleNotices?: number;
7
+ };
8
+
9
+ /**
10
+ * Renders the global notices.
11
+ *
12
+ * @param {GlobalNoticesProps} props - Component props.
13
+ *
14
+ * @returns {import('react').ReactNode} The rendered notices list.
15
+ */
16
+ export function GlobalNotices( { maxVisibleNotices = 3 }: GlobalNoticesProps ) {
17
+ const { getNotices, removeNotice } = useGlobalNotices();
18
+
19
+ const snackbarNotices = getNotices()
20
+ .filter( ( { type } ) => type === 'snackbar' )
21
+ // Slices from the tail end of the list.
22
+ .slice( -maxVisibleNotices );
23
+
24
+ return (
25
+ <SnackbarList
26
+ notices={ snackbarNotices }
27
+ className={ styles[ 'global-notices' ] }
28
+ onRemove={ removeNotice }
29
+ />
30
+ );
31
+ }
@@ -0,0 +1,3 @@
1
+ export * from './global-notices';
2
+ export * from './use-global-notices';
3
+ export { store as globalNoticesStore } from '@wordpress/notices';
@@ -0,0 +1,21 @@
1
+ @import '@automattic/jetpack-base-styles/gutenberg-base-styles';
2
+
3
+ .global-notices {
4
+ &:global(.components-snackbar-list) {
5
+ position: fixed;
6
+ inset-block-start: auto; // top
7
+ inset-block-end: 0; // bottom
8
+ inset-inline: 0; // left and right
9
+
10
+ @include break-small {
11
+ width: auto;
12
+ inset-inline: unset; // left and right
13
+ inset-block-start: 4rem;
14
+ inset-inline-end: 1rem;
15
+ }
16
+
17
+ @include break-medium {
18
+ inset-block-start: 3rem;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,37 @@
1
+ import { useDispatch, useSelect } from '@wordpress/data';
2
+ import { store as noticesStore } from '@wordpress/notices';
3
+
4
+ type NoticesStore = ReturnType< ( typeof noticesStore )[ 'instantiate' ] >;
5
+
6
+ export type TGlobalNotices = ReturnType< NoticesStore[ 'getActions' ] > &
7
+ ReturnType< NoticesStore[ 'getSelectors' ] >;
8
+
9
+ /**
10
+ * The global notices hook.
11
+ *
12
+ * @returns {TGlobalNotices} The global notices selectors and actions.
13
+ */
14
+ export function useGlobalNotices(): TGlobalNotices {
15
+ const actionCreators = useDispatch( noticesStore );
16
+ const notices = useSelect( select => select( noticesStore ).getNotices(), [] );
17
+
18
+ return {
19
+ ...actionCreators,
20
+ createNotice( status, content, options ) {
21
+ return actionCreators.createNotice( status, content, { type: 'snackbar', ...options } );
22
+ },
23
+ createErrorNotice( content, options ) {
24
+ return actionCreators.createErrorNotice( content, { type: 'snackbar', ...options } );
25
+ },
26
+ createInfoNotice( content, options ) {
27
+ return actionCreators.createInfoNotice( content, { type: 'snackbar', ...options } );
28
+ },
29
+ createSuccessNotice( content, options ) {
30
+ return actionCreators.createSuccessNotice( content, { type: 'snackbar', ...options } );
31
+ },
32
+ createWarningNotice( content, options ) {
33
+ return actionCreators.createWarningNotice( content, { type: 'snackbar', ...options } );
34
+ },
35
+ getNotices: () => notices,
36
+ };
37
+ }
package/index.ts CHANGED
@@ -75,3 +75,4 @@ export { default as ProgressBar } from './components/progress-bar';
75
75
  export { default as UpsellBanner } from './components/upsell-banner';
76
76
  export { getUserLocale, cleanLocale } from './lib/locale';
77
77
  export { default as RadioControl } from './components/radio-control';
78
+ export * from './components/global-notices';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-components",
3
- "version": "0.53.0",
3
+ "version": "0.53.1",
4
4
  "description": "Jetpack Components Package",
5
5
  "author": "Automattic",
6
6
  "license": "GPL-2.0-or-later",
@@ -25,6 +25,7 @@
25
25
  "@wordpress/element": "5.33.0",
26
26
  "@wordpress/i18n": "4.56.0",
27
27
  "@wordpress/icons": "9.47.0",
28
+ "@wordpress/notices": "4.24.0",
28
29
  "classnames": "2.3.2",
29
30
  "prop-types": "^15.7.2",
30
31
  "qrcode.react": "3.1.0",