@mantine/notifications 9.5.2 → 9.6.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.
@@ -11,6 +11,10 @@ import { Box, OptionalPortal, RemoveScroll, createVarsResolver, factory, getDefa
11
11
  import { jsx, jsxs } from "react/jsx-runtime";
12
12
  //#region packages/@mantine/notifications/src/Notifications.tsx
13
13
  const Transition$1 = Transition;
14
+ /** Vertical gap between notifications of an expanded stack, in px */
15
+ const STACK_EXPANDED_GAP = 16;
16
+ /** Offset step used for a notification that has not been measured yet, in px */
17
+ const FALLBACK_NOTIFICATION_HEIGHT = 80;
14
18
  const defaultProps = {
15
19
  position: "bottom-right",
16
20
  autoClose: 4e3,
@@ -23,7 +27,8 @@ const defaultProps = {
23
27
  zIndex: getDefaultZIndex("overlay"),
24
28
  store: notificationsStore,
25
29
  withinPortal: true,
26
- pauseResetOnHover: "all"
30
+ pauseResetOnHover: "all",
31
+ layout: "default"
27
32
  };
28
33
  const varsResolver = createVarsResolver((_, { zIndex, containerWidth }) => ({ root: {
29
34
  "--notifications-z-index": zIndex?.toString(),
@@ -31,16 +36,134 @@ const varsResolver = createVarsResolver((_, { zIndex, containerWidth }) => ({ ro
31
36
  } }));
32
37
  const Notifications = factory((_props) => {
33
38
  const props = useProps("Notifications", defaultProps, _props);
34
- const { classNames, className, style, styles, unstyled, vars, attributes, position, autoClose, transitionDuration, allowDragDismiss, allowScrollDismiss, containerWidth, notificationMaxHeight, limit, zIndex, store, portalProps, withinPortal, pauseResetOnHover, ...others } = props;
39
+ const { classNames, className, style, styles, unstyled, vars, attributes, position, autoClose, transitionDuration, allowDragDismiss, allowScrollDismiss, containerWidth, notificationMaxHeight, limit, zIndex, store, portalProps, withinPortal, pauseResetOnHover, renderNotification, layout, ...others } = props;
35
40
  const theme = useMantineTheme();
36
41
  const data = useNotifications(store);
37
42
  const forceUpdate = useForceUpdate();
38
43
  const shouldReduceMotion = useReducedMotion();
39
44
  const refs = useRef({});
40
45
  const previousLength = useRef(0);
41
- const [hoveredCount, setHoveredCount] = useState(0);
42
- const handleHoverStart = useCallback(() => setHoveredCount((c) => c + 1), []);
43
- const handleHoverEnd = useCallback(() => setHoveredCount((c) => Math.max(0, c - 1)), []);
46
+ const [hoveredCounts, setHoveredCounts] = useState({});
47
+ const [expandedPositions, setExpandedPositions] = useState({});
48
+ const [hoveredGroups, setHoveredGroups] = useState({});
49
+ const [pinnedPosition, setPinnedPosition] = useState(null);
50
+ const collapseTimeouts = useRef({});
51
+ const hoveredCount = Object.values(hoveredCounts).reduce((acc, count) => acc + (count ?? 0), 0) + Object.values(hoveredGroups).filter(Boolean).length;
52
+ const handleHoverStart = useCallback((pos) => setHoveredCounts((current) => ({
53
+ ...current,
54
+ [pos]: (current[pos] ?? 0) + 1
55
+ })), []);
56
+ const handleHoverEnd = useCallback((pos) => setHoveredCounts((current) => ({
57
+ ...current,
58
+ [pos]: Math.max(0, (current[pos] ?? 0) - 1)
59
+ })), []);
60
+ const getGroupHoverProps = useCallback((pos) => layout === "stacked" ? {
61
+ onMouseEnter: () => setHoveredGroups((current) => ({
62
+ ...current,
63
+ [pos]: true
64
+ })),
65
+ onMouseLeave: () => setHoveredGroups((current) => ({
66
+ ...current,
67
+ [pos]: false
68
+ }))
69
+ } : {}, [layout]);
70
+ const handleExpandRequest = useCallback((pos) => setPinnedPosition(pos), []);
71
+ useEffect(() => {
72
+ if (layout !== "stacked") return;
73
+ const timeouts = collapseTimeouts.current;
74
+ positions.forEach((pos) => {
75
+ if ((hoveredCounts[pos] ?? 0) > 0 || hoveredGroups[pos] || pinnedPosition === pos) {
76
+ window.clearTimeout(timeouts[pos]);
77
+ setExpandedPositions((current) => current[pos] ? current : {
78
+ ...current,
79
+ [pos]: true
80
+ });
81
+ } else timeouts[pos] = window.setTimeout(() => {
82
+ setExpandedPositions((current) => current[pos] ? {
83
+ ...current,
84
+ [pos]: false
85
+ } : current);
86
+ }, 200);
87
+ });
88
+ return () => positions.forEach((pos) => window.clearTimeout(timeouts[pos]));
89
+ }, [
90
+ hoveredCounts,
91
+ hoveredGroups,
92
+ pinnedPosition,
93
+ layout
94
+ ]);
95
+ useEffect(() => {
96
+ if (!pinnedPosition) return;
97
+ const handlePointerDown = (event) => {
98
+ const target = event.target;
99
+ if (!(target !== null && Object.values(refs.current).some((element) => element?.contains(target)))) setPinnedPosition(null);
100
+ };
101
+ document.addEventListener("pointerdown", handlePointerDown);
102
+ return () => document.removeEventListener("pointerdown", handlePointerDown);
103
+ }, [pinnedPosition]);
104
+ const grouped = getGroupedNotifications(data.notifications, position);
105
+ const pinnedCount = pinnedPosition ? grouped[pinnedPosition].length : 0;
106
+ useEffect(() => {
107
+ if (layout !== "stacked" || pinnedPosition !== null && pinnedCount === 0) setPinnedPosition(null);
108
+ }, [
109
+ pinnedCount,
110
+ pinnedPosition,
111
+ layout
112
+ ]);
113
+ useEffect(() => {
114
+ if (layout !== "stacked") setHoveredGroups((current) => Object.values(current).some(Boolean) ? {} : current);
115
+ }, [layout]);
116
+ const resizeObserver = useRef(null);
117
+ const measuredHeights = useRef({});
118
+ const observedIds = useRef(/* @__PURE__ */ new WeakMap());
119
+ const measureNotification = useCallback((id, element) => {
120
+ const height = element.offsetHeight;
121
+ if (measuredHeights.current[id] === height) return false;
122
+ measuredHeights.current[id] = height;
123
+ return true;
124
+ }, []);
125
+ useEffect(() => {
126
+ if (layout !== "stacked" || typeof ResizeObserver === "undefined") return;
127
+ const observer = new ResizeObserver((entries) => {
128
+ let changed = false;
129
+ entries.forEach((entry) => {
130
+ const id = observedIds.current.get(entry.target);
131
+ if (id && measureNotification(id, entry.target)) changed = true;
132
+ });
133
+ if (changed) forceUpdate();
134
+ });
135
+ resizeObserver.current = observer;
136
+ Object.values(refs.current).forEach((element) => element && observer.observe(element));
137
+ return () => {
138
+ observer.disconnect();
139
+ resizeObserver.current = null;
140
+ };
141
+ }, [
142
+ layout,
143
+ forceUpdate,
144
+ measureNotification
145
+ ]);
146
+ const refCallbacks = useRef({});
147
+ const getNotificationRef = useCallback((id) => {
148
+ if (!refCallbacks.current[id]) refCallbacks.current[id] = (node) => {
149
+ const previous = refs.current[id];
150
+ if (previous && previous !== node) {
151
+ resizeObserver.current?.unobserve(previous);
152
+ observedIds.current.delete(previous);
153
+ }
154
+ if (node) {
155
+ refs.current[id] = node;
156
+ observedIds.current.set(node, id);
157
+ measureNotification(id, node);
158
+ resizeObserver.current?.observe(node);
159
+ } else {
160
+ delete refs.current[id];
161
+ delete refCallbacks.current[id];
162
+ delete measuredHeights.current[id];
163
+ }
164
+ };
165
+ return refCallbacks.current[id];
166
+ }, [measureNotification]);
44
167
  const duration = (theme.respectReducedMotion ? shouldReduceMotion : false) ? 1 : transitionDuration;
45
168
  const getStyles = useStyles({
46
169
  name: "Notifications",
@@ -66,37 +189,57 @@ const Notifications = factory((_props) => {
66
189
  if (data.notifications.length > previousLength.current) setTimeout(() => forceUpdate(), 0);
67
190
  previousLength.current = data.notifications.length;
68
191
  }, [data.notifications]);
69
- const grouped = getGroupedNotifications(data.notifications, position);
70
192
  const groupedComponents = positions.reduce((acc, pos) => {
71
- acc[pos] = grouped[pos].map(({ style: notificationStyle, ...notification }) => /* @__PURE__ */ jsx(Transition$1, {
72
- timeout: duration,
73
- onEnter: () => refs.current[notification.id].offsetHeight,
74
- nodeRef: { current: refs.current[notification.id] },
75
- children: (state) => /* @__PURE__ */ jsx(NotificationContainer, {
76
- ref: (node) => {
77
- if (node) refs.current[notification.id] = node;
78
- else delete refs.current[notification.id];
79
- },
80
- data: notification,
81
- onHide: (id) => hideNotification(id, store),
82
- autoClose,
83
- transitionDuration: duration,
84
- allowDragDismiss,
85
- allowScrollDismiss,
86
- paused: pauseResetOnHover === "all" ? hoveredCount > 0 : false,
87
- onHoverStart: handleHoverStart,
88
- onHoverEnd: handleHoverEnd,
89
- ...getStyles("notification", { style: {
90
- ...getNotificationStateStyles({
91
- state,
92
- position: pos,
93
- transitionDuration: duration,
94
- maxHeight: notificationMaxHeight
95
- }),
96
- ...notificationStyle
97
- } })
98
- })
99
- }, notification.id));
193
+ const groupLength = grouped[pos].length;
194
+ const expandedOffsets = new Array(groupLength).fill(0);
195
+ const stackExpanded = layout === "stacked" && !!expandedPositions[pos];
196
+ const stackOrder = layout === "stacked" ? [...grouped[pos]].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0) || (b.__sequence ?? 0) - (a.__sequence ?? 0)) : grouped[pos];
197
+ if (stackExpanded && groupLength > 0) {
198
+ const direction = pos.startsWith("top") ? 1 : -1;
199
+ let cumOffset = 0;
200
+ for (let i = 0; i < groupLength; i += 1) {
201
+ expandedOffsets[i] = cumOffset * direction;
202
+ cumOffset += (measuredHeights.current[stackOrder[i].id] || FALLBACK_NOTIFICATION_HEIGHT) + STACK_EXPANDED_GAP;
203
+ }
204
+ }
205
+ acc[pos] = stackOrder.map((item, stackIndex) => {
206
+ const { style: notificationStyle, ...notification } = item;
207
+ return /* @__PURE__ */ jsx(Transition$1, {
208
+ timeout: duration,
209
+ onEnter: () => refs.current[notification.id].offsetHeight,
210
+ nodeRef: { current: refs.current[notification.id] },
211
+ children: (state) => /* @__PURE__ */ jsx(NotificationContainer, {
212
+ ref: getNotificationRef(notification.id),
213
+ data: notification,
214
+ onHide: (id) => hideNotification(id, store),
215
+ autoClose,
216
+ transitionDuration: duration,
217
+ allowDragDismiss,
218
+ allowScrollDismiss,
219
+ paused: (pauseResetOnHover === "all" ? hoveredCount > 0 : false) || layout === "stacked" && !stackExpanded && stackIndex > 0,
220
+ onHoverStart: () => handleHoverStart(pos),
221
+ onHoverEnd: () => handleHoverEnd(pos),
222
+ onExpandRequest: () => handleExpandRequest(pos),
223
+ renderNotification: "renderNotification" in notification ? notification.renderNotification : renderNotification,
224
+ layout,
225
+ stackIndex,
226
+ stackSize: groupLength,
227
+ stackPosition: pos,
228
+ stackExpanded,
229
+ stackExpandedOffset: expandedOffsets[stackIndex],
230
+ transitionState: state,
231
+ ...getStyles("notification", { style: {
232
+ ...getNotificationStateStyles({
233
+ state,
234
+ position: pos,
235
+ transitionDuration: duration,
236
+ maxHeight: notificationMaxHeight
237
+ }),
238
+ ...notificationStyle
239
+ } })
240
+ })
241
+ }, notification.id);
242
+ });
100
243
  return acc;
101
244
  }, {});
102
245
  return /* @__PURE__ */ jsxs(OptionalPortal, {
@@ -106,38 +249,62 @@ const Notifications = factory((_props) => {
106
249
  /* @__PURE__ */ jsx(Box, {
107
250
  ...getStyles("root"),
108
251
  "data-position": "top-center",
252
+ "data-layout": layout,
109
253
  ...others,
110
- children: /* @__PURE__ */ jsx(TransitionGroup, { children: groupedComponents["top-center"] })
254
+ children: /* @__PURE__ */ jsx(TransitionGroup, {
255
+ ...getGroupHoverProps("top-center"),
256
+ children: groupedComponents["top-center"]
257
+ })
111
258
  }),
112
259
  /* @__PURE__ */ jsx(Box, {
113
260
  ...getStyles("root"),
114
261
  "data-position": "top-left",
262
+ "data-layout": layout,
115
263
  ...others,
116
- children: /* @__PURE__ */ jsx(TransitionGroup, { children: groupedComponents["top-left"] })
264
+ children: /* @__PURE__ */ jsx(TransitionGroup, {
265
+ ...getGroupHoverProps("top-left"),
266
+ children: groupedComponents["top-left"]
267
+ })
117
268
  }),
118
269
  /* @__PURE__ */ jsx(Box, {
119
270
  ...getStyles("root", { className: RemoveScroll.classNames.fullWidth }),
120
271
  "data-position": "top-right",
272
+ "data-layout": layout,
121
273
  ...others,
122
- children: /* @__PURE__ */ jsx(TransitionGroup, { children: groupedComponents["top-right"] })
274
+ children: /* @__PURE__ */ jsx(TransitionGroup, {
275
+ ...getGroupHoverProps("top-right"),
276
+ children: groupedComponents["top-right"]
277
+ })
123
278
  }),
124
279
  /* @__PURE__ */ jsx(Box, {
125
280
  ...getStyles("root", { className: RemoveScroll.classNames.fullWidth }),
126
281
  "data-position": "bottom-right",
282
+ "data-layout": layout,
127
283
  ...others,
128
- children: /* @__PURE__ */ jsx(TransitionGroup, { children: groupedComponents["bottom-right"] })
284
+ children: /* @__PURE__ */ jsx(TransitionGroup, {
285
+ ...getGroupHoverProps("bottom-right"),
286
+ children: groupedComponents["bottom-right"]
287
+ })
129
288
  }),
130
289
  /* @__PURE__ */ jsx(Box, {
131
290
  ...getStyles("root"),
132
291
  "data-position": "bottom-left",
292
+ "data-layout": layout,
133
293
  ...others,
134
- children: /* @__PURE__ */ jsx(TransitionGroup, { children: groupedComponents["bottom-left"] })
294
+ children: /* @__PURE__ */ jsx(TransitionGroup, {
295
+ ...getGroupHoverProps("bottom-left"),
296
+ children: groupedComponents["bottom-left"]
297
+ })
135
298
  }),
136
299
  /* @__PURE__ */ jsx(Box, {
137
300
  ...getStyles("root"),
138
301
  "data-position": "bottom-center",
302
+ "data-layout": layout,
139
303
  ...others,
140
- children: /* @__PURE__ */ jsx(TransitionGroup, { children: groupedComponents["bottom-center"] })
304
+ children: /* @__PURE__ */ jsx(TransitionGroup, {
305
+ ...getGroupHoverProps("bottom-center"),
306
+ children: groupedComponents["bottom-center"]
307
+ })
141
308
  })
142
309
  ]
143
310
  });
@@ -1 +1 @@
1
- {"version":3,"file":"Notifications.mjs","names":["Transition","_Transition","classes"],"sources":["../src/Notifications.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport {\n Transition as _Transition,\n TransitionGroup,\n TransitionStatus,\n} from 'react-transition-group';\nimport {\n BasePortalProps,\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getDefaultZIndex,\n OptionalPortal,\n rem,\n RemoveScroll,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { useDidUpdate, useForceUpdate, useReducedMotion } from '@mantine/hooks';\nimport {\n getGroupedNotifications,\n positions,\n} from './get-grouped-notifications/get-grouped-notifications';\nimport { getNotificationStateStyles } from './get-notification-state-styles';\nimport { NotificationContainer } from './NotificationContainer';\nimport {\n hideNotification,\n NotificationPosition,\n notifications,\n NotificationsStore,\n notificationsStore,\n useNotifications,\n} from './notifications.store';\nimport classes from './Notifications.module.css';\n\nconst Transition: any = _Transition;\n\nexport type NotificationsStylesNames = 'root' | 'notification';\nexport type NotificationsCssVariables = {\n root: '--notifications-z-index' | '--notifications-container-width';\n};\n\nexport interface NotificationsProps\n extends BoxProps, StylesApiProps<NotificationsFactory>, ElementProps<'div'> {\n /** Notifications default position @default 'bottom-right' */\n position?: NotificationPosition;\n\n /** Auto close timeout for all notifications in ms, `false` to disable auto close, can be overwritten for individual notifications in `notifications.show` function @default 4000 */\n autoClose?: number | false;\n\n /** Notification transition duration in ms @default 250 */\n transitionDuration?: number;\n\n /** Determines whether notifications can be dismissed by dragging left or right @default true */\n allowDragDismiss?: boolean;\n\n /** Determines whether notifications can be dismissed with horizontal scroll gesture while hovered @default true */\n allowScrollDismiss?: boolean;\n\n /** Notification width, cannot exceed 100% @default 440 */\n containerWidth?: number | string;\n\n /** Notification `max-height`, used for transitions @default 200 */\n notificationMaxHeight?: number | string;\n\n /** Maximum number of notifications displayed at a time, other new notifications will be added to queue @default 5 */\n limit?: number;\n\n /** Notifications container z-index @default 400 */\n zIndex?: string | number;\n\n /** Props passed down to the `Portal` component */\n portalProps?: BasePortalProps;\n\n /** Store for notifications state, can be used to create multiple instances of notifications system in your application */\n store?: NotificationsStore;\n\n /** Determines whether notifications container should be rendered inside `Portal` @default true */\n withinPortal?: boolean;\n\n /** Determines which notifications should pause auto close on hover, `'all'` – pauses auto close for all notifications when any notification is hovered, `'notification'` – pauses auto close only for the hovered notification @default 'all' */\n pauseResetOnHover?: 'all' | 'notification';\n}\n\nexport type NotificationsFactory = Factory<{\n props: NotificationsProps;\n ref: HTMLDivElement;\n stylesNames: NotificationsStylesNames;\n vars: NotificationsCssVariables;\n staticComponents: {\n show: typeof notifications.show;\n hide: typeof notifications.hide;\n update: typeof notifications.update;\n clean: typeof notifications.clean;\n cleanQueue: typeof notifications.cleanQueue;\n updateState: typeof notifications.updateState;\n };\n}>;\n\nconst defaultProps = {\n position: 'bottom-right',\n autoClose: 4000,\n transitionDuration: 250,\n allowDragDismiss: true,\n allowScrollDismiss: true,\n containerWidth: 440,\n notificationMaxHeight: 200,\n limit: 5,\n zIndex: getDefaultZIndex('overlay'),\n store: notificationsStore,\n withinPortal: true,\n pauseResetOnHover: 'all',\n} satisfies Partial<NotificationsProps>;\n\nconst varsResolver = createVarsResolver<NotificationsFactory>((_, { zIndex, containerWidth }) => ({\n root: {\n '--notifications-z-index': zIndex?.toString(),\n '--notifications-container-width': rem(containerWidth),\n },\n}));\n\nexport const Notifications = factory<NotificationsFactory>((_props) => {\n const props = useProps('Notifications', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n attributes,\n position,\n autoClose,\n transitionDuration,\n allowDragDismiss,\n allowScrollDismiss,\n containerWidth,\n notificationMaxHeight,\n limit,\n zIndex,\n store,\n portalProps,\n withinPortal,\n pauseResetOnHover,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const data = useNotifications(store);\n const forceUpdate = useForceUpdate();\n const shouldReduceMotion = useReducedMotion();\n const refs = useRef<Record<string, HTMLDivElement>>({});\n const previousLength = useRef<number>(0);\n const [hoveredCount, setHoveredCount] = useState(0);\n\n const handleHoverStart = useCallback(() => setHoveredCount((c) => c + 1), []);\n const handleHoverEnd = useCallback(() => setHoveredCount((c) => Math.max(0, c - 1)), []);\n\n const reduceMotion = theme.respectReducedMotion ? shouldReduceMotion : false;\n const duration = reduceMotion ? 1 : transitionDuration;\n\n const getStyles = useStyles<NotificationsFactory>({\n name: 'Notifications',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n useEffect(() => {\n store?.updateState((current) => ({\n ...current,\n limit: limit || 5,\n defaultPosition: position,\n }));\n }, [limit, position]);\n\n useDidUpdate(() => {\n if (data.notifications.length > previousLength.current) {\n setTimeout(() => forceUpdate(), 0);\n }\n previousLength.current = data.notifications.length;\n }, [data.notifications]);\n\n const grouped = getGroupedNotifications(data.notifications, position);\n const groupedComponents = positions.reduce(\n (acc, pos) => {\n acc[pos] = grouped[pos].map(({ style: notificationStyle, ...notification }) => (\n <Transition\n key={notification.id}\n timeout={duration}\n onEnter={() => refs.current[notification.id!].offsetHeight}\n nodeRef={{ current: refs.current[notification.id!] }}\n >\n {(state: TransitionStatus) => (\n <NotificationContainer\n ref={(node) => {\n if (node) {\n refs.current[notification.id!] = node;\n } else {\n delete refs.current[notification.id!];\n }\n }}\n data={notification}\n onHide={(id) => hideNotification(id, store)}\n autoClose={autoClose}\n transitionDuration={duration}\n allowDragDismiss={allowDragDismiss}\n allowScrollDismiss={allowScrollDismiss}\n paused={pauseResetOnHover === 'all' ? hoveredCount > 0 : false}\n onHoverStart={handleHoverStart}\n onHoverEnd={handleHoverEnd}\n {...getStyles('notification', {\n style: {\n ...getNotificationStateStyles({\n state,\n position: pos,\n transitionDuration: duration,\n maxHeight: notificationMaxHeight,\n }),\n ...notificationStyle,\n },\n })}\n />\n )}\n </Transition>\n ));\n\n return acc;\n },\n {} as Record<NotificationPosition, React.ReactNode>\n );\n\n return (\n <OptionalPortal withinPortal={withinPortal} {...portalProps}>\n <Box {...getStyles('root')} data-position=\"top-center\" {...others}>\n <TransitionGroup>{groupedComponents['top-center']}</TransitionGroup>\n </Box>\n\n <Box {...getStyles('root')} data-position=\"top-left\" {...others}>\n <TransitionGroup>{groupedComponents['top-left']}</TransitionGroup>\n </Box>\n\n <Box\n {...getStyles('root', { className: RemoveScroll.classNames.fullWidth })}\n data-position=\"top-right\"\n {...others}\n >\n <TransitionGroup>{groupedComponents['top-right']}</TransitionGroup>\n </Box>\n\n <Box\n {...getStyles('root', { className: RemoveScroll.classNames.fullWidth })}\n data-position=\"bottom-right\"\n {...others}\n >\n <TransitionGroup>{groupedComponents['bottom-right']}</TransitionGroup>\n </Box>\n\n <Box {...getStyles('root')} data-position=\"bottom-left\" {...others}>\n <TransitionGroup>{groupedComponents['bottom-left']}</TransitionGroup>\n </Box>\n\n <Box {...getStyles('root')} data-position=\"bottom-center\" {...others}>\n <TransitionGroup>{groupedComponents['bottom-center']}</TransitionGroup>\n </Box>\n </OptionalPortal>\n );\n});\n\nNotifications.classes = classes;\nNotifications.varsResolver = varsResolver;\nNotifications.displayName = '@mantine/notifications/Notifications';\nNotifications.show = notifications.show;\nNotifications.hide = notifications.hide;\nNotifications.update = notifications.update;\nNotifications.clean = notifications.clean;\nNotifications.cleanQueue = notifications.cleanQueue;\nNotifications.updateState = notifications.updateState;\n"],"mappings":";;;;;;;;;;;;AAwCA,MAAMA,eAAkBC;AAgExB,MAAM,eAAe;CACnB,UAAU;CACV,WAAW;CACX,oBAAoB;CACpB,kBAAkB;CAClB,oBAAoB;CACpB,gBAAgB;CAChB,uBAAuB;CACvB,OAAO;CACP,QAAQ,iBAAiB,SAAS;CAClC,OAAO;CACP,cAAc;CACd,mBAAmB;AACrB;AAEA,MAAM,eAAe,oBAA0C,GAAG,EAAE,QAAQ,sBAAsB,EAChG,MAAM;CACJ,2BAA2B,QAAQ,SAAS;CAC5C,mCAAmC,IAAI,cAAc;AACvD,EACF,EAAE;AAEF,MAAa,gBAAgB,SAA+B,WAAW;CACrE,MAAM,QAAQ,SAAS,iBAAiB,cAAc,MAAM;CAC5D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,YACA,UACA,WACA,oBACA,kBACA,oBACA,gBACA,uBACA,OACA,QACA,OACA,aACA,cACA,mBACA,GAAG,WACD;CAEJ,MAAM,QAAQ,gBAAgB;CAC9B,MAAM,OAAO,iBAAiB,KAAK;CACnC,MAAM,cAAc,eAAe;CACnC,MAAM,qBAAqB,iBAAiB;CAC5C,MAAM,OAAO,OAAuC,CAAC,CAAC;CACtD,MAAM,iBAAiB,OAAe,CAAC;CACvC,MAAM,CAAC,cAAc,mBAAmB,SAAS,CAAC;CAElD,MAAM,mBAAmB,kBAAkB,iBAAiB,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;CAC5E,MAAM,iBAAiB,kBAAkB,iBAAiB,MAA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Transition","_Transition","classes"],"sources":["../src/Notifications.tsx"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport {\n Transition as _Transition,\n TransitionGroup,\n TransitionStatus,\n} from 'react-transition-group';\nimport {\n BasePortalProps,\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getDefaultZIndex,\n OptionalPortal,\n rem,\n RemoveScroll,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { useDidUpdate, useForceUpdate, useReducedMotion } from '@mantine/hooks';\nimport {\n getGroupedNotifications,\n positions,\n} from './get-grouped-notifications/get-grouped-notifications';\nimport { getNotificationStateStyles } from './get-notification-state-styles';\nimport { NotificationContainer } from './NotificationContainer';\nimport {\n hideNotification,\n NotificationData,\n NotificationPosition,\n notifications,\n NotificationsStore,\n notificationsStore,\n SequencedNotificationData,\n useNotifications,\n} from './notifications.store';\nimport classes from './Notifications.module.css';\n\nconst Transition: any = _Transition;\n\n/** Vertical gap between notifications of an expanded stack, in px */\nconst STACK_EXPANDED_GAP = 16;\n\n/** Offset step used for a notification that has not been measured yet, in px */\nconst FALLBACK_NOTIFICATION_HEIGHT = 80;\n\nexport type NotificationsStylesNames = 'root' | 'notification';\nexport type NotificationsCssVariables = {\n root: '--notifications-z-index' | '--notifications-container-width';\n};\n\nexport interface NotificationsProps\n extends BoxProps, StylesApiProps<NotificationsFactory>, ElementProps<'div'> {\n /** Notifications default position @default 'bottom-right' */\n position?: NotificationPosition;\n\n /** Auto close timeout for all notifications in ms, `false` to disable auto close, can be overwritten for individual notifications in `notifications.show` function @default 4000 */\n autoClose?: number | false;\n\n /** Notification transition duration in ms @default 250 */\n transitionDuration?: number;\n\n /** Determines whether notifications can be dismissed by dragging left or right @default true */\n allowDragDismiss?: boolean;\n\n /** Determines whether notifications can be dismissed with horizontal scroll gesture while hovered @default true */\n allowScrollDismiss?: boolean;\n\n /** Notification width, cannot exceed 100% @default 440 */\n containerWidth?: number | string;\n\n /** Notification `max-height`, used for transitions @default 200 */\n notificationMaxHeight?: number | string;\n\n /** Maximum number of notifications displayed at a time, other new notifications will be added to queue @default 5 */\n limit?: number;\n\n /** Notifications container z-index @default 400 */\n zIndex?: string | number;\n\n /** Props passed down to the `Portal` component */\n portalProps?: BasePortalProps;\n\n /** Store for notifications state, can be used to create multiple instances of notifications system in your application */\n store?: NotificationsStore;\n\n /** Determines whether notifications container should be rendered inside `Portal` @default true */\n withinPortal?: boolean;\n\n /** Determines which notifications should pause auto close on hover, `'all'` – pauses auto close for all notifications when any notification is hovered, `'notification'` – pauses auto close only for the hovered notification @default 'all' */\n pauseResetOnHover?: 'all' | 'notification';\n\n /** Custom render function that replaces the default notification, can be overridden per notification */\n renderNotification?: (notification: NotificationData) => React.ReactNode;\n\n /** Controls how notifications are positioned in the stack, `'default'` – standard vertical list, `'stacked'` – only first notification is fully visible, rest are stacked behind @default 'default' */\n layout?: 'default' | 'stacked';\n}\n\nexport type NotificationsFactory = Factory<{\n props: NotificationsProps;\n ref: HTMLDivElement;\n stylesNames: NotificationsStylesNames;\n vars: NotificationsCssVariables;\n staticComponents: {\n show: typeof notifications.show;\n hide: typeof notifications.hide;\n update: typeof notifications.update;\n clean: typeof notifications.clean;\n cleanQueue: typeof notifications.cleanQueue;\n updateState: typeof notifications.updateState;\n };\n}>;\n\nconst defaultProps = {\n position: 'bottom-right',\n autoClose: 4000,\n transitionDuration: 250,\n allowDragDismiss: true,\n allowScrollDismiss: true,\n containerWidth: 440,\n notificationMaxHeight: 200,\n limit: 5,\n zIndex: getDefaultZIndex('overlay'),\n store: notificationsStore,\n withinPortal: true,\n pauseResetOnHover: 'all',\n layout: 'default',\n} satisfies Partial<NotificationsProps>;\n\nconst varsResolver = createVarsResolver<NotificationsFactory>((_, { zIndex, containerWidth }) => ({\n root: {\n '--notifications-z-index': zIndex?.toString(),\n '--notifications-container-width': rem(containerWidth),\n },\n}));\n\nexport const Notifications = factory<NotificationsFactory>((_props) => {\n const props = useProps('Notifications', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n attributes,\n position,\n autoClose,\n transitionDuration,\n allowDragDismiss,\n allowScrollDismiss,\n containerWidth,\n notificationMaxHeight,\n limit,\n zIndex,\n store,\n portalProps,\n withinPortal,\n pauseResetOnHover,\n renderNotification,\n layout,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const data = useNotifications(store);\n const forceUpdate = useForceUpdate();\n const shouldReduceMotion = useReducedMotion();\n const refs = useRef<Record<string, HTMLDivElement>>({});\n const previousLength = useRef<number>(0);\n // Every position renders its own stack, so hover, expansion and pinning are tracked per\n // position – a single shared flag made hovering one corner expand all six of them.\n const [hoveredCounts, setHoveredCounts] = useState<Partial<Record<NotificationPosition, number>>>(\n {}\n );\n const [expandedPositions, setExpandedPositions] = useState<\n Partial<Record<NotificationPosition, boolean>>\n >({});\n const [hoveredGroups, setHoveredGroups] = useState<\n Partial<Record<NotificationPosition, boolean>>\n >({});\n const [pinnedPosition, setPinnedPosition] = useState<NotificationPosition | null>(null);\n const collapseTimeouts = useRef<Partial<Record<NotificationPosition, number>>>({});\n\n // `pauseResetOnHover=\"all\"` is documented as pausing every notification when any one of\n // them is hovered, so this stays global while the stack state above does not.\n const hoveredCount =\n Object.values(hoveredCounts).reduce((acc, count) => acc + (count ?? 0), 0) +\n Object.values(hoveredGroups).filter(Boolean).length;\n\n const handleHoverStart = useCallback(\n (pos: NotificationPosition) =>\n setHoveredCounts((current) => ({ ...current, [pos]: (current[pos] ?? 0) + 1 })),\n []\n );\n\n const handleHoverEnd = useCallback(\n (pos: NotificationPosition) =>\n setHoveredCounts((current) => ({ ...current, [pos]: Math.max(0, (current[pos] ?? 0) - 1) })),\n []\n );\n\n // Stacked hover is also tracked on the group element that wraps a stack, not only on the\n // individual notifications. When the hovered notification unmounts, React does not deliver\n // `onMouseEnter` to the one that slides under a stationary pointer: the browser dispatches\n // only a `mouseover` for the new target (no `mouseout`, the old node is gone), and the\n // enter/leave plugin drops it because its `relatedTarget` still resolves to a React\n // instance. The group is hovered throughout, so its state needs no event to stay correct\n // and the stack stays open until the pointer really leaves.\n // Kept apart from the notification counter above so that it can be released on its own –\n // the group has no unmount hook to fall back on the way a notification does.\n const getGroupHoverProps = useCallback(\n (pos: NotificationPosition) =>\n layout === 'stacked'\n ? {\n onMouseEnter: () => setHoveredGroups((current) => ({ ...current, [pos]: true })),\n onMouseLeave: () => setHoveredGroups((current) => ({ ...current, [pos]: false })),\n }\n : {},\n [layout]\n );\n\n // Touch devices have no hover, so tapping the stack pins it open until the next tap\n // outside of it. Without this the notifications behind the first one are unreachable.\n const handleExpandRequest = useCallback(\n (pos: NotificationPosition) => setPinnedPosition(pos),\n []\n );\n\n useEffect(() => {\n if (layout !== 'stacked') {\n return undefined;\n }\n\n const timeouts = collapseTimeouts.current;\n\n positions.forEach((pos) => {\n if ((hoveredCounts[pos] ?? 0) > 0 || hoveredGroups[pos] || pinnedPosition === pos) {\n window.clearTimeout(timeouts[pos]);\n setExpandedPositions((current) => (current[pos] ? current : { ...current, [pos]: true }));\n } else {\n timeouts[pos] = window.setTimeout(() => {\n setExpandedPositions((current) =>\n current[pos] ? { ...current, [pos]: false } : current\n );\n }, 200);\n }\n });\n\n return () => positions.forEach((pos) => window.clearTimeout(timeouts[pos]));\n }, [hoveredCounts, hoveredGroups, pinnedPosition, layout]);\n\n useEffect(() => {\n if (!pinnedPosition) {\n return undefined;\n }\n\n const handlePointerDown = (event: PointerEvent) => {\n const target = event.target as Node | null;\n const insideStack =\n target !== null && Object.values(refs.current).some((element) => element?.contains(target));\n\n if (!insideStack) {\n setPinnedPosition(null);\n }\n };\n\n document.addEventListener('pointerdown', handlePointerDown);\n return () => document.removeEventListener('pointerdown', handlePointerDown);\n }, [pinnedPosition]);\n\n const grouped = getGroupedNotifications(data.notifications, position);\n const pinnedCount = pinnedPosition ? grouped[pinnedPosition].length : 0;\n\n useEffect(() => {\n if (layout !== 'stacked' || (pinnedPosition !== null && pinnedCount === 0)) {\n setPinnedPosition(null);\n }\n }, [pinnedCount, pinnedPosition, layout]);\n\n // Leaving the stacked layout takes the handlers below out of the tree, so nothing can ever\n // deliver the `mouseleave` that would release the group and a stale flag would keep auto\n // close paused forever. Emptying a stack needs no such handling – the browser drops the\n // hover on its own once the last notification is removed, and releasing it here instead\n // would fire while the dismissed notification is still exiting under the pointer.\n useEffect(() => {\n if (layout !== 'stacked') {\n setHoveredGroups((current) => (Object.values(current).some(Boolean) ? {} : current));\n }\n }, [layout]);\n\n // Expanded stack offsets need the height of every notification. Measuring during render\n // would force a layout pass on every hover, focus and store update, so heights are cached\n // here and refreshed from the ResizeObserver – which also covers a notification that grows\n // after mount (image loads, async content, viewport reflow) and would otherwise leave the\n // ones after it overlapping or gapped until something else triggered a render.\n const resizeObserver = useRef<ResizeObserver | null>(null);\n const measuredHeights = useRef<Record<string, number>>({});\n const observedIds = useRef(new WeakMap<Element, string>());\n\n const measureNotification = useCallback((id: string, element: HTMLElement) => {\n const height = element.offsetHeight;\n\n if (measuredHeights.current[id] === height) {\n return false;\n }\n\n measuredHeights.current[id] = height;\n return true;\n }, []);\n\n useEffect(() => {\n if (layout !== 'stacked' || typeof ResizeObserver === 'undefined') {\n return undefined;\n }\n\n const observer = new ResizeObserver((entries) => {\n let changed = false;\n\n entries.forEach((entry) => {\n const id = observedIds.current.get(entry.target);\n\n if (id && measureNotification(id, entry.target as HTMLElement)) {\n changed = true;\n }\n });\n\n if (changed) {\n forceUpdate();\n }\n });\n\n resizeObserver.current = observer;\n Object.values(refs.current).forEach((element) => element && observer.observe(element));\n\n return () => {\n observer.disconnect();\n resizeObserver.current = null;\n };\n }, [layout, forceUpdate, measureNotification]);\n\n const refCallbacks = useRef<Record<string, (node: HTMLDivElement | null) => void>>({});\n\n const getNotificationRef = useCallback(\n (id: string) => {\n if (!refCallbacks.current[id]) {\n refCallbacks.current[id] = (node: HTMLDivElement | null) => {\n const previous = refs.current[id];\n\n if (previous && previous !== node) {\n resizeObserver.current?.unobserve(previous);\n observedIds.current.delete(previous);\n }\n\n if (node) {\n refs.current[id] = node;\n observedIds.current.set(node, id);\n // Measured here rather than during render – the commit phase is where a layout\n // read is already paid for, and the ResizeObserver keeps the value fresh after.\n measureNotification(id, node);\n resizeObserver.current?.observe(node);\n } else {\n delete refs.current[id];\n delete refCallbacks.current[id];\n delete measuredHeights.current[id];\n }\n };\n }\n\n return refCallbacks.current[id];\n },\n [measureNotification]\n );\n\n const reduceMotion = theme.respectReducedMotion ? shouldReduceMotion : false;\n const duration = reduceMotion ? 1 : transitionDuration;\n\n const getStyles = useStyles<NotificationsFactory>({\n name: 'Notifications',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n useEffect(() => {\n store?.updateState((current) => ({\n ...current,\n limit: limit || 5,\n defaultPosition: position,\n }));\n }, [limit, position]);\n\n useDidUpdate(() => {\n if (data.notifications.length > previousLength.current) {\n setTimeout(() => forceUpdate(), 0);\n }\n previousLength.current = data.notifications.length;\n }, [data.notifications]);\n\n const groupedComponents = positions.reduce(\n (acc, pos) => {\n const groupLength = grouped[pos].length;\n const expandedOffsets: number[] = new Array(groupLength).fill(0);\n const stackExpanded = layout === 'stacked' && !!expandedPositions[pos];\n\n // `grouped[pos]` is sorted by priority descending, with equal priorities in insertion\n // order. A stack is rendered front to back, so `stackOrder[0]` is the notification in\n // front: the most urgent one, and the newest among equal priorities – only the\n // tie-break is reversed here. Taking the front from the end of the priority-sorted\n // array instead would put the *lowest* priority notification in front and leave an\n // urgent one inert behind it.\n // Rendering front first also keeps DOM order matching the visual stack – otherwise a\n // forward Tab from the front notification (the only focusable one while collapsed)\n // skips past the ones it just un-inerted and leaves the region. Placement is\n // unaffected: stacked notifications share one grid cell and are positioned by\n // transform and an explicit z-index.\n const stackOrder =\n layout === 'stacked'\n ? [...(grouped[pos] as SequencedNotificationData[])].sort(\n (a, b) =>\n (b.priority ?? 0) - (a.priority ?? 0) || (b.__sequence ?? 0) - (a.__sequence ?? 0)\n )\n : grouped[pos];\n\n if (stackExpanded && groupLength > 0) {\n const direction = pos.startsWith('top') ? 1 : -1;\n let cumOffset = 0;\n\n for (let i = 0; i < groupLength; i += 1) {\n expandedOffsets[i] = cumOffset * direction;\n cumOffset +=\n (measuredHeights.current[stackOrder[i].id!] || FALLBACK_NOTIFICATION_HEIGHT) +\n STACK_EXPANDED_GAP;\n }\n }\n\n acc[pos] = stackOrder.map((item, stackIndex) => {\n const { style: notificationStyle, ...notification } = item;\n\n return (\n <Transition\n key={notification.id}\n timeout={duration}\n onEnter={() => refs.current[notification.id!].offsetHeight}\n nodeRef={{ current: refs.current[notification.id!] }}\n >\n {(state: TransitionStatus) => (\n <NotificationContainer\n ref={getNotificationRef(notification.id!)}\n data={notification}\n onHide={(id) => hideNotification(id, store)}\n autoClose={autoClose}\n transitionDuration={duration}\n allowDragDismiss={allowDragDismiss}\n allowScrollDismiss={allowScrollDismiss}\n paused={\n (pauseResetOnHover === 'all' ? hoveredCount > 0 : false) ||\n (layout === 'stacked' && !stackExpanded && stackIndex > 0)\n }\n onHoverStart={() => handleHoverStart(pos)}\n onHoverEnd={() => handleHoverEnd(pos)}\n onExpandRequest={() => handleExpandRequest(pos)}\n renderNotification={\n 'renderNotification' in notification\n ? notification.renderNotification\n : renderNotification\n }\n layout={layout}\n stackIndex={stackIndex}\n stackSize={groupLength}\n stackPosition={pos}\n stackExpanded={stackExpanded}\n stackExpandedOffset={expandedOffsets[stackIndex]}\n transitionState={state}\n {...getStyles('notification', {\n style: {\n ...getNotificationStateStyles({\n state,\n position: pos,\n transitionDuration: duration,\n maxHeight: notificationMaxHeight,\n }),\n ...notificationStyle,\n },\n })}\n />\n )}\n </Transition>\n );\n });\n\n return acc;\n },\n {} as Record<NotificationPosition, React.ReactNode>\n );\n\n return (\n <OptionalPortal withinPortal={withinPortal} {...portalProps}>\n <Box {...getStyles('root')} data-position=\"top-center\" data-layout={layout} {...others}>\n <TransitionGroup {...getGroupHoverProps('top-center')}>\n {groupedComponents['top-center']}\n </TransitionGroup>\n </Box>\n\n <Box {...getStyles('root')} data-position=\"top-left\" data-layout={layout} {...others}>\n <TransitionGroup {...getGroupHoverProps('top-left')}>\n {groupedComponents['top-left']}\n </TransitionGroup>\n </Box>\n\n <Box\n {...getStyles('root', { className: RemoveScroll.classNames.fullWidth })}\n data-position=\"top-right\"\n data-layout={layout}\n {...others}\n >\n <TransitionGroup {...getGroupHoverProps('top-right')}>\n {groupedComponents['top-right']}\n </TransitionGroup>\n </Box>\n\n <Box\n {...getStyles('root', { className: RemoveScroll.classNames.fullWidth })}\n data-position=\"bottom-right\"\n data-layout={layout}\n {...others}\n >\n <TransitionGroup {...getGroupHoverProps('bottom-right')}>\n {groupedComponents['bottom-right']}\n </TransitionGroup>\n </Box>\n\n <Box {...getStyles('root')} data-position=\"bottom-left\" data-layout={layout} {...others}>\n <TransitionGroup {...getGroupHoverProps('bottom-left')}>\n {groupedComponents['bottom-left']}\n </TransitionGroup>\n </Box>\n\n <Box {...getStyles('root')} data-position=\"bottom-center\" data-layout={layout} {...others}>\n <TransitionGroup {...getGroupHoverProps('bottom-center')}>\n {groupedComponents['bottom-center']}\n </TransitionGroup>\n </Box>\n </OptionalPortal>\n );\n});\n\nNotifications.classes = classes;\nNotifications.varsResolver = varsResolver;\nNotifications.displayName = '@mantine/notifications/Notifications';\nNotifications.show = notifications.show;\nNotifications.hide = notifications.hide;\nNotifications.update = notifications.update;\nNotifications.clean = notifications.clean;\nNotifications.cleanQueue = notifications.cleanQueue;\nNotifications.updateState = notifications.updateState;\n"],"mappings":";;;;;;;;;;;;AA0CA,MAAMA,eAAkBC;;AAGxB,MAAM,qBAAqB;;AAG3B,MAAM,+BAA+B;AAsErC,MAAM,eAAe;CACnB,UAAU;CACV,WAAW;CACX,oBAAoB;CACpB,kBAAkB;CAClB,oBAAoB;CACpB,gBAAgB;CAChB,uBAAuB;CACvB,OAAO;CACP,QAAQ,iBAAiB,SAAS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AAc;AACrC,cAAc,QAAQ,cAAc;AACpC,cAAc,aAAa,cAAc;AACzC,cAAc,cAAc,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"Notifications.module.mjs","names":[],"sources":["../src/Notifications.module.css"],"sourcesContent":[".root {\n width: calc(100% - var(--mantine-spacing-md) * 2);\n position: fixed;\n z-index: var(--notifications-z-index);\n max-width: var(--notifications-container-width);\n\n &:where([data-position='top-center']) {\n top: var(--mantine-spacing-md);\n left: 50%;\n transform: translateX(-50%);\n }\n\n &:where([data-position='top-left']) {\n top: var(--mantine-spacing-md);\n left: var(--mantine-spacing-md);\n }\n\n &:where([data-position='top-right']) {\n top: var(--mantine-spacing-md);\n right: var(--mantine-spacing-md);\n }\n\n &:where([data-position='bottom-center']) {\n bottom: var(--mantine-spacing-md);\n left: 50%;\n transform: translateX(-50%);\n }\n\n &:where([data-position='bottom-left']) {\n bottom: var(--mantine-spacing-md);\n left: var(--mantine-spacing-md);\n }\n\n &:where([data-position='bottom-right']) {\n bottom: var(--mantine-spacing-md);\n right: var(--mantine-spacing-md);\n }\n}\n\n.notification {\n & + & {\n margin-top: var(--mantine-spacing-md);\n }\n}\n"],"mappings":""}
1
+ {"version":3,"file":"Notifications.module.mjs","names":[],"sources":["../src/Notifications.module.css"],"sourcesContent":[".root {\n width: calc(100% - var(--mantine-spacing-md) * 2);\n position: fixed;\n z-index: var(--notifications-z-index);\n max-width: var(--notifications-container-width);\n\n &:where([data-position='top-center']) {\n top: var(--mantine-spacing-md);\n left: 50%;\n transform: translateX(-50%);\n }\n\n &:where([data-position='top-left']) {\n top: var(--mantine-spacing-md);\n left: var(--mantine-spacing-md);\n }\n\n &:where([data-position='top-right']) {\n top: var(--mantine-spacing-md);\n right: var(--mantine-spacing-md);\n }\n\n &:where([data-position='bottom-center']) {\n bottom: var(--mantine-spacing-md);\n left: 50%;\n transform: translateX(-50%);\n }\n\n &:where([data-position='bottom-left']) {\n bottom: var(--mantine-spacing-md);\n left: var(--mantine-spacing-md);\n }\n\n &:where([data-position='bottom-right']) {\n bottom: var(--mantine-spacing-md);\n right: var(--mantine-spacing-md);\n }\n}\n\n.notification {\n & + & {\n margin-top: var(--mantine-spacing-md);\n }\n\n :where([data-layout='stacked']) & {\n margin-top: 0;\n }\n}\n\n.root:where([data-layout='stacked']) {\n & > * {\n display: grid;\n }\n}\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"notifications.store.mjs","names":[],"sources":["../src/notifications.store.ts"],"sourcesContent":["import { NotificationProps } from '@mantine/core';\nimport { randomId } from '@mantine/hooks';\nimport { createStore, MantineStore, useStore } from '@mantine/store';\n\nexport type NotificationPosition =\n | 'top-left'\n | 'top-right'\n | 'top-center'\n | 'bottom-left'\n | 'bottom-right'\n | 'bottom-center';\n\nexport interface NotificationData\n extends Omit<NotificationProps, 'onClose'>, Record<`data-${string}`, any> {\n /** Notification id, can be used to close or update notification */\n id?: string;\n\n /** Position of the notification, if not set, the position is determined based on `position` prop on Notifications component */\n position?: NotificationPosition;\n\n /** Notification message, required for all notifications */\n message: React.ReactNode;\n\n /** Display priority. Higher numbers are shown before lower ones when the number of\n * active notifications exceeds `limit`. Notifications with equal priority keep insertion\n * order (FIFO). @default 0 */\n priority?: number;\n\n /** Determines whether notification should be closed automatically,\n * number is auto close timeout in ms, overrides `autoClose` from `Notifications`\n * */\n autoClose?: boolean | number;\n\n /** Determines whether notification can be closed with close button, drag or horizontal scroll swipe, `true` by default */\n allowClose?: boolean;\n\n /** Called when notification closes */\n onClose?: (props: NotificationData) => void;\n\n /** Called when notification opens */\n onOpen?: (props: NotificationData) => void;\n}\n\nexport interface NotificationsState {\n notifications: NotificationData[];\n queue: NotificationData[];\n defaultPosition: NotificationPosition;\n limit: number;\n}\n\nexport type NotificationsStore = MantineStore<NotificationsState>;\n\ninterface SequencedNotificationData extends NotificationData {\n __sequence?: number;\n}\n\nlet notificationSequence = 0;\n\nfunction getDistributedNotifications(\n data: SequencedNotificationData[],\n defaultPosition: NotificationPosition,\n limit: number\n) {\n const queue: NotificationData[] = [];\n const notifications: NotificationData[] = [];\n const groups = new Map<string, SequencedNotificationData[]>();\n\n for (const item of data) {\n const position = item.position || defaultPosition;\n const group = groups.get(position);\n if (group) {\n group.push(item);\n } else {\n groups.set(position, [item]);\n }\n }\n\n for (const group of groups.values()) {\n group.sort(\n (a, b) => (b.priority ?? 0) - (a.priority ?? 0) || (a.__sequence ?? 0) - (b.__sequence ?? 0)\n );\n group.forEach((item, index) => {\n if (index < limit) {\n notifications.push(item);\n } else {\n queue.push(item);\n }\n });\n }\n\n return { notifications, queue };\n}\n\nexport const createNotificationsStore = () =>\n createStore<NotificationsState>({\n notifications: [],\n queue: [],\n defaultPosition: 'bottom-right',\n limit: 5,\n });\n\nexport const notificationsStore = createNotificationsStore();\nexport const useNotifications = (store: NotificationsStore = notificationsStore) => useStore(store);\n\nexport function updateNotificationsState(\n store: NotificationsStore,\n update: (notifications: NotificationData[]) => NotificationData[]\n) {\n const state = store.getState();\n const notifications = update([...state.notifications, ...state.queue]);\n\n for (const item of notifications as SequencedNotificationData[]) {\n if (item.__sequence === undefined) {\n item.__sequence = notificationSequence;\n notificationSequence += 1;\n }\n }\n\n const updated = getDistributedNotifications(notifications, state.defaultPosition, state.limit);\n\n store.setState({\n notifications: updated.notifications,\n queue: updated.queue,\n limit: state.limit,\n defaultPosition: state.defaultPosition,\n });\n}\n\nexport function showNotification(\n notification: NotificationData,\n store: NotificationsStore = notificationsStore\n) {\n const id = notification.id || randomId();\n\n updateNotificationsState(store, (notifications) => {\n if (notification.id && notifications.some((n) => n.id === notification.id)) {\n return notifications;\n }\n\n return [...notifications, { ...notification, id }];\n });\n\n return id;\n}\n\nexport function hideNotification(id: string, store: NotificationsStore = notificationsStore) {\n updateNotificationsState(store, (notifications) =>\n notifications.filter((notification) => {\n if (notification.id === id) {\n notification.onClose?.(notification);\n return false;\n }\n\n return true;\n })\n );\n\n return id;\n}\n\nexport function updateNotification(\n notification: NotificationData,\n store: NotificationsStore = notificationsStore\n) {\n updateNotificationsState(store, (notifications) =>\n notifications.map((item) => {\n if (item.id === notification.id) {\n return { ...item, ...notification };\n }\n\n return item;\n })\n );\n\n return notification.id;\n}\n\nexport function cleanNotifications(store: NotificationsStore = notificationsStore) {\n updateNotificationsState(store, () => []);\n}\n\nexport function cleanNotificationsQueue(store: NotificationsStore = notificationsStore) {\n const { defaultPosition, limit } = store.getState();\n updateNotificationsState(\n store,\n (notifications) =>\n getDistributedNotifications(notifications, defaultPosition, limit).notifications\n );\n}\n\nexport const notifications = {\n show: showNotification,\n hide: hideNotification,\n update: updateNotification,\n clean: cleanNotifications,\n cleanQueue: cleanNotificationsQueue,\n updateState: updateNotificationsState,\n} as const;\n"],"mappings":";;;;AAwDA,IAAI,uBAAuB;AAE3B,SAAS,4BACP,MACA,iBACA,OACA;CACA,MAAM,QAA4B,CAAC;CACnC,MAAM,gBAAoC,CAAC;CAC3C,MAAM,yBAAS,IAAI,IAAyC;CAE5D,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,WAAW,KAAK,YAAY;EAClC,MAAM,QAAQ,OAAO,IAAI,QAAQ;EACjC,IAAI,OACF,MAAM,KAAK,IAAI;OAEf,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC;CAE/B;CAEA,KAAK,MAAM,SAAS,OAAO,OAAO,GAAG;EACnC,MAAM,MACH,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,YAAY,OAAO,EAAE,cAAc,MAAM,EAAE,cAAc,EAC5F;EACA,MAAM,SAAS,MAAM,UAAU;GAC7B,IAAI,QAAQ,OACV,cAAc,KAAK,IAAI;QAEvB,MAAM,KAAK,IAAI;EAEnB,CAAC;CACH;CAEA,OAAO;EAAE;EAAe;CAAM;AAChC;AAEA,MAAa,iCACX,YAAgC;CAC9B,eAAe,CAAC;CAChB,OAAO,CAAC;CACR,iBAAiB;CACjB,OAAO;AACT,CAAC;AAEH,MAAa,qBAAqB,yBAAyB;AAC3D,MAAa,oBAAoB,QA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B,oBAAoB;CACtF,MAAM,EAAE,iBAAiB,UAAU,MAAM,SAAS;CAClD,yBACE,QACC,kBACC,4BAA4B,eAAe,iBAAiB,KAAK,CAAC,CAAC,aACvE;AACF;AAEA,MAAa,gBAAgB;CAC3B,MAAM;CACN,MAAM;CACN,QAAQ;CACR,OAAO;CACP,YAAY;CACZ,aAAa;AACf"}
1
+ {"version":3,"file":"notifications.store.mjs","names":[],"sources":["../src/notifications.store.ts"],"sourcesContent":["import { NotificationProps } from '@mantine/core';\nimport { randomId } from '@mantine/hooks';\nimport { createStore, MantineStore, useStore } from '@mantine/store';\n\nexport type NotificationPosition =\n | 'top-left'\n | 'top-right'\n | 'top-center'\n | 'bottom-left'\n | 'bottom-right'\n | 'bottom-center';\n\nexport interface NotificationData\n extends Omit<NotificationProps, 'onClose'>, Record<`data-${string}`, any> {\n /** Notification id, can be used to close or update notification */\n id?: string;\n\n /** Position of the notification, if not set, the position is determined based on `position` prop on Notifications component */\n position?: NotificationPosition;\n\n /** Notification message, required for all notifications */\n message: React.ReactNode;\n\n /** Display priority. Higher numbers are shown before lower ones when the number of\n * active notifications exceeds `limit`. Notifications with equal priority keep insertion\n * order (FIFO). @default 0 */\n priority?: number;\n\n /** Determines whether notification should be closed automatically,\n * number is auto close timeout in ms, overrides `autoClose` from `Notifications`\n * */\n autoClose?: boolean | number;\n\n /** Determines whether notification can be closed with close button, drag or horizontal scroll swipe, `true` by default */\n allowClose?: boolean;\n\n /** Called when notification closes */\n onClose?: (props: NotificationData) => void;\n\n /** Called when notification opens */\n onOpen?: (props: NotificationData) => void;\n\n /** Custom render function that replaces the default notification, overrides `renderNotification` from `Notifications`. Set to `null` to use default rendering when a global `renderNotification` is set. */\n renderNotification?: ((notification: NotificationData) => React.ReactNode) | null;\n}\n\nexport interface NotificationsState {\n notifications: NotificationData[];\n queue: NotificationData[];\n defaultPosition: NotificationPosition;\n limit: number;\n}\n\nexport type NotificationsStore = MantineStore<NotificationsState>;\n\nexport interface SequencedNotificationData extends NotificationData {\n __sequence?: number;\n}\n\nlet notificationSequence = 0;\n\nfunction getDistributedNotifications(\n data: SequencedNotificationData[],\n defaultPosition: NotificationPosition,\n limit: number\n) {\n const queue: NotificationData[] = [];\n const notifications: NotificationData[] = [];\n const groups = new Map<string, SequencedNotificationData[]>();\n\n for (const item of data) {\n const position = item.position || defaultPosition;\n const group = groups.get(position);\n if (group) {\n group.push(item);\n } else {\n groups.set(position, [item]);\n }\n }\n\n for (const group of groups.values()) {\n group.sort(\n (a, b) => (b.priority ?? 0) - (a.priority ?? 0) || (a.__sequence ?? 0) - (b.__sequence ?? 0)\n );\n group.forEach((item, index) => {\n if (index < limit) {\n notifications.push(item);\n } else {\n queue.push(item);\n }\n });\n }\n\n return { notifications, queue };\n}\n\nexport const createNotificationsStore = () =>\n createStore<NotificationsState>({\n notifications: [],\n queue: [],\n defaultPosition: 'bottom-right',\n limit: 5,\n });\n\nexport const notificationsStore = createNotificationsStore();\nexport const useNotifications = (store: NotificationsStore = notificationsStore) => useStore(store);\n\nexport function updateNotificationsState(\n store: NotificationsStore,\n update: (notifications: NotificationData[]) => NotificationData[]\n) {\n const state = store.getState();\n const notifications = update([...state.notifications, ...state.queue]);\n\n for (const item of notifications as SequencedNotificationData[]) {\n if (item.__sequence === undefined) {\n item.__sequence = notificationSequence;\n notificationSequence += 1;\n }\n }\n\n const updated = getDistributedNotifications(notifications, state.defaultPosition, state.limit);\n\n store.setState({\n notifications: updated.notifications,\n queue: updated.queue,\n limit: state.limit,\n defaultPosition: state.defaultPosition,\n });\n}\n\nexport function showNotification(\n notification: NotificationData,\n store: NotificationsStore = notificationsStore\n) {\n const id = notification.id || randomId();\n\n updateNotificationsState(store, (notifications) => {\n if (notification.id && notifications.some((n) => n.id === notification.id)) {\n return notifications;\n }\n\n return [...notifications, { ...notification, id }];\n });\n\n return id;\n}\n\nexport function hideNotification(id: string, store: NotificationsStore = notificationsStore) {\n updateNotificationsState(store, (notifications) =>\n notifications.filter((notification) => {\n if (notification.id === id) {\n notification.onClose?.(notification);\n return false;\n }\n\n return true;\n })\n );\n\n return id;\n}\n\nexport function updateNotification(\n notification: NotificationData,\n store: NotificationsStore = notificationsStore\n) {\n updateNotificationsState(store, (notifications) =>\n notifications.map((item) => {\n if (item.id === notification.id) {\n return { ...item, ...notification };\n }\n\n return item;\n })\n );\n\n return notification.id;\n}\n\nexport function cleanNotifications(store: NotificationsStore = notificationsStore) {\n updateNotificationsState(store, () => []);\n}\n\nexport function cleanNotificationsQueue(store: NotificationsStore = notificationsStore) {\n const { defaultPosition, limit } = store.getState();\n updateNotificationsState(\n store,\n (notifications) =>\n getDistributedNotifications(notifications, defaultPosition, limit).notifications\n );\n}\n\nexport const notifications = {\n show: showNotification,\n hide: hideNotification,\n update: updateNotification,\n clean: cleanNotifications,\n cleanQueue: cleanNotificationsQueue,\n updateState: updateNotificationsState,\n} as const;\n"],"mappings":";;;;AA2DA,IAAI,uBAAuB;AAE3B,SAAS,4BACP,MACA,iBACA,OACA;CACA,MAAM,QAA4B,CAAC;CACnC,MAAM,gBAAoC,CAAC;CAC3C,MAAM,yBAAS,IAAI,IAAyC;CAE5D,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,WAAW,KAAK,YAAY;EAClC,MAAM,QAAQ,OAAO,IAAI,QAAQ;EACjC,IAAI,OACF,MAAM,KAAK,IAAI;OAEf,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC;CAE/B;CAEA,KAAK,MAAM,SAAS,OAAO,OAAO,GAAG;EACnC,MAAM,MACH,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,YAAY,OAAO,EAAE,cAAc,MAAM,EAAE,cAAc,EAC5F;EACA,MAAM,SAAS,MAAM,UAAU;GAC7B,IAAI,QAAQ,OACV,cAAc,KAAK,IAAI;QAEvB,MAAM,KAAK,IAAI;EAEnB,CAAC;CACH;CAEA,OAAO;EAAE;EAAe;CAAM;AAChC;AAEA,MAAa,iCACX,YAAgC;CAC9B,eAAe,CAAC;CAChB,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EA,SAAgB,mBAAmB,QAA4B,oBAAoB;CACjF,yBAAyB,aAAa,CAAC,CAAC;AAC1C;AAEA,SAAgB,wBAAwB,QAA4B,oBAAoB;CACtF,MAAM,EAAE,iBAAiB,UAAU,MAAM,SAAS;CAClD,yBACE,QACC,kBACC,4BAA4B,eAAe,iBAAiB,KAAK,CAAC,CAAC,aACvE;AACF;AAEA,MAAa,gBAAgB;CAC3B,MAAM;CACN,MAAM;CACN,QAAQ;CACR,OAAO;CACP,YAAY;CACZ,aAAa;AACf"}
@@ -10,9 +10,18 @@ interface NotificationContainerProps extends NotificationProps {
10
10
  paused: boolean;
11
11
  onHoverStart?: () => void;
12
12
  onHoverEnd?: () => void;
13
+ onExpandRequest?: () => void;
13
14
  ref?: React.Ref<HTMLDivElement>;
15
+ renderNotification?: ((notification: NotificationData) => React.ReactNode) | null;
16
+ layout?: 'default' | 'stacked';
17
+ stackIndex?: number;
18
+ stackSize?: number;
19
+ stackPosition?: string;
20
+ stackExpanded?: boolean;
21
+ stackExpandedOffset?: number;
22
+ transitionState?: string;
14
23
  }
15
- export declare function NotificationContainer({ data, onHide, autoClose, transitionDuration, allowDragDismiss, allowScrollDismiss, paused, onHoverStart, onHoverEnd, ref, style, ...others }: NotificationContainerProps): import("react/jsx-runtime").JSX.Element;
24
+ export declare function NotificationContainer({ data, onHide, autoClose, transitionDuration, allowDragDismiss, allowScrollDismiss, paused, onHoverStart, onHoverEnd, onExpandRequest, ref, style, renderNotification, layout, stackIndex, stackSize, stackPosition, stackExpanded, stackExpandedOffset, transitionState, ...others }: NotificationContainerProps): import("react").JSX.Element;
16
25
  export declare namespace NotificationContainer {
17
26
  var displayName: string;
18
27
  }
@@ -1,5 +1,5 @@
1
1
  import { BasePortalProps, BoxProps, ElementProps, Factory, StylesApiProps } from '@mantine/core';
2
- import { NotificationPosition, notifications, NotificationsStore } from './notifications.store';
2
+ import { NotificationData, NotificationPosition, notifications, NotificationsStore } from './notifications.store';
3
3
  export type NotificationsStylesNames = 'root' | 'notification';
4
4
  export type NotificationsCssVariables = {
5
5
  root: '--notifications-z-index' | '--notifications-container-width';
@@ -31,6 +31,10 @@ export interface NotificationsProps extends BoxProps, StylesApiProps<Notificatio
31
31
  withinPortal?: boolean;
32
32
  /** Determines which notifications should pause auto close on hover, `'all'` – pauses auto close for all notifications when any notification is hovered, `'notification'` – pauses auto close only for the hovered notification @default 'all' */
33
33
  pauseResetOnHover?: 'all' | 'notification';
34
+ /** Custom render function that replaces the default notification, can be overridden per notification */
35
+ renderNotification?: (notification: NotificationData) => React.ReactNode;
36
+ /** Controls how notifications are positioned in the stack, `'default'` – standard vertical list, `'stacked'` – only first notification is fully visible, rest are stacked behind @default 'default' */
37
+ layout?: 'default' | 'stacked';
34
38
  }
35
39
  export type NotificationsFactory = Factory<{
36
40
  props: NotificationsProps;
@@ -22,6 +22,8 @@ export interface NotificationData extends Omit<NotificationProps, 'onClose'>, Re
22
22
  onClose?: (props: NotificationData) => void;
23
23
  /** Called when notification opens */
24
24
  onOpen?: (props: NotificationData) => void;
25
+ /** Custom render function that replaces the default notification, overrides `renderNotification` from `Notifications`. Set to `null` to use default rendering when a global `renderNotification` is set. */
26
+ renderNotification?: ((notification: NotificationData) => React.ReactNode) | null;
25
27
  }
26
28
  export interface NotificationsState {
27
29
  notifications: NotificationData[];
@@ -30,6 +32,9 @@ export interface NotificationsState {
30
32
  limit: number;
31
33
  }
32
34
  export type NotificationsStore = MantineStore<NotificationsState>;
35
+ export interface SequencedNotificationData extends NotificationData {
36
+ __sequence?: number;
37
+ }
33
38
  export declare const createNotificationsStore: () => MantineStore<NotificationsState>;
34
39
  export declare const notificationsStore: MantineStore<NotificationsState>;
35
40
  export declare const useNotifications: (store?: NotificationsStore) => NotificationsState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantine/notifications",
3
- "version": "9.5.2",
3
+ "version": "9.6.0",
4
4
  "description": "Mantine notifications system",
5
5
  "homepage": "https://mantine.dev",
6
6
  "license": "MIT",
@@ -44,20 +44,20 @@
44
44
  "directory": "packages/@mantine/notifications"
45
45
  },
46
46
  "peerDependencies": {
47
- "@mantine/core": "9.5.2",
48
- "@mantine/hooks": "9.5.2",
47
+ "@mantine/core": "9.6.0",
48
+ "@mantine/hooks": "9.6.0",
49
49
  "react": "^19.2.0",
50
50
  "react-dom": "^19.2.0"
51
51
  },
52
52
  "dependencies": {
53
- "@mantine/store": "9.5.2",
53
+ "@mantine/store": "9.6.0",
54
54
  "react-transition-group": "4.4.5"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@mantine-tests/core": "workspace:*",
58
58
  "@mantine/core": "workspace:*",
59
59
  "@mantine/hooks": "workspace:*",
60
- "react": "19.2.7",
61
- "react-dom": "19.2.7"
60
+ "react": "19.2.8",
61
+ "react-dom": "19.2.8"
62
62
  }
63
63
  }
package/styles.css CHANGED
@@ -40,3 +40,11 @@
40
40
  .m_5ed0edd0 + .m_5ed0edd0 {
41
41
  margin-top: var(--mantine-spacing-md);
42
42
  }
43
+
44
+ :where([data-layout='stacked']) .m_5ed0edd0 {
45
+ margin-top: 0;
46
+ }
47
+
48
+ .m_b37d9ac7:where([data-layout='stacked']) > * {
49
+ display: grid;
50
+ }
package/styles.layer.css CHANGED
@@ -40,4 +40,12 @@
40
40
  .m_5ed0edd0 + .m_5ed0edd0 {
41
41
  margin-top: var(--mantine-spacing-md);
42
42
  }
43
+
44
+ :where([data-layout='stacked']) .m_5ed0edd0 {
45
+ margin-top: 0;
46
+ }
47
+
48
+ .m_b37d9ac7:where([data-layout='stacked']) > * {
49
+ display: grid;
50
+ }
43
51
  }