| 1 |
import { useState } from 'react'; |
| 2 |
import { |
| 3 |
NotificationDrawer, |
| 4 |
NotificationDrawerBody, |
| 5 |
NotificationDrawerHeader, |
| 6 |
NotificationDrawerList, |
| 7 |
NotificationDrawerListItem, |
| 8 |
NotificationDrawerListItemBody, |
| 9 |
NotificationDrawerListItemHeader, |
| 10 |
Dropdown, |
| 11 |
DropdownList, |
| 12 |
DropdownItem, |
| 13 |
MenuToggle, |
| 14 |
MenuToggleElement |
| 15 |
} from '@patternfly/react-core'; |
| 16 |
import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon'; |
| 17 |
|
| 18 |
export const NotificationDrawerBasic: React.FunctionComponent = () => { |
| 19 |
const [isOpenMap, setIsOpenMap] = useState(new Array(7).fill(false)); |
| 20 |
|
| 21 |
const onToggle = (index: number) => () => { |
| 22 |
const newState = [...isOpenMap.slice(0, index), !isOpenMap[index], ...isOpenMap.slice(index + 1)]; |
| 23 |
setIsOpenMap(newState); |
| 24 |
}; |
| 25 |
|
| 26 |
const onSelect = () => { |
| 27 |
setIsOpenMap(new Array(7).fill(false)); |
| 28 |
}; |
| 29 |
|
| 30 |
const onDrawerClose = (_event: React.MouseEvent<Element, MouseEvent> | KeyboardEvent) => { |
| 31 |
setIsOpenMap(new Array(7).fill(false)); |
| 32 |
}; |
| 33 |
|
| 34 |
const [isOpen0, isOpen1, isOpen2, isOpen3, isOpen4, isOpen5, isOpen6] = isOpenMap; |
| 35 |
const dropdownItems = ( |
| 36 |
<> |
| 37 |
<DropdownItem>Action</DropdownItem> |
| 38 |
<DropdownItem |
| 39 |
to="#default-link2" |
| 40 |
// Prevent the default onClick functionality for example purposes |
| 41 |
onClick={(ev: any) => ev.preventDefault()} |
| 42 |
> |
| 43 |
Link |
| 44 |
</DropdownItem> |
| 45 |
<DropdownItem isDisabled>Disabled Action</DropdownItem> |
| 46 |
<DropdownItem isDisabled to="#default-link4"> |
| 47 |
Disabled Link |
| 48 |
</DropdownItem> |
| 49 |
</> |
| 50 |
); |
| 51 |
|
| 52 |
return ( |
| 53 |
<NotificationDrawer> |
| 54 |
<NotificationDrawerHeader count={3} onClose={onDrawerClose}> |
| 55 |
<Dropdown |
| 56 |
onSelect={onSelect} |
| 57 |
isOpen={isOpen0} |
| 58 |
onOpenChange={() => setIsOpenMap(new Array(7).fill(false))} |
| 59 |
popperProps={{ position: 'right' }} |
| 60 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 61 |
<MenuToggle |
| 62 |
ref={toggleRef} |
| 63 |
isExpanded={isOpen0} |
| 64 |
onClick={onToggle(0)} |
| 65 |
variant="plain" |
| 66 |
aria-label={`Basic example header kebab toggle`} |
| 67 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 68 |
/> |
| 69 |
)} |
| 70 |
> |
| 71 |
<DropdownList>{dropdownItems}</DropdownList> |
| 72 |
</Dropdown> |
| 73 |
</NotificationDrawerHeader> |
| 74 |
<NotificationDrawerBody> |
| 75 |
<NotificationDrawerList aria-label="Notifications in the basic example"> |
| 76 |
<NotificationDrawerListItem variant="info"> |
| 77 |
<NotificationDrawerListItemHeader |
| 78 |
variant="info" |
| 79 |
title="Unread info notification title" |
| 80 |
srTitle="Info notification:" |
| 81 |
> |
| 82 |
<Dropdown |
| 83 |
onSelect={onSelect} |
| 84 |
isOpen={isOpen1} |
| 85 |
onOpenChange={() => setIsOpenMap(new Array(7).fill(false))} |
| 86 |
popperProps={{ position: 'right' }} |
| 87 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 88 |
<MenuToggle |
| 89 |
ref={toggleRef} |
| 90 |
isExpanded={isOpen0} |
| 91 |
onClick={onToggle(1)} |
| 92 |
variant="plain" |
| 93 |
aria-label={`Basic example notification 1 kebab toggle`} |
| 94 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 95 |
/> |
| 96 |
)} |
| 97 |
> |
| 98 |
<DropdownList>{dropdownItems}</DropdownList> |
| 99 |
</Dropdown> |
| 100 |
</NotificationDrawerListItemHeader> |
| 101 |
<NotificationDrawerListItemBody timestamp="5 minutes ago"> |
| 102 |
This is an info notification description. |
| 103 |
</NotificationDrawerListItemBody> |
| 104 |
</NotificationDrawerListItem> |
| 105 |
<NotificationDrawerListItem variant="danger"> |
| 106 |
<NotificationDrawerListItemHeader |
| 107 |
variant="danger" |
| 108 |
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." |
| 109 |
srTitle="Danger notification:" |
| 110 |
> |
| 111 |
<Dropdown |
| 112 |
onSelect={onSelect} |
| 113 |
isOpen={isOpen2} |
| 114 |
onOpenChange={() => setIsOpenMap(new Array(7).fill(false))} |
| 115 |
popperProps={{ position: 'right' }} |
| 116 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 117 |
<MenuToggle |
| 118 |
ref={toggleRef} |
| 119 |
isExpanded={isOpen2} |
| 120 |
onClick={onToggle(2)} |
| 121 |
variant="plain" |
| 122 |
aria-label={`Basic example notification 2 kebab toggle`} |
| 123 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 124 |
/> |
| 125 |
)} |
| 126 |
> |
| 127 |
<DropdownList>{dropdownItems}</DropdownList> |
| 128 |
</Dropdown> |
| 129 |
</NotificationDrawerListItemHeader> |
| 130 |
<NotificationDrawerListItemBody timestamp="10 minutes ago"> |
| 131 |
This is a danger notification description. This is a long description to show how the title will wrap if |
| 132 |
it is long and wraps to multiple lines. |
| 133 |
</NotificationDrawerListItemBody> |
| 134 |
</NotificationDrawerListItem> |
| 135 |
<NotificationDrawerListItem variant="danger"> |
| 136 |
<NotificationDrawerListItemHeader |
| 137 |
truncateTitle={1} |
| 138 |
variant="danger" |
| 139 |
title="Unread danger notification title. 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." |
| 140 |
srTitle="Danger notification:" |
| 141 |
> |
| 142 |
<Dropdown |
| 143 |
onSelect={onSelect} |
| 144 |
isOpen={isOpen3} |
| 145 |
onOpenChange={() => setIsOpenMap(new Array(7).fill(false))} |
| 146 |
popperProps={{ position: 'right' }} |
| 147 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 148 |
<MenuToggle |
| 149 |
ref={toggleRef} |
| 150 |
isExpanded={isOpen3} |
| 151 |
onClick={onToggle(3)} |
| 152 |
variant="plain" |
| 153 |
aria-label={`Basic example notification 3 kebab toggle`} |
| 154 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 155 |
/> |
| 156 |
)} |
| 157 |
> |
| 158 |
<DropdownList>{dropdownItems}</DropdownList> |
| 159 |
</Dropdown> |
| 160 |
</NotificationDrawerListItemHeader> |
| 161 |
<NotificationDrawerListItemBody timestamp="10 minutes ago"> |
| 162 |
This is a danger notification description. This is a long description to show how the title will wrap if |
| 163 |
it is long and wraps to multiple lines. |
| 164 |
</NotificationDrawerListItemBody> |
| 165 |
</NotificationDrawerListItem> |
| 166 |
<NotificationDrawerListItem variant="warning" isRead> |
| 167 |
<NotificationDrawerListItemHeader |
| 168 |
variant="warning" |
| 169 |
title="Read warning notification title" |
| 170 |
srTitle="Warning notification:" |
| 171 |
> |
| 172 |
<Dropdown |
| 173 |
onSelect={onSelect} |
| 174 |
isOpen={isOpen4} |
| 175 |
onOpenChange={() => setIsOpenMap(new Array(7).fill(false))} |
| 176 |
popperProps={{ position: 'right' }} |
| 177 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 178 |
<MenuToggle |
| 179 |
ref={toggleRef} |
| 180 |
isExpanded={isOpen4} |
| 181 |
onClick={onToggle(4)} |
| 182 |
variant="plain" |
| 183 |
aria-label={`Basic example notification 4 kebab toggle`} |
| 184 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 185 |
/> |
| 186 |
)} |
| 187 |
> |
| 188 |
<DropdownList>{dropdownItems}</DropdownList> |
| 189 |
</Dropdown> |
| 190 |
</NotificationDrawerListItemHeader> |
| 191 |
<NotificationDrawerListItemBody timestamp="20 minutes ago"> |
| 192 |
This is a warning notification description. |
| 193 |
</NotificationDrawerListItemBody> |
| 194 |
</NotificationDrawerListItem> |
| 195 |
<NotificationDrawerListItem variant="success" isRead> |
| 196 |
<NotificationDrawerListItemHeader |
| 197 |
variant="success" |
| 198 |
title="Read success notification title" |
| 199 |
srTitle="Success notification:" |
| 200 |
> |
| 201 |
<Dropdown |
| 202 |
onSelect={onSelect} |
| 203 |
isOpen={isOpen5} |
| 204 |
onOpenChange={() => setIsOpenMap(new Array(7).fill(false))} |
| 205 |
popperProps={{ position: 'right' }} |
| 206 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 207 |
<MenuToggle |
| 208 |
ref={toggleRef} |
| 209 |
isExpanded={isOpen5} |
| 210 |
onClick={onToggle(5)} |
| 211 |
variant="plain" |
| 212 |
aria-label={`Basic example notification 5 kebab toggle`} |
| 213 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 214 |
/> |
| 215 |
)} |
| 216 |
> |
| 217 |
<DropdownList>{dropdownItems}</DropdownList> |
| 218 |
</Dropdown> |
| 219 |
</NotificationDrawerListItemHeader> |
| 220 |
<NotificationDrawerListItemBody timestamp="30 minutes ago"> |
| 221 |
This is a success notification description. |
| 222 |
</NotificationDrawerListItemBody> |
| 223 |
</NotificationDrawerListItem> |
| 224 |
<NotificationDrawerListItem isRead> |
| 225 |
<NotificationDrawerListItemHeader title="Read (default) notification title" srTitle="notification:"> |
| 226 |
<Dropdown |
| 227 |
onSelect={onSelect} |
| 228 |
isOpen={isOpen6} |
| 229 |
onOpenChange={() => setIsOpenMap(new Array(7).fill(false))} |
| 230 |
popperProps={{ position: 'right' }} |
| 231 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 232 |
<MenuToggle |
| 233 |
ref={toggleRef} |
| 234 |
isExpanded={isOpen6} |
| 235 |
onClick={onToggle(6)} |
| 236 |
variant="plain" |
| 237 |
aria-label={`Basic example notification 6 kebab toggle`} |
| 238 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 239 |
/> |
| 240 |
)} |
| 241 |
> |
| 242 |
<DropdownList>{dropdownItems}</DropdownList> |
| 243 |
</Dropdown> |
| 244 |
</NotificationDrawerListItemHeader> |
| 245 |
<NotificationDrawerListItemBody timestamp="35 minutes ago"> |
| 246 |
This is a default notification description. |
| 247 |
</NotificationDrawerListItemBody> |
| 248 |
</NotificationDrawerListItem> |
| 249 |
</NotificationDrawerList> |
| 250 |
</NotificationDrawerBody> |
| 251 |
</NotificationDrawer> |
| 252 |
); |
| 253 |
}; |