Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
feat: Add notices actions override
Browse files Browse the repository at this point in the history
  • Loading branch information
SofiaSousa committed Nov 7, 2018
1 parent d3e784d commit a9a95a5
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/js/gutenberg-overrides/@wordpress/notices/build/store/actions.js
Original file line number Diff line number Diff line change
@@ -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<WPNoticeAction>} 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,
};
}

0 comments on commit a9a95a5

Please sign in to comment.