UNPKG

@wordpress/notices

Version:
80 lines (79 loc) 1.77 kB
// packages/notices/src/store/actions.ts import { DEFAULT_CONTEXT, DEFAULT_STATUS } from "./constants.mjs"; var uniqueId = 0; function createNotice(status = DEFAULT_STATUS, content, options = {}) { const { speak = true, isDismissible = true, context = DEFAULT_CONTEXT, id = `${context}${++uniqueId}`, actions = [], type = "default", __unstableHTML, icon = null, explicitDismiss = false, onDismiss } = options; content = String(content); return { type: "CREATE_NOTICE", context, notice: { id, status, content, spokenMessage: speak ? content : null, __unstableHTML, isDismissible, actions, type, icon, explicitDismiss, onDismiss } }; } function createSuccessNotice(content, options) { return createNotice("success", content, options); } function createInfoNotice(content, options) { return createNotice("info", content, options); } function createErrorNotice(content, options) { return createNotice("error", content, options); } function createWarningNotice(content, options) { return createNotice("warning", content, options); } function removeNotice(id, context = DEFAULT_CONTEXT) { return { type: "REMOVE_NOTICE", id, context }; } function removeAllNotices(noticeType = "default", context = DEFAULT_CONTEXT) { return { type: "REMOVE_ALL_NOTICES", noticeType, context }; } function removeNotices(ids, context = DEFAULT_CONTEXT) { return { type: "REMOVE_NOTICES", ids, context }; } export { createErrorNotice, createInfoNotice, createNotice, createSuccessNotice, createWarningNotice, removeAllNotices, removeNotice, removeNotices }; //# sourceMappingURL=actions.mjs.map