| 1 |
import { useState } from 'react'; |
| 2 |
import { |
| 3 |
Card, |
| 4 |
CardHeader, |
| 5 |
CardTitle, |
| 6 |
CardBody, |
| 7 |
CardFooter, |
| 8 |
Checkbox, |
| 9 |
Dropdown, |
| 10 |
DropdownList, |
| 11 |
DropdownItem, |
| 12 |
MenuToggle, |
| 13 |
MenuToggleElement, |
| 14 |
Divider |
| 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 CardTitleInHeader: React.FunctionComponent = () => { |
| 19 |
const [isOpen, setIsOpen] = useState<boolean>(false); |
| 20 |
const [isChecked, setIsChecked] = useState<boolean>(false); |
| 21 |
|
| 22 |
const onSelect = () => { |
| 23 |
setIsOpen(!isOpen); |
| 24 |
}; |
| 25 |
const onClick = (checked: boolean) => { |
| 26 |
setIsChecked(checked); |
| 27 |
}; |
| 28 |
|
| 29 |
const dropdownItems = ( |
| 30 |
<> |
| 31 |
<DropdownItem key="action">Action</DropdownItem> |
| 32 |
{/* Prevent default onClick functionality for example purposes */} |
| 33 |
<DropdownItem key="link" to="#" onClick={(event: any) => event.preventDefault()}> |
| 34 |
Link |
| 35 |
</DropdownItem> |
| 36 |
<DropdownItem key="disabled action" isDisabled> |
| 37 |
Disabled Action |
| 38 |
</DropdownItem> |
| 39 |
<DropdownItem key="disabled link" isDisabled to="#" onClick={(event: any) => event.preventDefault()}> |
| 40 |
Disabled Link |
| 41 |
</DropdownItem> |
| 42 |
<Divider component="li" key="separator" /> |
| 43 |
<DropdownItem key="separated action">Separated Action</DropdownItem> |
| 44 |
<DropdownItem key="separated link" to="#" onClick={(event: any) => event.preventDefault()}> |
| 45 |
Separated Link |
| 46 |
</DropdownItem> |
| 47 |
</> |
| 48 |
); |
| 49 |
|
| 50 |
const headerActions = ( |
| 51 |
<> |
| 52 |
<Dropdown |
| 53 |
onSelect={onSelect} |
| 54 |
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( |
| 55 |
<MenuToggle |
| 56 |
ref={toggleRef} |
| 57 |
isExpanded={isOpen} |
| 58 |
onClick={() => setIsOpen(!isOpen)} |
| 59 |
variant="plain" |
| 60 |
aria-label="Card title inline with images and actions example kebab toggle" |
| 61 |
icon={<RhUiEllipsisVerticalFillIcon />} |
| 62 |
/> |
| 63 |
)} |
| 64 |
isOpen={isOpen} |
| 65 |
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)} |
| 66 |
> |
| 67 |
<DropdownList>{dropdownItems}</DropdownList> |
| 68 |
</Dropdown> |
| 69 |
<Checkbox |
| 70 |
isChecked={isChecked} |
| 71 |
onChange={(_event, checked) => onClick(checked)} |
| 72 |
aria-label="card checkbox example" |
| 73 |
id="check-2" |
| 74 |
name="check2" |
| 75 |
/> |
| 76 |
</> |
| 77 |
); |
| 78 |
|
| 79 |
return ( |
| 80 |
<Card> |
| 81 |
<CardHeader actions={{ actions: headerActions }}> |
| 82 |
<CardTitle> |
| 83 |
This is a really really really really really really really really really really long header |
| 84 |
</CardTitle> |
| 85 |
</CardHeader> |
| 86 |
<CardBody>Body</CardBody> |
| 87 |
<CardFooter>Footer</CardFooter> |
| 88 |
</Card> |
| 89 |
); |
| 90 |
}; |