@dream-encode/wp-js-plugin-utils 0.2.6 → 0.3.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/dist/components/NotificationsDrawer/DismissAllButton.js +67 -0
- package/dist/components/NotificationsDrawer/NotificationItem.js +109 -0
- package/dist/components/NotificationsDrawer/NotificationsDrawer.js +161 -0
- package/dist/components/NotificationsDrawer/NotificationsList.js +75 -0
- package/dist/components/NotificationsDrawer/index.js +40 -0
- package/dist/components/NotificationsDrawer/styles/_notifications-drawer.scss +186 -0
- package/dist/components/index.js +26 -0
- package/package.json +2 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _i18n = require("@wordpress/i18n");
|
|
8
|
+
var _components = require("@wordpress/components");
|
|
9
|
+
var _element = require("@wordpress/element");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
/**
|
|
12
|
+
* "Dismiss All" button used inside the notifications drawer.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} props
|
|
15
|
+
* @param {Function} props.onDismissAll Async dismiss-all handler. Returns truthy on success.
|
|
16
|
+
* @param {Function} [props.onDismissingChange] Optional callback invoked with `true` when dismiss-all begins and `false` once the animation completes (or the request fails).
|
|
17
|
+
* @param {string} [props.textDomain] Translation domain for the button label.
|
|
18
|
+
* @param {number} [props.startDelay] Delay (ms) before the API call fires after dismiss-all begins, to allow the start animation to play.
|
|
19
|
+
* @param {number} [props.resetDelay] Delay (ms) after a successful dismiss-all before resetting the busy state.
|
|
20
|
+
* @return {JSX.Element}
|
|
21
|
+
*/const DismissAllButton = ({
|
|
22
|
+
onDismissAll,
|
|
23
|
+
onDismissingChange,
|
|
24
|
+
textDomain = 'default',
|
|
25
|
+
startDelay = 300,
|
|
26
|
+
resetDelay = 800
|
|
27
|
+
}) => {
|
|
28
|
+
const [dismissing, setDismissing] = (0, _element.useState)(false);
|
|
29
|
+
const dismissAll = async () => {
|
|
30
|
+
if (dismissing) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setDismissing(true);
|
|
34
|
+
if (typeof onDismissingChange === 'function') {
|
|
35
|
+
onDismissingChange(true);
|
|
36
|
+
}
|
|
37
|
+
setTimeout(async () => {
|
|
38
|
+
const result = await onDismissAll();
|
|
39
|
+
if (!result) {
|
|
40
|
+
setDismissing(false);
|
|
41
|
+
if (typeof onDismissingChange === 'function') {
|
|
42
|
+
onDismissingChange(false);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
setDismissing(false);
|
|
48
|
+
if (typeof onDismissingChange === 'function') {
|
|
49
|
+
onDismissingChange(false);
|
|
50
|
+
}
|
|
51
|
+
}, resetDelay);
|
|
52
|
+
}, startDelay);
|
|
53
|
+
};
|
|
54
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
55
|
+
className: "dismiss-all",
|
|
56
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
57
|
+
className: "dismiss-all-button",
|
|
58
|
+
variant: "secondary",
|
|
59
|
+
size: "default",
|
|
60
|
+
isBusy: dismissing,
|
|
61
|
+
disabled: dismissing,
|
|
62
|
+
onClick: dismissAll,
|
|
63
|
+
children: dismissing ? (0, _i18n.__)('Dismissing...', textDomain) : (0, _i18n.__)('Dismiss All', textDomain)
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
var _default = exports.default = DismissAllButton;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _components = require("@wordpress/components");
|
|
8
|
+
var _element = require("@wordpress/element");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
const iconType = type => {
|
|
11
|
+
switch (type) {
|
|
12
|
+
case 'error':
|
|
13
|
+
case 'warning':
|
|
14
|
+
return 'warning';
|
|
15
|
+
case 'success':
|
|
16
|
+
return 'yes';
|
|
17
|
+
case 'info':
|
|
18
|
+
default:
|
|
19
|
+
return 'info-outline';
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const NotificationIcon = ({
|
|
23
|
+
type
|
|
24
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Dashicon, {
|
|
25
|
+
icon: iconType(type)
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Single notification rendered inside the drawer.
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} props
|
|
32
|
+
* @param {Object} props.notification Notification object: `{ id, type, message }`.
|
|
33
|
+
* @param {Function} props.onDismiss Async dismiss handler. Receives the notification id, returns a truthy value on success.
|
|
34
|
+
* @param {string} [props.className] Additional class name applied to the underlying `Notice`.
|
|
35
|
+
* @param {boolean} [props.allowHtml] Render `notification.message` via `dangerouslySetInnerHTML`.
|
|
36
|
+
* @param {Function} [props.renderMessage] Custom message renderer. Receives `notification`, returns a node.
|
|
37
|
+
* @param {Function} [props.onMessageMount] Called with `(element, notification)` after the message DOM node mounts. Useful for post-render DOM transforms.
|
|
38
|
+
* @param {number} [props.dismissAnimationDuration] Delay (ms) between successful dismiss and the parent removing the item.
|
|
39
|
+
* @return {JSX.Element}
|
|
40
|
+
*/
|
|
41
|
+
const NotificationItem = ({
|
|
42
|
+
notification,
|
|
43
|
+
onDismiss,
|
|
44
|
+
className = '',
|
|
45
|
+
allowHtml = false,
|
|
46
|
+
renderMessage,
|
|
47
|
+
onMessageMount,
|
|
48
|
+
dismissAnimationDuration = 500
|
|
49
|
+
}) => {
|
|
50
|
+
const [dismissing, setDismissing] = (0, _element.useState)(false);
|
|
51
|
+
const messageRef = (0, _element.useRef)(null);
|
|
52
|
+
(0, _element.useEffect)(() => {
|
|
53
|
+
if (typeof onMessageMount === 'function' && messageRef.current) {
|
|
54
|
+
onMessageMount(messageRef.current, notification);
|
|
55
|
+
}
|
|
56
|
+
}, [notification, onMessageMount]);
|
|
57
|
+
const dismissNotice = async () => {
|
|
58
|
+
if (dismissing) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setDismissing(true);
|
|
62
|
+
setTimeout(async () => {
|
|
63
|
+
const result = await onDismiss(notification.id);
|
|
64
|
+
if (!result) {
|
|
65
|
+
setDismissing(false);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
setDismissing(false);
|
|
70
|
+
}, dismissAnimationDuration);
|
|
71
|
+
}, 50);
|
|
72
|
+
};
|
|
73
|
+
const noticeClassName = `${className} ${dismissing ? 'dismissing' : ''}`.trim();
|
|
74
|
+
let messageContent;
|
|
75
|
+
if (typeof renderMessage === 'function') {
|
|
76
|
+
messageContent = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
77
|
+
ref: messageRef,
|
|
78
|
+
children: renderMessage(notification)
|
|
79
|
+
});
|
|
80
|
+
} else if (allowHtml) {
|
|
81
|
+
messageContent = /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
82
|
+
ref: messageRef,
|
|
83
|
+
dangerouslySetInnerHTML: {
|
|
84
|
+
__html: notification.message
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
messageContent = /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
89
|
+
ref: messageRef,
|
|
90
|
+
children: notification.message
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Notice, {
|
|
94
|
+
className: noticeClassName,
|
|
95
|
+
status: notification.type,
|
|
96
|
+
isDismissible: true,
|
|
97
|
+
onRemove: dismissNotice,
|
|
98
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Flex, {
|
|
99
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.FlexItem, {
|
|
100
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(NotificationIcon, {
|
|
101
|
+
type: notification.type
|
|
102
|
+
})
|
|
103
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.FlexBlock, {
|
|
104
|
+
children: messageContent
|
|
105
|
+
})]
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
var _default = exports.default = NotificationItem;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _element = require("@wordpress/element");
|
|
8
|
+
var _NotificationsList = _interopRequireDefault(require("./NotificationsList"));
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const DEFAULT_AUTO_HIDE_DELAY = 2000;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Floating notifications drawer with a count badge and hover/click expansion.
|
|
15
|
+
*
|
|
16
|
+
* The consumer owns the notifications state. Pass it in via `notifications`
|
|
17
|
+
* and provide async `onDismiss(id)` and `onDismissAll()` handlers that update
|
|
18
|
+
* that state on success.
|
|
19
|
+
*
|
|
20
|
+
* @param {Object} props
|
|
21
|
+
* @param {Array} props.notifications Array of `{ id, type, message }` objects.
|
|
22
|
+
* @param {Function} props.onDismiss Async per-item dismiss handler. Returns truthy on success.
|
|
23
|
+
* @param {Function} props.onDismissAll Async dismiss-all handler. Returns truthy on success.
|
|
24
|
+
* @param {string} [props.textDomain] Translation domain for built-in strings.
|
|
25
|
+
* @param {string} [props.id] DOM id for the drawer container.
|
|
26
|
+
* @param {string} [props.className] Additional class name for the drawer container.
|
|
27
|
+
* @param {string} [props.itemClassName] Class name applied to each notification's underlying `Notice`.
|
|
28
|
+
* @param {string} [props.iconName] Dashicon name used for the drawer trigger icon.
|
|
29
|
+
* @param {boolean} [props.allowHtml] Render notification messages via `dangerouslySetInnerHTML`.
|
|
30
|
+
* @param {Function} [props.renderMessage] Custom message renderer. Receives `notification`.
|
|
31
|
+
* @param {Function} [props.onMessageMount] Called with `(element, notification)` after each message DOM node mounts.
|
|
32
|
+
* @param {boolean} [props.expandOnHover] Expand the drawer on mouse enter (default true).
|
|
33
|
+
* @param {boolean} [props.expandOnClick] Toggle the drawer on icon click (default true).
|
|
34
|
+
* @param {number} [props.autoHideDelay] Delay (ms) before auto-collapsing after mouse leave.
|
|
35
|
+
* @param {boolean} [props.animateOnNew] Briefly add a `new-message` class to the icon when the count increases (default true).
|
|
36
|
+
* @param {number} [props.dismissAnimationDuration] Forwarded to each notification item.
|
|
37
|
+
* @param {number} [props.dismissAllStartDelay] Forwarded to the dismiss-all button.
|
|
38
|
+
* @param {number} [props.dismissAllResetDelay] Forwarded to the dismiss-all button.
|
|
39
|
+
* @return {JSX.Element|null}
|
|
40
|
+
*/
|
|
41
|
+
const NotificationsDrawer = ({
|
|
42
|
+
notifications,
|
|
43
|
+
onDismiss,
|
|
44
|
+
onDismissAll,
|
|
45
|
+
textDomain = 'default',
|
|
46
|
+
id,
|
|
47
|
+
className = '',
|
|
48
|
+
itemClassName = '',
|
|
49
|
+
iconName = 'email',
|
|
50
|
+
allowHtml = false,
|
|
51
|
+
renderMessage,
|
|
52
|
+
onMessageMount,
|
|
53
|
+
expandOnHover = true,
|
|
54
|
+
expandOnClick = true,
|
|
55
|
+
autoHideDelay = DEFAULT_AUTO_HIDE_DELAY,
|
|
56
|
+
animateOnNew = true,
|
|
57
|
+
dismissAnimationDuration = 500,
|
|
58
|
+
dismissAllStartDelay = 300,
|
|
59
|
+
dismissAllResetDelay = 800
|
|
60
|
+
}) => {
|
|
61
|
+
const count = notifications?.length || 0;
|
|
62
|
+
const [isExpanded, setIsExpanded] = (0, _element.useState)(false);
|
|
63
|
+
const [animate, setAnimate] = (0, _element.useState)(false);
|
|
64
|
+
const prevCountRef = (0, _element.useRef)(0);
|
|
65
|
+
const containerRef = (0, _element.useRef)(null);
|
|
66
|
+
const iconRef = (0, _element.useRef)(null);
|
|
67
|
+
const autoHideTimerRef = (0, _element.useRef)(null);
|
|
68
|
+
(0, _element.useEffect)(() => {
|
|
69
|
+
if (animateOnNew && count > prevCountRef.current && prevCountRef.current > 0) {
|
|
70
|
+
setAnimate(true);
|
|
71
|
+
const timerId = setTimeout(() => setAnimate(false), 1000);
|
|
72
|
+
prevCountRef.current = count;
|
|
73
|
+
return () => clearTimeout(timerId);
|
|
74
|
+
}
|
|
75
|
+
prevCountRef.current = count;
|
|
76
|
+
}, [count, animateOnNew]);
|
|
77
|
+
(0, _element.useEffect)(() => {
|
|
78
|
+
if (!expandOnHover) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const clearAutoHide = () => {
|
|
82
|
+
if (autoHideTimerRef.current) {
|
|
83
|
+
clearTimeout(autoHideTimerRef.current);
|
|
84
|
+
autoHideTimerRef.current = null;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const startAutoHide = () => {
|
|
88
|
+
clearAutoHide();
|
|
89
|
+
autoHideTimerRef.current = setTimeout(() => {
|
|
90
|
+
setIsExpanded(false);
|
|
91
|
+
}, autoHideDelay);
|
|
92
|
+
};
|
|
93
|
+
const handleMouseEnter = () => {
|
|
94
|
+
if (count === 0) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
setIsExpanded(true);
|
|
98
|
+
clearAutoHide();
|
|
99
|
+
};
|
|
100
|
+
const handleMouseLeave = () => {
|
|
101
|
+
startAutoHide();
|
|
102
|
+
};
|
|
103
|
+
const container = containerRef.current;
|
|
104
|
+
const icon = iconRef.current;
|
|
105
|
+
if (container) {
|
|
106
|
+
container.addEventListener('mouseenter', handleMouseEnter);
|
|
107
|
+
container.addEventListener('mouseleave', handleMouseLeave);
|
|
108
|
+
}
|
|
109
|
+
if (icon) {
|
|
110
|
+
icon.addEventListener('mouseenter', handleMouseEnter);
|
|
111
|
+
icon.addEventListener('mouseleave', handleMouseLeave);
|
|
112
|
+
}
|
|
113
|
+
return () => {
|
|
114
|
+
if (container) {
|
|
115
|
+
container.removeEventListener('mouseenter', handleMouseEnter);
|
|
116
|
+
container.removeEventListener('mouseleave', handleMouseLeave);
|
|
117
|
+
}
|
|
118
|
+
if (icon) {
|
|
119
|
+
icon.removeEventListener('mouseenter', handleMouseEnter);
|
|
120
|
+
icon.removeEventListener('mouseleave', handleMouseLeave);
|
|
121
|
+
}
|
|
122
|
+
clearAutoHide();
|
|
123
|
+
};
|
|
124
|
+
}, [expandOnHover, autoHideDelay, count]);
|
|
125
|
+
const handleIconClick = () => {
|
|
126
|
+
if (!expandOnClick || count === 0) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
setIsExpanded(prev => !prev);
|
|
130
|
+
};
|
|
131
|
+
const containerClassName = `${className} ${isExpanded ? 'expanded' : ''}`.trim();
|
|
132
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
133
|
+
id: id,
|
|
134
|
+
ref: containerRef,
|
|
135
|
+
className: containerClassName,
|
|
136
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
137
|
+
ref: iconRef,
|
|
138
|
+
className: `messages-icon ${animate ? 'new-message' : ''}`.trim(),
|
|
139
|
+
onClick: handleIconClick,
|
|
140
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
141
|
+
className: `dashicons dashicons-${iconName}`
|
|
142
|
+
}), count > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
143
|
+
className: "messages-count",
|
|
144
|
+
children: count
|
|
145
|
+
})]
|
|
146
|
+
}), count > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_NotificationsList.default, {
|
|
147
|
+
notifications: notifications,
|
|
148
|
+
onDismiss: onDismiss,
|
|
149
|
+
onDismissAll: onDismissAll,
|
|
150
|
+
textDomain: textDomain,
|
|
151
|
+
allowHtml: allowHtml,
|
|
152
|
+
renderMessage: renderMessage,
|
|
153
|
+
onMessageMount: onMessageMount,
|
|
154
|
+
itemClassName: itemClassName,
|
|
155
|
+
dismissAnimationDuration: dismissAnimationDuration,
|
|
156
|
+
dismissAllStartDelay: dismissAllStartDelay,
|
|
157
|
+
dismissAllResetDelay: dismissAllResetDelay
|
|
158
|
+
})]
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
var _default = exports.default = NotificationsDrawer;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _element = require("@wordpress/element");
|
|
8
|
+
var _NotificationItem = _interopRequireDefault(require("./NotificationItem"));
|
|
9
|
+
var _DismissAllButton = _interopRequireDefault(require("./DismissAllButton"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
/**
|
|
13
|
+
* List of notifications with a "Dismiss All" control.
|
|
14
|
+
*
|
|
15
|
+
* Stateless with respect to the notifications array — the consumer owns the
|
|
16
|
+
* source-of-truth and is expected to update it from within `onDismiss`/`onDismissAll`.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} props
|
|
19
|
+
* @param {Array} props.notifications Array of `{ id, type, message }` objects.
|
|
20
|
+
* @param {Function} props.onDismiss Async per-item dismiss handler. Receives the notification id, returns truthy on success.
|
|
21
|
+
* @param {Function} props.onDismissAll Async dismiss-all handler. Returns truthy on success.
|
|
22
|
+
* @param {string} [props.textDomain] Translation domain for built-in strings.
|
|
23
|
+
* @param {boolean} [props.allowHtml] Render notification messages via `dangerouslySetInnerHTML`.
|
|
24
|
+
* @param {Function} [props.renderMessage] Custom message renderer. Receives `notification`.
|
|
25
|
+
* @param {Function} [props.onMessageMount] Called with `(element, notification)` after each message DOM node mounts.
|
|
26
|
+
* @param {string} [props.containerClassName] Additional class names for the list container.
|
|
27
|
+
* @param {string} [props.itemClassName] Class name applied to each `NotificationItem`'s underlying `Notice`.
|
|
28
|
+
* @param {boolean} [props.showDismissAll] Toggle visibility of the "Dismiss All" button.
|
|
29
|
+
* @param {boolean} [props.alwaysRender] When true, the list container is rendered even when empty (useful while a dismiss-all animation is running).
|
|
30
|
+
* @param {number} [props.dismissAnimationDuration] Forwarded to each `NotificationItem`.
|
|
31
|
+
* @param {number} [props.dismissAllStartDelay] Forwarded to `DismissAllButton`.
|
|
32
|
+
* @param {number} [props.dismissAllResetDelay] Forwarded to `DismissAllButton`.
|
|
33
|
+
* @return {JSX.Element|null}
|
|
34
|
+
*/const NotificationsList = ({
|
|
35
|
+
notifications,
|
|
36
|
+
onDismiss,
|
|
37
|
+
onDismissAll,
|
|
38
|
+
textDomain = 'default',
|
|
39
|
+
allowHtml = false,
|
|
40
|
+
renderMessage,
|
|
41
|
+
onMessageMount,
|
|
42
|
+
containerClassName = '',
|
|
43
|
+
itemClassName = '',
|
|
44
|
+
showDismissAll = true,
|
|
45
|
+
alwaysRender = false,
|
|
46
|
+
dismissAnimationDuration = 500,
|
|
47
|
+
dismissAllStartDelay = 300,
|
|
48
|
+
dismissAllResetDelay = 800
|
|
49
|
+
}) => {
|
|
50
|
+
const [isDismissingAll, setIsDismissingAll] = (0, _element.useState)(false);
|
|
51
|
+
const count = notifications?.length || 0;
|
|
52
|
+
if (!alwaysRender && count === 0 && !isDismissingAll) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const className = `messages-container ${containerClassName} ${isDismissingAll ? 'dismissing-all' : ''}`.trim();
|
|
56
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
57
|
+
className: className,
|
|
58
|
+
children: [showDismissAll && count > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_DismissAllButton.default, {
|
|
59
|
+
onDismissAll: onDismissAll,
|
|
60
|
+
onDismissingChange: setIsDismissingAll,
|
|
61
|
+
textDomain: textDomain,
|
|
62
|
+
startDelay: dismissAllStartDelay,
|
|
63
|
+
resetDelay: dismissAllResetDelay
|
|
64
|
+
}), notifications?.map(notification => /*#__PURE__*/(0, _jsxRuntime.jsx)(_NotificationItem.default, {
|
|
65
|
+
notification: notification,
|
|
66
|
+
onDismiss: onDismiss,
|
|
67
|
+
className: itemClassName,
|
|
68
|
+
allowHtml: allowHtml,
|
|
69
|
+
renderMessage: renderMessage,
|
|
70
|
+
onMessageMount: onMessageMount,
|
|
71
|
+
dismissAnimationDuration: dismissAnimationDuration
|
|
72
|
+
}, notification.id))]
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var _default = exports.default = NotificationsList;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "DismissAllButton", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _DismissAllButton.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "NotificationItem", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _NotificationItem.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "NotificationsDrawer", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _NotificationsDrawer.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "NotificationsList", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _NotificationsList.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "default", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _NotificationsDrawer.default;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var _NotificationsDrawer = _interopRequireDefault(require("./NotificationsDrawer"));
|
|
37
|
+
var _NotificationsList = _interopRequireDefault(require("./NotificationsList"));
|
|
38
|
+
var _NotificationItem = _interopRequireDefault(require("./NotificationItem"));
|
|
39
|
+
var _DismissAllButton = _interopRequireDefault(require("./DismissAllButton"));
|
|
40
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Generic styling for the wp-plugin-utils NotificationsDrawer component.
|
|
3
|
+
*
|
|
4
|
+
* Apply to the drawer's id/class selector and pass the same item class name
|
|
5
|
+
* that you supply via the `itemClassName` prop on the React component:
|
|
6
|
+
*
|
|
7
|
+
* #my-plugin-messages {
|
|
8
|
+
* @include de-wp-plugin-utils-notifications-drawer('my-plugin-alert');
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
@keyframes de-wp-plugin-utils-notifications-drawer-pulse {
|
|
13
|
+
0% {
|
|
14
|
+
transform: scale(1);
|
|
15
|
+
box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
|
|
16
|
+
}
|
|
17
|
+
50% {
|
|
18
|
+
transform: scale(1.1);
|
|
19
|
+
box-shadow: -2px 0 15px rgba(202, 74, 31, 0.4);
|
|
20
|
+
}
|
|
21
|
+
100% {
|
|
22
|
+
transform: scale(1);
|
|
23
|
+
box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@mixin de-wp-plugin-utils-notifications-drawer($item-class: 'notification-item') {
|
|
28
|
+
position: fixed;
|
|
29
|
+
bottom: 2rem;
|
|
30
|
+
right: -400px;
|
|
31
|
+
width: 400px;
|
|
32
|
+
transition: right 0.3s ease-in-out;
|
|
33
|
+
z-index: 99999;
|
|
34
|
+
|
|
35
|
+
.messages-icon {
|
|
36
|
+
position: absolute;
|
|
37
|
+
bottom: 0;
|
|
38
|
+
left: -50px;
|
|
39
|
+
width: 50px;
|
|
40
|
+
height: 50px;
|
|
41
|
+
background-color: #fff;
|
|
42
|
+
border-radius: 4px 0 0 4px;
|
|
43
|
+
box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
|
|
49
|
+
&.new-message {
|
|
50
|
+
animation: de-wp-plugin-utils-notifications-drawer-pulse 1s;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.dashicons {
|
|
54
|
+
font-size: 24px;
|
|
55
|
+
color: #444;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.messages-count {
|
|
59
|
+
position: absolute;
|
|
60
|
+
top: -7px;
|
|
61
|
+
left: -10px;
|
|
62
|
+
min-width: 18px;
|
|
63
|
+
height: 18px;
|
|
64
|
+
padding: 0 4px;
|
|
65
|
+
border-radius: 9px;
|
|
66
|
+
background-color: #ca4a1f;
|
|
67
|
+
color: #fff;
|
|
68
|
+
font-size: 11px;
|
|
69
|
+
font-weight: 600;
|
|
70
|
+
display: flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
transition: transform 0.3s ease, opacity 0.3s ease;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&.expanded {
|
|
78
|
+
right: 0;
|
|
79
|
+
|
|
80
|
+
.messages-icon {
|
|
81
|
+
box-shadow: none;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.messages-container {
|
|
86
|
+
background-color: #fff;
|
|
87
|
+
border-radius: 4px 0 0 4px;
|
|
88
|
+
box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
|
|
89
|
+
max-height: 80vh;
|
|
90
|
+
padding: 10px;
|
|
91
|
+
display: flex;
|
|
92
|
+
flex-direction: column;
|
|
93
|
+
overflow-y: auto;
|
|
94
|
+
|
|
95
|
+
&.dismissing-all {
|
|
96
|
+
opacity: 0.5;
|
|
97
|
+
pointer-events: none;
|
|
98
|
+
transition: opacity 0.5s ease-in-out;
|
|
99
|
+
|
|
100
|
+
.#{$item-class} {
|
|
101
|
+
opacity: 0.5;
|
|
102
|
+
transform: scale(0.98);
|
|
103
|
+
transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.dismiss-all {
|
|
109
|
+
display: flex;
|
|
110
|
+
flex-direction: row;
|
|
111
|
+
align-items: center;
|
|
112
|
+
justify-content: end;
|
|
113
|
+
margin-bottom: 6px;
|
|
114
|
+
|
|
115
|
+
button {
|
|
116
|
+
color: #444444;
|
|
117
|
+
background-color: #ffffff;
|
|
118
|
+
box-shadow: none;
|
|
119
|
+
font-weight: 500;
|
|
120
|
+
|
|
121
|
+
&:hover {
|
|
122
|
+
border-color: #000;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.#{$item-class} {
|
|
128
|
+
padding: 3px 6px;
|
|
129
|
+
box-sizing: border-box;
|
|
130
|
+
margin-bottom: 8px;
|
|
131
|
+
transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
|
|
132
|
+
max-height: 200px;
|
|
133
|
+
overflow: hidden;
|
|
134
|
+
transform-origin: top;
|
|
135
|
+
opacity: 1;
|
|
136
|
+
|
|
137
|
+
&.dismissing {
|
|
138
|
+
opacity: 0;
|
|
139
|
+
max-height: 0;
|
|
140
|
+
margin-bottom: 0;
|
|
141
|
+
padding-top: 0;
|
|
142
|
+
padding-bottom: 0;
|
|
143
|
+
transform: translateY(-10px) scale(0.95);
|
|
144
|
+
transition:
|
|
145
|
+
opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1),
|
|
146
|
+
max-height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
|
|
147
|
+
margin-bottom 0.5s cubic-bezier(0.4, 0, 0.2, 1),
|
|
148
|
+
padding 0.5s cubic-bezier(0.4, 0, 0.2, 1),
|
|
149
|
+
transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.dashicons-warning {
|
|
153
|
+
color: #cc1818;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.message-action-button {
|
|
157
|
+
background-color: #cc1818;
|
|
158
|
+
color: #fff;
|
|
159
|
+
border: #cc1818;
|
|
160
|
+
box-shadow: none;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
p {
|
|
164
|
+
color: #000000;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
&.is-dismissible {
|
|
168
|
+
padding-right: 0;
|
|
169
|
+
|
|
170
|
+
.components-button.has-icon {
|
|
171
|
+
padding: 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.components-notice__dismiss {
|
|
175
|
+
svg {
|
|
176
|
+
width: 18px;
|
|
177
|
+
height: 18px;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.components-notice__action.components-button.is-link {
|
|
184
|
+
margin-left: 30px;
|
|
185
|
+
}
|
|
186
|
+
}
|
package/dist/components/index.js
CHANGED
|
@@ -3,11 +3,37 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "DismissAllButton", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _NotificationsDrawer.DismissAllButton;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "Notices", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
9
15
|
return _Notices.default;
|
|
10
16
|
}
|
|
11
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "NotificationItem", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _NotificationsDrawer.NotificationItem;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "NotificationsDrawer", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _NotificationsDrawer.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "NotificationsList", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _NotificationsDrawer.NotificationsList;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
12
36
|
var _Notices = _interopRequireDefault(require("./Notices"));
|
|
37
|
+
var _NotificationsDrawer = _interopRequireWildcard(require("./NotificationsDrawer"));
|
|
38
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
39
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dream-encode/wp-js-plugin-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Common JS functionality used by custom WP plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wordpress",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"./settings/styles": "./dist/settings/styles/_settings-page.scss",
|
|
28
28
|
"./data-migrations": "./dist/data-migrations/index.js",
|
|
29
29
|
"./components": "./dist/components/index.js",
|
|
30
|
+
"./components/notifications-drawer/styles": "./dist/components/NotificationsDrawer/styles/_notifications-drawer.scss",
|
|
30
31
|
"./hooks": "./dist/hooks/index.js",
|
|
31
32
|
"./api": "./dist/api/index.js",
|
|
32
33
|
"./utils": "./dist/utils/index.js",
|