@yamada-ui/notice 0.3.6 → 0.3.8

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.
@@ -1,5 +1,10 @@
1
1
  // src/notice.tsx
2
- import { Alert, AlertDescription, AlertIcon, AlertTitle } from "@yamada-ui/alert";
2
+ import {
3
+ Alert,
4
+ AlertDescription,
5
+ AlertIcon,
6
+ AlertTitle
7
+ } from "@yamada-ui/alert";
3
8
  import { CloseButton } from "@yamada-ui/close-button";
4
9
  import {
5
10
  ui,
@@ -21,7 +26,14 @@ var getNoticePlacement = (state, id) => {
21
26
  }
22
27
  };
23
28
  var counter = 0;
24
- var createNotice = (message, { id, placement = "top", duration, onCloseComplete, status, style }) => {
29
+ var createNotice = (message, {
30
+ id,
31
+ placement = "top",
32
+ duration,
33
+ onCloseComplete,
34
+ status,
35
+ style
36
+ }) => {
25
37
  counter += 1;
26
38
  id = id != null ? id : counter;
27
39
  return {
@@ -67,7 +79,10 @@ var createNoticeFunc = (defaultOptions, theme) => {
67
79
  };
68
80
  var useNotice = (defaultOptions) => {
69
81
  const { theme } = useTheme();
70
- return useMemo(() => createNoticeFunc(defaultOptions != null ? defaultOptions : {}, theme), [defaultOptions, theme]);
82
+ return useMemo(
83
+ () => createNoticeFunc(defaultOptions != null ? defaultOptions : {}, theme),
84
+ [defaultOptions, theme]
85
+ );
71
86
  };
72
87
  var initialState = {
73
88
  top: [],
@@ -79,18 +94,18 @@ var initialState = {
79
94
  };
80
95
  var createNoticeStore = (initialState2) => {
81
96
  let state = initialState2;
82
- const listeners = /* @__PURE__ */ new Set();
83
- const setState = (setStateFn) => {
84
- state = setStateFn(state);
85
- listeners.forEach((l) => l());
97
+ const storeChangeCache = /* @__PURE__ */ new Set();
98
+ const setState = (setStateFunc) => {
99
+ state = setStateFunc(state);
100
+ storeChangeCache.forEach((onStoreChange) => onStoreChange());
86
101
  };
87
102
  return {
88
103
  getSnapshot: () => state,
89
- subscribe: (listener) => {
90
- listeners.add(listener);
104
+ subscribe: (onStoreChange) => {
105
+ storeChangeCache.add(onStoreChange);
91
106
  return () => {
92
107
  setState(() => initialState2);
93
- listeners.delete(listener);
108
+ storeChangeCache.delete(onStoreChange);
94
109
  };
95
110
  },
96
111
  remove: (id, placement) => {
@@ -148,7 +163,10 @@ var createNoticeStore = (initialState2) => {
148
163
  placements = placement;
149
164
  return placements.reduce(
150
165
  (acc, placement2) => {
151
- acc[placement2] = prev[placement2].map((notice) => ({ ...notice, isDelete: true }));
166
+ acc[placement2] = prev[placement2].map((notice) => ({
167
+ ...notice,
168
+ isDelete: true
169
+ }));
152
170
  return acc;
153
171
  },
154
172
  { ...prev }
@@ -192,12 +210,28 @@ var Notice = ({
192
210
  boxShadow: "lg",
193
211
  pe: isClosable ? 8 : void 0,
194
212
  children: [
195
- /* @__PURE__ */ jsx(AlertIcon, { variant: icon == null ? void 0 : icon.variant, ...(icon == null ? void 0 : icon.color) ? { color: icon.color } : {}, children: icon == null ? void 0 : icon.children }),
213
+ /* @__PURE__ */ jsx(
214
+ 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
+ ),
196
221
  /* @__PURE__ */ jsxs(ui.div, { flex: "1", children: [
197
222
  title ? /* @__PURE__ */ jsx(AlertTitle, { noOfLines: 1, children: title }) : null,
198
223
  description ? /* @__PURE__ */ jsx(AlertDescription, { noOfLines: 3, children: description }) : null
199
224
  ] }),
200
- isClosable ? /* @__PURE__ */ jsx(CloseButton, { size: "sm", onClick: onClose, position: "absolute", top: 2, right: 2 }) : null
225
+ isClosable ? /* @__PURE__ */ jsx(
226
+ CloseButton,
227
+ {
228
+ size: "sm",
229
+ onClick: onClose,
230
+ position: "absolute",
231
+ top: 2,
232
+ right: 2
233
+ }
234
+ ) : null
201
235
  ]
202
236
  }
203
237
  );
package/dist/index.js CHANGED
@@ -45,7 +45,14 @@ var getNoticePlacement = (state, id) => {
45
45
  }
46
46
  };
47
47
  var counter = 0;
48
- var createNotice = (message, { id, placement = "top", duration, onCloseComplete, status, style }) => {
48
+ var createNotice = (message, {
49
+ id,
50
+ placement = "top",
51
+ duration,
52
+ onCloseComplete,
53
+ status,
54
+ style
55
+ }) => {
49
56
  counter += 1;
50
57
  id = id != null ? id : counter;
51
58
  return {
@@ -91,7 +98,10 @@ var createNoticeFunc = (defaultOptions, theme) => {
91
98
  };
92
99
  var useNotice = (defaultOptions) => {
93
100
  const { theme } = (0, import_core.useTheme)();
94
- return (0, import_react.useMemo)(() => createNoticeFunc(defaultOptions != null ? defaultOptions : {}, theme), [defaultOptions, theme]);
101
+ return (0, import_react.useMemo)(
102
+ () => createNoticeFunc(defaultOptions != null ? defaultOptions : {}, theme),
103
+ [defaultOptions, theme]
104
+ );
95
105
  };
96
106
  var initialState = {
97
107
  top: [],
@@ -103,18 +113,18 @@ var initialState = {
103
113
  };
104
114
  var createNoticeStore = (initialState2) => {
105
115
  let state = initialState2;
106
- const listeners = /* @__PURE__ */ new Set();
107
- const setState = (setStateFn) => {
108
- state = setStateFn(state);
109
- listeners.forEach((l) => l());
116
+ const storeChangeCache = /* @__PURE__ */ new Set();
117
+ const setState = (setStateFunc) => {
118
+ state = setStateFunc(state);
119
+ storeChangeCache.forEach((onStoreChange) => onStoreChange());
110
120
  };
111
121
  return {
112
122
  getSnapshot: () => state,
113
- subscribe: (listener) => {
114
- listeners.add(listener);
123
+ subscribe: (onStoreChange) => {
124
+ storeChangeCache.add(onStoreChange);
115
125
  return () => {
116
126
  setState(() => initialState2);
117
- listeners.delete(listener);
127
+ storeChangeCache.delete(onStoreChange);
118
128
  };
119
129
  },
120
130
  remove: (id, placement) => {
@@ -172,7 +182,10 @@ var createNoticeStore = (initialState2) => {
172
182
  placements = placement;
173
183
  return placements.reduce(
174
184
  (acc, placement2) => {
175
- acc[placement2] = prev[placement2].map((notice) => ({ ...notice, isDelete: true }));
185
+ acc[placement2] = prev[placement2].map((notice) => ({
186
+ ...notice,
187
+ isDelete: true
188
+ }));
176
189
  return acc;
177
190
  },
178
191
  { ...prev }
@@ -216,12 +229,28 @@ var Notice = ({
216
229
  boxShadow: "lg",
217
230
  pe: isClosable ? 8 : void 0,
218
231
  children: [
219
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertIcon, { variant: icon == null ? void 0 : icon.variant, ...(icon == null ? void 0 : icon.color) ? { color: icon.color } : {}, children: icon == null ? void 0 : icon.children }),
232
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
233
+ import_alert.AlertIcon,
234
+ {
235
+ variant: icon == null ? void 0 : icon.variant,
236
+ ...(icon == null ? void 0 : icon.color) ? { color: icon.color } : {},
237
+ children: icon == null ? void 0 : icon.children
238
+ }
239
+ ),
220
240
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.ui.div, { flex: "1", children: [
221
241
  title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertTitle, { noOfLines: 1, children: title }) : null,
222
242
  description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { noOfLines: 3, children: description }) : null
223
243
  ] }),
224
- isClosable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_close_button.CloseButton, { size: "sm", onClick: onClose, position: "absolute", top: 2, right: 2 }) : null
244
+ isClosable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
245
+ import_close_button.CloseButton,
246
+ {
247
+ size: "sm",
248
+ onClick: onClose,
249
+ position: "absolute",
250
+ top: 2,
251
+ right: 2
252
+ }
253
+ ) : null
225
254
  ]
226
255
  }
227
256
  );
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  noticeStore,
3
3
  useNotice
4
- } from "./chunk-BILB5EAU.mjs";
4
+ } from "./chunk-DZK7YYV2.mjs";
5
5
  export {
6
6
  noticeStore,
7
7
  useNotice
package/dist/notice.js CHANGED
@@ -43,7 +43,14 @@ var getNoticePlacement = (state, id) => {
43
43
  }
44
44
  };
45
45
  var counter = 0;
46
- var createNotice = (message, { id, placement = "top", duration, onCloseComplete, status, style }) => {
46
+ var createNotice = (message, {
47
+ id,
48
+ placement = "top",
49
+ duration,
50
+ onCloseComplete,
51
+ status,
52
+ style
53
+ }) => {
47
54
  counter += 1;
48
55
  id = id != null ? id : counter;
49
56
  return {
@@ -89,7 +96,10 @@ var createNoticeFunc = (defaultOptions, theme) => {
89
96
  };
90
97
  var useNotice = (defaultOptions) => {
91
98
  const { theme } = (0, import_core.useTheme)();
92
- return (0, import_react.useMemo)(() => createNoticeFunc(defaultOptions != null ? defaultOptions : {}, theme), [defaultOptions, theme]);
99
+ return (0, import_react.useMemo)(
100
+ () => createNoticeFunc(defaultOptions != null ? defaultOptions : {}, theme),
101
+ [defaultOptions, theme]
102
+ );
93
103
  };
94
104
  var initialState = {
95
105
  top: [],
@@ -101,18 +111,18 @@ var initialState = {
101
111
  };
102
112
  var createNoticeStore = (initialState2) => {
103
113
  let state = initialState2;
104
- const listeners = /* @__PURE__ */ new Set();
105
- const setState = (setStateFn) => {
106
- state = setStateFn(state);
107
- listeners.forEach((l) => l());
114
+ const storeChangeCache = /* @__PURE__ */ new Set();
115
+ const setState = (setStateFunc) => {
116
+ state = setStateFunc(state);
117
+ storeChangeCache.forEach((onStoreChange) => onStoreChange());
108
118
  };
109
119
  return {
110
120
  getSnapshot: () => state,
111
- subscribe: (listener) => {
112
- listeners.add(listener);
121
+ subscribe: (onStoreChange) => {
122
+ storeChangeCache.add(onStoreChange);
113
123
  return () => {
114
124
  setState(() => initialState2);
115
- listeners.delete(listener);
125
+ storeChangeCache.delete(onStoreChange);
116
126
  };
117
127
  },
118
128
  remove: (id, placement) => {
@@ -170,7 +180,10 @@ var createNoticeStore = (initialState2) => {
170
180
  placements = placement;
171
181
  return placements.reduce(
172
182
  (acc, placement2) => {
173
- acc[placement2] = prev[placement2].map((notice) => ({ ...notice, isDelete: true }));
183
+ acc[placement2] = prev[placement2].map((notice) => ({
184
+ ...notice,
185
+ isDelete: true
186
+ }));
174
187
  return acc;
175
188
  },
176
189
  { ...prev }
@@ -214,12 +227,28 @@ var Notice = ({
214
227
  boxShadow: "lg",
215
228
  pe: isClosable ? 8 : void 0,
216
229
  children: [
217
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertIcon, { variant: icon == null ? void 0 : icon.variant, ...(icon == null ? void 0 : icon.color) ? { color: icon.color } : {}, children: icon == null ? void 0 : icon.children }),
230
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
231
+ import_alert.AlertIcon,
232
+ {
233
+ variant: icon == null ? void 0 : icon.variant,
234
+ ...(icon == null ? void 0 : icon.color) ? { color: icon.color } : {},
235
+ children: icon == null ? void 0 : icon.children
236
+ }
237
+ ),
218
238
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.ui.div, { flex: "1", children: [
219
239
  title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertTitle, { noOfLines: 1, children: title }) : null,
220
240
  description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { noOfLines: 3, children: description }) : null
221
241
  ] }),
222
- isClosable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_close_button.CloseButton, { size: "sm", onClick: onClose, position: "absolute", top: 2, right: 2 }) : null
242
+ isClosable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
243
+ import_close_button.CloseButton,
244
+ {
245
+ size: "sm",
246
+ onClick: onClose,
247
+ position: "absolute",
248
+ top: 2,
249
+ right: 2
250
+ }
251
+ ) : null
223
252
  ]
224
253
  }
225
254
  );
package/dist/notice.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  noticeStore,
3
3
  useNotice
4
- } from "./chunk-BILB5EAU.mjs";
4
+ } from "./chunk-DZK7YYV2.mjs";
5
5
  export {
6
6
  noticeStore,
7
7
  useNotice
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/notice",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "Yamada UI notice component",
5
5
  "keywords": [
6
6
  "yamada",
@@ -35,10 +35,10 @@
35
35
  "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
36
36
  },
37
37
  "dependencies": {
38
- "@yamada-ui/core": "0.5.1",
39
- "@yamada-ui/close-button": "0.2.6",
40
- "@yamada-ui/alert": "0.3.6",
41
- "@yamada-ui/utils": "0.1.3"
38
+ "@yamada-ui/core": "0.5.3",
39
+ "@yamada-ui/close-button": "0.2.8",
40
+ "@yamada-ui/alert": "0.3.8",
41
+ "@yamada-ui/utils": "0.1.4"
42
42
  },
43
43
  "devDependencies": {
44
44
  "react": "^18.0.0",