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