@wordpress/notices 5.39.1-next.v.202602111440.0 → 5.40.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 +2 -0
- package/README.md +74 -1
- package/build/components/inline-notices/index.cjs +93 -0
- package/build/components/inline-notices/index.cjs.map +7 -0
- package/build/components/snackbar-notices/index.cjs +61 -0
- package/build/components/snackbar-notices/index.cjs.map +7 -0
- package/build/index.cjs +16 -0
- package/build/index.cjs.map +2 -2
- package/build-module/components/inline-notices/index.mjs +62 -0
- package/build-module/components/inline-notices/index.mjs.map +7 -0
- package/build-module/components/snackbar-notices/index.mjs +30 -0
- package/build-module/components/snackbar-notices/index.mjs.map +7 -0
- package/build-module/index.mjs +4 -0
- package/build-module/index.mjs.map +3 -3
- package/build-types/components/inline-notices/index.d.ts +14 -0
- package/build-types/components/inline-notices/index.d.ts.map +1 -0
- package/build-types/components/snackbar-notices/index.d.ts +7 -0
- package/build-types/components/snackbar-notices/index.d.ts.map +1 -0
- package/build-types/index.d.ts +2 -0
- package/build-types/index.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/components/inline-notices/index.tsx +65 -0
- package/src/components/inline-notices/style.scss +21 -0
- package/src/components/snackbar-notices/index.tsx +45 -0
- package/src/index.ts +2 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Notices
|
|
2
2
|
|
|
3
|
-
State management for notices.
|
|
3
|
+
State management and UI components for notices.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -20,6 +20,79 @@ For more information about consuming from a data store, refer to [the `@wordpres
|
|
|
20
20
|
|
|
21
21
|
For a full list of actions and selectors available in the `core/notices` namespace, refer to the [_Notices Data_ Handbook page](https://github.com/WordPress/gutenberg/tree/HEAD/docs/reference-guides/data/data-core-notices.md).
|
|
22
22
|
|
|
23
|
+
## Components
|
|
24
|
+
|
|
25
|
+
The package also exports ready-to-use notice UI components powered by the `core/notices` store.
|
|
26
|
+
|
|
27
|
+
### `InlineNotices`
|
|
28
|
+
|
|
29
|
+
Renders notice lists for notices with type `default`:
|
|
30
|
+
|
|
31
|
+
- non-dismissible notices in a pinned list.
|
|
32
|
+
- dismissible notices in a removable list.
|
|
33
|
+
|
|
34
|
+
`children` are rendered inside the dismissible list.
|
|
35
|
+
|
|
36
|
+
_Props_
|
|
37
|
+
|
|
38
|
+
- `children: ReactNode` (optional): Additional content rendered in the dismissible notice list.
|
|
39
|
+
- `pinnedNoticesClassName: string` (optional): Extra class name added to the pinned list.
|
|
40
|
+
- `dismissibleNoticesClassName: string` (optional): Extra class name added to the dismissible list.
|
|
41
|
+
- `context: string` (optional): Notice context to read and remove notices from. Defaults to `default`.
|
|
42
|
+
|
|
43
|
+
### `SnackbarNotices`
|
|
44
|
+
|
|
45
|
+
Renders notices with type `snackbar` using `SnackbarList`.
|
|
46
|
+
|
|
47
|
+
- It renders the last three snackbar notices.
|
|
48
|
+
- Dismiss actions are wired to `removeNotice`.
|
|
49
|
+
|
|
50
|
+
_Props_
|
|
51
|
+
|
|
52
|
+
- `className: string` (optional): Extra class name added to the snackbar list.
|
|
53
|
+
- `context: string` (optional): Notice context to read and remove notices from. Defaults to `default`.
|
|
54
|
+
|
|
55
|
+
## Example
|
|
56
|
+
|
|
57
|
+
```jsx
|
|
58
|
+
import { useDispatch } from '@wordpress/data';
|
|
59
|
+
import {
|
|
60
|
+
InlineNotices,
|
|
61
|
+
SnackbarNotices,
|
|
62
|
+
store as noticesStore,
|
|
63
|
+
} from '@wordpress/notices';
|
|
64
|
+
|
|
65
|
+
function AppNotices() {
|
|
66
|
+
const { createSuccessNotice } = useDispatch( noticesStore );
|
|
67
|
+
const noticeContext = 'my-plugin/screen';
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<>
|
|
71
|
+
<button
|
|
72
|
+
onClick={ () =>
|
|
73
|
+
createSuccessNotice( 'Saved successfully.', {
|
|
74
|
+
type: 'snackbar',
|
|
75
|
+
context: noticeContext,
|
|
76
|
+
} )
|
|
77
|
+
}
|
|
78
|
+
>
|
|
79
|
+
Create snackbar notice
|
|
80
|
+
</button>
|
|
81
|
+
|
|
82
|
+
<InlineNotices
|
|
83
|
+
pinnedNoticesClassName="my-plugin-notices__pinned"
|
|
84
|
+
dismissibleNoticesClassName="my-plugin-notices__dismissible"
|
|
85
|
+
context={ noticeContext }
|
|
86
|
+
/>
|
|
87
|
+
<SnackbarNotices
|
|
88
|
+
className="my-plugin-notices__snackbar"
|
|
89
|
+
context={ noticeContext }
|
|
90
|
+
/>
|
|
91
|
+
</>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
23
96
|
## Contributing to this package
|
|
24
97
|
|
|
25
98
|
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/notices/src/components/inline-notices/index.tsx
|
|
31
|
+
var inline_notices_exports = {};
|
|
32
|
+
__export(inline_notices_exports, {
|
|
33
|
+
default: () => InlineNotices
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(inline_notices_exports);
|
|
36
|
+
var import_clsx = __toESM(require("clsx"));
|
|
37
|
+
var import_components = require("@wordpress/components");
|
|
38
|
+
var import_data = require("@wordpress/data");
|
|
39
|
+
var import_store = require("../../store/index.cjs");
|
|
40
|
+
|
|
41
|
+
// packages/notices/src/components/inline-notices/style.scss
|
|
42
|
+
if (typeof document !== "undefined" && !document.head.querySelector("style[data-wp-hash='1cf680fb74']")) {
|
|
43
|
+
const style = document.createElement("style");
|
|
44
|
+
style.setAttribute("data-wp-hash", "1cf680fb74");
|
|
45
|
+
style.appendChild(document.createTextNode(".components-notices__dismissible,.components-notices__pinned{color:#1e1e1e}.components-notices__dismissible .components-notice,.components-notices__pinned .components-notice{border-bottom:1px solid #0003;box-sizing:border-box;min-height:64px;padding:0 12px}.components-notices__dismissible .components-notice .components-notice__dismiss,.components-notices__pinned .components-notice .components-notice__dismiss{margin-top:12px}"));
|
|
46
|
+
document.head.appendChild(style);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// packages/notices/src/components/inline-notices/index.tsx
|
|
50
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
|
+
function InlineNotices({
|
|
52
|
+
children,
|
|
53
|
+
pinnedNoticesClassName,
|
|
54
|
+
dismissibleNoticesClassName,
|
|
55
|
+
context
|
|
56
|
+
}) {
|
|
57
|
+
const notices = (0, import_data.useSelect)(
|
|
58
|
+
(select) => select(import_store.store).getNotices(context),
|
|
59
|
+
[context]
|
|
60
|
+
);
|
|
61
|
+
const { removeNotice } = (0, import_data.useDispatch)(import_store.store);
|
|
62
|
+
const dismissibleNotices = notices.filter(
|
|
63
|
+
({ isDismissible, type }) => isDismissible && type === "default"
|
|
64
|
+
);
|
|
65
|
+
const nonDismissibleNotices = notices.filter(
|
|
66
|
+
({ isDismissible, type }) => !isDismissible && type === "default"
|
|
67
|
+
);
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
69
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
70
|
+
import_components.NoticeList,
|
|
71
|
+
{
|
|
72
|
+
notices: nonDismissibleNotices,
|
|
73
|
+
className: (0, import_clsx.default)(
|
|
74
|
+
"components-notices__pinned",
|
|
75
|
+
pinnedNoticesClassName
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
),
|
|
79
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
80
|
+
import_components.NoticeList,
|
|
81
|
+
{
|
|
82
|
+
notices: dismissibleNotices,
|
|
83
|
+
className: (0, import_clsx.default)(
|
|
84
|
+
"components-notices__dismissible",
|
|
85
|
+
dismissibleNoticesClassName
|
|
86
|
+
),
|
|
87
|
+
onRemove: (id) => removeNotice(id, context),
|
|
88
|
+
children
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
] });
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/inline-notices/index.tsx", "../../../src/components/inline-notices/style.scss"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactNode } from 'react';\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { NoticeList } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as noticesStore } from '../../store';\nimport './style.scss';\n\ntype InlineNoticesProps = {\n\tchildren?: ReactNode;\n\tpinnedNoticesClassName?: string;\n\tdismissibleNoticesClassName?: string;\n\tcontext?: string;\n};\n\nexport default function InlineNotices( {\n\tchildren,\n\tpinnedNoticesClassName,\n\tdismissibleNoticesClassName,\n\tcontext,\n}: InlineNoticesProps ) {\n\tconst notices = useSelect(\n\t\t( select ) => select( noticesStore ).getNotices( context ),\n\t\t[ context ]\n\t);\n\tconst { removeNotice } = useDispatch( noticesStore );\n\tconst dismissibleNotices = notices.filter(\n\t\t( { isDismissible, type } ) => isDismissible && type === 'default'\n\t);\n\tconst nonDismissibleNotices = notices.filter(\n\t\t( { isDismissible, type } ) => ! isDismissible && type === 'default'\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<NoticeList\n\t\t\t\tnotices={ nonDismissibleNotices }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'components-notices__pinned',\n\t\t\t\t\tpinnedNoticesClassName\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t<NoticeList\n\t\t\t\tnotices={ dismissibleNotices }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'components-notices__dismissible',\n\t\t\t\t\tdismissibleNoticesClassName\n\t\t\t\t) }\n\t\t\t\tonRemove={ ( id ) => removeNotice( id, context ) }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</NoticeList>\n\t\t</>\n\t);\n}\n", "if (typeof document !== 'undefined' && !document.head.querySelector(\"style[data-wp-hash='1cf680fb74']\")) {\n\tconst style = document.createElement(\"style\");\n\tstyle.setAttribute(\"data-wp-hash\", \"1cf680fb74\");\n\tstyle.appendChild(document.createTextNode(\".components-notices__dismissible,.components-notices__pinned{color:#1e1e1e}.components-notices__dismissible .components-notice,.components-notices__pinned .components-notice{border-bottom:1px solid #0003;box-sizing:border-box;min-height:64px;padding:0 12px}.components-notices__dismissible .components-notice .components-notice__dismiss,.components-notices__pinned .components-notice .components-notice__dismiss{margin-top:12px}\"));\n\tdocument.head.appendChild(style);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAiB;AAKjB,wBAA2B;AAC3B,kBAAuC;AAKvC,mBAAsC;;;ACftC,IAAI,OAAO,aAAa,eAAe,CAAC,SAAS,KAAK,cAAc,kCAAkC,GAAG;AACxG,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,aAAa,gBAAgB,YAAY;AAC/C,QAAM,YAAY,SAAS,eAAe,8aAA8a,CAAC;AACzd,WAAS,KAAK,YAAY,KAAK;AAChC;;;ADuCE;AAnBa,SAAR,cAAgC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAwB;AACvB,QAAM,cAAU;AAAA,IACf,CAAE,WAAY,OAAQ,aAAAA,KAAa,EAAE,WAAY,OAAQ;AAAA,IACzD,CAAE,OAAQ;AAAA,EACX;AACA,QAAM,EAAE,aAAa,QAAI,yBAAa,aAAAA,KAAa;AACnD,QAAM,qBAAqB,QAAQ;AAAA,IAClC,CAAE,EAAE,eAAe,KAAK,MAAO,iBAAiB,SAAS;AAAA,EAC1D;AACA,QAAM,wBAAwB,QAAQ;AAAA,IACrC,CAAE,EAAE,eAAe,KAAK,MAAO,CAAE,iBAAiB,SAAS;AAAA,EAC5D;AAEA,SACC,4EACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,SAAU;AAAA,QACV,eAAY,YAAAC;AAAA,UACX;AAAA,UACA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,SAAU;AAAA,QACV,eAAY,YAAAA;AAAA,UACX;AAAA,UACA;AAAA,QACD;AAAA,QACA,UAAW,CAAE,OAAQ,aAAc,IAAI,OAAQ;AAAA,QAE7C;AAAA;AAAA,IACH;AAAA,KACD;AAEF;",
|
|
6
|
+
"names": ["noticesStore", "clsx"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/notices/src/components/snackbar-notices/index.tsx
|
|
31
|
+
var snackbar_notices_exports = {};
|
|
32
|
+
__export(snackbar_notices_exports, {
|
|
33
|
+
default: () => SnackbarNotices
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(snackbar_notices_exports);
|
|
36
|
+
var import_clsx = __toESM(require("clsx"));
|
|
37
|
+
var import_components = require("@wordpress/components");
|
|
38
|
+
var import_data = require("@wordpress/data");
|
|
39
|
+
var import_store = require("../../store/index.cjs");
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
var MAX_VISIBLE_NOTICES = -3;
|
|
42
|
+
function SnackbarNotices({
|
|
43
|
+
className,
|
|
44
|
+
context
|
|
45
|
+
}) {
|
|
46
|
+
const notices = (0, import_data.useSelect)(
|
|
47
|
+
(select) => select(import_store.store).getNotices(context),
|
|
48
|
+
[context]
|
|
49
|
+
);
|
|
50
|
+
const { removeNotice } = (0, import_data.useDispatch)(import_store.store);
|
|
51
|
+
const snackbarNotices = notices.filter(({ type }) => type === "snackbar").slice(MAX_VISIBLE_NOTICES);
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
53
|
+
import_components.SnackbarList,
|
|
54
|
+
{
|
|
55
|
+
notices: snackbarNotices,
|
|
56
|
+
className: (0, import_clsx.default)("components-notices__snackbar", className),
|
|
57
|
+
onRemove: (id) => removeNotice(id, context)
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/snackbar-notices/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { SnackbarList } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as noticesStore } from '../../store';\n\n// Last three notices. Slices from the tail end of the list.\nconst MAX_VISIBLE_NOTICES = -3;\n\ntype SnackbarNoticesProps = {\n\tclassName?: string;\n\tcontext?: string;\n};\n\nexport default function SnackbarNotices( {\n\tclassName,\n\tcontext,\n}: SnackbarNoticesProps ) {\n\tconst notices = useSelect(\n\t\t( select ) => select( noticesStore ).getNotices( context ),\n\t\t[ context ]\n\t);\n\tconst { removeNotice } = useDispatch( noticesStore );\n\tconst snackbarNotices = notices\n\t\t.filter( ( { type } ) => type === 'snackbar' )\n\t\t.slice( MAX_VISIBLE_NOTICES );\n\n\treturn (\n\t\t<SnackbarList\n\t\t\tnotices={ snackbarNotices }\n\t\t\tclassName={ clsx( 'components-notices__snackbar', className ) }\n\t\t\tonRemove={ ( id ) => removeNotice( id, context ) }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,wBAA6B;AAC7B,kBAAuC;AAKvC,mBAAsC;AAwBpC;AArBF,IAAM,sBAAsB;AAOb,SAAR,gBAAkC;AAAA,EACxC;AAAA,EACA;AACD,GAA0B;AACzB,QAAM,cAAU;AAAA,IACf,CAAE,WAAY,OAAQ,aAAAA,KAAa,EAAE,WAAY,OAAQ;AAAA,IACzD,CAAE,OAAQ;AAAA,EACX;AACA,QAAM,EAAE,aAAa,QAAI,yBAAa,aAAAA,KAAa;AACnD,QAAM,kBAAkB,QACtB,OAAQ,CAAE,EAAE,KAAK,MAAO,SAAS,UAAW,EAC5C,MAAO,mBAAoB;AAE7B,SACC;AAAA,IAAC;AAAA;AAAA,MACA,SAAU;AAAA,MACV,eAAY,YAAAC,SAAM,gCAAgC,SAAU;AAAA,MAC5D,UAAW,CAAE,OAAQ,aAAc,IAAI,OAAQ;AAAA;AAAA,EAChD;AAEF;",
|
|
6
|
+
"names": ["noticesStore", "clsx"]
|
|
7
|
+
}
|
package/build/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,17 +17,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// packages/notices/src/index.ts
|
|
21
31
|
var index_exports = {};
|
|
22
32
|
__export(index_exports, {
|
|
33
|
+
InlineNotices: () => import_inline_notices.default,
|
|
34
|
+
SnackbarNotices: () => import_snackbar_notices.default,
|
|
23
35
|
store: () => import_store.store
|
|
24
36
|
});
|
|
25
37
|
module.exports = __toCommonJS(index_exports);
|
|
26
38
|
var import_store = require("./store/index.cjs");
|
|
39
|
+
var import_inline_notices = __toESM(require("./components/inline-notices/index.cjs"));
|
|
40
|
+
var import_snackbar_notices = __toESM(require("./components/snackbar-notices/index.cjs"));
|
|
27
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
42
|
0 && (module.exports = {
|
|
43
|
+
InlineNotices,
|
|
44
|
+
SnackbarNotices,
|
|
29
45
|
store
|
|
30
46
|
});
|
|
31
47
|
//# sourceMappingURL=index.cjs.map
|
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { store } from './store';\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["export { store } from './store';\nexport { default as InlineNotices } from './components/inline-notices';\nexport { default as SnackbarNotices } from './components/snackbar-notices';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,4BAAyC;AACzC,8BAA2C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// packages/notices/src/components/inline-notices/index.tsx
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { NoticeList } from "@wordpress/components";
|
|
4
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
5
|
+
import { store as noticesStore } from "../../store/index.mjs";
|
|
6
|
+
|
|
7
|
+
// packages/notices/src/components/inline-notices/style.scss
|
|
8
|
+
if (typeof document !== "undefined" && !document.head.querySelector("style[data-wp-hash='1cf680fb74']")) {
|
|
9
|
+
const style = document.createElement("style");
|
|
10
|
+
style.setAttribute("data-wp-hash", "1cf680fb74");
|
|
11
|
+
style.appendChild(document.createTextNode(".components-notices__dismissible,.components-notices__pinned{color:#1e1e1e}.components-notices__dismissible .components-notice,.components-notices__pinned .components-notice{border-bottom:1px solid #0003;box-sizing:border-box;min-height:64px;padding:0 12px}.components-notices__dismissible .components-notice .components-notice__dismiss,.components-notices__pinned .components-notice .components-notice__dismiss{margin-top:12px}"));
|
|
12
|
+
document.head.appendChild(style);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// packages/notices/src/components/inline-notices/index.tsx
|
|
16
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
function InlineNotices({
|
|
18
|
+
children,
|
|
19
|
+
pinnedNoticesClassName,
|
|
20
|
+
dismissibleNoticesClassName,
|
|
21
|
+
context
|
|
22
|
+
}) {
|
|
23
|
+
const notices = useSelect(
|
|
24
|
+
(select) => select(noticesStore).getNotices(context),
|
|
25
|
+
[context]
|
|
26
|
+
);
|
|
27
|
+
const { removeNotice } = useDispatch(noticesStore);
|
|
28
|
+
const dismissibleNotices = notices.filter(
|
|
29
|
+
({ isDismissible, type }) => isDismissible && type === "default"
|
|
30
|
+
);
|
|
31
|
+
const nonDismissibleNotices = notices.filter(
|
|
32
|
+
({ isDismissible, type }) => !isDismissible && type === "default"
|
|
33
|
+
);
|
|
34
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
35
|
+
/* @__PURE__ */ jsx(
|
|
36
|
+
NoticeList,
|
|
37
|
+
{
|
|
38
|
+
notices: nonDismissibleNotices,
|
|
39
|
+
className: clsx(
|
|
40
|
+
"components-notices__pinned",
|
|
41
|
+
pinnedNoticesClassName
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
),
|
|
45
|
+
/* @__PURE__ */ jsx(
|
|
46
|
+
NoticeList,
|
|
47
|
+
{
|
|
48
|
+
notices: dismissibleNotices,
|
|
49
|
+
className: clsx(
|
|
50
|
+
"components-notices__dismissible",
|
|
51
|
+
dismissibleNoticesClassName
|
|
52
|
+
),
|
|
53
|
+
onRemove: (id) => removeNotice(id, context),
|
|
54
|
+
children
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
] });
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
InlineNotices as default
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/inline-notices/index.tsx", "../../../src/components/inline-notices/style.scss"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactNode } from 'react';\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { NoticeList } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as noticesStore } from '../../store';\nimport './style.scss';\n\ntype InlineNoticesProps = {\n\tchildren?: ReactNode;\n\tpinnedNoticesClassName?: string;\n\tdismissibleNoticesClassName?: string;\n\tcontext?: string;\n};\n\nexport default function InlineNotices( {\n\tchildren,\n\tpinnedNoticesClassName,\n\tdismissibleNoticesClassName,\n\tcontext,\n}: InlineNoticesProps ) {\n\tconst notices = useSelect(\n\t\t( select ) => select( noticesStore ).getNotices( context ),\n\t\t[ context ]\n\t);\n\tconst { removeNotice } = useDispatch( noticesStore );\n\tconst dismissibleNotices = notices.filter(\n\t\t( { isDismissible, type } ) => isDismissible && type === 'default'\n\t);\n\tconst nonDismissibleNotices = notices.filter(\n\t\t( { isDismissible, type } ) => ! isDismissible && type === 'default'\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<NoticeList\n\t\t\t\tnotices={ nonDismissibleNotices }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'components-notices__pinned',\n\t\t\t\t\tpinnedNoticesClassName\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t<NoticeList\n\t\t\t\tnotices={ dismissibleNotices }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'components-notices__dismissible',\n\t\t\t\t\tdismissibleNoticesClassName\n\t\t\t\t) }\n\t\t\t\tonRemove={ ( id ) => removeNotice( id, context ) }\n\t\t\t>\n\t\t\t\t{ children }\n\t\t\t</NoticeList>\n\t\t</>\n\t);\n}\n", "if (typeof document !== 'undefined' && !document.head.querySelector(\"style[data-wp-hash='1cf680fb74']\")) {\n\tconst style = document.createElement(\"style\");\n\tstyle.setAttribute(\"data-wp-hash\", \"1cf680fb74\");\n\tstyle.appendChild(document.createTextNode(\".components-notices__dismissible,.components-notices__pinned{color:#1e1e1e}.components-notices__dismissible .components-notice,.components-notices__pinned .components-notice{border-bottom:1px solid #0003;box-sizing:border-box;min-height:64px;padding:0 12px}.components-notices__dismissible .components-notice .components-notice__dismiss,.components-notices__pinned .components-notice .components-notice__dismiss{margin-top:12px}\"));\n\tdocument.head.appendChild(style);\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO,UAAU;AAKjB,SAAS,kBAAkB;AAC3B,SAAS,aAAa,iBAAiB;AAKvC,SAAS,SAAS,oBAAoB;;;ACftC,IAAI,OAAO,aAAa,eAAe,CAAC,SAAS,KAAK,cAAc,kCAAkC,GAAG;AACxG,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,aAAa,gBAAgB,YAAY;AAC/C,QAAM,YAAY,SAAS,eAAe,8aAA8a,CAAC;AACzd,WAAS,KAAK,YAAY,KAAK;AAChC;;;ADuCE,mBACC,KADD;AAnBa,SAAR,cAAgC;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAwB;AACvB,QAAM,UAAU;AAAA,IACf,CAAE,WAAY,OAAQ,YAAa,EAAE,WAAY,OAAQ;AAAA,IACzD,CAAE,OAAQ;AAAA,EACX;AACA,QAAM,EAAE,aAAa,IAAI,YAAa,YAAa;AACnD,QAAM,qBAAqB,QAAQ;AAAA,IAClC,CAAE,EAAE,eAAe,KAAK,MAAO,iBAAiB,SAAS;AAAA,EAC1D;AACA,QAAM,wBAAwB,QAAQ;AAAA,IACrC,CAAE,EAAE,eAAe,KAAK,MAAO,CAAE,iBAAiB,SAAS;AAAA,EAC5D;AAEA,SACC,iCACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,SAAU;AAAA,QACV,WAAY;AAAA,UACX;AAAA,UACA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,SAAU;AAAA,QACV,WAAY;AAAA,UACX;AAAA,UACA;AAAA,QACD;AAAA,QACA,UAAW,CAAE,OAAQ,aAAc,IAAI,OAAQ;AAAA,QAE7C;AAAA;AAAA,IACH;AAAA,KACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// packages/notices/src/components/snackbar-notices/index.tsx
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { SnackbarList } from "@wordpress/components";
|
|
4
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
5
|
+
import { store as noticesStore } from "../../store/index.mjs";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
var MAX_VISIBLE_NOTICES = -3;
|
|
8
|
+
function SnackbarNotices({
|
|
9
|
+
className,
|
|
10
|
+
context
|
|
11
|
+
}) {
|
|
12
|
+
const notices = useSelect(
|
|
13
|
+
(select) => select(noticesStore).getNotices(context),
|
|
14
|
+
[context]
|
|
15
|
+
);
|
|
16
|
+
const { removeNotice } = useDispatch(noticesStore);
|
|
17
|
+
const snackbarNotices = notices.filter(({ type }) => type === "snackbar").slice(MAX_VISIBLE_NOTICES);
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
SnackbarList,
|
|
20
|
+
{
|
|
21
|
+
notices: snackbarNotices,
|
|
22
|
+
className: clsx("components-notices__snackbar", className),
|
|
23
|
+
onRemove: (id) => removeNotice(id, context)
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
SnackbarNotices as default
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/snackbar-notices/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { SnackbarList } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as noticesStore } from '../../store';\n\n// Last three notices. Slices from the tail end of the list.\nconst MAX_VISIBLE_NOTICES = -3;\n\ntype SnackbarNoticesProps = {\n\tclassName?: string;\n\tcontext?: string;\n};\n\nexport default function SnackbarNotices( {\n\tclassName,\n\tcontext,\n}: SnackbarNoticesProps ) {\n\tconst notices = useSelect(\n\t\t( select ) => select( noticesStore ).getNotices( context ),\n\t\t[ context ]\n\t);\n\tconst { removeNotice } = useDispatch( noticesStore );\n\tconst snackbarNotices = notices\n\t\t.filter( ( { type } ) => type === 'snackbar' )\n\t\t.slice( MAX_VISIBLE_NOTICES );\n\n\treturn (\n\t\t<SnackbarList\n\t\t\tnotices={ snackbarNotices }\n\t\t\tclassName={ clsx( 'components-notices__snackbar', className ) }\n\t\t\tonRemove={ ( id ) => removeNotice( id, context ) }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,oBAAoB;AAC7B,SAAS,aAAa,iBAAiB;AAKvC,SAAS,SAAS,oBAAoB;AAwBpC;AArBF,IAAM,sBAAsB;AAOb,SAAR,gBAAkC;AAAA,EACxC;AAAA,EACA;AACD,GAA0B;AACzB,QAAM,UAAU;AAAA,IACf,CAAE,WAAY,OAAQ,YAAa,EAAE,WAAY,OAAQ;AAAA,IACzD,CAAE,OAAQ;AAAA,EACX;AACA,QAAM,EAAE,aAAa,IAAI,YAAa,YAAa;AACnD,QAAM,kBAAkB,QACtB,OAAQ,CAAE,EAAE,KAAK,MAAO,SAAS,UAAW,EAC5C,MAAO,mBAAoB;AAE7B,SACC;AAAA,IAAC;AAAA;AAAA,MACA,SAAU;AAAA,MACV,WAAY,KAAM,gCAAgC,SAAU;AAAA,MAC5D,UAAW,CAAE,OAAQ,aAAc,IAAI,OAAQ;AAAA;AAAA,EAChD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// packages/notices/src/index.ts
|
|
2
2
|
import { store } from "./store/index.mjs";
|
|
3
|
+
import { default as default2 } from "./components/inline-notices/index.mjs";
|
|
4
|
+
import { default as default3 } from "./components/snackbar-notices/index.mjs";
|
|
3
5
|
export {
|
|
6
|
+
default2 as InlineNotices,
|
|
7
|
+
default3 as SnackbarNotices,
|
|
4
8
|
store
|
|
5
9
|
};
|
|
6
10
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { store } from './store';\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,aAAa;",
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["export { store } from './store';\nexport { default as InlineNotices } from './components/inline-notices';\nexport { default as SnackbarNotices } from './components/snackbar-notices';\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,aAAa;AACtB,SAAoB,WAAXA,gBAAgC;AACzC,SAAoB,WAAXA,gBAAkC;",
|
|
6
|
+
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
import './style.scss';
|
|
6
|
+
type InlineNoticesProps = {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
pinnedNoticesClassName?: string;
|
|
9
|
+
dismissibleNoticesClassName?: string;
|
|
10
|
+
context?: string;
|
|
11
|
+
};
|
|
12
|
+
export default function InlineNotices({ children, pinnedNoticesClassName, dismissibleNoticesClassName, context, }: InlineNoticesProps): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/inline-notices/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAavC,OAAO,cAAc,CAAC;AAEtB,KAAK,kBAAkB,GAAG;IACzB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,aAAa,CAAE,EACtC,QAAQ,EACR,sBAAsB,EACtB,2BAA2B,EAC3B,OAAO,GACP,EAAE,kBAAkB,+BAkCpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/snackbar-notices/index.tsx"],"names":[],"mappings":"AAmBA,KAAK,oBAAoB,GAAG;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAE,EACxC,SAAS,EACT,OAAO,GACP,EAAE,oBAAoB,+BAiBtB"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,+BAA+B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/notices",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.40.0",
|
|
4
4
|
"description": "State management for notices.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -43,8 +43,10 @@
|
|
|
43
43
|
"wpScript": true,
|
|
44
44
|
"types": "build-types",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@wordpress/a11y": "^4.
|
|
47
|
-
"@wordpress/
|
|
46
|
+
"@wordpress/a11y": "^4.40.0",
|
|
47
|
+
"@wordpress/components": "^32.2.0",
|
|
48
|
+
"@wordpress/data": "^10.40.0",
|
|
49
|
+
"clsx": "^2.1.1"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
52
|
"deep-freeze": "0.0.1"
|
|
@@ -55,5 +57,5 @@
|
|
|
55
57
|
"publishConfig": {
|
|
56
58
|
"access": "public"
|
|
57
59
|
},
|
|
58
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "376124aa10dbc2cc0c81c964ec00b99fcfee5382"
|
|
59
61
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { NoticeList } from '@wordpress/components';
|
|
11
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { store as noticesStore } from '../../store';
|
|
17
|
+
import './style.scss';
|
|
18
|
+
|
|
19
|
+
type InlineNoticesProps = {
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
pinnedNoticesClassName?: string;
|
|
22
|
+
dismissibleNoticesClassName?: string;
|
|
23
|
+
context?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default function InlineNotices( {
|
|
27
|
+
children,
|
|
28
|
+
pinnedNoticesClassName,
|
|
29
|
+
dismissibleNoticesClassName,
|
|
30
|
+
context,
|
|
31
|
+
}: InlineNoticesProps ) {
|
|
32
|
+
const notices = useSelect(
|
|
33
|
+
( select ) => select( noticesStore ).getNotices( context ),
|
|
34
|
+
[ context ]
|
|
35
|
+
);
|
|
36
|
+
const { removeNotice } = useDispatch( noticesStore );
|
|
37
|
+
const dismissibleNotices = notices.filter(
|
|
38
|
+
( { isDismissible, type } ) => isDismissible && type === 'default'
|
|
39
|
+
);
|
|
40
|
+
const nonDismissibleNotices = notices.filter(
|
|
41
|
+
( { isDismissible, type } ) => ! isDismissible && type === 'default'
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
<NoticeList
|
|
47
|
+
notices={ nonDismissibleNotices }
|
|
48
|
+
className={ clsx(
|
|
49
|
+
'components-notices__pinned',
|
|
50
|
+
pinnedNoticesClassName
|
|
51
|
+
) }
|
|
52
|
+
/>
|
|
53
|
+
<NoticeList
|
|
54
|
+
notices={ dismissibleNotices }
|
|
55
|
+
className={ clsx(
|
|
56
|
+
'components-notices__dismissible',
|
|
57
|
+
dismissibleNoticesClassName
|
|
58
|
+
) }
|
|
59
|
+
onRemove={ ( id ) => removeNotice( id, context ) }
|
|
60
|
+
>
|
|
61
|
+
{ children }
|
|
62
|
+
</NoticeList>
|
|
63
|
+
</>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
2
|
+
@use "@wordpress/base-styles/colors" as *;
|
|
3
|
+
|
|
4
|
+
.components-notices__dismissible,
|
|
5
|
+
.components-notices__pinned {
|
|
6
|
+
color: $gray-900;
|
|
7
|
+
|
|
8
|
+
.components-notice {
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
border-bottom: $border-width solid rgba(0, 0, 0, 0.2);
|
|
11
|
+
padding: 0 $grid-unit-15;
|
|
12
|
+
|
|
13
|
+
// Min-height matches the height of a single-line notice with an action button.
|
|
14
|
+
min-height: $header-height;
|
|
15
|
+
|
|
16
|
+
// Margins ensure that the dismiss button aligns to the center of the first line of text.
|
|
17
|
+
.components-notice__dismiss {
|
|
18
|
+
margin-top: $grid-unit-15;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { SnackbarList } from '@wordpress/components';
|
|
10
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { store as noticesStore } from '../../store';
|
|
16
|
+
|
|
17
|
+
// Last three notices. Slices from the tail end of the list.
|
|
18
|
+
const MAX_VISIBLE_NOTICES = -3;
|
|
19
|
+
|
|
20
|
+
type SnackbarNoticesProps = {
|
|
21
|
+
className?: string;
|
|
22
|
+
context?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default function SnackbarNotices( {
|
|
26
|
+
className,
|
|
27
|
+
context,
|
|
28
|
+
}: SnackbarNoticesProps ) {
|
|
29
|
+
const notices = useSelect(
|
|
30
|
+
( select ) => select( noticesStore ).getNotices( context ),
|
|
31
|
+
[ context ]
|
|
32
|
+
);
|
|
33
|
+
const { removeNotice } = useDispatch( noticesStore );
|
|
34
|
+
const snackbarNotices = notices
|
|
35
|
+
.filter( ( { type } ) => type === 'snackbar' )
|
|
36
|
+
.slice( MAX_VISIBLE_NOTICES );
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<SnackbarList
|
|
40
|
+
notices={ snackbarNotices }
|
|
41
|
+
className={ clsx( 'components-notices__snackbar', className ) }
|
|
42
|
+
onRemove={ ( id ) => removeNotice( id, context ) }
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
package/src/index.ts
CHANGED