@wordpress/notices 3.12.0 → 3.13.0

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,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.13.0 (2022-07-13)
6
+
5
7
  ## 3.12.0 (2022-06-29)
6
8
 
7
9
  ## 3.11.0 (2022-06-15)
@@ -48,13 +48,34 @@ let uniqueId = 0;
48
48
  * readers.
49
49
  * @param {Array<WPNoticeAction>} [options.actions] User actions to be
50
50
  * presented with notice.
51
- * @param {Object} [options.icon] An icon displayed with the notice.
51
+ * @param {string} [options.icon] An icon displayed with the notice.
52
+ * Only used when type is set to `snackbar`.
52
53
  * @param {boolean} [options.explicitDismiss] Whether the notice includes
53
- * an explict dismiss button and
54
+ * an explicit dismiss button and
54
55
  * can't be dismissed by clicking
55
- * the body of the notice.
56
+ * the body of the notice. Only applies
57
+ * when type is set to `snackbar`.
56
58
  * @param {Function} [options.onDismiss] Called when the notice is dismissed.
57
59
  *
60
+ * @example
61
+ * ```js
62
+ * import { __ } from '@wordpress/i18n';
63
+ * import { useDispatch } from '@wordpress/data';
64
+ * import { store as noticesStore } from '@wordpress/notices';
65
+ * import { Button } from '@wordpress/components';
66
+ *
67
+ * const ExampleComponent = () => {
68
+ * const { createNotice } = useDispatch( noticesStore );
69
+ * return (
70
+ * <Button
71
+ * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }
72
+ * >
73
+ * { __( 'Generate a success notice!' ) }
74
+ * </Button>
75
+ * );
76
+ * };
77
+ * ```
78
+ *
58
79
  * @return {Object} Action object.
59
80
  */
60
81
 
@@ -105,6 +126,30 @@ function createNotice() {
105
126
  * @param {string} content Notice message.
106
127
  * @param {Object} [options] Optional notice options.
107
128
  *
129
+ * @example
130
+ * ```js
131
+ * import { __ } from '@wordpress/i18n';
132
+ * import { useDispatch } from '@wordpress/data';
133
+ * import { store as noticesStore } from '@wordpress/notices';
134
+ * import { Button } from '@wordpress/components';
135
+ *
136
+ * const ExampleComponent = () => {
137
+ * const { createSuccessNotice } = useDispatch( noticesStore );
138
+ * return (
139
+ * <Button
140
+ * onClick={ () =>
141
+ * createSuccessNotice( __( 'Success!' ), {
142
+ * type: 'snackbar',
143
+ * icon: '🔥',
144
+ * } )
145
+ * }
146
+ * >
147
+ * { __( 'Generate a snackbar success notice!' ) }
148
+ * </Button>
149
+ * );
150
+ * };
151
+ * ```
152
+ *
108
153
  * @return {Object} Action object.
109
154
  */
110
155
 
@@ -121,6 +166,29 @@ function createSuccessNotice(content, options) {
121
166
  * @param {string} content Notice message.
122
167
  * @param {Object} [options] Optional notice options.
123
168
  *
169
+ * @example
170
+ * ```js
171
+ * import { __ } from '@wordpress/i18n';
172
+ * import { useDispatch } from '@wordpress/data';
173
+ * import { store as noticesStore } from '@wordpress/notices';
174
+ * import { Button } from '@wordpress/components';
175
+ *
176
+ * const ExampleComponent = () => {
177
+ * const { createInfoNotice } = useDispatch( noticesStore );
178
+ * return (
179
+ * <Button
180
+ * onClick={ () =>
181
+ * createInfoNotice( __( 'Something happened!' ), {
182
+ * isDismissible: false,
183
+ * } )
184
+ * }
185
+ * >
186
+ * { __( 'Generate a notice that cannot be dismissed.' ) }
187
+ * </Button>
188
+ * );
189
+ * };
190
+ *```
191
+ *
124
192
  * @return {Object} Action object.
125
193
  */
126
194
 
@@ -137,6 +205,32 @@ function createInfoNotice(content, options) {
137
205
  * @param {string} content Notice message.
138
206
  * @param {Object} [options] Optional notice options.
139
207
  *
208
+ * @example
209
+ * ```js
210
+ * import { __ } from '@wordpress/i18n';
211
+ * import { useDispatch } from '@wordpress/data';
212
+ * import { store as noticesStore } from '@wordpress/notices';
213
+ * import { Button } from '@wordpress/components';
214
+ *
215
+ * const ExampleComponent = () => {
216
+ * const { createErrorNotice } = useDispatch( noticesStore );
217
+ * return (
218
+ * <Button
219
+ * onClick={ () =>
220
+ * createErrorNotice( __( 'An error occurred!' ), {
221
+ * type: 'snackbar',
222
+ * explicitDismiss: true,
223
+ * } )
224
+ * }
225
+ * >
226
+ * { __(
227
+ * 'Generate an snackbar error notice with explicit dismiss button.'
228
+ * ) }
229
+ * </Button>
230
+ * );
231
+ * };
232
+ * ```
233
+ *
140
234
  * @return {Object} Action object.
141
235
  */
142
236
 
@@ -153,6 +247,33 @@ function createErrorNotice(content, options) {
153
247
  * @param {string} content Notice message.
154
248
  * @param {Object} [options] Optional notice options.
155
249
  *
250
+ * @example
251
+ * ```js
252
+ * import { __ } from '@wordpress/i18n';
253
+ * import { useDispatch } from '@wordpress/data';
254
+ * import { store as noticesStore } from '@wordpress/notices';
255
+ * import { Button } from '@wordpress/components';
256
+ *
257
+ * const ExampleComponent = () => {
258
+ * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );
259
+ * return (
260
+ * <Button
261
+ * onClick={ () =>
262
+ * createWarningNotice( __( 'Warning!' ), {
263
+ * onDismiss: () => {
264
+ * createInfoNotice(
265
+ * __( 'The warning has been dismissed!' )
266
+ * );
267
+ * },
268
+ * } )
269
+ * }
270
+ * >
271
+ * { __( 'Generates a warning notice with onDismiss callback' ) }
272
+ * </Button>
273
+ * );
274
+ * };
275
+ * ```
276
+ *
156
277
  * @return {Object} Action object.
157
278
  */
158
279
 
@@ -167,6 +288,38 @@ function createWarningNotice(content, options) {
167
288
  * @param {string} [context='global'] Optional context (grouping) in which the notice is
168
289
  * intended to appear. Defaults to default context.
169
290
  *
291
+ * @example
292
+ * ```js
293
+ * import { __ } from '@wordpress/i18n';
294
+ * import { useDispatch } from '@wordpress/data';
295
+ * import { store as noticesStore } from '@wordpress/notices';
296
+ * import { Button } from '@wordpress/components';
297
+ *
298
+ * const ExampleComponent = () => {
299
+ * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
300
+ * const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
301
+ *
302
+ * return (
303
+ * <>
304
+ * <Button
305
+ * onClick={ () =>
306
+ * createWarningNotice( __( 'Warning!' ), {
307
+ * isDismissible: false,
308
+ * } )
309
+ * }
310
+ * >
311
+ * { __( 'Generate a notice' ) }
312
+ * </Button>
313
+ * { notices.length > 0 && (
314
+ * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>
315
+ * { __( 'Remove the notice' ) }
316
+ * </Button>
317
+ * ) }
318
+ * </>
319
+ * );
320
+ *};
321
+ * ```
322
+ *
170
323
  * @return {Object} Action object.
171
324
  */
172
325
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["uniqueId","createNotice","status","DEFAULT_STATUS","content","options","speak","isDismissible","context","DEFAULT_CONTEXT","id","actions","type","__unstableHTML","icon","explicitDismiss","onDismiss","String","notice","spokenMessage","createSuccessNotice","createInfoNotice","createErrorNotice","createWarningNotice","removeNotice"],"mappings":";;;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAIA,QAAQ,GAAG,CAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,YAAT,GAAwE;AAAA,MAAjDC,MAAiD,uEAAxCC,yBAAwC;AAAA,MAAxBC,OAAwB;AAAA,MAAfC,OAAe,uEAAL,EAAK;AAC9E,QAAM;AACLC,IAAAA,KAAK,GAAG,IADH;AAELC,IAAAA,aAAa,GAAG,IAFX;AAGLC,IAAAA,OAAO,GAAGC,0BAHL;AAILC,IAAAA,EAAE,GAAI,GAAGF,OAAS,GAAG,EAAER,QAAU,EAJ5B;AAKLW,IAAAA,OAAO,GAAG,EALL;AAMLC,IAAAA,IAAI,GAAG,SANF;AAOLC,IAAAA,cAPK;AAQLC,IAAAA,IAAI,GAAG,IARF;AASLC,IAAAA,eAAe,GAAG,KATb;AAULC,IAAAA;AAVK,MAWFX,OAXJ,CAD8E,CAc9E;AACA;AACA;;AACAD,EAAAA,OAAO,GAAGa,MAAM,CAAEb,OAAF,CAAhB;AAEA,SAAO;AACNQ,IAAAA,IAAI,EAAE,eADA;AAENJ,IAAAA,OAFM;AAGNU,IAAAA,MAAM,EAAE;AACPR,MAAAA,EADO;AAEPR,MAAAA,MAFO;AAGPE,MAAAA,OAHO;AAIPe,MAAAA,aAAa,EAAEb,KAAK,GAAGF,OAAH,GAAa,IAJ1B;AAKPS,MAAAA,cALO;AAMPN,MAAAA,aANO;AAOPI,MAAAA,OAPO;AAQPC,MAAAA,IARO;AASPE,MAAAA,IATO;AAUPC,MAAAA,eAVO;AAWPC,MAAAA;AAXO;AAHF,GAAP;AAiBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,mBAAT,CAA8BhB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOJ,YAAY,CAAE,SAAF,EAAaG,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASgB,gBAAT,CAA2BjB,OAA3B,EAAoCC,OAApC,EAA8C;AACpD,SAAOJ,YAAY,CAAE,MAAF,EAAUG,OAAV,EAAmBC,OAAnB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASiB,iBAAT,CAA4BlB,OAA5B,EAAqCC,OAArC,EAA+C;AACrD,SAAOJ,YAAY,CAAE,OAAF,EAAWG,OAAX,EAAoBC,OAApB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASkB,mBAAT,CAA8BnB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOJ,YAAY,CAAE,SAAF,EAAaG,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASmB,YAAT,CAAuBd,EAAvB,EAAuD;AAAA,MAA5BF,OAA4B,uEAAlBC,0BAAkB;AAC7D,SAAO;AACNG,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,EAFM;AAGNF,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';\n\n/**\n * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.\n *\n * @property {string} label Message to use as action label.\n * @property {?string} url Optional URL of resource if action incurs\n * browser navigation.\n * @property {?Function} onClick Optional function to invoke when action is\n * triggered by user.\n *\n */\n\nlet uniqueId = 0;\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string} [status='info'] Notice status.\n * @param {string} content Notice message.\n * @param {Object} [options] Notice options.\n * @param {string} [options.context='global'] Context under which to\n * group notice.\n * @param {string} [options.id] Identifier for notice.\n * Automatically assigned\n * if not specified.\n * @param {boolean} [options.isDismissible=true] Whether the notice can\n * be dismissed by user.\n * @param {string} [options.type='default'] Type of notice, one of\n * `default`, or `snackbar`.\n * @param {boolean} [options.speak=true] Whether the notice\n * content should be\n * announced to screen\n * readers.\n * @param {Array<WPNoticeAction>} [options.actions] User actions to be\n * presented with notice.\n * @param {Object} [options.icon] An icon displayed with the notice.\n * @param {boolean} [options.explicitDismiss] Whether the notice includes\n * an explict dismiss button and\n * can't be dismissed by clicking\n * the body of the notice.\n * @param {Function} [options.onDismiss] Called when the notice is dismissed.\n *\n * @return {Object} Action object.\n */\nexport function createNotice( status = DEFAULT_STATUS, content, options = {} ) {\n\tconst {\n\t\tspeak = true,\n\t\tisDismissible = true,\n\t\tcontext = DEFAULT_CONTEXT,\n\t\tid = `${ context }${ ++uniqueId }`,\n\t\tactions = [],\n\t\ttype = 'default',\n\t\t__unstableHTML,\n\t\ticon = null,\n\t\texplicitDismiss = false,\n\t\tonDismiss,\n\t} = options;\n\n\t// The supported value shape of content is currently limited to plain text\n\t// strings. To avoid setting expectation that e.g. a WPElement could be\n\t// supported, cast to a string.\n\tcontent = String( content );\n\n\treturn {\n\t\ttype: 'CREATE_NOTICE',\n\t\tcontext,\n\t\tnotice: {\n\t\t\tid,\n\t\t\tstatus,\n\t\t\tcontent,\n\t\t\tspokenMessage: speak ? content : null,\n\t\t\t__unstableHTML,\n\t\t\tisDismissible,\n\t\t\tactions,\n\t\t\ttype,\n\t\t\ticon,\n\t\t\texplicitDismiss,\n\t\t\tonDismiss,\n\t\t},\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a success notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createSuccessNotice( content, options ) {\n\treturn createNotice( 'success', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an info notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createInfoNotice( content, options ) {\n\treturn createNotice( 'info', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an error notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createErrorNotice( content, options ) {\n\treturn createNotice( 'error', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a warning notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createWarningNotice( content, options ) {\n\treturn createNotice( 'warning', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a notice is to be removed.\n *\n * @param {string} id Notice unique identifier.\n * @param {string} [context='global'] Optional context (grouping) in which the notice is\n * intended to appear. Defaults to default context.\n *\n * @return {Object} Action object.\n */\nexport function removeNotice( id, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICE',\n\t\tid,\n\t\tcontext,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["uniqueId","createNotice","status","DEFAULT_STATUS","content","options","speak","isDismissible","context","DEFAULT_CONTEXT","id","actions","type","__unstableHTML","icon","explicitDismiss","onDismiss","String","notice","spokenMessage","createSuccessNotice","createInfoNotice","createErrorNotice","createWarningNotice","removeNotice"],"mappings":";;;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAIA,QAAQ,GAAG,CAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,YAAT,GAAwE;AAAA,MAAjDC,MAAiD,uEAAxCC,yBAAwC;AAAA,MAAxBC,OAAwB;AAAA,MAAfC,OAAe,uEAAL,EAAK;AAC9E,QAAM;AACLC,IAAAA,KAAK,GAAG,IADH;AAELC,IAAAA,aAAa,GAAG,IAFX;AAGLC,IAAAA,OAAO,GAAGC,0BAHL;AAILC,IAAAA,EAAE,GAAI,GAAGF,OAAS,GAAG,EAAER,QAAU,EAJ5B;AAKLW,IAAAA,OAAO,GAAG,EALL;AAMLC,IAAAA,IAAI,GAAG,SANF;AAOLC,IAAAA,cAPK;AAQLC,IAAAA,IAAI,GAAG,IARF;AASLC,IAAAA,eAAe,GAAG,KATb;AAULC,IAAAA;AAVK,MAWFX,OAXJ,CAD8E,CAc9E;AACA;AACA;;AACAD,EAAAA,OAAO,GAAGa,MAAM,CAAEb,OAAF,CAAhB;AAEA,SAAO;AACNQ,IAAAA,IAAI,EAAE,eADA;AAENJ,IAAAA,OAFM;AAGNU,IAAAA,MAAM,EAAE;AACPR,MAAAA,EADO;AAEPR,MAAAA,MAFO;AAGPE,MAAAA,OAHO;AAIPe,MAAAA,aAAa,EAAEb,KAAK,GAAGF,OAAH,GAAa,IAJ1B;AAKPS,MAAAA,cALO;AAMPN,MAAAA,aANO;AAOPI,MAAAA,OAPO;AAQPC,MAAAA,IARO;AASPE,MAAAA,IATO;AAUPC,MAAAA,eAVO;AAWPC,MAAAA;AAXO;AAHF,GAAP;AAiBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,mBAAT,CAA8BhB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOJ,YAAY,CAAE,SAAF,EAAaG,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASgB,gBAAT,CAA2BjB,OAA3B,EAAoCC,OAApC,EAA8C;AACpD,SAAOJ,YAAY,CAAE,MAAF,EAAUG,OAAV,EAAmBC,OAAnB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASiB,iBAAT,CAA4BlB,OAA5B,EAAqCC,OAArC,EAA+C;AACrD,SAAOJ,YAAY,CAAE,OAAF,EAAWG,OAAX,EAAoBC,OAApB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASkB,mBAAT,CAA8BnB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOJ,YAAY,CAAE,SAAF,EAAaG,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASmB,YAAT,CAAuBd,EAAvB,EAAuD;AAAA,MAA5BF,OAA4B,uEAAlBC,0BAAkB;AAC7D,SAAO;AACNG,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,EAFM;AAGNF,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';\n\n/**\n * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.\n *\n * @property {string} label Message to use as action label.\n * @property {?string} url Optional URL of resource if action incurs\n * browser navigation.\n * @property {?Function} onClick Optional function to invoke when action is\n * triggered by user.\n *\n */\n\nlet uniqueId = 0;\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string} [status='info'] Notice status.\n * @param {string} content Notice message.\n * @param {Object} [options] Notice options.\n * @param {string} [options.context='global'] Context under which to\n * group notice.\n * @param {string} [options.id] Identifier for notice.\n * Automatically assigned\n * if not specified.\n * @param {boolean} [options.isDismissible=true] Whether the notice can\n * be dismissed by user.\n * @param {string} [options.type='default'] Type of notice, one of\n * `default`, or `snackbar`.\n * @param {boolean} [options.speak=true] Whether the notice\n * content should be\n * announced to screen\n * readers.\n * @param {Array<WPNoticeAction>} [options.actions] User actions to be\n * presented with notice.\n * @param {string} [options.icon] An icon displayed with the notice.\n * Only used when type is set to `snackbar`.\n * @param {boolean} [options.explicitDismiss] Whether the notice includes\n * an explicit dismiss button and\n * can't be dismissed by clicking\n * the body of the notice. Only applies\n * when type is set to `snackbar`.\n * @param {Function} [options.onDismiss] Called when the notice is dismissed.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }\n * >\n * { __( 'Generate a success notice!' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createNotice( status = DEFAULT_STATUS, content, options = {} ) {\n\tconst {\n\t\tspeak = true,\n\t\tisDismissible = true,\n\t\tcontext = DEFAULT_CONTEXT,\n\t\tid = `${ context }${ ++uniqueId }`,\n\t\tactions = [],\n\t\ttype = 'default',\n\t\t__unstableHTML,\n\t\ticon = null,\n\t\texplicitDismiss = false,\n\t\tonDismiss,\n\t} = options;\n\n\t// The supported value shape of content is currently limited to plain text\n\t// strings. To avoid setting expectation that e.g. a WPElement could be\n\t// supported, cast to a string.\n\tcontent = String( content );\n\n\treturn {\n\t\ttype: 'CREATE_NOTICE',\n\t\tcontext,\n\t\tnotice: {\n\t\t\tid,\n\t\t\tstatus,\n\t\t\tcontent,\n\t\t\tspokenMessage: speak ? content : null,\n\t\t\t__unstableHTML,\n\t\t\tisDismissible,\n\t\t\tactions,\n\t\t\ttype,\n\t\t\ticon,\n\t\t\texplicitDismiss,\n\t\t\tonDismiss,\n\t\t},\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a success notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createSuccessNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createSuccessNotice( __( 'Success!' ), {\n * type: 'snackbar',\n * icon: '🔥',\n * } )\n * }\n * >\n * { __( 'Generate a snackbar success notice!' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createSuccessNotice( content, options ) {\n\treturn createNotice( 'success', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an info notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createInfoNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createInfoNotice( __( 'Something happened!' ), {\n * isDismissible: false,\n * } )\n * }\n * >\n * { __( 'Generate a notice that cannot be dismissed.' ) }\n * </Button>\n * );\n * };\n *```\n *\n * @return {Object} Action object.\n */\nexport function createInfoNotice( content, options ) {\n\treturn createNotice( 'info', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an error notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createErrorNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createErrorNotice( __( 'An error occurred!' ), {\n * type: 'snackbar',\n * explicitDismiss: true,\n * } )\n * }\n * >\n * { __(\n * 'Generate an snackbar error notice with explicit dismiss button.'\n * ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createErrorNotice( content, options ) {\n\treturn createNotice( 'error', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a warning notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createWarningNotice( __( 'Warning!' ), {\n * onDismiss: () => {\n * createInfoNotice(\n * __( 'The warning has been dismissed!' )\n * );\n * },\n * } )\n * }\n * >\n * { __( 'Generates a warning notice with onDismiss callback' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createWarningNotice( content, options ) {\n\treturn createNotice( 'warning', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a notice is to be removed.\n *\n * @param {string} id Notice unique identifier.\n * @param {string} [context='global'] Optional context (grouping) in which the notice is\n * intended to appear. Defaults to default context.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * const { createWarningNotice, removeNotice } = useDispatch( noticesStore );\n *\n * return (\n * <>\n * <Button\n * onClick={ () =>\n * createWarningNotice( __( 'Warning!' ), {\n * isDismissible: false,\n * } )\n * }\n * >\n * { __( 'Generate a notice' ) }\n * </Button>\n * { notices.length > 0 && (\n * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>\n * { __( 'Remove the notice' ) }\n * </Button>\n * ) }\n * </>\n * );\n *};\n * ```\n *\n * @return {Object} Action object.\n */\nexport function removeNotice( id, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICE',\n\t\tid,\n\t\tcontext,\n\t};\n}\n"]}
@@ -56,6 +56,24 @@ const DEFAULT_NOTICES = [];
56
56
  * @param {Object} state Notices state.
57
57
  * @param {?string} context Optional grouping context.
58
58
  *
59
+ * @example
60
+ *
61
+ *```js
62
+ * import { useSelect } from '@wordpress/data';
63
+ * import { store as noticesStore } from '@wordpress/notices';
64
+ *
65
+ * const ExampleComponent = () => {
66
+ * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
67
+ * return (
68
+ * <ul>
69
+ * { notices.map( ( notice ) => (
70
+ * <li key={ notice.ID }>{ notice.content }</li>
71
+ * ) ) }
72
+ * </ul>
73
+ * )
74
+ * };
75
+ *```
76
+ *
59
77
  * @return {WPNotice[]} Array of notices.
60
78
  */
61
79
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/notices/src/store/selectors.js"],"names":["DEFAULT_NOTICES","getNotices","state","context","DEFAULT_CONTEXT"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,UAAT,CAAqBC,KAArB,EAAwD;AAAA,MAA5BC,OAA4B,uEAAlBC,0BAAkB;AAC9D,SAAOF,KAAK,CAAEC,OAAF,CAAL,IAAoBH,eAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\n\n/** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n * @type {Array}\n */\nconst DEFAULT_NOTICES = [];\n\n/**\n * @typedef {Object} WPNotice Notice object.\n *\n * @property {string} id Unique identifier of notice.\n * @property {string} status Status of notice, one of `success`,\n * `info`, `error`, or `warning`. Defaults\n * to `info`.\n * @property {string} content Notice message.\n * @property {string} spokenMessage Audibly announced message text used by\n * assistive technologies.\n * @property {string} __unstableHTML Notice message as raw HTML. Intended to\n * serve primarily for compatibility of\n * server-rendered notices, and SHOULD NOT\n * be used for notices. It is subject to\n * removal without notice.\n * @property {boolean} isDismissible Whether the notice can be dismissed by\n * user. Defaults to `true`.\n * @property {string} type Type of notice, one of `default`,\n * or `snackbar`. Defaults to `default`.\n * @property {boolean} speak Whether the notice content should be\n * announced to screen readers. Defaults to\n * `true`.\n * @property {WPNoticeAction[]} actions User actions to present with notice.\n *\n */\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param {Object} state Notices state.\n * @param {?string} context Optional grouping context.\n *\n * @return {WPNotice[]} Array of notices.\n */\nexport function getNotices( state, context = DEFAULT_CONTEXT ) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/notices/src/store/selectors.js"],"names":["DEFAULT_NOTICES","getNotices","state","context","DEFAULT_CONTEXT"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,UAAT,CAAqBC,KAArB,EAAwD;AAAA,MAA5BC,OAA4B,uEAAlBC,0BAAkB;AAC9D,SAAOF,KAAK,CAAEC,OAAF,CAAL,IAAoBH,eAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\n\n/** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n * @type {Array}\n */\nconst DEFAULT_NOTICES = [];\n\n/**\n * @typedef {Object} WPNotice Notice object.\n *\n * @property {string} id Unique identifier of notice.\n * @property {string} status Status of notice, one of `success`,\n * `info`, `error`, or `warning`. Defaults\n * to `info`.\n * @property {string} content Notice message.\n * @property {string} spokenMessage Audibly announced message text used by\n * assistive technologies.\n * @property {string} __unstableHTML Notice message as raw HTML. Intended to\n * serve primarily for compatibility of\n * server-rendered notices, and SHOULD NOT\n * be used for notices. It is subject to\n * removal without notice.\n * @property {boolean} isDismissible Whether the notice can be dismissed by\n * user. Defaults to `true`.\n * @property {string} type Type of notice, one of `default`,\n * or `snackbar`. Defaults to `default`.\n * @property {boolean} speak Whether the notice content should be\n * announced to screen readers. Defaults to\n * `true`.\n * @property {WPNoticeAction[]} actions User actions to present with notice.\n *\n */\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param {Object} state Notices state.\n * @param {?string} context Optional grouping context.\n *\n * @example\n *\n *```js\n * import { useSelect } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * return (\n * <ul>\n * { notices.map( ( notice ) => (\n * <li key={ notice.ID }>{ notice.content }</li>\n * ) ) }\n * </ul>\n * )\n * };\n *```\n *\n * @return {WPNotice[]} Array of notices.\n */\nexport function getNotices( state, context = DEFAULT_CONTEXT ) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"]}
@@ -35,13 +35,34 @@ let uniqueId = 0;
35
35
  * readers.
36
36
  * @param {Array<WPNoticeAction>} [options.actions] User actions to be
37
37
  * presented with notice.
38
- * @param {Object} [options.icon] An icon displayed with the notice.
38
+ * @param {string} [options.icon] An icon displayed with the notice.
39
+ * Only used when type is set to `snackbar`.
39
40
  * @param {boolean} [options.explicitDismiss] Whether the notice includes
40
- * an explict dismiss button and
41
+ * an explicit dismiss button and
41
42
  * can't be dismissed by clicking
42
- * the body of the notice.
43
+ * the body of the notice. Only applies
44
+ * when type is set to `snackbar`.
43
45
  * @param {Function} [options.onDismiss] Called when the notice is dismissed.
44
46
  *
47
+ * @example
48
+ * ```js
49
+ * import { __ } from '@wordpress/i18n';
50
+ * import { useDispatch } from '@wordpress/data';
51
+ * import { store as noticesStore } from '@wordpress/notices';
52
+ * import { Button } from '@wordpress/components';
53
+ *
54
+ * const ExampleComponent = () => {
55
+ * const { createNotice } = useDispatch( noticesStore );
56
+ * return (
57
+ * <Button
58
+ * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }
59
+ * >
60
+ * { __( 'Generate a success notice!' ) }
61
+ * </Button>
62
+ * );
63
+ * };
64
+ * ```
65
+ *
45
66
  * @return {Object} Action object.
46
67
  */
47
68
 
@@ -92,6 +113,30 @@ export function createNotice() {
92
113
  * @param {string} content Notice message.
93
114
  * @param {Object} [options] Optional notice options.
94
115
  *
116
+ * @example
117
+ * ```js
118
+ * import { __ } from '@wordpress/i18n';
119
+ * import { useDispatch } from '@wordpress/data';
120
+ * import { store as noticesStore } from '@wordpress/notices';
121
+ * import { Button } from '@wordpress/components';
122
+ *
123
+ * const ExampleComponent = () => {
124
+ * const { createSuccessNotice } = useDispatch( noticesStore );
125
+ * return (
126
+ * <Button
127
+ * onClick={ () =>
128
+ * createSuccessNotice( __( 'Success!' ), {
129
+ * type: 'snackbar',
130
+ * icon: '🔥',
131
+ * } )
132
+ * }
133
+ * >
134
+ * { __( 'Generate a snackbar success notice!' ) }
135
+ * </Button>
136
+ * );
137
+ * };
138
+ * ```
139
+ *
95
140
  * @return {Object} Action object.
96
141
  */
97
142
 
@@ -107,6 +152,29 @@ export function createSuccessNotice(content, options) {
107
152
  * @param {string} content Notice message.
108
153
  * @param {Object} [options] Optional notice options.
109
154
  *
155
+ * @example
156
+ * ```js
157
+ * import { __ } from '@wordpress/i18n';
158
+ * import { useDispatch } from '@wordpress/data';
159
+ * import { store as noticesStore } from '@wordpress/notices';
160
+ * import { Button } from '@wordpress/components';
161
+ *
162
+ * const ExampleComponent = () => {
163
+ * const { createInfoNotice } = useDispatch( noticesStore );
164
+ * return (
165
+ * <Button
166
+ * onClick={ () =>
167
+ * createInfoNotice( __( 'Something happened!' ), {
168
+ * isDismissible: false,
169
+ * } )
170
+ * }
171
+ * >
172
+ * { __( 'Generate a notice that cannot be dismissed.' ) }
173
+ * </Button>
174
+ * );
175
+ * };
176
+ *```
177
+ *
110
178
  * @return {Object} Action object.
111
179
  */
112
180
 
@@ -122,6 +190,32 @@ export function createInfoNotice(content, options) {
122
190
  * @param {string} content Notice message.
123
191
  * @param {Object} [options] Optional notice options.
124
192
  *
193
+ * @example
194
+ * ```js
195
+ * import { __ } from '@wordpress/i18n';
196
+ * import { useDispatch } from '@wordpress/data';
197
+ * import { store as noticesStore } from '@wordpress/notices';
198
+ * import { Button } from '@wordpress/components';
199
+ *
200
+ * const ExampleComponent = () => {
201
+ * const { createErrorNotice } = useDispatch( noticesStore );
202
+ * return (
203
+ * <Button
204
+ * onClick={ () =>
205
+ * createErrorNotice( __( 'An error occurred!' ), {
206
+ * type: 'snackbar',
207
+ * explicitDismiss: true,
208
+ * } )
209
+ * }
210
+ * >
211
+ * { __(
212
+ * 'Generate an snackbar error notice with explicit dismiss button.'
213
+ * ) }
214
+ * </Button>
215
+ * );
216
+ * };
217
+ * ```
218
+ *
125
219
  * @return {Object} Action object.
126
220
  */
127
221
 
@@ -137,6 +231,33 @@ export function createErrorNotice(content, options) {
137
231
  * @param {string} content Notice message.
138
232
  * @param {Object} [options] Optional notice options.
139
233
  *
234
+ * @example
235
+ * ```js
236
+ * import { __ } from '@wordpress/i18n';
237
+ * import { useDispatch } from '@wordpress/data';
238
+ * import { store as noticesStore } from '@wordpress/notices';
239
+ * import { Button } from '@wordpress/components';
240
+ *
241
+ * const ExampleComponent = () => {
242
+ * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );
243
+ * return (
244
+ * <Button
245
+ * onClick={ () =>
246
+ * createWarningNotice( __( 'Warning!' ), {
247
+ * onDismiss: () => {
248
+ * createInfoNotice(
249
+ * __( 'The warning has been dismissed!' )
250
+ * );
251
+ * },
252
+ * } )
253
+ * }
254
+ * >
255
+ * { __( 'Generates a warning notice with onDismiss callback' ) }
256
+ * </Button>
257
+ * );
258
+ * };
259
+ * ```
260
+ *
140
261
  * @return {Object} Action object.
141
262
  */
142
263
 
@@ -150,6 +271,38 @@ export function createWarningNotice(content, options) {
150
271
  * @param {string} [context='global'] Optional context (grouping) in which the notice is
151
272
  * intended to appear. Defaults to default context.
152
273
  *
274
+ * @example
275
+ * ```js
276
+ * import { __ } from '@wordpress/i18n';
277
+ * import { useDispatch } from '@wordpress/data';
278
+ * import { store as noticesStore } from '@wordpress/notices';
279
+ * import { Button } from '@wordpress/components';
280
+ *
281
+ * const ExampleComponent = () => {
282
+ * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
283
+ * const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
284
+ *
285
+ * return (
286
+ * <>
287
+ * <Button
288
+ * onClick={ () =>
289
+ * createWarningNotice( __( 'Warning!' ), {
290
+ * isDismissible: false,
291
+ * } )
292
+ * }
293
+ * >
294
+ * { __( 'Generate a notice' ) }
295
+ * </Button>
296
+ * { notices.length > 0 && (
297
+ * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>
298
+ * { __( 'Remove the notice' ) }
299
+ * </Button>
300
+ * ) }
301
+ * </>
302
+ * );
303
+ *};
304
+ * ```
305
+ *
153
306
  * @return {Object} Action object.
154
307
  */
155
308
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["DEFAULT_CONTEXT","DEFAULT_STATUS","uniqueId","createNotice","status","content","options","speak","isDismissible","context","id","actions","type","__unstableHTML","icon","explicitDismiss","onDismiss","String","notice","spokenMessage","createSuccessNotice","createInfoNotice","createErrorNotice","createWarningNotice","removeNotice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,EAA0BC,cAA1B,QAAgD,aAAhD;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIC,QAAQ,GAAG,CAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAAwE;AAAA,MAAjDC,MAAiD,uEAAxCH,cAAwC;AAAA,MAAxBI,OAAwB;AAAA,MAAfC,OAAe,uEAAL,EAAK;AAC9E,QAAM;AACLC,IAAAA,KAAK,GAAG,IADH;AAELC,IAAAA,aAAa,GAAG,IAFX;AAGLC,IAAAA,OAAO,GAAGT,eAHL;AAILU,IAAAA,EAAE,GAAI,GAAGD,OAAS,GAAG,EAAEP,QAAU,EAJ5B;AAKLS,IAAAA,OAAO,GAAG,EALL;AAMLC,IAAAA,IAAI,GAAG,SANF;AAOLC,IAAAA,cAPK;AAQLC,IAAAA,IAAI,GAAG,IARF;AASLC,IAAAA,eAAe,GAAG,KATb;AAULC,IAAAA;AAVK,MAWFV,OAXJ,CAD8E,CAc9E;AACA;AACA;;AACAD,EAAAA,OAAO,GAAGY,MAAM,CAAEZ,OAAF,CAAhB;AAEA,SAAO;AACNO,IAAAA,IAAI,EAAE,eADA;AAENH,IAAAA,OAFM;AAGNS,IAAAA,MAAM,EAAE;AACPR,MAAAA,EADO;AAEPN,MAAAA,MAFO;AAGPC,MAAAA,OAHO;AAIPc,MAAAA,aAAa,EAAEZ,KAAK,GAAGF,OAAH,GAAa,IAJ1B;AAKPQ,MAAAA,cALO;AAMPL,MAAAA,aANO;AAOPG,MAAAA,OAPO;AAQPC,MAAAA,IARO;AASPE,MAAAA,IATO;AAUPC,MAAAA,eAVO;AAWPC,MAAAA;AAXO;AAHF,GAAP;AAiBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,mBAAT,CAA8Bf,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOH,YAAY,CAAE,SAAF,EAAaE,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASe,gBAAT,CAA2BhB,OAA3B,EAAoCC,OAApC,EAA8C;AACpD,SAAOH,YAAY,CAAE,MAAF,EAAUE,OAAV,EAAmBC,OAAnB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASgB,iBAAT,CAA4BjB,OAA5B,EAAqCC,OAArC,EAA+C;AACrD,SAAOH,YAAY,CAAE,OAAF,EAAWE,OAAX,EAAoBC,OAApB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASiB,mBAAT,CAA8BlB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOH,YAAY,CAAE,SAAF,EAAaE,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,YAAT,CAAuBd,EAAvB,EAAuD;AAAA,MAA5BD,OAA4B,uEAAlBT,eAAkB;AAC7D,SAAO;AACNY,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,EAFM;AAGND,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';\n\n/**\n * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.\n *\n * @property {string} label Message to use as action label.\n * @property {?string} url Optional URL of resource if action incurs\n * browser navigation.\n * @property {?Function} onClick Optional function to invoke when action is\n * triggered by user.\n *\n */\n\nlet uniqueId = 0;\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string} [status='info'] Notice status.\n * @param {string} content Notice message.\n * @param {Object} [options] Notice options.\n * @param {string} [options.context='global'] Context under which to\n * group notice.\n * @param {string} [options.id] Identifier for notice.\n * Automatically assigned\n * if not specified.\n * @param {boolean} [options.isDismissible=true] Whether the notice can\n * be dismissed by user.\n * @param {string} [options.type='default'] Type of notice, one of\n * `default`, or `snackbar`.\n * @param {boolean} [options.speak=true] Whether the notice\n * content should be\n * announced to screen\n * readers.\n * @param {Array<WPNoticeAction>} [options.actions] User actions to be\n * presented with notice.\n * @param {Object} [options.icon] An icon displayed with the notice.\n * @param {boolean} [options.explicitDismiss] Whether the notice includes\n * an explict dismiss button and\n * can't be dismissed by clicking\n * the body of the notice.\n * @param {Function} [options.onDismiss] Called when the notice is dismissed.\n *\n * @return {Object} Action object.\n */\nexport function createNotice( status = DEFAULT_STATUS, content, options = {} ) {\n\tconst {\n\t\tspeak = true,\n\t\tisDismissible = true,\n\t\tcontext = DEFAULT_CONTEXT,\n\t\tid = `${ context }${ ++uniqueId }`,\n\t\tactions = [],\n\t\ttype = 'default',\n\t\t__unstableHTML,\n\t\ticon = null,\n\t\texplicitDismiss = false,\n\t\tonDismiss,\n\t} = options;\n\n\t// The supported value shape of content is currently limited to plain text\n\t// strings. To avoid setting expectation that e.g. a WPElement could be\n\t// supported, cast to a string.\n\tcontent = String( content );\n\n\treturn {\n\t\ttype: 'CREATE_NOTICE',\n\t\tcontext,\n\t\tnotice: {\n\t\t\tid,\n\t\t\tstatus,\n\t\t\tcontent,\n\t\t\tspokenMessage: speak ? content : null,\n\t\t\t__unstableHTML,\n\t\t\tisDismissible,\n\t\t\tactions,\n\t\t\ttype,\n\t\t\ticon,\n\t\t\texplicitDismiss,\n\t\t\tonDismiss,\n\t\t},\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a success notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createSuccessNotice( content, options ) {\n\treturn createNotice( 'success', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an info notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createInfoNotice( content, options ) {\n\treturn createNotice( 'info', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an error notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createErrorNotice( content, options ) {\n\treturn createNotice( 'error', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a warning notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @return {Object} Action object.\n */\nexport function createWarningNotice( content, options ) {\n\treturn createNotice( 'warning', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a notice is to be removed.\n *\n * @param {string} id Notice unique identifier.\n * @param {string} [context='global'] Optional context (grouping) in which the notice is\n * intended to appear. Defaults to default context.\n *\n * @return {Object} Action object.\n */\nexport function removeNotice( id, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICE',\n\t\tid,\n\t\tcontext,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/notices/src/store/actions.js"],"names":["DEFAULT_CONTEXT","DEFAULT_STATUS","uniqueId","createNotice","status","content","options","speak","isDismissible","context","id","actions","type","__unstableHTML","icon","explicitDismiss","onDismiss","String","notice","spokenMessage","createSuccessNotice","createInfoNotice","createErrorNotice","createWarningNotice","removeNotice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,EAA0BC,cAA1B,QAAgD,aAAhD;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIC,QAAQ,GAAG,CAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAAwE;AAAA,MAAjDC,MAAiD,uEAAxCH,cAAwC;AAAA,MAAxBI,OAAwB;AAAA,MAAfC,OAAe,uEAAL,EAAK;AAC9E,QAAM;AACLC,IAAAA,KAAK,GAAG,IADH;AAELC,IAAAA,aAAa,GAAG,IAFX;AAGLC,IAAAA,OAAO,GAAGT,eAHL;AAILU,IAAAA,EAAE,GAAI,GAAGD,OAAS,GAAG,EAAEP,QAAU,EAJ5B;AAKLS,IAAAA,OAAO,GAAG,EALL;AAMLC,IAAAA,IAAI,GAAG,SANF;AAOLC,IAAAA,cAPK;AAQLC,IAAAA,IAAI,GAAG,IARF;AASLC,IAAAA,eAAe,GAAG,KATb;AAULC,IAAAA;AAVK,MAWFV,OAXJ,CAD8E,CAc9E;AACA;AACA;;AACAD,EAAAA,OAAO,GAAGY,MAAM,CAAEZ,OAAF,CAAhB;AAEA,SAAO;AACNO,IAAAA,IAAI,EAAE,eADA;AAENH,IAAAA,OAFM;AAGNS,IAAAA,MAAM,EAAE;AACPR,MAAAA,EADO;AAEPN,MAAAA,MAFO;AAGPC,MAAAA,OAHO;AAIPc,MAAAA,aAAa,EAAEZ,KAAK,GAAGF,OAAH,GAAa,IAJ1B;AAKPQ,MAAAA,cALO;AAMPL,MAAAA,aANO;AAOPG,MAAAA,OAPO;AAQPC,MAAAA,IARO;AASPE,MAAAA,IATO;AAUPC,MAAAA,eAVO;AAWPC,MAAAA;AAXO;AAHF,GAAP;AAiBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,mBAAT,CAA8Bf,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOH,YAAY,CAAE,SAAF,EAAaE,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASe,gBAAT,CAA2BhB,OAA3B,EAAoCC,OAApC,EAA8C;AACpD,SAAOH,YAAY,CAAE,MAAF,EAAUE,OAAV,EAAmBC,OAAnB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASgB,iBAAT,CAA4BjB,OAA5B,EAAqCC,OAArC,EAA+C;AACrD,SAAOH,YAAY,CAAE,OAAF,EAAWE,OAAX,EAAoBC,OAApB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASiB,mBAAT,CAA8BlB,OAA9B,EAAuCC,OAAvC,EAAiD;AACvD,SAAOH,YAAY,CAAE,SAAF,EAAaE,OAAb,EAAsBC,OAAtB,CAAnB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,YAAT,CAAuBd,EAAvB,EAAuD;AAAA,MAA5BD,OAA4B,uEAAlBT,eAAkB;AAC7D,SAAO;AACNY,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,EAFM;AAGND,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT, DEFAULT_STATUS } from './constants';\n\n/**\n * @typedef {Object} WPNoticeAction Object describing a user action option associated with a notice.\n *\n * @property {string} label Message to use as action label.\n * @property {?string} url Optional URL of resource if action incurs\n * browser navigation.\n * @property {?Function} onClick Optional function to invoke when action is\n * triggered by user.\n *\n */\n\nlet uniqueId = 0;\n\n/**\n * Returns an action object used in signalling that a notice is to be created.\n *\n * @param {string} [status='info'] Notice status.\n * @param {string} content Notice message.\n * @param {Object} [options] Notice options.\n * @param {string} [options.context='global'] Context under which to\n * group notice.\n * @param {string} [options.id] Identifier for notice.\n * Automatically assigned\n * if not specified.\n * @param {boolean} [options.isDismissible=true] Whether the notice can\n * be dismissed by user.\n * @param {string} [options.type='default'] Type of notice, one of\n * `default`, or `snackbar`.\n * @param {boolean} [options.speak=true] Whether the notice\n * content should be\n * announced to screen\n * readers.\n * @param {Array<WPNoticeAction>} [options.actions] User actions to be\n * presented with notice.\n * @param {string} [options.icon] An icon displayed with the notice.\n * Only used when type is set to `snackbar`.\n * @param {boolean} [options.explicitDismiss] Whether the notice includes\n * an explicit dismiss button and\n * can't be dismissed by clicking\n * the body of the notice. Only applies\n * when type is set to `snackbar`.\n * @param {Function} [options.onDismiss] Called when the notice is dismissed.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }\n * >\n * { __( 'Generate a success notice!' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createNotice( status = DEFAULT_STATUS, content, options = {} ) {\n\tconst {\n\t\tspeak = true,\n\t\tisDismissible = true,\n\t\tcontext = DEFAULT_CONTEXT,\n\t\tid = `${ context }${ ++uniqueId }`,\n\t\tactions = [],\n\t\ttype = 'default',\n\t\t__unstableHTML,\n\t\ticon = null,\n\t\texplicitDismiss = false,\n\t\tonDismiss,\n\t} = options;\n\n\t// The supported value shape of content is currently limited to plain text\n\t// strings. To avoid setting expectation that e.g. a WPElement could be\n\t// supported, cast to a string.\n\tcontent = String( content );\n\n\treturn {\n\t\ttype: 'CREATE_NOTICE',\n\t\tcontext,\n\t\tnotice: {\n\t\t\tid,\n\t\t\tstatus,\n\t\t\tcontent,\n\t\t\tspokenMessage: speak ? content : null,\n\t\t\t__unstableHTML,\n\t\t\tisDismissible,\n\t\t\tactions,\n\t\t\ttype,\n\t\t\ticon,\n\t\t\texplicitDismiss,\n\t\t\tonDismiss,\n\t\t},\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a success notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createSuccessNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createSuccessNotice( __( 'Success!' ), {\n * type: 'snackbar',\n * icon: '🔥',\n * } )\n * }\n * >\n * { __( 'Generate a snackbar success notice!' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createSuccessNotice( content, options ) {\n\treturn createNotice( 'success', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an info notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createInfoNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createInfoNotice( __( 'Something happened!' ), {\n * isDismissible: false,\n * } )\n * }\n * >\n * { __( 'Generate a notice that cannot be dismissed.' ) }\n * </Button>\n * );\n * };\n *```\n *\n * @return {Object} Action object.\n */\nexport function createInfoNotice( content, options ) {\n\treturn createNotice( 'info', content, options );\n}\n\n/**\n * Returns an action object used in signalling that an error notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createErrorNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createErrorNotice( __( 'An error occurred!' ), {\n * type: 'snackbar',\n * explicitDismiss: true,\n * } )\n * }\n * >\n * { __(\n * 'Generate an snackbar error notice with explicit dismiss button.'\n * ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createErrorNotice( content, options ) {\n\treturn createNotice( 'error', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a warning notice is to be\n * created. Refer to `createNotice` for options documentation.\n *\n * @see createNotice\n *\n * @param {string} content Notice message.\n * @param {Object} [options] Optional notice options.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );\n * return (\n * <Button\n * onClick={ () =>\n * createWarningNotice( __( 'Warning!' ), {\n * onDismiss: () => {\n * createInfoNotice(\n * __( 'The warning has been dismissed!' )\n * );\n * },\n * } )\n * }\n * >\n * { __( 'Generates a warning notice with onDismiss callback' ) }\n * </Button>\n * );\n * };\n * ```\n *\n * @return {Object} Action object.\n */\nexport function createWarningNotice( content, options ) {\n\treturn createNotice( 'warning', content, options );\n}\n\n/**\n * Returns an action object used in signalling that a notice is to be removed.\n *\n * @param {string} id Notice unique identifier.\n * @param {string} [context='global'] Optional context (grouping) in which the notice is\n * intended to appear. Defaults to default context.\n *\n * @example\n * ```js\n * import { __ } from '@wordpress/i18n';\n * import { useDispatch } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n * import { Button } from '@wordpress/components';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * const { createWarningNotice, removeNotice } = useDispatch( noticesStore );\n *\n * return (\n * <>\n * <Button\n * onClick={ () =>\n * createWarningNotice( __( 'Warning!' ), {\n * isDismissible: false,\n * } )\n * }\n * >\n * { __( 'Generate a notice' ) }\n * </Button>\n * { notices.length > 0 && (\n * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>\n * { __( 'Remove the notice' ) }\n * </Button>\n * ) }\n * </>\n * );\n *};\n * ```\n *\n * @return {Object} Action object.\n */\nexport function removeNotice( id, context = DEFAULT_CONTEXT ) {\n\treturn {\n\t\ttype: 'REMOVE_NOTICE',\n\t\tid,\n\t\tcontext,\n\t};\n}\n"]}
@@ -48,6 +48,24 @@ const DEFAULT_NOTICES = [];
48
48
  * @param {Object} state Notices state.
49
49
  * @param {?string} context Optional grouping context.
50
50
  *
51
+ * @example
52
+ *
53
+ *```js
54
+ * import { useSelect } from '@wordpress/data';
55
+ * import { store as noticesStore } from '@wordpress/notices';
56
+ *
57
+ * const ExampleComponent = () => {
58
+ * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
59
+ * return (
60
+ * <ul>
61
+ * { notices.map( ( notice ) => (
62
+ * <li key={ notice.ID }>{ notice.content }</li>
63
+ * ) ) }
64
+ * </ul>
65
+ * )
66
+ * };
67
+ *```
68
+ *
51
69
  * @return {WPNotice[]} Array of notices.
52
70
  */
53
71
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/notices/src/store/selectors.js"],"names":["DEFAULT_CONTEXT","DEFAULT_NOTICES","getNotices","state","context"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,aAAhC;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAqBC,KAArB,EAAwD;AAAA,MAA5BC,OAA4B,uEAAlBJ,eAAkB;AAC9D,SAAOG,KAAK,CAAEC,OAAF,CAAL,IAAoBH,eAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\n\n/** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n * @type {Array}\n */\nconst DEFAULT_NOTICES = [];\n\n/**\n * @typedef {Object} WPNotice Notice object.\n *\n * @property {string} id Unique identifier of notice.\n * @property {string} status Status of notice, one of `success`,\n * `info`, `error`, or `warning`. Defaults\n * to `info`.\n * @property {string} content Notice message.\n * @property {string} spokenMessage Audibly announced message text used by\n * assistive technologies.\n * @property {string} __unstableHTML Notice message as raw HTML. Intended to\n * serve primarily for compatibility of\n * server-rendered notices, and SHOULD NOT\n * be used for notices. It is subject to\n * removal without notice.\n * @property {boolean} isDismissible Whether the notice can be dismissed by\n * user. Defaults to `true`.\n * @property {string} type Type of notice, one of `default`,\n * or `snackbar`. Defaults to `default`.\n * @property {boolean} speak Whether the notice content should be\n * announced to screen readers. Defaults to\n * `true`.\n * @property {WPNoticeAction[]} actions User actions to present with notice.\n *\n */\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param {Object} state Notices state.\n * @param {?string} context Optional grouping context.\n *\n * @return {WPNotice[]} Array of notices.\n */\nexport function getNotices( state, context = DEFAULT_CONTEXT ) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/notices/src/store/selectors.js"],"names":["DEFAULT_CONTEXT","DEFAULT_NOTICES","getNotices","state","context"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,aAAhC;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAqBC,KAArB,EAAwD;AAAA,MAA5BC,OAA4B,uEAAlBJ,eAAkB;AAC9D,SAAOG,KAAK,CAAEC,OAAF,CAAL,IAAoBH,eAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { DEFAULT_CONTEXT } from './constants';\n\n/** @typedef {import('./actions').WPNoticeAction} WPNoticeAction */\n\n/**\n * The default empty set of notices to return when there are no notices\n * assigned for a given notices context. This can occur if the getNotices\n * selector is called without a notice ever having been created for the\n * context. A shared value is used to ensure referential equality between\n * sequential selector calls, since otherwise `[] !== []`.\n *\n * @type {Array}\n */\nconst DEFAULT_NOTICES = [];\n\n/**\n * @typedef {Object} WPNotice Notice object.\n *\n * @property {string} id Unique identifier of notice.\n * @property {string} status Status of notice, one of `success`,\n * `info`, `error`, or `warning`. Defaults\n * to `info`.\n * @property {string} content Notice message.\n * @property {string} spokenMessage Audibly announced message text used by\n * assistive technologies.\n * @property {string} __unstableHTML Notice message as raw HTML. Intended to\n * serve primarily for compatibility of\n * server-rendered notices, and SHOULD NOT\n * be used for notices. It is subject to\n * removal without notice.\n * @property {boolean} isDismissible Whether the notice can be dismissed by\n * user. Defaults to `true`.\n * @property {string} type Type of notice, one of `default`,\n * or `snackbar`. Defaults to `default`.\n * @property {boolean} speak Whether the notice content should be\n * announced to screen readers. Defaults to\n * `true`.\n * @property {WPNoticeAction[]} actions User actions to present with notice.\n *\n */\n\n/**\n * Returns all notices as an array, optionally for a given context. Defaults to\n * the global context.\n *\n * @param {Object} state Notices state.\n * @param {?string} context Optional grouping context.\n *\n * @example\n *\n *```js\n * import { useSelect } from '@wordpress/data';\n * import { store as noticesStore } from '@wordpress/notices';\n *\n * const ExampleComponent = () => {\n * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );\n * return (\n * <ul>\n * { notices.map( ( notice ) => (\n * <li key={ notice.ID }>{ notice.content }</li>\n * ) ) }\n * </ul>\n * )\n * };\n *```\n *\n * @return {WPNotice[]} Array of notices.\n */\nexport function getNotices( state, context = DEFAULT_CONTEXT ) {\n\treturn state[ context ] || DEFAULT_NOTICES;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/notices",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
4
4
  "description": "State management for notices.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,8 +26,8 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/a11y": "^3.12.0",
30
- "@wordpress/data": "^6.12.0"
29
+ "@wordpress/a11y": "^3.13.0",
30
+ "@wordpress/data": "^6.13.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": "^17.0.0"
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "a80eeb62ec7cb1418b9915c277e084a29d6665e3"
38
+ "gitHead": "9d9d33bbdf317a4381b8ca1713e43bb50df653b3"
39
39
  }
@@ -37,13 +37,34 @@ let uniqueId = 0;
37
37
  * readers.
38
38
  * @param {Array<WPNoticeAction>} [options.actions] User actions to be
39
39
  * presented with notice.
40
- * @param {Object} [options.icon] An icon displayed with the notice.
40
+ * @param {string} [options.icon] An icon displayed with the notice.
41
+ * Only used when type is set to `snackbar`.
41
42
  * @param {boolean} [options.explicitDismiss] Whether the notice includes
42
- * an explict dismiss button and
43
+ * an explicit dismiss button and
43
44
  * can't be dismissed by clicking
44
- * the body of the notice.
45
+ * the body of the notice. Only applies
46
+ * when type is set to `snackbar`.
45
47
  * @param {Function} [options.onDismiss] Called when the notice is dismissed.
46
48
  *
49
+ * @example
50
+ * ```js
51
+ * import { __ } from '@wordpress/i18n';
52
+ * import { useDispatch } from '@wordpress/data';
53
+ * import { store as noticesStore } from '@wordpress/notices';
54
+ * import { Button } from '@wordpress/components';
55
+ *
56
+ * const ExampleComponent = () => {
57
+ * const { createNotice } = useDispatch( noticesStore );
58
+ * return (
59
+ * <Button
60
+ * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) }
61
+ * >
62
+ * { __( 'Generate a success notice!' ) }
63
+ * </Button>
64
+ * );
65
+ * };
66
+ * ```
67
+ *
47
68
  * @return {Object} Action object.
48
69
  */
49
70
  export function createNotice( status = DEFAULT_STATUS, content, options = {} ) {
@@ -93,6 +114,30 @@ export function createNotice( status = DEFAULT_STATUS, content, options = {} ) {
93
114
  * @param {string} content Notice message.
94
115
  * @param {Object} [options] Optional notice options.
95
116
  *
117
+ * @example
118
+ * ```js
119
+ * import { __ } from '@wordpress/i18n';
120
+ * import { useDispatch } from '@wordpress/data';
121
+ * import { store as noticesStore } from '@wordpress/notices';
122
+ * import { Button } from '@wordpress/components';
123
+ *
124
+ * const ExampleComponent = () => {
125
+ * const { createSuccessNotice } = useDispatch( noticesStore );
126
+ * return (
127
+ * <Button
128
+ * onClick={ () =>
129
+ * createSuccessNotice( __( 'Success!' ), {
130
+ * type: 'snackbar',
131
+ * icon: '🔥',
132
+ * } )
133
+ * }
134
+ * >
135
+ * { __( 'Generate a snackbar success notice!' ) }
136
+ * </Button>
137
+ * );
138
+ * };
139
+ * ```
140
+ *
96
141
  * @return {Object} Action object.
97
142
  */
98
143
  export function createSuccessNotice( content, options ) {
@@ -108,6 +153,29 @@ export function createSuccessNotice( content, options ) {
108
153
  * @param {string} content Notice message.
109
154
  * @param {Object} [options] Optional notice options.
110
155
  *
156
+ * @example
157
+ * ```js
158
+ * import { __ } from '@wordpress/i18n';
159
+ * import { useDispatch } from '@wordpress/data';
160
+ * import { store as noticesStore } from '@wordpress/notices';
161
+ * import { Button } from '@wordpress/components';
162
+ *
163
+ * const ExampleComponent = () => {
164
+ * const { createInfoNotice } = useDispatch( noticesStore );
165
+ * return (
166
+ * <Button
167
+ * onClick={ () =>
168
+ * createInfoNotice( __( 'Something happened!' ), {
169
+ * isDismissible: false,
170
+ * } )
171
+ * }
172
+ * >
173
+ * { __( 'Generate a notice that cannot be dismissed.' ) }
174
+ * </Button>
175
+ * );
176
+ * };
177
+ *```
178
+ *
111
179
  * @return {Object} Action object.
112
180
  */
113
181
  export function createInfoNotice( content, options ) {
@@ -123,6 +191,32 @@ export function createInfoNotice( content, options ) {
123
191
  * @param {string} content Notice message.
124
192
  * @param {Object} [options] Optional notice options.
125
193
  *
194
+ * @example
195
+ * ```js
196
+ * import { __ } from '@wordpress/i18n';
197
+ * import { useDispatch } from '@wordpress/data';
198
+ * import { store as noticesStore } from '@wordpress/notices';
199
+ * import { Button } from '@wordpress/components';
200
+ *
201
+ * const ExampleComponent = () => {
202
+ * const { createErrorNotice } = useDispatch( noticesStore );
203
+ * return (
204
+ * <Button
205
+ * onClick={ () =>
206
+ * createErrorNotice( __( 'An error occurred!' ), {
207
+ * type: 'snackbar',
208
+ * explicitDismiss: true,
209
+ * } )
210
+ * }
211
+ * >
212
+ * { __(
213
+ * 'Generate an snackbar error notice with explicit dismiss button.'
214
+ * ) }
215
+ * </Button>
216
+ * );
217
+ * };
218
+ * ```
219
+ *
126
220
  * @return {Object} Action object.
127
221
  */
128
222
  export function createErrorNotice( content, options ) {
@@ -138,6 +232,33 @@ export function createErrorNotice( content, options ) {
138
232
  * @param {string} content Notice message.
139
233
  * @param {Object} [options] Optional notice options.
140
234
  *
235
+ * @example
236
+ * ```js
237
+ * import { __ } from '@wordpress/i18n';
238
+ * import { useDispatch } from '@wordpress/data';
239
+ * import { store as noticesStore } from '@wordpress/notices';
240
+ * import { Button } from '@wordpress/components';
241
+ *
242
+ * const ExampleComponent = () => {
243
+ * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore );
244
+ * return (
245
+ * <Button
246
+ * onClick={ () =>
247
+ * createWarningNotice( __( 'Warning!' ), {
248
+ * onDismiss: () => {
249
+ * createInfoNotice(
250
+ * __( 'The warning has been dismissed!' )
251
+ * );
252
+ * },
253
+ * } )
254
+ * }
255
+ * >
256
+ * { __( 'Generates a warning notice with onDismiss callback' ) }
257
+ * </Button>
258
+ * );
259
+ * };
260
+ * ```
261
+ *
141
262
  * @return {Object} Action object.
142
263
  */
143
264
  export function createWarningNotice( content, options ) {
@@ -151,6 +272,38 @@ export function createWarningNotice( content, options ) {
151
272
  * @param {string} [context='global'] Optional context (grouping) in which the notice is
152
273
  * intended to appear. Defaults to default context.
153
274
  *
275
+ * @example
276
+ * ```js
277
+ * import { __ } from '@wordpress/i18n';
278
+ * import { useDispatch } from '@wordpress/data';
279
+ * import { store as noticesStore } from '@wordpress/notices';
280
+ * import { Button } from '@wordpress/components';
281
+ *
282
+ * const ExampleComponent = () => {
283
+ * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
284
+ * const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
285
+ *
286
+ * return (
287
+ * <>
288
+ * <Button
289
+ * onClick={ () =>
290
+ * createWarningNotice( __( 'Warning!' ), {
291
+ * isDismissible: false,
292
+ * } )
293
+ * }
294
+ * >
295
+ * { __( 'Generate a notice' ) }
296
+ * </Button>
297
+ * { notices.length > 0 && (
298
+ * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }>
299
+ * { __( 'Remove the notice' ) }
300
+ * </Button>
301
+ * ) }
302
+ * </>
303
+ * );
304
+ *};
305
+ * ```
306
+ *
154
307
  * @return {Object} Action object.
155
308
  */
156
309
  export function removeNotice( id, context = DEFAULT_CONTEXT ) {
@@ -49,6 +49,24 @@ const DEFAULT_NOTICES = [];
49
49
  * @param {Object} state Notices state.
50
50
  * @param {?string} context Optional grouping context.
51
51
  *
52
+ * @example
53
+ *
54
+ *```js
55
+ * import { useSelect } from '@wordpress/data';
56
+ * import { store as noticesStore } from '@wordpress/notices';
57
+ *
58
+ * const ExampleComponent = () => {
59
+ * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() );
60
+ * return (
61
+ * <ul>
62
+ * { notices.map( ( notice ) => (
63
+ * <li key={ notice.ID }>{ notice.content }</li>
64
+ * ) ) }
65
+ * </ul>
66
+ * )
67
+ * };
68
+ *```
69
+ *
52
70
  * @return {WPNotice[]} Array of notices.
53
71
  */
54
72
  export function getNotices( state, context = DEFAULT_CONTEXT ) {