| 1 |
import { Fragment, useState } from 'react'; |
| 2 |
import { |
| 3 |
Badge, |
| 4 |
Button, |
| 5 |
Card, |
| 6 |
CardHeader, |
| 7 |
CardBody, |
| 8 |
CardTitle, |
| 9 |
Content, |
| 10 |
Divider, |
| 11 |
Drawer, |
| 12 |
DrawerActions, |
| 13 |
DrawerPanelBody, |
| 14 |
DrawerCloseButton, |
| 15 |
DrawerContent, |
| 16 |
DrawerContentBody, |
| 17 |
DrawerHead, |
| 18 |
DrawerPanelContent, |
| 19 |
Dropdown, |
| 20 |
DropdownItem, |
| 21 |
DropdownList, |
| 22 |
Flex, |
| 23 |
FlexItem, |
| 24 |
Gallery, |
| 25 |
MenuToggle, |
| 26 |
MenuToggleCheckbox, |
| 27 |
PageSection, |
| 28 |
Pagination, |
| 29 |
Progress, |
| 30 |
Select, |
| 31 |
SelectList, |
| 32 |
SelectOption, |
| 33 |
Title, |
| 34 |
Toolbar, |
| 35 |
ToolbarFilter, |
| 36 |
ToolbarItem, |
| 37 |
ToolbarContent, |
| 38 |
MenuToggleElement |
| 39 |
} from '@patternfly/react-core'; |
| 40 |
import TrashIcon from '@patternfly/react-icons/dist/esm/icons/trash-icon'; |
| 41 |
import pfIcon from './assets/pf-logo-small.svg'; |
| 42 |
import activeMQIcon from './assets/activemq-core_200x150.png'; |
| 43 |
import avroIcon from './assets/camel-avro_200x150.png'; |
| 44 |
import dropBoxIcon from './assets/camel-dropbox_200x150.png'; |
| 45 |
import infinispanIcon from './assets/camel-infinispan_200x150.png'; |
| 46 |
import saxonIcon from './assets/camel-saxon_200x150.png'; |
| 47 |
import sparkIcon from './assets/camel-spark_200x150.png'; |
| 48 |
import swaggerIcon from './assets/camel-swagger-java_200x150.png'; |
| 49 |
import azureIcon from './assets/FuseConnector_Icons_AzureServices.png'; |
| 50 |
import restIcon from './assets/FuseConnector_Icons_REST.png'; |
| 51 |
import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon'; |
| 52 |
import { DashboardWrapper } from '@patternfly/react-core/src/demos/DashboardWrapper'; |
| 53 |
import { data } from '@patternfly/react-core/src/demos/CardView/examples/CardViewData.jsx'; |
| 54 |
|
| 55 |
export const PrimaryDetailCardView: React.FunctionComponent = () => { |
| 56 |
const [totalItemCount, setTotalItemCount] = useState(10); |
| 57 |
const [cardData, setCardData] = useState(data); |
| 58 |
const [isChecked, setIsChecked] = useState(false); |
| 59 |
const [isDrawerExpanded, setIsDrawerExpanded] = useState(false); |
| 60 |
const [selectedItems, setSelectedItems] = useState<number[]>([]); |
| 61 |
const [areAllSelected, setAreAllSelected] = useState<boolean>(false); |
| 62 |
const [splitButtonDropdownIsOpen, setSplitButtonDropdownIsOpen] = useState(false); |
| 63 |
const [isLowerToolbarDropdownOpen, setIsLowerToolbarDropdownOpen] = useState(false); |
| 64 |
const [isLowerToolbarKebabDropdownOpen, setIsLowerToolbarKebabDropdownOpen] = useState(false); |
| 65 |
const [page, setPage] = useState(1); |
| 66 |
const [perPage, setPerPage] = useState(10); |
| 67 |
const [filters, setFilters] = useState<Record<string, string[]>>({ products: [] }); |
| 68 |
const [state, setState] = useState({}); |
| 69 |
const [activeCard, setActiveCard] = useState(-1); |
| 70 |
|
| 71 |
interface ProductType { |
| 72 |
id: number; |
| 73 |
name: string; |
| 74 |
icon: string; |
| 75 |
description: string; |
| 76 |
} |
| 77 |
|
| 78 |
const onToolbarDropdownToggle = () => { |
| 79 |
setIsLowerToolbarDropdownOpen(!isLowerToolbarDropdownOpen); |
| 80 |
}; |
| 81 |
|
| 82 |
const onToolbarKebabDropdownToggle = () => { |
| 83 |
setIsLowerToolbarKebabDropdownOpen(!isLowerToolbarKebabDropdownOpen); |
| 84 |
}; |
| 85 |
|
| 86 |
const onToolbarKebabDropdownSelect = () => { |
| 87 |
setIsLowerToolbarKebabDropdownOpen(!isLowerToolbarKebabDropdownOpen); |
| 88 |
}; |
| 89 |
|
| 90 |
const onCardKebabDropdownToggle = ( |
| 91 |
event: React.MouseEvent<HTMLButtonElement, MouseEvent> | React.MouseEvent<HTMLDivElement, MouseEvent>, |
| 92 |
key: string |
| 93 |
) => { |
| 94 |
setState({ |
| 95 |
[key]: !state[key as keyof Object] |
| 96 |
}); |
| 97 |
}; |
| 98 |
|
| 99 |
const checkAllSelected = (selected: number, total: number) => { |
| 100 |
if (selected && selected < total) { |
| 101 |
return null; |
| 102 |
} |
| 103 |
return selected === total; |
| 104 |
}; |
| 105 |
|
| 106 |
const onNameSelect = (event: any, selection = '') => { |
| 107 |
const checked = event.target.checked; |
| 108 |
const prevSelections = filters.products; |
| 109 |
|
| 110 |
setFilters({ |
| 111 |
...filters, |
| 112 |
products: checked ? [...prevSelections, selection] : prevSelections.filter((value) => value !== selection) |
| 113 |
}); |
| 114 |
}; |
| 115 |
|
| 116 |
const onDelete = (type = '', _id = '') => { |
| 117 |
if (type) { |
| 118 |
setFilters(filters); |
| 119 |
} else { |
| 120 |
setFilters({ products: [] }); |
| 121 |
} |
| 122 |
}; |
| 123 |
|
| 124 |
const deleteItem = (item: ProductType) => { |
| 125 |
const filter = (getter) => (val) => getter(val) !== item.id; |
| 126 |
|
| 127 |
setCardData(cardData.filter(filter(({ id }) => id))); |
| 128 |
|
| 129 |
setSelectedItems(selectedItems.filter(filter((id) => id))); |
| 130 |
|
| 131 |
setTotalItemCount(totalItemCount - 1); |
| 132 |
setIsDrawerExpanded(false); |
| 133 |
setActiveCard(-1); |
| 134 |
}; |
| 135 |
|
| 136 |
const onSetPage = (_event: any, pageNumber: number) => { |
| 137 |
setPage(pageNumber); |
| 138 |
}; |
| 139 |
|
| 140 |
const onPerPageSelect = (_event: any, perPage: number) => { |
| 141 |
setPerPage(perPage); |
| 142 |
setPage(1); |
| 143 |
}; |
| 144 |
|
| 145 |
const onSplitButtonToggle = () => { |
| 146 |
setSplitButtonDropdownIsOpen(!splitButtonDropdownIsOpen); |
| 147 |
}; |
| 148 |
|
| 149 |
const onSplitButtonSelect = () => { |
| 150 |
setSplitButtonDropdownIsOpen(false); |
| 151 |
setIsDrawerExpanded(false); |
| 152 |
setActiveCard(-1); |
| 153 |
}; |
| 154 |
|
| 155 |
const onCloseDrawerClick = () => { |
| 156 |
setActiveCard(-1); |
| 157 |
setIsDrawerExpanded(false); |
| 158 |
}; |
| 159 |
|
| 160 |
const onChange = (event: React.FormEvent<HTMLInputElement>) => { |
| 161 |
const name = event.currentTarget.name; |
| 162 |
const productId = Number(name.charAt(name.length - 1)); |
| 163 |
|
| 164 |
if (selectedItems.includes(productId * 1)) { |
| 165 |
setSelectedItems(selectedItems.filter((id) => productId * 1 !== id)); |
| 166 |
|
| 167 |
const checkAll = checkAllSelected(selectedItems.length - 1, totalItemCount); |
| 168 |
setAreAllSelected(!!checkAll); |
| 169 |
} else { |
| 170 |
setSelectedItems([...selectedItems, productId * 1]); |
| 171 |
const checkAll = checkAllSelected(selectedItems.length + 1, totalItemCount); |
| 172 |
setAreAllSelected(!!checkAll); |
| 173 |
} |
| 174 |
}; |
| 175 |
|
| 176 |
const onCardClick = (productId) => { |
| 177 |
if (productId === activeCard) { |
| 178 |
setIsDrawerExpanded(!isDrawerExpanded); |
| 179 |
setActiveCard(-1); |
| 180 |
} else { |
| 181 |
setActiveCard(productId); |
| 182 |
setIsDrawerExpanded(true); |
| 183 |
} |
| 184 |
}; |
| 185 |
|
| 186 |
const selectPage = (e: { target: { checked: any } }) => { |
| 187 |
const { checked } = e.target; |
| 188 |
let collection: number[] = []; |
| 189 |
|
| 190 |
collection = getAllItems(); |
| 191 |
|
| 192 |
setSelectedItems(collection); |
| 193 |
setIsChecked(checked); |
| 194 |
setAreAllSelected(totalItemCount === perPage ? true : false); |
| 195 |
|
| 196 |
updateSelected(); |
| 197 |
}; |
| 198 |
|
| 199 |
const selectAll = () => { |
| 200 |
let collection: number[] = []; |
| 201 |
for (let i = 0; i <= 9; i++) { |
| 202 |
collection = [...collection, i]; |
| 203 |
} |
| 204 |
|
| 205 |
setSelectedItems(collection); |
| 206 |
setIsChecked(true); |
| 207 |
setAreAllSelected(true); |
| 208 |
|
| 209 |
updateSelected(); |
| 210 |
}; |
| 211 |
|
| 212 |
const selectNone = () => { |
| 213 |
setSelectedItems([]); |
| 214 |
setIsChecked(false); |
| 215 |
setAreAllSelected(false); |
| 216 |
setIsDrawerExpanded(false); |
| 217 |
setActiveCard(-1); |
| 218 |
|
| 219 |
updateSelected(); |
| 220 |
}; |
| 221 |
|
| 222 |
const updateSelected = () => { |
| 223 |
const rows = cardData.map((post) => { |
| 224 |
post.selected = selectedItems.includes(post.id); |
| 225 |
return post; |
| 226 |
}); |
| 227 |
|
| 228 |
setCardData(rows); |
| 229 |
}; |
| 230 |
|
| 231 |
const getAllItems = () => { |
| 232 |
const collection: number[] = []; |
| 233 |
for (const items of cardData) { |
| 234 |
collection.push(items.id); |
| 235 |
} |
| 236 |
|
| 237 |
return collection; |
| 238 |
}; |
| 239 |
|
| 240 |
const splitCheckboxSelectAll = (e: any) => { |
| 241 |
let collection: number[] = []; |
| 242 |
|
| 243 |
if (e.target.checked) { |
| 244 |
for (let i = 0; i <= 9; i++) { |
| 245 |
collection = [...collection, i]; |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
setSelectedItems(collection); |
| 250 |
setIsChecked(isChecked); |
| 251 |
setAreAllSelected(e.target.checked); |
| 252 |
setIsDrawerExpanded(false); |
| 253 |
setActiveCard(-1); |
| 254 |
|
| 255 |
updateSelected(); |
| 256 |
}; |
| 257 |
|
| 258 |
const renderPagination = () => { |
| 259 |
const defaultPerPageOptions = [ |
| 260 |
{ |
| 261 |
title: '1', |
| 262 |
value: 1 |
| 263 |
}, |
| 264 |
{ |
| 265 |
title: '5', |
| 266 |
value: 5 |
| 267 |
}, |
| 268 |
{ |
| 269 |
title: '10', |
| 270 |
value: 10 |
| 271 |
} |
| 272 |
]; |
| 273 |
|
| 274 |
return ( |
| 275 |
<Pagination |
| 276 |
itemCount={totalItemCount} |
| 277 |
page={page} |
| 278 |
perPage={perPage} |
| 279 |
perPageOptions={defaultPerPageOptions} |
| 280 |
onSetPage={onSetPage} |
| 281 |
onPerPageSelect={onPerPageSelect} |
| 282 |
variant="top" |
| 283 |
isCompact |
| 284 |
/> |
| 285 |
); |
| 286 |
}; |
| 287 |
|
| 288 |
const buildSelectDropdown = () => { |
| 289 |
const numSelected = selectedItems.length; |
| 290 |
const anySelected = numSelected > 0; |
| 291 |
const splitButtonDropdownItems = ( |
| 292 |
<> |
| 293 |
<DropdownItem key="item-1" onClick={selectNone}> |
| 294 |
Select none (0 items) |
| 295 |
</DropdownItem> |
| 296 |
<DropdownItem key="item-2" onClick={selectPage}> |
| 297 |
Select page ({perPage} items) |
| 298 |
</DropdownItem> |
| 299 |
<DropdownItem key="item-3" onClick={selectAll}> |
| 300 |
Select all ({totalItemCount} items) |
| 301 |
</DropdownItem> |
| 302 |
</> |
| 303 |
); |
| 304 |
|
| 305 |
return ( |
| 306 |
<Dropdown |
| 307 |
onSelect={onSplitButtonSelect} |
| 308 |
isOpen={splitButtonDropdownIsOpen} |
| 309 |
onOpenChange={(isOpen) => setSplitButtonDropdownIsOpen(isOpen)} |
| 310 |
toggle={(toggleRef) => ( |
| 311 |
<MenuToggle |
| 312 |
ref={toggleRef} |
| 313 |
isExpanded={splitButtonDropdownIsOpen} |
| 314 |
onClick={onSplitButtonToggle} |
| 315 |
aria-label="Select cards" |
| 316 |
splitButtonItems={[ |
| 317 |
<MenuToggleCheckbox |
| 318 |
id="split-dropdown-checkbox" |
| 319 |
key="split-dropdown-checkbox" |
| 320 |
aria-label={anySelected ? 'Deselect all cards' : 'Select all cards'} |
| 321 |
isChecked={areAllSelected} |
| 322 |
onClick={splitCheckboxSelectAll.bind(this)} |
| 323 |
> |
| 324 |
{numSelected !== 0 && `${numSelected} selected`} |
| 325 |
</MenuToggleCheckbox> |
| 326 |
]} |
| 327 |
></MenuToggle> |
| 328 |
)} |
| 329 |
> |
| 330 |
<DropdownList>{splitButtonDropdownItems}</DropdownList> |
| 331 |
</Dropdown> |
| 332 |
); |
| 333 |
}; |
| 334 |
|
| 335 |
const buildFilterDropdown = () => { |
| 336 |
const filterDropdownItems = ( |
| 337 |
<SelectList> |
| 338 |
<SelectOption |
| 339 |
hasCheckbox |
| 340 |
key="patternfly" |
| 341 |
value="PatternFly" |
| 342 |
isSelected={filters.products.includes('PatternFly')} |
| 343 |
> |
| 344 |
PatternFly |
| 345 |
</SelectOption> |
| 346 |
<SelectOption hasCheckbox key="activemq" value="ActiveMQ" isSelected={filters.products.includes('ActiveMQ')}> |
| 347 |
ActiveMQ |
| 348 |
</SelectOption> |
| 349 |
<SelectOption |
| 350 |
hasCheckbox |
| 351 |
key="apachespark" |
| 352 |
value="Apache Spark" |
| 353 |
isSelected={filters.products.includes('Apache Spark')} |
| 354 |
> |
| 355 |
Apache Spark |
| 356 |
</SelectOption> |
| 357 |
<SelectOption hasCheckbox key="avro" value="Avro" isSelected={filters.products.includes('Avro')}> |
| 358 |
Avro |
| 359 |
</SelectOption> |
| 360 |
<SelectOption |
| 361 |
hasCheckbox |
| 362 |
key="azureservices" |
| 363 |
value="Azure Services" |
| 364 |
isSelected={filters.products.includes('Azure Services')} |
| 365 |
> |
| 366 |
Azure Services |
| 367 |
</SelectOption> |
| 368 |
<SelectOption hasCheckbox key="crypto" value="Crypto" isSelected={filters.products.includes('Crypto')}> |
| 369 |
Crypto |
| 370 |
</SelectOption> |
| 371 |
<SelectOption hasCheckbox key="dropbox" value="DropBox" isSelected={filters.products.includes('DropBox')}> |
| 372 |
DropBox |
| 373 |
</SelectOption> |
| 374 |
<SelectOption |
| 375 |
hasCheckbox |
| 376 |
key="jbossdatagrid" |
| 377 |
value="JBoss Data Grid" |
| 378 |
isSelected={filters.products.includes('JBoss Data Grid')} |
| 379 |
> |
| 380 |
JBoss Data Grid |
| 381 |
</SelectOption> |
| 382 |
<SelectOption hasCheckbox key="rest" value="REST" isSelected={filters.products.includes('REST')}> |
| 383 |
REST |
| 384 |
</SelectOption> |
| 385 |
<SelectOption hasCheckbox key="swagger" value="SWAGGER" isSelected={filters.products.includes('SWAGGER')}> |
| 386 |
SWAGGER |
| 387 |
</SelectOption> |
| 388 |
</SelectList> |
| 389 |
); |
| 390 |
|
| 391 |
return ( |
| 392 |
<ToolbarFilter |
| 393 |
categoryName="Products" |
| 394 |
labels={filters.products} |
| 395 |
deleteLabel={(type, id) => onDelete(type as string, id as string)} |
| 396 |
> |
| 397 |
<Select |
| 398 |
aria-label="Products" |
| 399 |
role="menu" |
| 400 |
toggle={(toggleRef) => ( |
| 401 |
<MenuToggle ref={toggleRef} onClick={onToolbarDropdownToggle} isExpanded={isLowerToolbarDropdownOpen}> |
| 402 |
Filter by creator name |
| 403 |
{filters.products.length > 0 && <Badge isRead>{filters.products.length}</Badge>} |
| 404 |
</MenuToggle> |
| 405 |
)} |
| 406 |
onSelect={(event, selection) => onNameSelect(event, selection?.toString())} |
| 407 |
onOpenChange={(isOpen) => { |
| 408 |
setIsLowerToolbarDropdownOpen(isOpen); |
| 409 |
}} |
| 410 |
selected={filters.products} |
| 411 |
isOpen={isLowerToolbarDropdownOpen} |
| 412 |
> |
| 413 |
{filterDropdownItems} |
| 414 |
</Select> |
| 415 |
</ToolbarFilter> |
| 416 |
); |
| 417 |
}; |
| 418 |
|
| 419 |
const toolbarKebabDropdownItems = ( |
| 420 |
<> |
| 421 |
<DropdownItem value={0} key="action"> |
| 422 |
Action |
| 423 |
</DropdownItem> |
| 424 |
<DropdownItem |
| 425 |
value={1} |
| 426 |
key="link" |
| 427 |
to="#default-link2" |
| 428 |
// Prevent the default onClick functionality for example purposes |
| 429 |
onClick={(ev) => ev.preventDefault()} |
| 430 |
> |
| 431 |
Link |
| 432 |
</DropdownItem> |
| 433 |
<DropdownItem value={2} isDisabled key="disabled action"> |
| 434 |
Disabled Action |
| 435 |
</DropdownItem> |
| 436 |
<DropdownItem value={3} isDisabled key="disabled link" to="#default-link4"> |
| 437 |
Disabled Link |
| 438 |
</DropdownItem> |
| 439 |
<Divider component="li" key="separator" /> |
| 440 |
<DropdownItem value={4} key="separated action"> |
| 441 |
Separated Action |
| 442 |
</DropdownItem> |
| 443 |
<DropdownItem value={5} key="separated link" to="#default-link6" onClick={(ev) => ev.preventDefault()}> |
| 444 |
Separated Link |
| 445 |
</DropdownItem> |
| 446 |
</> |
| 447 |
); |
| 448 |
const toolbarItems = ( |
| 449 |
<Fragment> |
| 450 |
<ToolbarItem>{buildSelectDropdown()}</ToolbarItem> |
| 451 |
<ToolbarItem>{buildFilterDropdown()}</ToolbarItem> |
| 452 |
<ToolbarItem> |
| 453 |
<Button variant="primary">Create instance</Button> |
| 454 |
</ToolbarItem> |
| 455 |
<ToolbarItem> |
| 456 |
<Button variant="secondary">Action</Button> |
| 457 |
</ToolbarItem> |
| 458 |
<ToolbarItem> |
| 459 |
<Dropdown |
| 460 |
onSelect={onToolbarKebabDropdownSelect} |
| 461 |
isOpen={isLowerToolbarKebabDropdownOpen} |
| 462 |
onOpenChange={(isOpen) => setIsLowerToolbarKebabDropdownOpen(isOpen)} |
| 463 |
toggle={(toggleRef) => ( |
| 464 |
<MenuToggle |
| 465 |
ref={toggleRef} |
| 466 |
isExpanded={isLowerToolbarKebabDropdownOpen} |
| 467 |
variant="plain" |
| 468 |
onClick={onToolbarKebabDropdownToggle} |
| 469 |
aria-label="Toolbar actions" |
| 470 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 471 |
/> |
| 472 |
)} |
| 473 |
> |
| 474 |
<DropdownList>{toolbarKebabDropdownItems}</DropdownList> |
| 475 |
</Dropdown> |
| 476 |
</ToolbarItem> |
| 477 |
<ToolbarItem variant="pagination" align={{ default: 'alignEnd' }}> |
| 478 |
{renderPagination()} |
| 479 |
</ToolbarItem> |
| 480 |
</Fragment> |
| 481 |
); |
| 482 |
|
| 483 |
const filtered = |
| 484 |
filters.products.length > 0 |
| 485 |
? data.filter((card: { name: string }) => filters.products.length === 0 || filters.products.includes(card.name)) |
| 486 |
: cardData.slice((page - 1) * perPage, perPage === 1 ? page * perPage : page * perPage - 1); |
| 487 |
|
| 488 |
const icons = { |
| 489 |
pfIcon, |
| 490 |
activeMQIcon, |
| 491 |
sparkIcon, |
| 492 |
avroIcon, |
| 493 |
azureIcon, |
| 494 |
saxonIcon, |
| 495 |
dropBoxIcon, |
| 496 |
infinispanIcon, |
| 497 |
restIcon, |
| 498 |
swaggerIcon |
| 499 |
}; |
| 500 |
|
| 501 |
const drawerContent = ( |
| 502 |
<Gallery hasGutter role="region" aria-label="Selectable card container"> |
| 503 |
{filtered.map((product, key) => ( |
| 504 |
<Card |
| 505 |
key={product.name} |
| 506 |
id={'card-view-' + key} |
| 507 |
isClickable |
| 508 |
isSelectable |
| 509 |
isSelected={activeCard === product.id} |
| 510 |
> |
| 511 |
<CardHeader |
| 512 |
actions={{ |
| 513 |
actions: ( |
| 514 |
<> |
| 515 |
<Dropdown |
| 516 |
isOpen={!!state[key] ?? false} |
| 517 |
onOpenChange={(isOpen) => setState({ [key]: isOpen })} |
| 518 |
popperProps={{ position: 'right' }} |
| 519 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 520 |
<MenuToggle |
| 521 |
ref={toggleRef} |
| 522 |
aria-label={`${product.name} actions`} |
| 523 |
variant="plain" |
| 524 |
onClick={(e) => { |
| 525 |
onCardKebabDropdownToggle(e, key.toString()); |
| 526 |
}} |
| 527 |
isExpanded={!!state[key]} |
| 528 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 529 |
/> |
| 530 |
)} |
| 531 |
> |
| 532 |
<DropdownList> |
| 533 |
<DropdownItem |
| 534 |
key="trash" |
| 535 |
onClick={() => { |
| 536 |
deleteItem(product); |
| 537 |
}} |
| 538 |
> |
| 539 |
<TrashIcon /> |
| 540 |
Delete |
| 541 |
</DropdownItem> |
| 542 |
</DropdownList> |
| 543 |
</Dropdown> |
| 544 |
</> |
| 545 |
) |
| 546 |
}} |
| 547 |
selectableActions={{ |
| 548 |
isChecked: selectedItems.includes(product.id), |
| 549 |
selectableActionId: `selectable-actions-item-${product.id}`, |
| 550 |
selectableActionAriaLabelledby: `${'card-view-' + key}`, |
| 551 |
name: `check-${product.id}`, |
| 552 |
onChange |
| 553 |
}} |
| 554 |
> |
| 555 |
<img src={icons[product.icon]} alt={`${product.name} icon`} style={{ height: '50px' }} /> |
| 556 |
</CardHeader> |
| 557 |
<CardTitle> |
| 558 |
<Flex direction={{ default: 'column' }} spaceItems={{ default: 'spaceItemsNone' }}> |
| 559 |
<FlexItem> |
| 560 |
<Button |
| 561 |
variant="link" |
| 562 |
isInline |
| 563 |
onClick={() => onCardClick(product.id)} |
| 564 |
aria-expanded={activeCard === product.id} |
| 565 |
> |
| 566 |
{product.name} |
| 567 |
</Button> |
| 568 |
</FlexItem> |
| 569 |
<FlexItem> |
| 570 |
<Content> |
| 571 |
<small className="pf-v6-u-color-200 pf-v6-u-font-family-text">Provided by Red Hat</small> |
| 572 |
</Content> |
| 573 |
</FlexItem> |
| 574 |
</Flex> |
| 575 |
</CardTitle> |
| 576 |
|
| 577 |
<CardBody>{product.description}</CardBody> |
| 578 |
</Card> |
| 579 |
))} |
| 580 |
</Gallery> |
| 581 |
); |
| 582 |
|
| 583 |
const panelContent = ( |
| 584 |
<DrawerPanelContent> |
| 585 |
<DrawerHead> |
| 586 |
<Title headingLevel="h2" size="xl"> |
| 587 |
node-{activeCard} |
| 588 |
</Title> |
| 589 |
<DrawerActions> |
| 590 |
<DrawerCloseButton onClick={onCloseDrawerClick} /> |
| 591 |
</DrawerActions> |
| 592 |
</DrawerHead> |
| 593 |
<DrawerPanelBody> |
| 594 |
<Flex spaceItems={{ default: 'spaceItemsLg' }} direction={{ default: 'column' }}> |
| 595 |
<FlexItem> |
| 596 |
<p> |
| 597 |
The content of the drawer really is up to you. It could have form fields, definition lists, text lists, |
| 598 |
labels, charts, progress bars, etc. Spacing recommendation is 24px margins. You can put tabs in here, and |
| 599 |
can also make the drawer scrollable. |
| 600 |
</p> |
| 601 |
</FlexItem> |
| 602 |
<FlexItem> |
| 603 |
<Progress value={activeCard * 10} title="Title" /> |
| 604 |
</FlexItem> |
| 605 |
<FlexItem> |
| 606 |
<Progress value={activeCard * 5} title="Title" /> |
| 607 |
</FlexItem> |
| 608 |
</Flex> |
| 609 |
</DrawerPanelBody> |
| 610 |
</DrawerPanelContent> |
| 611 |
); |
| 612 |
|
| 613 |
return ( |
| 614 |
<DashboardWrapper mainContainerId="main-content-card-view-default-nav" breadcrumb={null}> |
| 615 |
<PageSection aria-labelledby="projects"> |
| 616 |
<Content> |
| 617 |
<h1 id="projects">Projects</h1> |
| 618 |
<p>This is a demo that showcases Patternfly cards.</p> |
| 619 |
</Content> |
| 620 |
</PageSection> |
| 621 |
<PageSection isFilled padding={{ md: 'padding' }} aria-label="Card filtering toolbar"> |
| 622 |
<Toolbar id="card-view-data-toolbar-group-types" clearAllFilters={onDelete}> |
| 623 |
<ToolbarContent>{toolbarItems}</ToolbarContent> |
| 624 |
</Toolbar> |
| 625 |
<Divider component="div" /> |
| 626 |
</PageSection> |
| 627 |
<PageSection isFilled padding={{ default: 'noPadding' }} aria-label="Card content area"> |
| 628 |
<Drawer isExpanded={isDrawerExpanded} className={'pf-m-inline-on-2xl'}> |
| 629 |
<DrawerContent panelContent={panelContent}> |
| 630 |
<DrawerContentBody hasPadding>{drawerContent}</DrawerContentBody> |
| 631 |
</DrawerContent> |
| 632 |
</Drawer> |
| 633 |
</PageSection> |
| 634 |
<PageSection |
| 635 |
isFilled={false} |
| 636 |
stickyOnBreakpoint={{ default: 'bottom' }} |
| 637 |
padding={{ default: 'noPadding' }} |
| 638 |
variant="light" |
| 639 |
aria-label="Pagination controls" |
| 640 |
> |
| 641 |
<Pagination |
| 642 |
itemCount={filtered.length} |
| 643 |
page={page} |
| 644 |
perPage={perPage} |
| 645 |
onPerPageSelect={onPerPageSelect} |
| 646 |
onSetPage={onSetPage} |
| 647 |
variant="bottom" |
| 648 |
/> |
| 649 |
</PageSection> |
| 650 |
</DashboardWrapper> |
| 651 |
); |
| 652 |
}; |