Skip to content

Commit cc4a0db

Browse files
committed
feat: Change duration to number|false type
1 parent 307d8a7 commit cc4a0db

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ props details:
9797
<thead>
9898
<tr>
9999
<th style="width: 100px;">name</th>
100-
<th style="width: 50px;">type</th>
100+
<th style="width: 200px;">type</th>
101101
<th style="width: 50px;">default</th>
102102
<th>description</th>
103103
</tr>
@@ -129,8 +129,8 @@ props details:
129129
</tr>
130130
<tr>
131131
<td>duration</td>
132-
<td>number</td>
133-
<td>1.5</td>
132+
<td>number | false</td>
133+
<td>4.5</td>
134134
<td>after duration of time, this notice will disappear.(seconds)</td>
135135
</tr>
136136
<tr>

src/Notice.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ 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 > 0 && showProgress;
41+
const mergedShowProgress = duration && showProgress;
4242

4343
// ======================== Close =========================
4444
const onInternalClose = () => {
@@ -53,7 +53,7 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
5353

5454
// ======================== Effect ========================
5555
React.useEffect(() => {
56-
if (!mergedHovering && duration > 0) {
56+
if (!mergedHovering && duration) {
5757
const start = Date.now() - spentTime;
5858
const timeout = setTimeout(
5959
() => {

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;
22+
duration?: number | false;
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 | null;
9+
duration?: number | false;
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 | null;
35+
duration?: number | false;
3636
}
3737

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

tests/index.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe('Notification.Basic', () => {
162162
</p>
163163
),
164164
key,
165-
duration: null,
165+
duration: false,
166166
});
167167
});
168168

@@ -192,7 +192,7 @@ describe('Notification.Basic', () => {
192192
{notUpdatableValue}
193193
</p>
194194
),
195-
duration: null,
195+
duration: false,
196196
});
197197
});
198198

@@ -204,7 +204,7 @@ describe('Notification.Basic', () => {
204204
</p>
205205
),
206206
key,
207-
duration: null,
207+
duration: false,
208208
});
209209
});
210210

@@ -490,7 +490,7 @@ describe('Notification.Basic', () => {
490490
</p>
491491
),
492492
key,
493-
duration: null,
493+
duration: false,
494494
onClick: () => {
495495
clicked += 1;
496496
},

tests/stack.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('stack', () => {
1717
onClick={() => {
1818
api.open({
1919
content: <div className="context-content">Test</div>,
20-
duration: null,
20+
duration: false,
2121
});
2222
}}
2323
/>
@@ -56,7 +56,7 @@ describe('stack', () => {
5656
onClick={() => {
5757
api.open({
5858
content: <div className="context-content">Test</div>,
59-
duration: null,
59+
duration: false,
6060
closable: true,
6161
});
6262
}}

0 commit comments

Comments
 (0)