Skip to content

Commit e8483f3

Browse files
committed
feat: update
1 parent b9ce131 commit e8483f3

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/Notice.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
3838
const [percent, setPercent] = React.useState(0);
3939
const [spentTime, setSpentTime] = React.useState(0);
4040
const mergedHovering = forcedHovering || hovering;
41-
const mergedShowProgress = duration && showProgress;
41+
const mergedDuration: number = typeof duration === 'number' ? duration : 0;
42+
const mergedShowProgress = mergedDuration > 0 && showProgress;
4243

4344
// ======================== Close =========================
4445
const onInternalClose = () => {
@@ -53,13 +54,13 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
5354

5455
// ======================== Effect ========================
5556
React.useEffect(() => {
56-
if (!mergedHovering && duration) {
57+
if (!mergedHovering && mergedDuration > 0) {
5758
const start = Date.now() - spentTime;
5859
const timeout = setTimeout(
5960
() => {
6061
onInternalClose();
6162
},
62-
duration * 1000 - spentTime,
63+
mergedDuration * 1000 - spentTime,
6364
);
6465

6566
return () => {
@@ -70,7 +71,7 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
7071
};
7172
}
7273
// eslint-disable-next-line react-hooks/exhaustive-deps
73-
}, [duration, mergedHovering, times]);
74+
}, [mergedDuration, mergedHovering, times]);
7475

7576
React.useEffect(() => {
7677
if (!mergedHovering && mergedShowProgress && (pauseOnHover || spentTime === 0)) {
@@ -81,7 +82,7 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
8182
cancelAnimationFrame(animationFrame);
8283
animationFrame = requestAnimationFrame((timestamp) => {
8384
const runtime = timestamp + spentTime - start;
84-
const progress = Math.min(runtime / (duration * 1000), 1);
85+
const progress = Math.min(runtime / (mergedDuration * 1000), 1);
8586
setPercent(progress * 100);
8687
if (progress < 1) {
8788
calculate();
@@ -98,7 +99,7 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
9899
};
99100
}
100101
// eslint-disable-next-line react-hooks/exhaustive-deps
101-
}, [duration, spentTime, mergedHovering, mergedShowProgress, times]);
102+
}, [mergedDuration, spentTime, mergedHovering, mergedShowProgress, times]);
102103

103104
// ======================== Closable ========================
104105
const closableObj = React.useMemo(() => {

src/hooks/useNotification.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface NotificationConfig {
1919
| boolean
2020
| ({ closeIcon?: React.ReactNode; onClose?: VoidFunction } & React.AriaAttributes);
2121
maxCount?: number;
22-
duration?: number | false;
22+
duration?: number | false | null;
2323
showProgress?: boolean;
2424
pauseOnHover?: boolean;
2525
/** @private. Config for notification holder style. Safe to remove if refactor */

src/interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type NoticeSemanticProps = 'wrapper';
66

77
export interface NoticeConfig {
88
content?: React.ReactNode;
9-
duration?: number | false;
9+
duration?: number | false | null;
1010
showProgress?: boolean;
1111
pauseOnHover?: boolean;
1212

@@ -32,7 +32,7 @@ export interface OpenConfig extends NoticeConfig {
3232
key: React.Key;
3333
placement?: Placement;
3434
content?: React.ReactNode;
35-
duration?: number | false;
35+
duration?: number | false | null;
3636
}
3737

3838
export type InnerOpenConfig = OpenConfig & { times?: number };

0 commit comments

Comments
 (0)