Debian Codegraph @

node/@patternfly/react-core/src/components/Dropdown/DropdownItem.tsx

raw
1 import { forwardRef } from 'react';
2 import { css } from '@patternfly/react-styles';
3 import { MenuItemProps, MenuItem } from '../Menu';
4 import { TooltipProps } from '../Tooltip';
5 import { useOUIAProps, OUIAProps } from '../../helpers';
6
7 /**
8 * See the MenuItem section of the Menu documentation for additional props that may be passed.
9 */
10 export interface DropdownItemProps extends Omit<MenuItemProps, 'ref'>, OUIAProps {
11 /** Anything which can be rendered in a dropdown item */
12 children?: React.ReactNode;
13 /** Classes applied to root element of dropdown item */
14 className?: string;
15 /** @hide Forwarded ref */
16 innerRef?: React.Ref<HTMLAnchorElement | HTMLButtonElement>;
17 /** Description of the dropdown item */
18 description?: React.ReactNode;
19 /** Render item as disabled option */
20 isDisabled?: boolean;
21 /** Render item as aria-disabled option */
22 isAriaDisabled?: boolean;
23 /** Identifies the component in the dropdown onSelect callback */
24 value?: any;
25 /** Callback for item click */
26 onClick?: (event?: any) => void;
27 /** Value to overwrite the randomly generated data-ouia-component-id.*/
28 ouiaId?: number | string;
29 /** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */
30 ouiaSafe?: boolean;
31 /** Props for adding a tooltip to a menu item */
32 tooltipProps?: TooltipProps;
33 }
34
35 const DropdownItemBase: React.FunctionComponent<DropdownItemProps> = ({
36 children,
37 className,
38 description,
39 isDisabled,
40 isAriaDisabled,
41 value,
42 onClick,
43 ouiaId,
44 ouiaSafe,
45 innerRef,
46 tooltipProps,
47 ...props
48 }: DropdownItemProps) => {
49 const ouiaProps = useOUIAProps(DropdownItem.displayName, ouiaId, ouiaSafe);
50 return (
51 <MenuItem
52 className={css(className)}
53 description={description}
54 isDisabled={isDisabled}
55 isAriaDisabled={isAriaDisabled}
56 itemId={value}
57 onClick={onClick}
58 tooltipProps={tooltipProps}
59 ref={innerRef}
60 {...ouiaProps}
61 {...props}
62 >
63 {children}
64 </MenuItem>
65 );
66 };
67
68 export const DropdownItem = forwardRef(
69 (props: DropdownItemProps, ref: React.Ref<HTMLAnchorElement | HTMLButtonElement>) => (
70 <DropdownItemBase {...props} innerRef={ref} />
71 )
72 );
73
74 DropdownItem.displayName = 'DropdownItem';