| 1 |
import { forwardRef } from 'react'; |
| 2 |
import { css } from '@patternfly/react-styles'; |
| 3 |
import styles from '@patternfly/react-styles/css/components/Tabs/tabs'; |
| 4 |
import { Button } from '../Button'; |
| 5 |
import { getOUIAProps, OUIAProps } from '../../helpers'; |
| 6 |
|
| 7 |
export interface TabActionProps extends Omit<React.HTMLProps<HTMLButtonElement>, 'ref' | 'type' | 'size'>, OUIAProps { |
| 8 |
/** Content rendered in the tab action */ |
| 9 |
children?: React.ReactNode; |
| 10 |
/** Additional classes added to the tab action span */ |
| 11 |
className?: string; |
| 12 |
/** Click callback for tab action button */ |
| 13 |
onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void; |
| 14 |
/** Flag indicating if the tab action is disabled */ |
| 15 |
isDisabled?: boolean; |
| 16 |
/** Accessible label for the tab action */ |
| 17 |
'aria-label'?: string; |
| 18 |
/** @hide Callback for the section ref */ |
| 19 |
innerRef?: React.Ref<any>; |
| 20 |
} |
| 21 |
|
| 22 |
const TabActionBase: React.FunctionComponent<TabActionProps> = ({ |
| 23 |
children, |
| 24 |
className, |
| 25 |
onClick, |
| 26 |
isDisabled, |
| 27 |
'aria-label': ariaLabel = 'Tab action', |
| 28 |
innerRef, |
| 29 |
|
| 30 |
ouiaId, |
| 31 |
ouiaSafe, |
| 32 |
...props |
| 33 |
}: TabActionProps) => ( |
| 34 |
<span className={css(styles.tabsItemAction, className)}> |
| 35 |
<Button |
| 36 |
ref={innerRef} |
| 37 |
type="button" |
| 38 |
variant="plain" |
| 39 |
aria-label={ariaLabel} |
| 40 |
onClick={onClick} |
| 41 |
isDisabled={isDisabled} |
| 42 |
icon={<span className={css(styles.tabsItemActionIcon)}>{children}</span>} |
| 43 |
{...getOUIAProps(TabAction.displayName, ouiaId, ouiaSafe)} |
| 44 |
{...props} |
| 45 |
/> |
| 46 |
</span> |
| 47 |
); |
| 48 |
|
| 49 |
export const TabAction = forwardRef((props: TabActionProps, ref: React.Ref<HTMLElement>) => ( |
| 50 |
<TabActionBase {...props} innerRef={ref} /> |
| 51 |
)); |
| 52 |
|
| 53 |
TabAction.displayName = 'TabAction'; |