| 1 |
import { createRef, Fragment, useState } from 'react'; |
| 2 |
import { Tabs, Tab, TabTitleText, TabContent, TabContentBody } from '@patternfly/react-core'; |
| 3 |
|
| 4 |
export const TabContentWithBodyPadding: React.FunctionComponent = () => { |
| 5 |
const [activeTabKey, setActiveTabKey] = useState<string | number>(0); |
| 6 |
// Toggle currently active tab |
| 7 |
const handleTabClick = ( |
| 8 |
event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent, |
| 9 |
tabIndex: string | number |
| 10 |
) => { |
| 11 |
setActiveTabKey(tabIndex); |
| 12 |
}; |
| 13 |
|
| 14 |
const contentRef1 = createRef<HTMLElement>(); |
| 15 |
const contentRef2 = createRef<HTMLElement>(); |
| 16 |
const contentRef3 = createRef<HTMLElement>(); |
| 17 |
|
| 18 |
return ( |
| 19 |
<Fragment> |
| 20 |
<Tabs |
| 21 |
activeKey={activeTabKey} |
| 22 |
onSelect={handleTabClick} |
| 23 |
aria-label="Tabs in the body and padding example" |
| 24 |
role="region" |
| 25 |
> |
| 26 |
<Tab |
| 27 |
eventKey={0} |
| 28 |
title={<TabTitleText>Tab item 1</TabTitleText>} |
| 29 |
tabContentId="tab1SectionBodyPadding" |
| 30 |
tabContentRef={contentRef1} |
| 31 |
/> |
| 32 |
<Tab |
| 33 |
eventKey={1} |
| 34 |
title={<TabTitleText>Tab item 2</TabTitleText>} |
| 35 |
tabContentId="tab2SectionBodyPadding" |
| 36 |
tabContentRef={contentRef2} |
| 37 |
/> |
| 38 |
<Tab |
| 39 |
eventKey={2} |
| 40 |
title={<TabTitleText>Tab item 3</TabTitleText>} |
| 41 |
tabContentId="tab3SectionBodyPadding" |
| 42 |
tabContentRef={contentRef3} |
| 43 |
/> |
| 44 |
</Tabs> |
| 45 |
<div> |
| 46 |
<TabContent eventKey={0} id="tab1SectionBodyPadding" ref={contentRef1}> |
| 47 |
<TabContentBody hasPadding> Tab 1 section with body and padding </TabContentBody> |
| 48 |
</TabContent> |
| 49 |
<TabContent eventKey={1} id="tab2SectionBodyPadding" ref={contentRef2} hidden> |
| 50 |
<TabContentBody hasPadding> Tab 2 section with body and padding </TabContentBody> |
| 51 |
</TabContent> |
| 52 |
<TabContent eventKey={2} id="tab3SectionBodyPadding" ref={contentRef3} hidden> |
| 53 |
<TabContentBody hasPadding> Tab 3 section with body and padding </TabContentBody> |
| 54 |
</TabContent> |
| 55 |
</div> |
| 56 |
</Fragment> |
| 57 |
); |
| 58 |
}; |