Debian Codegraph @

node/@patternfly/react-core/src/components/NotificationBadge/examples/NotificationBadgeWithAnimation.tsx

raw
1 import { useEffect, useState } from 'react';
2 import { NotificationBadge, NotificationBadgeVariant, Button, Stack, StackItem } from '@patternfly/react-core';
3
4 export const NotificationBadgeWithAnimation: React.FunctionComponent = () => {
5 const [count, setCount] = useState(0);
6 const [notify, setNotify] = useState(false);
7
8 useEffect(() => {
9 if (count > 0) {
10 setNotify(true);
11 }
12 }, [count]);
13
14 const onAnimationEnd = () => {
15 setNotify(false);
16 };
17
18 return (
19 <Stack hasGutter>
20 <StackItem>
21 <NotificationBadge
22 variant={NotificationBadgeVariant.read}
23 aria-label="Notification badge with read variant and no count"
24 count={count}
25 shouldNotify={notify}
26 onAnimationEnd={onAnimationEnd}
27 />
28 <NotificationBadge
29 variant={NotificationBadgeVariant.unread}
30 aria-label="Notification badge animation with unread variant and count"
31 count={count}
32 shouldNotify={notify}
33 onAnimationEnd={onAnimationEnd}
34 />
35 <NotificationBadge
36 variant={NotificationBadgeVariant.attention}
37 aria-label="Notification badge animation with attention variant and count"
38 count={count}
39 shouldNotify={notify}
40 onAnimationEnd={onAnimationEnd}
41 />
42 </StackItem>
43 <StackItem>
44 <Button onClick={() => setCount((prevCount) => prevCount + 1)}>Add Notification</Button>
45 </StackItem>
46 </Stack>
47 );
48 };