Skip to content

Commit f99ff51

Browse files
committed
simplify notification position
1 parent 41b154f commit f99ff51

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

src/Notification.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ export interface NotificationProps {
4343
icon?: React.ReactNode;
4444
actions?: React.ReactNode;
4545
closable?: ClosableType;
46-
offset?: {
47-
y: number;
48-
};
46+
offset?: number;
4947
notificationIndex?: number;
5048
stackInThreshold?: boolean;
5149
props?: React.HTMLAttributes<HTMLDivElement> & Record<string, any>;
@@ -213,7 +211,7 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
213211
};
214212

215213
if (mergedOffset) {
216-
mergedStyle['--notification-y'] = `${mergedOffset.y}px`;
214+
mergedStyle['--notification-y'] = `${mergedOffset}px`;
217215
}
218216

219217
return (

src/hooks/useListPosition/index.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import * as React from 'react';
22
import type { StackConfig } from '../../interface';
33
import useSizes from './useSizes';
44

5-
export type NodePosition = {
6-
y: number;
7-
};
8-
95
/**
106
* Calculates each notification's position and the full list height.
117
*/
@@ -20,7 +16,7 @@ export default function useListPosition(
2016
let offsetY = 0;
2117
let nextTotalHeight = 0;
2218
const stackThreshold = stack?.threshold ?? 0;
23-
const nextNotificationPosition = new Map<string, NodePosition>();
19+
const nextNotificationPosition = new Map<string, number>();
2420

2521
configList
2622
.slice()
@@ -29,18 +25,16 @@ export default function useListPosition(
2925
// Walk from newest to oldest so each notice can be positioned after the ones below it.
3026
const key = String(config.key);
3127
const height = sizeMap[key]?.height ?? 0;
32-
const nodePosition = {
33-
y: stack && index > 0 ? offsetY + (stack.offset ?? 0) - height : offsetY,
34-
};
28+
const y = stack && index > 0 ? offsetY + (stack.offset ?? 0) - height : offsetY;
3529

36-
nextNotificationPosition.set(key, nodePosition);
30+
nextNotificationPosition.set(key, y);
3731

3832
if (!stack || index < stackThreshold) {
39-
nextTotalHeight = Math.max(nextTotalHeight, nodePosition.y + height);
33+
nextTotalHeight = Math.max(nextTotalHeight, y + height);
4034
}
4135

4236
if (stack) {
43-
offsetY = nodePosition.y + height;
37+
offsetY = y + height;
4438
} else {
4539
offsetY += height + gap;
4640
}

0 commit comments

Comments
 (0)