@ttoss/components 2.2.18 → 2.2.20

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.
@@ -11,6 +11,8 @@ type Notification = {
11
11
  label?: string;
12
12
  }[];
13
13
  createdAt: string;
14
+ readAt?: string | null;
15
+ onClose?: () => void;
14
16
  };
15
17
  type Props = {
16
18
  notifications: Notification[];
@@ -1,3 +1,3 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { NotificationCard } from "../chunk-ERHWYNDS.js";
2
+ import { NotificationCard } from "../chunk-5OYT3X4J.js";
3
3
  export { NotificationCard };
@@ -1,5 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Icon, NotificationCard } from "../chunk-ERHWYNDS.js";
2
+ import { Icon, NotificationCard } from "../chunk-5OYT3X4J.js";
3
3
 
4
4
  // src/components/NotificationsMenu/NotificationsMenu.tsx
5
5
  import { Box, Card, Flex, IconButton, Link, Text } from "@ttoss/ui";
@@ -45,7 +45,6 @@ var NotificationsMenu = ({
45
45
  const buttonRef = React.useRef(null);
46
46
  const containerRef = React.useRef(null);
47
47
  const loadMoreRef = React.useRef(null);
48
- const unread = unreadCount ?? notifications.length;
49
48
  const togglePanel = () => {
50
49
  setIsOpen(prev => {
51
50
  const next = !prev;
@@ -53,6 +52,12 @@ var NotificationsMenu = ({
53
52
  return next;
54
53
  });
55
54
  };
55
+ const unread = unreadCount ?? notifications.filter(n => {
56
+ if (defaultOpen) {
57
+ return 0;
58
+ }
59
+ return n.readAt === null;
60
+ }).length;
56
61
  React.useEffect(() => {
57
62
  if (!isOpen || !buttonRef.current) return;
58
63
  const rect = buttonRef.current.getBoundingClientRect();
@@ -78,6 +83,20 @@ var NotificationsMenu = ({
78
83
  }
79
84
  };
80
85
  }, [hasMore, onLoadMore, notifications.length]);
86
+ React.useEffect(() => {
87
+ if (!isOpen) return;
88
+ const handleClickOutside = event => {
89
+ if (containerRef.current && !containerRef.current.contains(event.target) && buttonRef.current && !buttonRef.current.contains(event.target)) {
90
+ setIsOpen(false);
91
+ onOpenChange?.(false);
92
+ onClose?.();
93
+ }
94
+ };
95
+ document.addEventListener("mousedown", handleClickOutside);
96
+ return () => {
97
+ document.removeEventListener("mousedown", handleClickOutside);
98
+ };
99
+ }, [isOpen, onOpenChange, onClose]);
81
100
  return /* @__PURE__ */jsx(Flex, {
82
101
  sx: {
83
102
  position: "relative",
@@ -93,29 +112,34 @@ var NotificationsMenu = ({
93
112
  sx: {
94
113
  position: "relative",
95
114
  borderRadius: "full",
96
- padding: 2,
115
+ padding: 1,
97
116
  transition: "background-color 0.3s ease",
98
117
  "&:hover": {
99
118
  backgroundColor: "action.background.muted.default"
100
119
  }
101
120
  },
102
121
  onClick: togglePanel,
103
- children: [/* @__PURE__ */jsx(Icon, {
104
- icon: "mdi:bell-outline",
105
- width: 25,
106
- height: 25
122
+ children: [/* @__PURE__ */jsx(Box, {
123
+ sx: {
124
+ color: "display.text.muted.default"
125
+ },
126
+ children: /* @__PURE__ */jsx(Icon, {
127
+ icon: "mdi:bell-outline",
128
+ width: 22,
129
+ height: 22
130
+ })
107
131
  }), unread > 0 && /* @__PURE__ */jsx(Box, {
108
132
  sx: {
109
133
  position: "absolute",
110
- top: "-4px",
111
- right: "-4px",
112
- minWidth: "16px",
113
- height: "16px",
134
+ top: "-2px",
135
+ right: "-2px",
136
+ minWidth: "14px",
137
+ height: "14px",
114
138
  paddingX: 1,
115
139
  borderRadius: "full",
116
140
  backgroundColor: "action.background.negative.default",
117
141
  color: "feedback.text.primary.default",
118
- fontSize: "xs",
142
+ fontSize: "10px",
119
143
  fontWeight: "bold",
120
144
  display: "flex",
121
145
  alignItems: "center",
@@ -143,7 +167,8 @@ var NotificationsMenu = ({
143
167
  ref: containerRef,
144
168
  children: /* @__PURE__ */jsxs(Flex, {
145
169
  sx: {
146
- flexDirection: "column"
170
+ flexDirection: "column",
171
+ gap: 2
147
172
  },
148
173
  children: [notifications.length === 0 && /* @__PURE__ */jsx(Text, {
149
174
  sx: {
@@ -157,7 +182,7 @@ var NotificationsMenu = ({
157
182
  type: notification.type,
158
183
  title: notification.title,
159
184
  message: renderMessage(notification.message, notification.actions),
160
- onClose,
185
+ onClose: notification.onClose || onClose,
161
186
  metaInfo: notification.createdAt
162
187
  }, notification.id);
163
188
  }), hasMore && /* @__PURE__ */jsx("div", {
@@ -2313,8 +2313,13 @@ var NotificationCard = props => {
2313
2313
  children: [/* @__PURE__ */jsx2(Icon2, {
2314
2314
  icon: icon[props.type]
2315
2315
  }), props.title]
2316
- }), props.onClose && /* @__PURE__ */jsx2(CloseButton, {
2317
- onClick: props.onClose
2316
+ }), props.onClose && /* @__PURE__ */jsx2(Box, {
2317
+ sx: {
2318
+ marginLeft: "auto"
2319
+ },
2320
+ children: /* @__PURE__ */jsx2(CloseButton, {
2321
+ onClick: props.onClose
2322
+ })
2318
2323
  })]
2319
2324
  }), /* @__PURE__ */jsxs(Card.Body, {
2320
2325
  sx: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/components",
3
- "version": "2.2.18",
3
+ "version": "2.2.20",
4
4
  "description": "React components for ttoss ecosystem.",
5
5
  "license": "MIT",
6
6
  "author": "ttoss",
@@ -98,7 +98,7 @@
98
98
  "peerDependencies": {
99
99
  "react": ">=16.8.0",
100
100
  "@ttoss/react-hooks": "^2.0.11",
101
- "@ttoss/ui": "^5.7.0"
101
+ "@ttoss/ui": "^5.8.0"
102
102
  },
103
103
  "devDependencies": {
104
104
  "@types/jest": "^29.5.14",
@@ -107,11 +107,11 @@
107
107
  "react": "^19.0.0",
108
108
  "tsup": "^8.3.5",
109
109
  "tsx": "^4.19.2",
110
+ "@ttoss/react-icons": "^0.4.11",
110
111
  "@ttoss/config": "^1.35.3",
111
- "@ttoss/react-hooks": "^2.0.11",
112
112
  "@ttoss/test-utils": "^2.1.23",
113
- "@ttoss/ui": "^5.7.0",
114
- "@ttoss/react-icons": "^0.4.11"
113
+ "@ttoss/ui": "^5.8.0",
114
+ "@ttoss/react-hooks": "^2.0.11"
115
115
  },
116
116
  "keywords": [
117
117
  "React",