This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3e784d
commit a9a95a5
Showing
1 changed file
with
127 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
src/js/gutenberg-overrides/@wordpress/notices/build/store/actions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |