Skip to content

Commit 89d5c97

Browse files
authored
feat(toast): add functionality to make toast persistent until manually cleared (#3410)
1 parent 2060383 commit 89d5c97

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/packages/toast/demos/h5/demo2.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { useState } from 'react'
22
import { Toast, Cell, Button } from '@nutui/nutui-react'
33

44
const Demo2 = () => {
@@ -16,6 +16,17 @@ const Demo2 = () => {
1616
})
1717
}
1818

19+
const [neverDisappear, setNeverDisappear] = useState(false)
20+
21+
const hideToastStyle: React.CSSProperties = neverDisappear
22+
? {
23+
position: 'fixed',
24+
top: '53%',
25+
left: '35%',
26+
zIndex: 9999,
27+
}
28+
: {}
29+
1930
return (
2031
<>
2132
<Cell
@@ -28,18 +39,24 @@ const Demo2 = () => {
2839
title="Toast 不消失"
2940
onClick={(
3041
event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>
31-
) => permanentToast('Toast 不消失')}
32-
/>
33-
<Button
34-
style={{ margin: 8 }}
35-
type="primary"
36-
shape="round"
37-
onClick={() => {
38-
Toast.clear()
42+
) => {
43+
setNeverDisappear(true)
44+
permanentToast('Toast 不消失')
3945
}}
40-
>
41-
隐藏Toast
42-
</Button>
46+
/>
47+
<div style={hideToastStyle}>
48+
<Button
49+
style={{ margin: 8 }}
50+
type="primary"
51+
shape="round"
52+
onClick={() => {
53+
setNeverDisappear(false)
54+
Toast.clear()
55+
}}
56+
>
57+
隐藏Toast
58+
</Button>
59+
</div>
4360
</>
4461
)
4562
}

0 commit comments

Comments
 (0)