import React, { useRef, useEffect } from "react";
import { useSnackbar, Button, Page, Box, Text } from "zmp-ui";
export default function HomePage() {
const { openSnackbar, setDownloadProgress, closeSnackbar } = useSnackbar();
const timmerId = useRef();
useEffect(
() => () => {
closeSnackbar();
clearInterval(timmerId.current);
},
[]
);
return (
<Page className='section-container'>
<Text.Title size='small'>Snackbar</Text.Title>
<Box mr={2} mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
icon: true,
text: " Snackbar",
action: {
text: "close",
close: true
},
duration: 10000000
});
}}
>
Default with Action
</Button>
</Box>
<Box mr={2} mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "text"
});
}}
>
Text Only
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "Vertical action",
action: {
text: "close",
close: true
},
verticalAction: true,
icon: true,
duration: 10000000
});
}}
>
Vertical action
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "Default top snackbar",
position: "top"
});
}}
>
Default Top
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "Error",
type: "error"
});
}}
>
Error
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "Success",
type: "success"
});
}}
>
Success
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "Waring",
type: "warning",
duration: 10000
});
}}
>
Warning
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "Loading...",
type: "loading"
});
}}
>
Loading
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "loading...",
type: "countdown",
duration: 5000
});
}}
>
Countdown
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
let i = 0;
timmerId.current = setInterval(() => {
if (i === 0) {
openSnackbar({
text: "download...",
type: "download",
duration: 10000000,
onClose() {
clearInterval(timmerId.current);
}
});
}
if (i < 100) {
setDownloadProgress(++i);
}
if (i === 100) {
setTimeout(() => {
closeSnackbar();
clearInterval(timmerId.current);
}, 1000);
}
}, 100);
}}
>
Download
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "Connected!",
type: "wifi-connected"
});
}}
>
Connect Wifi
</Button>
</Box>
<Box mt={6}>
<Button
variant='secondary'
type='highlight'
onClick={() => {
openSnackbar({
text: "Disconnected!",
type: "wifi-disconnected"
});
}}
>
Disconnect Wifi
</Button>
</Box>
</Page>
);
}