| 1 |
import { forwardRef } from 'react'; |
| 2 |
import { css } from '@patternfly/react-styles'; |
| 3 |
import { MenuItemProps, MenuItem } from '../Menu'; |
| 4 |
|
| 5 |
/** |
| 6 |
* See the MenuItem section of the Menu documentation for additional props that may be passed. |
| 7 |
*/ |
| 8 |
|
| 9 |
export interface SelectOptionProps extends Omit<MenuItemProps, 'ref'> { |
| 10 |
/** Anything which can be rendered in a select option */ |
| 11 |
children?: React.ReactNode; |
| 12 |
/** Classes applied to root element of select option */ |
| 13 |
className?: string; |
| 14 |
/** @hide Forwarded ref */ |
| 15 |
innerRef?: React.Ref<HTMLAnchorElement | HTMLButtonElement>; |
| 16 |
/** Identifies the component in the Select onSelect callback */ |
| 17 |
value?: any; |
| 18 |
/** Indicates the option has a checkbox */ |
| 19 |
hasCheckbox?: boolean; |
| 20 |
/** Indicates the option is disabled */ |
| 21 |
isDisabled?: boolean; |
| 22 |
/** Indicates the option is selected */ |
| 23 |
isSelected?: boolean; |
| 24 |
/** Indicates the option is focused */ |
| 25 |
isFocused?: boolean; |
| 26 |
/** Render an external link icon on focus or hover, and set the link's |
| 27 |
* "target" attribute to a value of "_blank". |
| 28 |
*/ |
| 29 |
isExternalLink?: boolean; |
| 30 |
/** Render option with icon */ |
| 31 |
icon?: React.ReactNode; |
| 32 |
/** Description of the option */ |
| 33 |
description?: React.ReactNode; |
| 34 |
} |
| 35 |
|
| 36 |
const SelectOptionBase: React.FunctionComponent<MenuItemProps> = ({ |
| 37 |
children, |
| 38 |
className, |
| 39 |
innerRef, |
| 40 |
value, |
| 41 |
...props |
| 42 |
}: SelectOptionProps) => ( |
| 43 |
<MenuItem itemId={value} ref={innerRef} className={css(className)} {...props}> |
| 44 |
{children} |
| 45 |
</MenuItem> |
| 46 |
); |
| 47 |
|
| 48 |
export const SelectOption = forwardRef((props: SelectOptionProps, ref: React.Ref<any>) => ( |
| 49 |
<SelectOptionBase {...props} innerRef={ref} /> |
| 50 |
)); |
| 51 |
|
| 52 |
SelectOption.displayName = 'SelectOption'; |