| 1 |
import { getOUIAProps, OUIAProps } from '../../helpers'; |
| 2 |
|
| 3 |
export interface TabButtonProps extends Omit<React.HTMLProps<HTMLAnchorElement | HTMLButtonElement>, 'ref'>, OUIAProps { |
| 4 |
/** content rendered inside the Tab content area. */ |
| 5 |
children?: React.ReactNode; |
| 6 |
/** additional classes added to the Tab */ |
| 7 |
className?: string; |
| 8 |
/** URL associated with the Tab. A Tab with an href will render as an <a> instead of a <button>. A Tab inside a <Tabs component="nav"> should have an href. */ |
| 9 |
href?: string; |
| 10 |
/** child reference for case in which a TabContent section is defined outside of a Tabs component */ |
| 11 |
tabContentRef?: React.Ref<any>; |
| 12 |
/** Parents' innerRef passed down for properly displaying Tooltips */ |
| 13 |
parentInnerRef?: React.Ref<any>; |
| 14 |
} |
| 15 |
|
| 16 |
export const TabButton: React.FunctionComponent<TabButtonProps> = ({ |
| 17 |
children, |
| 18 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 19 |
tabContentRef, |
| 20 |
ouiaId, |
| 21 |
parentInnerRef, |
| 22 |
ouiaSafe, |
| 23 |
...props |
| 24 |
}: TabButtonProps) => { |
| 25 |
const Component = (props.href ? 'a' : 'button') as any; |
| 26 |
|
| 27 |
return ( |
| 28 |
<Component |
| 29 |
{...(!props.href && { type: 'button' })} |
| 30 |
ref={parentInnerRef} |
| 31 |
{...getOUIAProps(TabButton.displayName, ouiaId, ouiaSafe)} |
| 32 |
{...props} |
| 33 |
> |
| 34 |
{children} |
| 35 |
</Component> |
| 36 |
); |
| 37 |
}; |
| 38 |
TabButton.displayName = 'TabButton'; |