@yamada-ui/notice 0.4.12 → 0.5.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/chunk-H6JQLH3P.mjs +144 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +134 -0
- package/dist/index.mjs +4 -0
- package/dist/notice-provider.d.mts +7 -0
- package/dist/notice-provider.d.ts +7 -0
- package/dist/notice-provider.js +368 -0
- package/dist/notice-provider.mjs +8 -0
- package/package.json +7 -4
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import {
|
|
3
|
+
noticeStore
|
|
4
|
+
} from "./chunk-VLY5Y4MA.mjs";
|
|
5
|
+
|
|
6
|
+
// src/notice-provider.tsx
|
|
7
|
+
import { ui } from "@yamada-ui/core";
|
|
8
|
+
import {
|
|
9
|
+
AnimatePresence,
|
|
10
|
+
motion,
|
|
11
|
+
useIsPresent
|
|
12
|
+
} from "@yamada-ui/motion";
|
|
13
|
+
import { Portal } from "@yamada-ui/portal";
|
|
14
|
+
import { useTimeout } from "@yamada-ui/use-timeout";
|
|
15
|
+
import { runIfFunc, useUpdateEffect } from "@yamada-ui/utils";
|
|
16
|
+
import { memo, useEffect, useState, useSyncExternalStore } from "react";
|
|
17
|
+
import { jsx } from "react/jsx-runtime";
|
|
18
|
+
var NoticeProvider = ({
|
|
19
|
+
variants,
|
|
20
|
+
gap = "md",
|
|
21
|
+
appendToParentPortal,
|
|
22
|
+
containerRef
|
|
23
|
+
}) => {
|
|
24
|
+
const state = useSyncExternalStore(
|
|
25
|
+
noticeStore.subscribe,
|
|
26
|
+
noticeStore.getSnapshot,
|
|
27
|
+
noticeStore.getSnapshot
|
|
28
|
+
);
|
|
29
|
+
const components = Object.entries(state).map(([placement, notices]) => {
|
|
30
|
+
const top = placement.includes("top") ? "env(safe-area-inset-top, 0px)" : void 0;
|
|
31
|
+
const bottom = placement.includes("bottom") ? "env(safe-area-inset-bottom, 0px)" : void 0;
|
|
32
|
+
const right = !placement.includes("left") ? "env(safe-area-inset-right, 0px)" : void 0;
|
|
33
|
+
const left = !placement.includes("right") ? "env(safe-area-inset-left, 0px)" : void 0;
|
|
34
|
+
const css = {
|
|
35
|
+
position: "fixed",
|
|
36
|
+
zIndex: "zarbon",
|
|
37
|
+
pointerEvents: "none",
|
|
38
|
+
display: "flex",
|
|
39
|
+
flexDirection: "column",
|
|
40
|
+
margin: gap,
|
|
41
|
+
gap,
|
|
42
|
+
top,
|
|
43
|
+
bottom,
|
|
44
|
+
right,
|
|
45
|
+
left
|
|
46
|
+
};
|
|
47
|
+
return /* @__PURE__ */ jsx(ui.ul, { className: "ui-notice-list", __css: css, children: /* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: notices.map((notice) => /* @__PURE__ */ jsx(NoticeComponent, { variants, ...notice }, notice.id)) }) }, placement);
|
|
48
|
+
});
|
|
49
|
+
return /* @__PURE__ */ jsx(
|
|
50
|
+
Portal,
|
|
51
|
+
{
|
|
52
|
+
appendToParentPortal,
|
|
53
|
+
containerRef,
|
|
54
|
+
children: components
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
var defaultVariants = {
|
|
59
|
+
initial: ({ placement }) => ({
|
|
60
|
+
opacity: 0,
|
|
61
|
+
[["top", "bottom"].includes(placement) ? "y" : "x"]: (placement === "bottom" ? 1 : placement.includes("right") ? 1 : -1) * 24
|
|
62
|
+
}),
|
|
63
|
+
animate: {
|
|
64
|
+
opacity: 1,
|
|
65
|
+
y: 0,
|
|
66
|
+
x: 0,
|
|
67
|
+
scale: 1,
|
|
68
|
+
transition: {
|
|
69
|
+
duration: 0.4,
|
|
70
|
+
ease: [0.4, 0, 0.2, 1]
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
exit: {
|
|
74
|
+
opacity: 0,
|
|
75
|
+
scale: 0.95,
|
|
76
|
+
transition: {
|
|
77
|
+
duration: 0.2,
|
|
78
|
+
ease: [0.4, 0, 1, 1]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var NoticeComponent = memo(
|
|
83
|
+
({
|
|
84
|
+
variants = defaultVariants,
|
|
85
|
+
placement,
|
|
86
|
+
duration = 5e3,
|
|
87
|
+
message,
|
|
88
|
+
onCloseComplete,
|
|
89
|
+
isDelete = false,
|
|
90
|
+
onDelete,
|
|
91
|
+
style
|
|
92
|
+
}) => {
|
|
93
|
+
const [delay, setDelay] = useState(duration);
|
|
94
|
+
const isPresent = useIsPresent();
|
|
95
|
+
useUpdateEffect(() => {
|
|
96
|
+
if (!isPresent)
|
|
97
|
+
onCloseComplete == null ? void 0 : onCloseComplete();
|
|
98
|
+
}, [isPresent]);
|
|
99
|
+
useUpdateEffect(() => {
|
|
100
|
+
setDelay(duration);
|
|
101
|
+
}, [duration]);
|
|
102
|
+
const onMouseEnter = () => setDelay(null);
|
|
103
|
+
const onMouseLeave = () => setDelay(duration);
|
|
104
|
+
const onClose = () => {
|
|
105
|
+
if (isPresent)
|
|
106
|
+
onDelete();
|
|
107
|
+
};
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (isPresent && isDelete)
|
|
110
|
+
onDelete();
|
|
111
|
+
}, [isPresent, isDelete, onDelete]);
|
|
112
|
+
useTimeout(onClose, delay);
|
|
113
|
+
const css = {
|
|
114
|
+
pointerEvents: "auto",
|
|
115
|
+
maxW: "2xl",
|
|
116
|
+
minW: "sm",
|
|
117
|
+
...style
|
|
118
|
+
};
|
|
119
|
+
return /* @__PURE__ */ jsx(
|
|
120
|
+
motion.li,
|
|
121
|
+
{
|
|
122
|
+
layout: true,
|
|
123
|
+
className: "ui-notice",
|
|
124
|
+
variants,
|
|
125
|
+
initial: "initial",
|
|
126
|
+
animate: "animate",
|
|
127
|
+
exit: "exit",
|
|
128
|
+
onHoverStart: onMouseEnter,
|
|
129
|
+
onHoverEnd: onMouseLeave,
|
|
130
|
+
custom: { placement },
|
|
131
|
+
style: {
|
|
132
|
+
display: "flex",
|
|
133
|
+
justifyContent: placement.includes("left") ? "flex-start" : placement.includes("right") ? "flex-end" : "center"
|
|
134
|
+
},
|
|
135
|
+
children: /* @__PURE__ */ jsx(ui.div, { className: "ui-notice-container", __css: css, children: runIfFunc(message, { onClose }) })
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
NoticeComponent.displayName = "NoticeComponent";
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
NoticeProvider
|
|
144
|
+
};
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var src_exports = {};
|
|
23
23
|
__export(src_exports, {
|
|
24
|
+
NoticeProvider: () => NoticeProvider,
|
|
24
25
|
noticeStore: () => noticeStore,
|
|
25
26
|
useNotice: () => useNotice
|
|
26
27
|
});
|
|
@@ -256,8 +257,141 @@ var Notice = ({
|
|
|
256
257
|
}
|
|
257
258
|
);
|
|
258
259
|
};
|
|
260
|
+
|
|
261
|
+
// src/notice-provider.tsx
|
|
262
|
+
var import_core2 = require("@yamada-ui/core");
|
|
263
|
+
var import_motion = require("@yamada-ui/motion");
|
|
264
|
+
var import_portal = require("@yamada-ui/portal");
|
|
265
|
+
var import_use_timeout = require("@yamada-ui/use-timeout");
|
|
266
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
267
|
+
var import_react2 = require("react");
|
|
268
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
269
|
+
var NoticeProvider = ({
|
|
270
|
+
variants,
|
|
271
|
+
gap = "md",
|
|
272
|
+
appendToParentPortal,
|
|
273
|
+
containerRef
|
|
274
|
+
}) => {
|
|
275
|
+
const state = (0, import_react2.useSyncExternalStore)(
|
|
276
|
+
noticeStore.subscribe,
|
|
277
|
+
noticeStore.getSnapshot,
|
|
278
|
+
noticeStore.getSnapshot
|
|
279
|
+
);
|
|
280
|
+
const components = Object.entries(state).map(([placement, notices]) => {
|
|
281
|
+
const top = placement.includes("top") ? "env(safe-area-inset-top, 0px)" : void 0;
|
|
282
|
+
const bottom = placement.includes("bottom") ? "env(safe-area-inset-bottom, 0px)" : void 0;
|
|
283
|
+
const right = !placement.includes("left") ? "env(safe-area-inset-right, 0px)" : void 0;
|
|
284
|
+
const left = !placement.includes("right") ? "env(safe-area-inset-left, 0px)" : void 0;
|
|
285
|
+
const css = {
|
|
286
|
+
position: "fixed",
|
|
287
|
+
zIndex: "zarbon",
|
|
288
|
+
pointerEvents: "none",
|
|
289
|
+
display: "flex",
|
|
290
|
+
flexDirection: "column",
|
|
291
|
+
margin: gap,
|
|
292
|
+
gap,
|
|
293
|
+
top,
|
|
294
|
+
bottom,
|
|
295
|
+
right,
|
|
296
|
+
left
|
|
297
|
+
};
|
|
298
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.ul, { className: "ui-notice-list", __css: css, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_motion.AnimatePresence, { initial: false, children: notices.map((notice) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NoticeComponent, { variants, ...notice }, notice.id)) }) }, placement);
|
|
299
|
+
});
|
|
300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
301
|
+
import_portal.Portal,
|
|
302
|
+
{
|
|
303
|
+
appendToParentPortal,
|
|
304
|
+
containerRef,
|
|
305
|
+
children: components
|
|
306
|
+
}
|
|
307
|
+
);
|
|
308
|
+
};
|
|
309
|
+
var defaultVariants = {
|
|
310
|
+
initial: ({ placement }) => ({
|
|
311
|
+
opacity: 0,
|
|
312
|
+
[["top", "bottom"].includes(placement) ? "y" : "x"]: (placement === "bottom" ? 1 : placement.includes("right") ? 1 : -1) * 24
|
|
313
|
+
}),
|
|
314
|
+
animate: {
|
|
315
|
+
opacity: 1,
|
|
316
|
+
y: 0,
|
|
317
|
+
x: 0,
|
|
318
|
+
scale: 1,
|
|
319
|
+
transition: {
|
|
320
|
+
duration: 0.4,
|
|
321
|
+
ease: [0.4, 0, 0.2, 1]
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
exit: {
|
|
325
|
+
opacity: 0,
|
|
326
|
+
scale: 0.95,
|
|
327
|
+
transition: {
|
|
328
|
+
duration: 0.2,
|
|
329
|
+
ease: [0.4, 0, 1, 1]
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
var NoticeComponent = (0, import_react2.memo)(
|
|
334
|
+
({
|
|
335
|
+
variants = defaultVariants,
|
|
336
|
+
placement,
|
|
337
|
+
duration = 5e3,
|
|
338
|
+
message,
|
|
339
|
+
onCloseComplete,
|
|
340
|
+
isDelete = false,
|
|
341
|
+
onDelete,
|
|
342
|
+
style
|
|
343
|
+
}) => {
|
|
344
|
+
const [delay, setDelay] = (0, import_react2.useState)(duration);
|
|
345
|
+
const isPresent = (0, import_motion.useIsPresent)();
|
|
346
|
+
(0, import_utils2.useUpdateEffect)(() => {
|
|
347
|
+
if (!isPresent)
|
|
348
|
+
onCloseComplete == null ? void 0 : onCloseComplete();
|
|
349
|
+
}, [isPresent]);
|
|
350
|
+
(0, import_utils2.useUpdateEffect)(() => {
|
|
351
|
+
setDelay(duration);
|
|
352
|
+
}, [duration]);
|
|
353
|
+
const onMouseEnter = () => setDelay(null);
|
|
354
|
+
const onMouseLeave = () => setDelay(duration);
|
|
355
|
+
const onClose = () => {
|
|
356
|
+
if (isPresent)
|
|
357
|
+
onDelete();
|
|
358
|
+
};
|
|
359
|
+
(0, import_react2.useEffect)(() => {
|
|
360
|
+
if (isPresent && isDelete)
|
|
361
|
+
onDelete();
|
|
362
|
+
}, [isPresent, isDelete, onDelete]);
|
|
363
|
+
(0, import_use_timeout.useTimeout)(onClose, delay);
|
|
364
|
+
const css = {
|
|
365
|
+
pointerEvents: "auto",
|
|
366
|
+
maxW: "2xl",
|
|
367
|
+
minW: "sm",
|
|
368
|
+
...style
|
|
369
|
+
};
|
|
370
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
371
|
+
import_motion.motion.li,
|
|
372
|
+
{
|
|
373
|
+
layout: true,
|
|
374
|
+
className: "ui-notice",
|
|
375
|
+
variants,
|
|
376
|
+
initial: "initial",
|
|
377
|
+
animate: "animate",
|
|
378
|
+
exit: "exit",
|
|
379
|
+
onHoverStart: onMouseEnter,
|
|
380
|
+
onHoverEnd: onMouseLeave,
|
|
381
|
+
custom: { placement },
|
|
382
|
+
style: {
|
|
383
|
+
display: "flex",
|
|
384
|
+
justifyContent: placement.includes("left") ? "flex-start" : placement.includes("right") ? "flex-end" : "center"
|
|
385
|
+
},
|
|
386
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.div, { className: "ui-notice-container", __css: css, children: (0, import_utils2.runIfFunc)(message, { onClose }) })
|
|
387
|
+
}
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
NoticeComponent.displayName = "NoticeComponent";
|
|
259
392
|
// Annotate the CommonJS export names for ESM import in node:
|
|
260
393
|
0 && (module.exports = {
|
|
394
|
+
NoticeProvider,
|
|
261
395
|
noticeStore,
|
|
262
396
|
useNotice
|
|
263
397
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/notice-provider.tsx
|
|
22
|
+
var notice_provider_exports = {};
|
|
23
|
+
__export(notice_provider_exports, {
|
|
24
|
+
NoticeProvider: () => NoticeProvider
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(notice_provider_exports);
|
|
27
|
+
var import_core2 = require("@yamada-ui/core");
|
|
28
|
+
var import_motion = require("@yamada-ui/motion");
|
|
29
|
+
var import_portal = require("@yamada-ui/portal");
|
|
30
|
+
var import_use_timeout = require("@yamada-ui/use-timeout");
|
|
31
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
32
|
+
var import_react2 = require("react");
|
|
33
|
+
|
|
34
|
+
// src/notice.tsx
|
|
35
|
+
var import_alert = require("@yamada-ui/alert");
|
|
36
|
+
var import_close_button = require("@yamada-ui/close-button");
|
|
37
|
+
var import_core = require("@yamada-ui/core");
|
|
38
|
+
var import_utils = require("@yamada-ui/utils");
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
var findId = (options, id) => options.find((notice) => notice.id === id);
|
|
42
|
+
var findNotice = (state, id) => {
|
|
43
|
+
const placement = getNoticePlacement(state, id);
|
|
44
|
+
const index = placement ? state[placement].findIndex((notice) => notice.id === id) : -1;
|
|
45
|
+
return { placement, index };
|
|
46
|
+
};
|
|
47
|
+
var getNoticePlacement = (state, id) => {
|
|
48
|
+
for (const [placement, values] of Object.entries(state)) {
|
|
49
|
+
if (findId(values, id))
|
|
50
|
+
return placement;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var counter = 0;
|
|
54
|
+
var createNotice = (message, {
|
|
55
|
+
id,
|
|
56
|
+
placement = "top",
|
|
57
|
+
duration,
|
|
58
|
+
onCloseComplete,
|
|
59
|
+
status,
|
|
60
|
+
style
|
|
61
|
+
}) => {
|
|
62
|
+
counter += 1;
|
|
63
|
+
id = id != null ? id : counter;
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
placement,
|
|
67
|
+
status,
|
|
68
|
+
duration,
|
|
69
|
+
message,
|
|
70
|
+
onDelete: () => noticeStore.remove(String(id), placement),
|
|
71
|
+
isDelete: false,
|
|
72
|
+
onCloseComplete,
|
|
73
|
+
style
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var createRender = (options) => {
|
|
77
|
+
const { component } = options;
|
|
78
|
+
const Render = (props) => {
|
|
79
|
+
if (typeof component === "function") {
|
|
80
|
+
return component({ ...props, ...options });
|
|
81
|
+
} else {
|
|
82
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Notice, { ...props, ...options });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return Render;
|
|
86
|
+
};
|
|
87
|
+
var initialState = {
|
|
88
|
+
top: [],
|
|
89
|
+
"top-left": [],
|
|
90
|
+
"top-right": [],
|
|
91
|
+
bottom: [],
|
|
92
|
+
"bottom-left": [],
|
|
93
|
+
"bottom-right": []
|
|
94
|
+
};
|
|
95
|
+
var createNoticeStore = (initialState2) => {
|
|
96
|
+
let state = initialState2;
|
|
97
|
+
const storeChangeCache = /* @__PURE__ */ new Set();
|
|
98
|
+
const setState = (setStateFunc) => {
|
|
99
|
+
state = setStateFunc(state);
|
|
100
|
+
storeChangeCache.forEach((onStoreChange) => onStoreChange());
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
getSnapshot: () => state,
|
|
104
|
+
subscribe: (onStoreChange) => {
|
|
105
|
+
storeChangeCache.add(onStoreChange);
|
|
106
|
+
return () => {
|
|
107
|
+
setState(() => initialState2);
|
|
108
|
+
storeChangeCache.delete(onStoreChange);
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
remove: (id, placement) => {
|
|
112
|
+
setState((prevState) => ({
|
|
113
|
+
...prevState,
|
|
114
|
+
[placement]: prevState[placement].filter((notice) => notice.id != id)
|
|
115
|
+
}));
|
|
116
|
+
},
|
|
117
|
+
create: (message, options) => {
|
|
118
|
+
var _a;
|
|
119
|
+
const limit = ((_a = options.limit) != null ? _a : 0) - 1;
|
|
120
|
+
const notice = createNotice(message, options);
|
|
121
|
+
const { placement, id } = notice;
|
|
122
|
+
setState((prev) => {
|
|
123
|
+
var _a2;
|
|
124
|
+
let prevNotices = (_a2 = prev[placement]) != null ? _a2 : [];
|
|
125
|
+
if (limit > 0 && prevNotices.length > limit) {
|
|
126
|
+
const n = prevNotices.length - limit;
|
|
127
|
+
const notices2 = placement.includes("top") ? prevNotices.slice(n * -1) : prevNotices.slice(0, n);
|
|
128
|
+
const ids = notices2.map(({ id: id2 }) => id2);
|
|
129
|
+
prevNotices = prevNotices.map(
|
|
130
|
+
(notice2) => ids.includes(notice2.id) ? { ...notice2, isDelete: true } : notice2
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
const notices = placement.includes("top") ? [notice, ...prevNotices] : [...prevNotices, notice];
|
|
134
|
+
return { ...prev, [placement]: notices };
|
|
135
|
+
});
|
|
136
|
+
return id;
|
|
137
|
+
},
|
|
138
|
+
update: (id, options) => {
|
|
139
|
+
setState((prev) => {
|
|
140
|
+
const next = { ...prev };
|
|
141
|
+
const { placement, index } = findNotice(next, id);
|
|
142
|
+
if (placement && index !== -1) {
|
|
143
|
+
next[placement][index] = {
|
|
144
|
+
...next[placement][index],
|
|
145
|
+
...options,
|
|
146
|
+
message: createRender(options)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return next;
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
closeAll: ({ placement } = {}) => {
|
|
153
|
+
setState((prev) => {
|
|
154
|
+
let placements = [
|
|
155
|
+
"bottom",
|
|
156
|
+
"bottom-right",
|
|
157
|
+
"bottom-left",
|
|
158
|
+
"top",
|
|
159
|
+
"top-left",
|
|
160
|
+
"top-right"
|
|
161
|
+
];
|
|
162
|
+
if (placement)
|
|
163
|
+
placements = placement;
|
|
164
|
+
return placements.reduce(
|
|
165
|
+
(acc, placement2) => {
|
|
166
|
+
acc[placement2] = prev[placement2].map((notice) => ({
|
|
167
|
+
...notice,
|
|
168
|
+
isDelete: true
|
|
169
|
+
}));
|
|
170
|
+
return acc;
|
|
171
|
+
},
|
|
172
|
+
{ ...prev }
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
close: (id) => {
|
|
177
|
+
setState((prev) => {
|
|
178
|
+
const placement = getNoticePlacement(prev, id);
|
|
179
|
+
if (!placement)
|
|
180
|
+
return prev;
|
|
181
|
+
return {
|
|
182
|
+
...prev,
|
|
183
|
+
[placement]: prev[placement].map(
|
|
184
|
+
(notice) => notice.id == id ? { ...notice, isDelete: true } : notice
|
|
185
|
+
)
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
isActive: (id) => Boolean(findNotice(noticeStore.getSnapshot(), id).placement)
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
var noticeStore = createNoticeStore(initialState);
|
|
193
|
+
var Notice = ({
|
|
194
|
+
variant = "basic",
|
|
195
|
+
colorScheme,
|
|
196
|
+
status,
|
|
197
|
+
icon,
|
|
198
|
+
title,
|
|
199
|
+
description,
|
|
200
|
+
isClosable,
|
|
201
|
+
onClose
|
|
202
|
+
}) => {
|
|
203
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
204
|
+
import_alert.Alert,
|
|
205
|
+
{
|
|
206
|
+
status,
|
|
207
|
+
variant,
|
|
208
|
+
colorScheme,
|
|
209
|
+
alignItems: "start",
|
|
210
|
+
boxShadow: "lg",
|
|
211
|
+
pe: isClosable ? 8 : void 0,
|
|
212
|
+
children: [
|
|
213
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
214
|
+
import_alert.AlertIcon,
|
|
215
|
+
{
|
|
216
|
+
variant: icon == null ? void 0 : icon.variant,
|
|
217
|
+
...(icon == null ? void 0 : icon.color) ? { color: icon.color } : {},
|
|
218
|
+
children: icon == null ? void 0 : icon.children
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.ui.div, { flex: "1", children: [
|
|
222
|
+
title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertTitle, { noOfLines: 1, children: title }) : null,
|
|
223
|
+
description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { noOfLines: 3, children: description }) : null
|
|
224
|
+
] }),
|
|
225
|
+
isClosable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
226
|
+
import_close_button.CloseButton,
|
|
227
|
+
{
|
|
228
|
+
size: "sm",
|
|
229
|
+
onClick: onClose,
|
|
230
|
+
position: "absolute",
|
|
231
|
+
top: 2,
|
|
232
|
+
right: 2
|
|
233
|
+
}
|
|
234
|
+
) : null
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// src/notice-provider.tsx
|
|
241
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
242
|
+
var NoticeProvider = ({
|
|
243
|
+
variants,
|
|
244
|
+
gap = "md",
|
|
245
|
+
appendToParentPortal,
|
|
246
|
+
containerRef
|
|
247
|
+
}) => {
|
|
248
|
+
const state = (0, import_react2.useSyncExternalStore)(
|
|
249
|
+
noticeStore.subscribe,
|
|
250
|
+
noticeStore.getSnapshot,
|
|
251
|
+
noticeStore.getSnapshot
|
|
252
|
+
);
|
|
253
|
+
const components = Object.entries(state).map(([placement, notices]) => {
|
|
254
|
+
const top = placement.includes("top") ? "env(safe-area-inset-top, 0px)" : void 0;
|
|
255
|
+
const bottom = placement.includes("bottom") ? "env(safe-area-inset-bottom, 0px)" : void 0;
|
|
256
|
+
const right = !placement.includes("left") ? "env(safe-area-inset-right, 0px)" : void 0;
|
|
257
|
+
const left = !placement.includes("right") ? "env(safe-area-inset-left, 0px)" : void 0;
|
|
258
|
+
const css = {
|
|
259
|
+
position: "fixed",
|
|
260
|
+
zIndex: "zarbon",
|
|
261
|
+
pointerEvents: "none",
|
|
262
|
+
display: "flex",
|
|
263
|
+
flexDirection: "column",
|
|
264
|
+
margin: gap,
|
|
265
|
+
gap,
|
|
266
|
+
top,
|
|
267
|
+
bottom,
|
|
268
|
+
right,
|
|
269
|
+
left
|
|
270
|
+
};
|
|
271
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.ul, { className: "ui-notice-list", __css: css, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_motion.AnimatePresence, { initial: false, children: notices.map((notice) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NoticeComponent, { variants, ...notice }, notice.id)) }) }, placement);
|
|
272
|
+
});
|
|
273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
274
|
+
import_portal.Portal,
|
|
275
|
+
{
|
|
276
|
+
appendToParentPortal,
|
|
277
|
+
containerRef,
|
|
278
|
+
children: components
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
var defaultVariants = {
|
|
283
|
+
initial: ({ placement }) => ({
|
|
284
|
+
opacity: 0,
|
|
285
|
+
[["top", "bottom"].includes(placement) ? "y" : "x"]: (placement === "bottom" ? 1 : placement.includes("right") ? 1 : -1) * 24
|
|
286
|
+
}),
|
|
287
|
+
animate: {
|
|
288
|
+
opacity: 1,
|
|
289
|
+
y: 0,
|
|
290
|
+
x: 0,
|
|
291
|
+
scale: 1,
|
|
292
|
+
transition: {
|
|
293
|
+
duration: 0.4,
|
|
294
|
+
ease: [0.4, 0, 0.2, 1]
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
exit: {
|
|
298
|
+
opacity: 0,
|
|
299
|
+
scale: 0.95,
|
|
300
|
+
transition: {
|
|
301
|
+
duration: 0.2,
|
|
302
|
+
ease: [0.4, 0, 1, 1]
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
var NoticeComponent = (0, import_react2.memo)(
|
|
307
|
+
({
|
|
308
|
+
variants = defaultVariants,
|
|
309
|
+
placement,
|
|
310
|
+
duration = 5e3,
|
|
311
|
+
message,
|
|
312
|
+
onCloseComplete,
|
|
313
|
+
isDelete = false,
|
|
314
|
+
onDelete,
|
|
315
|
+
style
|
|
316
|
+
}) => {
|
|
317
|
+
const [delay, setDelay] = (0, import_react2.useState)(duration);
|
|
318
|
+
const isPresent = (0, import_motion.useIsPresent)();
|
|
319
|
+
(0, import_utils2.useUpdateEffect)(() => {
|
|
320
|
+
if (!isPresent)
|
|
321
|
+
onCloseComplete == null ? void 0 : onCloseComplete();
|
|
322
|
+
}, [isPresent]);
|
|
323
|
+
(0, import_utils2.useUpdateEffect)(() => {
|
|
324
|
+
setDelay(duration);
|
|
325
|
+
}, [duration]);
|
|
326
|
+
const onMouseEnter = () => setDelay(null);
|
|
327
|
+
const onMouseLeave = () => setDelay(duration);
|
|
328
|
+
const onClose = () => {
|
|
329
|
+
if (isPresent)
|
|
330
|
+
onDelete();
|
|
331
|
+
};
|
|
332
|
+
(0, import_react2.useEffect)(() => {
|
|
333
|
+
if (isPresent && isDelete)
|
|
334
|
+
onDelete();
|
|
335
|
+
}, [isPresent, isDelete, onDelete]);
|
|
336
|
+
(0, import_use_timeout.useTimeout)(onClose, delay);
|
|
337
|
+
const css = {
|
|
338
|
+
pointerEvents: "auto",
|
|
339
|
+
maxW: "2xl",
|
|
340
|
+
minW: "sm",
|
|
341
|
+
...style
|
|
342
|
+
};
|
|
343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
344
|
+
import_motion.motion.li,
|
|
345
|
+
{
|
|
346
|
+
layout: true,
|
|
347
|
+
className: "ui-notice",
|
|
348
|
+
variants,
|
|
349
|
+
initial: "initial",
|
|
350
|
+
animate: "animate",
|
|
351
|
+
exit: "exit",
|
|
352
|
+
onHoverStart: onMouseEnter,
|
|
353
|
+
onHoverEnd: onMouseLeave,
|
|
354
|
+
custom: { placement },
|
|
355
|
+
style: {
|
|
356
|
+
display: "flex",
|
|
357
|
+
justifyContent: placement.includes("left") ? "flex-start" : placement.includes("right") ? "flex-end" : "center"
|
|
358
|
+
},
|
|
359
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.div, { className: "ui-notice-container", __css: css, children: (0, import_utils2.runIfFunc)(message, { onClose }) })
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
NoticeComponent.displayName = "NoticeComponent";
|
|
365
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
366
|
+
0 && (module.exports = {
|
|
367
|
+
NoticeProvider
|
|
368
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamada-ui/notice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Yamada UI notice component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yamada",
|
|
@@ -35,9 +35,12 @@
|
|
|
35
35
|
"url": "https://github.com/hirotomoyamada/yamada-ui/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@yamada-ui/core": "0.12.
|
|
39
|
-
"@yamada-ui/close-button": "0.3.
|
|
40
|
-
"@yamada-ui/alert": "0.5.
|
|
38
|
+
"@yamada-ui/core": "0.12.3",
|
|
39
|
+
"@yamada-ui/close-button": "0.3.13",
|
|
40
|
+
"@yamada-ui/alert": "0.5.7",
|
|
41
|
+
"@yamada-ui/portal": "0.3.4",
|
|
42
|
+
"@yamada-ui/motion": "0.4.13",
|
|
43
|
+
"@yamada-ui/use-timeout": "0.2.3",
|
|
41
44
|
"@yamada-ui/utils": "0.3.1"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|