From a9a95a59fd6c6b6d64e5e1cc813c4880b959db58 Mon Sep 17 00:00:00 2001 From: Sofia Sousa Date: Wed, 7 Nov 2018 13:27:31 +0000 Subject: [PATCH] feat: Add notices actions override --- .../@wordpress/notices/build/store/actions.js | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/js/gutenberg-overrides/@wordpress/notices/build/store/actions.js diff --git a/src/js/gutenberg-overrides/@wordpress/notices/build/store/actions.js b/src/js/gutenberg-overrides/@wordpress/notices/build/store/actions.js new file mode 100644 index 0000000..5d2ca79 --- /dev/null +++ b/src/js/gutenberg-overrides/@wordpress/notices/build/store/actions.js @@ -0,0 +1,127 @@ +/** + * External dependencies + */ +import { uniqueId } from 'lodash'; + +/** + * Internal dependencies + */ +import { DEFAULT_CONTEXT } from './constants'; + +/** + * Yields action objects used in signalling that a notice is to be created. + * + * @param {?string} status Notice status. + * Defaults to `info`. + * @param {string} content Notice message. + * @param {?Object} options Notice options. + * @param {?string} options.context Context under which to + * group notice. + * @param {?string} options.id Identifier for notice. + * Automatically assigned + * if not specified. + * @param {?boolean} options.isDismissible Whether the notice can + * be dismissed by user. + * Defaults to `true`. + * @param {?Array} options.actions User actions to be + * presented with notice. + */ +export function *createNotice (status = 'info', content, options = {}) { + const { + isDismissible = true, + context = DEFAULT_CONTEXT, + id = uniqueId(context), + actions = [], + } = options; + + yield { type: 'SPEAK', message: content }; + + yield { + type: 'CREATE_NOTICE', + context, + notice: { + id, + status, + content, + isDismissible, + actions, + }, + }; +} + +/** + * Returns an action object used in signalling that a success notice is to be + * created. Refer to `createNotice` for options documentation. + * + * @see createNotice + * + * @param {string} content Notice message. + * @param {?Object} options Optional notice options. + * + * @return {Object} Action object. + */ +export function createSuccessNotice (content, options) { + return createNotice('success', content, options); +} + +/** + * Returns an action object used in signalling that an info notice is to be + * created. Refer to `createNotice` for options documentation. + * + * @see createNotice + * + * @param {string} content Notice message. + * @param {?Object} options Optional notice options. + * + * @return {Object} Action object. + */ +export function createInfoNotice (content, options) { + return createNotice('info', content, options); +} + +/** + * Returns an action object used in signalling that an error notice is to be + * created. Refer to `createNotice` for options documentation. + * + * @see createNotice + * + * @param {string} content Notice message. + * @param {?Object} options Optional notice options. + * + * @return {Object} Action object. + */ +export function createErrorNotice (content, options) { + return createNotice('error', content, options); +} + +/** + * Returns an action object used in signalling that a warning notice is to be + * created. Refer to `createNotice` for options documentation. + * + * @see createNotice + * + * @param {string} content Notice message. + * @param {?Object} options Optional notice options. + * + * @return {Object} Action object. + */ +export function createWarningNotice (content, options) { + return createNotice('warning', content, options); +} + +/** + * Returns an action object used in signalling that a notice is to be removed. + * + * @param {string} id Notice unique identifier. + * @param {?string} context Optional context (grouping) in which the notice is + * intended to appear. Defaults to default context. + * + * @return {Object} Action object. + */ +export function removeNotice (id, context = DEFAULT_CONTEXT) { + return { + type: 'REMOVE_NOTICE', + id, + context, + }; +}