| 1 |
/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 2 |
import React from "react"; |
| 3 |
// PatternFly |
| 4 |
import { |
| 5 |
Dropdown, |
| 6 |
MenuToggle, |
| 7 |
MenuToggleElement, |
| 8 |
} from "@patternfly/react-core"; |
| 9 |
// Icons |
| 10 |
import { EllipsisVIcon } from "@patternfly/react-icons"; |
| 11 |
|
| 12 |
interface PropsToKebab { |
| 13 |
dataCy: string; |
| 14 |
// Dropdown |
| 15 |
onDropdownSelect?: |
| 16 |
| ((event?: React.MouseEvent<Element, MouseEvent> | undefined) => void) |
| 17 |
| undefined; |
| 18 |
isKebabOpen?: boolean; |
| 19 |
className?: string; |
| 20 |
isDisabled?: boolean; |
| 21 |
isPlain?: boolean; |
| 22 |
dropdownItems?: any[] | undefined; |
| 23 |
// Toggle |
| 24 |
onKebabToggle?: () => void; |
| 25 |
idKebab: string; |
| 26 |
direction?: "up" | "down"; |
| 27 |
} |
| 28 |
|
| 29 |
const KebabLayout = (props: PropsToKebab) => { |
| 30 |
// Toggle |
| 31 |
const toggleKebab = (toggleRef: React.Ref<MenuToggleElement>) => ( |
| 32 |
<MenuToggle |
| 33 |
data-cy={props.dataCy} |
| 34 |
ref={toggleRef} |
| 35 |
id={props.idKebab} |
| 36 |
aria-label="kebab dropdown toggle" |
| 37 |
variant="plain" |
| 38 |
onClick={props.onKebabToggle} |
| 39 |
isExpanded={props.isKebabOpen} |
| 40 |
isDisabled={props.isDisabled} |
| 41 |
> |
| 42 |
<EllipsisVIcon /> |
| 43 |
</MenuToggle> |
| 44 |
); |
| 45 |
|
| 46 |
return ( |
| 47 |
<Dropdown |
| 48 |
data-cy={props.dataCy + "-kebab"} |
| 49 |
onSelect={props.onDropdownSelect} |
| 50 |
className={props.className} |
| 51 |
toggle={toggleKebab} |
| 52 |
isOpen={props.isKebabOpen} |
| 53 |
isPlain={props.isPlain || false} |
| 54 |
popperProps={{ direction: props.direction }} |
| 55 |
> |
| 56 |
{props.dropdownItems} |
| 57 |
</Dropdown> |
| 58 |
); |
| 59 |
}; |
| 60 |
|
| 61 |
export default KebabLayout; |