| 1 |
import { useState } from 'react'; |
| 2 |
import { |
| 3 |
Card, |
| 4 |
CardHeader, |
| 5 |
CardBody, |
| 6 |
CardFooter, |
| 7 |
CardExpandableContent, |
| 8 |
Checkbox, |
| 9 |
Dropdown, |
| 10 |
DropdownList, |
| 11 |
DropdownItem, |
| 12 |
Divider, |
| 13 |
MenuToggle, |
| 14 |
MenuToggleElement |
| 15 |
} from '@patternfly/react-core'; |
| 16 |
import pfLogoSmall from '../../PF-IconLogo.svg'; |
| 17 |
import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon'; |
| 18 |
|
| 19 |
export const CardExpandableWithIcon: React.FunctionComponent = () => { |
| 20 |
const [isOpen, setIsOpen] = useState<boolean>(false); |
| 21 |
const [isChecked, setIsChecked] = useState<boolean>(false); |
| 22 |
const [isExpanded, setIsExpanded] = useState<boolean>(false); |
| 23 |
|
| 24 |
const onSelect = () => { |
| 25 |
setIsOpen(!isOpen); |
| 26 |
}; |
| 27 |
|
| 28 |
const onClick = (checked: boolean) => { |
| 29 |
setIsChecked(checked); |
| 30 |
}; |
| 31 |
|
| 32 |
const onExpand = (event: React.MouseEvent, id: string) => { |
| 33 |
// eslint-disable-next-line no-console |
| 34 |
console.log(id); |
| 35 |
setIsExpanded(!isExpanded); |
| 36 |
}; |
| 37 |
|
| 38 |
const dropdownItems = ( |
| 39 |
<> |
| 40 |
<DropdownItem key="action">Action</DropdownItem> |
| 41 |
{/* Prevent default onClick functionality for example purposes */} |
| 42 |
<DropdownItem key="link" to="#" onClick={(event: any) => event.preventDefault()}> |
| 43 |
Link |
| 44 |
</DropdownItem> |
| 45 |
<DropdownItem key="disabled action" isDisabled> |
| 46 |
Disabled Action |
| 47 |
</DropdownItem> |
| 48 |
<DropdownItem key="disabled link" isDisabled to="#" onClick={(event: any) => event.preventDefault()}> |
| 49 |
Disabled Link |
| 50 |
</DropdownItem> |
| 51 |
<Divider component="li" key="separator" /> |
| 52 |
<DropdownItem key="separated action">Separated Action</DropdownItem> |
| 53 |
<DropdownItem key="separated link" to="#" onClick={(event: any) => event.preventDefault()}> |
| 54 |
Separated Link |
| 55 |
</DropdownItem> |
| 56 |
</> |
| 57 |
); |
| 58 |
|
| 59 |
const headerActions = ( |
| 60 |
<> |
| 61 |
<Dropdown |
| 62 |
onSelect={onSelect} |
| 63 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 64 |
<MenuToggle |
| 65 |
ref={toggleRef} |
| 66 |
isExpanded={isOpen} |
| 67 |
onClick={() => setIsOpen(!isOpen)} |
| 68 |
variant="plain" |
| 69 |
aria-label="Card expandable with icon example kebab toggle" |
| 70 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 71 |
/> |
| 72 |
)} |
| 73 |
isOpen={isOpen} |
| 74 |
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)} |
| 75 |
> |
| 76 |
<DropdownList>{dropdownItems}</DropdownList> |
| 77 |
</Dropdown> |
| 78 |
<Checkbox |
| 79 |
isChecked={isChecked} |
| 80 |
onChange={(_event, checked) => onClick(checked)} |
| 81 |
aria-label="card checkbox example" |
| 82 |
id="check-5" |
| 83 |
name="check5" |
| 84 |
/> |
| 85 |
</> |
| 86 |
); |
| 87 |
|
| 88 |
return ( |
| 89 |
<Card id="expandable-card-icon" isExpanded={isExpanded}> |
| 90 |
<CardHeader |
| 91 |
actions={{ actions: headerActions }} |
| 92 |
onExpand={onExpand} |
| 93 |
toggleButtonProps={{ |
| 94 |
id: 'toggle-button2', |
| 95 |
'aria-label': 'Patternfly Details', |
| 96 |
'aria-expanded': isExpanded |
| 97 |
}} |
| 98 |
> |
| 99 |
<img src={pfLogoSmall} alt="PatternFly logo" width="27px" /> |
| 100 |
</CardHeader> |
| 101 |
<CardExpandableContent> |
| 102 |
<CardBody>Body</CardBody> |
| 103 |
<CardFooter>Footer</CardFooter> |
| 104 |
</CardExpandableContent> |
| 105 |
</Card> |
| 106 |
); |
| 107 |
}; |