Debian Codegraph @

node/@patternfly/react-core/src/components/NotificationDrawer/examples/NotificationDrawerGroups.tsx

raw
1 import { useState } from 'react';
2 import {
3 Button,
4 EmptyState,
5 EmptyStateBody,
6 EmptyStateFooter,
7 NotificationDrawer,
8 NotificationDrawerBody,
9 NotificationDrawerHeader,
10 NotificationDrawerGroup,
11 NotificationDrawerGroupList,
12 NotificationDrawerList,
13 NotificationDrawerListItem,
14 NotificationDrawerListItemBody,
15 NotificationDrawerListItemHeader,
16 EmptyStateVariant,
17 EmptyStateActions,
18 Dropdown,
19 DropdownList,
20 DropdownItem,
21 MenuToggle,
22 MenuToggleElement
23 } from '@patternfly/react-core';
24 import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon';
25 import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
26
27 export const NotificationDrawerGroups: React.FunctionComponent = () => {
28 const [firstGroupExpanded, setFirstGroupExpanded] = useState(false);
29 const [secondGroupExpanded, setSecondGroupExpanded] = useState(true);
30 const [thirdGroupExpanded, setThirdGroupExpanded] = useState(false);
31 const [isOpenMap, setIsOpenMap] = useState({});
32
33 const onToggle = (id: string) => {
34 setIsOpenMap((prevState) => ({ ...prevState, [id]: !prevState[id] }));
35 };
36
37 const onSelect = () => {
38 setIsOpenMap({});
39 };
40
41 const toggleFirstDrawer = (_event: any, value: boolean) => {
42 setFirstGroupExpanded(value);
43 setSecondGroupExpanded(false);
44 setThirdGroupExpanded(false);
45 };
46
47 const toggleSecondDrawer = (_event: any, value: boolean) => {
48 setSecondGroupExpanded(value);
49 setFirstGroupExpanded(false);
50 setThirdGroupExpanded(false);
51 };
52
53 const toggleThirdDrawer = (_event: any, value: boolean) => {
54 setThirdGroupExpanded(value);
55 setSecondGroupExpanded(false);
56 setFirstGroupExpanded(false);
57 };
58
59 const dropdownItems = (
60 <>
61 <DropdownItem>Action</DropdownItem>
62 <DropdownItem
63 to="#default-link2"
64 // Prevent the default onClick functionality for example purposes
65 onClick={(ev: any) => ev.preventDefault()}
66 >
67 Link
68 </DropdownItem>
69 <DropdownItem isDisabled>Disabled Action</DropdownItem>
70 <DropdownItem isDisabled to="#default-link4">
71 Disabled Link
72 </DropdownItem>
73 </>
74 );
75
76 return (
77 <NotificationDrawer>
78 <NotificationDrawerHeader count={4}>
79 <Dropdown
80 onSelect={onSelect}
81 isOpen={isOpenMap['groups-kebab-toggle-1'] || false}
82 onOpenChange={() => setIsOpenMap({})}
83 popperProps={{ position: 'right' }}
84 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
85 <MenuToggle
86 ref={toggleRef}
87 id="groups-kebab-toggle-1"
88 isExpanded={isOpenMap['groups-kebab-toggle-1'] || false}
89 onClick={() => onToggle('groups-kebab-toggle-1')}
90 variant="plain"
91 aria-label={`Groups example header kebab toggle`}
92 icon={<RhUiEllipsisVerticalFillIcon />}
93 />
94 )}
95 >
96 <DropdownList>{dropdownItems}</DropdownList>
97 </Dropdown>
98 </NotificationDrawerHeader>
99 <NotificationDrawerBody>
100 <NotificationDrawerGroupList>
101 <NotificationDrawerGroup
102 title="First notification group"
103 isExpanded={firstGroupExpanded}
104 count={2}
105 onExpand={toggleFirstDrawer}
106 >
107 <NotificationDrawerList isHidden={!firstGroupExpanded} aria-label="Notifications in the first group">
108 <NotificationDrawerListItem variant="info">
109 <NotificationDrawerListItemHeader
110 variant="info"
111 title="Unread info notification title"
112 srTitle="Info notification:"
113 >
114 <Dropdown
115 onSelect={onSelect}
116 isOpen={isOpenMap['groups-kebab-toggle-2'] || false}
117 onOpenChange={() => setIsOpenMap({})}
118 popperProps={{ position: 'right' }}
119 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
120 <MenuToggle
121 ref={toggleRef}
122 id="groups-kebab-toggle-2"
123 isExpanded={isOpenMap['groups-kebab-toggle-2'] || false}
124 onClick={() => onToggle('groups-kebab-toggle-2')}
125 variant="plain"
126 aria-label={`Groups example group 1 notification 1 kebab toggle`}
127 icon={<RhUiEllipsisVerticalFillIcon />}
128 />
129 )}
130 >
131 <DropdownList>{dropdownItems}</DropdownList>
132 </Dropdown>
133 </NotificationDrawerListItemHeader>
134 <NotificationDrawerListItemBody timestamp="5 minutes ago">
135 This is an info notification description.
136 </NotificationDrawerListItemBody>
137 </NotificationDrawerListItem>
138 <NotificationDrawerListItem variant="danger">
139 <NotificationDrawerListItemHeader
140 variant="danger"
141 title="Unread danger notification title. This is a long title to show how the title will wrap if it is long and wraps to multiple lines."
142 srTitle="Danger notification:"
143 >
144 <Dropdown
145 onSelect={onSelect}
146 isOpen={isOpenMap['groups-kebab-toggle-3'] || false}
147 onOpenChange={() => setIsOpenMap({})}
148 popperProps={{ position: 'right' }}
149 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
150 <MenuToggle
151 ref={toggleRef}
152 id="groups-kebab-toggle-3"
153 isExpanded={isOpenMap['groups-kebab-toggle-3'] || false}
154 onClick={() => onToggle('groups-kebab-toggle-3')}
155 variant="plain"
156 aria-label={`Groups example group 1 notification 2 kebab toggle`}
157 icon={<RhUiEllipsisVerticalFillIcon />}
158 />
159 )}
160 >
161 <DropdownList>{dropdownItems}</DropdownList>
162 </Dropdown>
163 </NotificationDrawerListItemHeader>
164 <NotificationDrawerListItemBody timestamp="10 minutes ago">
165 This is a danger notification description. This is a long description to show how the title will wrap
166 if it is long and wraps to multiple lines.
167 </NotificationDrawerListItemBody>
168 </NotificationDrawerListItem>
169 <NotificationDrawerListItem variant="warning" isRead>
170 <NotificationDrawerListItemHeader
171 variant="warning"
172 title="Read warning notification title"
173 srTitle="Warning notification:"
174 >
175 <Dropdown
176 onSelect={onSelect}
177 isOpen={isOpenMap['groups-kebab-toggle-4'] || false}
178 onOpenChange={() => setIsOpenMap({})}
179 popperProps={{ position: 'right' }}
180 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
181 <MenuToggle
182 ref={toggleRef}
183 id="groups-kebab-toggle-4"
184 isExpanded={isOpenMap['groups-kebab-toggle-4'] || false}
185 onClick={() => onToggle('groups-kebab-toggle-4')}
186 variant="plain"
187 aria-label={`Groups example group 1 notification 3 kebab toggle`}
188 icon={<RhUiEllipsisVerticalFillIcon />}
189 />
190 )}
191 >
192 <DropdownList>{dropdownItems}</DropdownList>
193 </Dropdown>
194 </NotificationDrawerListItemHeader>
195 <NotificationDrawerListItemBody timestamp="20 minutes ago">
196 This is a warning notification description.
197 </NotificationDrawerListItemBody>
198 </NotificationDrawerListItem>
199 <NotificationDrawerListItem variant="success" isRead>
200 <NotificationDrawerListItemHeader
201 variant="success"
202 title="Read success notification title"
203 srTitle="Success notification:"
204 >
205 <Dropdown
206 onSelect={onSelect}
207 isOpen={isOpenMap['groups-kebab-toggle-5'] || false}
208 onOpenChange={() => setIsOpenMap({})}
209 popperProps={{ position: 'right' }}
210 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
211 <MenuToggle
212 ref={toggleRef}
213 id="groups-kebab-toggle-5"
214 isExpanded={isOpenMap['groups-kebab-toggle-5'] || false}
215 onClick={() => onToggle('groups-kebab-toggle-5')}
216 variant="plain"
217 aria-label={`Groups example group 1 notification 4 kebab toggle`}
218 icon={<RhUiEllipsisVerticalFillIcon />}
219 />
220 )}
221 >
222 <DropdownList>{dropdownItems}</DropdownList>
223 </Dropdown>
224 </NotificationDrawerListItemHeader>
225 <NotificationDrawerListItemBody timestamp="30 minutes ago">
226 This is a success notification description.
227 </NotificationDrawerListItemBody>
228 </NotificationDrawerListItem>
229 </NotificationDrawerList>
230 </NotificationDrawerGroup>
231 <NotificationDrawerGroup
232 title="Second notification group"
233 isExpanded={secondGroupExpanded}
234 count={2}
235 onExpand={toggleSecondDrawer}
236 >
237 <NotificationDrawerList isHidden={!secondGroupExpanded} aria-label="Notifications in the second group">
238 <NotificationDrawerListItem variant="info">
239 <NotificationDrawerListItemHeader
240 variant="info"
241 title="Unread info notification title"
242 srTitle="Info notification:"
243 >
244 <Dropdown
245 onSelect={onSelect}
246 isOpen={isOpenMap['groups-kebab-toggle-6'] || false}
247 onOpenChange={() => setIsOpenMap({})}
248 popperProps={{ position: 'right' }}
249 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
250 <MenuToggle
251 ref={toggleRef}
252 id="groups-kebab-toggle-6"
253 isExpanded={isOpenMap['groups-kebab-toggle-6'] || false}
254 onClick={() => onToggle('groups-kebab-toggle-6')}
255 variant="plain"
256 aria-label={`Groups example group 2 notification 1 kebab toggle`}
257 icon={<RhUiEllipsisVerticalFillIcon />}
258 />
259 )}
260 >
261 <DropdownList>{dropdownItems}</DropdownList>
262 </Dropdown>
263 </NotificationDrawerListItemHeader>
264 <NotificationDrawerListItemBody timestamp="5 minutes ago">
265 This is an info notification description.
266 </NotificationDrawerListItemBody>
267 </NotificationDrawerListItem>
268 <NotificationDrawerListItem variant="danger">
269 <NotificationDrawerListItemHeader
270 variant="danger"
271 title="Unread danger notification title. This is a long title to show how the title will wrap if it is long and wraps to multiple lines."
272 srTitle="Danger notification:"
273 >
274 <Dropdown
275 onSelect={onSelect}
276 isOpen={isOpenMap['groups-kebab-toggle-7'] || false}
277 onOpenChange={() => setIsOpenMap({})}
278 popperProps={{ position: 'right' }}
279 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
280 <MenuToggle
281 ref={toggleRef}
282 id="groups-kebab-toggle-7"
283 isExpanded={isOpenMap['groups-kebab-toggle-7'] || false}
284 onClick={() => onToggle('groups-kebab-toggle-7')}
285 variant="plain"
286 aria-label={`Groups example group 2 notification 2 kebab toggle`}
287 icon={<RhUiEllipsisVerticalFillIcon />}
288 />
289 )}
290 >
291 <DropdownList>{dropdownItems}</DropdownList>
292 </Dropdown>
293 </NotificationDrawerListItemHeader>
294 <NotificationDrawerListItemBody timestamp="10 minutes ago">
295 This is a danger notification description. This is a long description to show how the title will wrap
296 if it is long and wraps to multiple lines.
297 </NotificationDrawerListItemBody>
298 </NotificationDrawerListItem>
299 <NotificationDrawerListItem variant="warning" isRead>
300 <NotificationDrawerListItemHeader
301 variant="warning"
302 title="Read warning notification title"
303 srTitle="Warning notification:"
304 >
305 <Dropdown
306 onSelect={onSelect}
307 isOpen={isOpenMap['groups-kebab-toggle-8'] || false}
308 onOpenChange={() => setIsOpenMap({})}
309 popperProps={{ position: 'right' }}
310 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
311 <MenuToggle
312 ref={toggleRef}
313 id="groups-kebab-toggle-8"
314 isExpanded={isOpenMap['groups-kebab-toggle-8'] || false}
315 onClick={() => onToggle('groups-kebab-toggle-8')}
316 variant="plain"
317 aria-label={`Groups example group 2 notification 3 kebab toggle`}
318 icon={<RhUiEllipsisVerticalFillIcon />}
319 />
320 )}
321 >
322 <DropdownList>{dropdownItems}</DropdownList>
323 </Dropdown>
324 </NotificationDrawerListItemHeader>
325 <NotificationDrawerListItemBody timestamp="20 minutes ago">
326 This is a warning notification description.
327 </NotificationDrawerListItemBody>
328 </NotificationDrawerListItem>
329 <NotificationDrawerListItem variant="success" isRead>
330 <NotificationDrawerListItemHeader
331 variant="success"
332 title="Read success notification title"
333 srTitle="Success notification:"
334 >
335 <Dropdown
336 onSelect={onSelect}
337 isOpen={isOpenMap['groups-kebab-toggle-9'] || false}
338 onOpenChange={() => setIsOpenMap({})}
339 popperProps={{ position: 'right' }}
340 toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
341 <MenuToggle
342 ref={toggleRef}
343 id="groups-kebab-toggle-9"
344 isExpanded={isOpenMap['groups-kebab-toggle-9'] || false}
345 onClick={() => onToggle('groups-kebab-toggle-9')}
346 variant="plain"
347 aria-label={`Groups example group 2 notification 4 kebab toggle`}
348 icon={<RhUiEllipsisVerticalFillIcon />}
349 />
350 )}
351 >
352 <DropdownList>{dropdownItems}</DropdownList>
353 </Dropdown>
354 </NotificationDrawerListItemHeader>
355 <NotificationDrawerListItemBody timestamp="30 minutes ago">
356 This is a success notification description.
357 </NotificationDrawerListItemBody>
358 </NotificationDrawerListItem>
359 </NotificationDrawerList>
360 </NotificationDrawerGroup>
361 <NotificationDrawerGroup
362 title="Third notification group. This is a long title to show how the title will be truncated if it is long and will be shown in a single line."
363 isExpanded={thirdGroupExpanded}
364 count={0}
365 onExpand={toggleThirdDrawer}
366 truncateTitle={1}
367 >
368 <NotificationDrawerList isHidden={!thirdGroupExpanded} aria-label="Notifications in the third group">
369 <EmptyState
370 headingLevel="h2"
371 titleText="No alerts found"
372 icon={SearchIcon}
373 variant={EmptyStateVariant.full}
374 >
375 <EmptyStateBody>
376 There are currently no critical alerts firing. There may be firing alerts of other severities or
377 silenced critical alerts however.
378 </EmptyStateBody>
379 <EmptyStateFooter>
380 <EmptyStateActions>
381 <Button variant="link">Action</Button>
382 </EmptyStateActions>
383 </EmptyStateFooter>
384 </EmptyState>
385 </NotificationDrawerList>
386 </NotificationDrawerGroup>
387 </NotificationDrawerGroupList>
388 </NotificationDrawerBody>
389 </NotificationDrawer>
390 );
391 };