| 1 |
import { useState } from 'react'; |
| 2 |
import { Tabs, Tab, TabTitleText, Checkbox } from '@patternfly/react-core'; |
| 3 |
|
| 4 |
export const TabsSubtabs: React.FunctionComponent = () => { |
| 5 |
const [activeTabKey1, setActiveTabKey1] = useState<string | number>(0); |
| 6 |
const [activeTabKey2, setActiveTabKey2] = useState<string | number>(0); |
| 7 |
const [isBox, setIsBox] = useState<boolean>(false); |
| 8 |
|
| 9 |
// Toggle currently active primary tab |
| 10 |
const handleTabClickFirst = ( |
| 11 |
event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent, |
| 12 |
tabIndex: string | number |
| 13 |
) => { |
| 14 |
setActiveTabKey1(tabIndex); |
| 15 |
}; |
| 16 |
|
| 17 |
// Toggle currently active subtab |
| 18 |
const handleTabClickSecond = ( |
| 19 |
event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent, |
| 20 |
tabIndex: string | number |
| 21 |
) => { |
| 22 |
setActiveTabKey2(tabIndex); |
| 23 |
}; |
| 24 |
|
| 25 |
const toggleBox = (checked: boolean) => { |
| 26 |
setIsBox(checked); |
| 27 |
}; |
| 28 |
|
| 29 |
return ( |
| 30 |
<div> |
| 31 |
<Tabs |
| 32 |
activeKey={activeTabKey1} |
| 33 |
onSelect={handleTabClickFirst} |
| 34 |
isBox={isBox} |
| 35 |
aria-label="Tabs in the tabs with subtabs example" |
| 36 |
tabListAriaLabel="Primary" |
| 37 |
role="region" |
| 38 |
> |
| 39 |
<Tab eventKey={0} title={<TabTitleText>Users</TabTitleText>} aria-label="Tabs with subtabs content users"> |
| 40 |
<Tabs |
| 41 |
aria-label="subtabs for users" |
| 42 |
role="region" |
| 43 |
activeKey={activeTabKey2} |
| 44 |
isSubtab |
| 45 |
tabListAriaLabel="Users" |
| 46 |
onSelect={handleTabClickSecond} |
| 47 |
> |
| 48 |
<Tab eventKey={20} title={<TabTitleText>Subtab item 1</TabTitleText>}> |
| 49 |
Subtab item 1 item section |
| 50 |
</Tab> |
| 51 |
<Tab eventKey={21} title={<TabTitleText>Subtab item 2</TabTitleText>}> |
| 52 |
Subtab item 2 section |
| 53 |
</Tab> |
| 54 |
<Tab eventKey={22} title={<TabTitleText>Subtab item 3</TabTitleText>}> |
| 55 |
Subtab item 3 section |
| 56 |
</Tab> |
| 57 |
<Tab eventKey={23} title={<TabTitleText>Subtab item 4</TabTitleText>}> |
| 58 |
Subtab item 4 section |
| 59 |
</Tab> |
| 60 |
<Tab eventKey={24} title={<TabTitleText>Subtab item 5</TabTitleText>}> |
| 61 |
Subtab item 5 section |
| 62 |
</Tab> |
| 63 |
<Tab eventKey={25} title={<TabTitleText>Subtab item 6</TabTitleText>}> |
| 64 |
Subtab item 6 section |
| 65 |
</Tab> |
| 66 |
<Tab eventKey={26} title={<TabTitleText>Subtab item 7</TabTitleText>}> |
| 67 |
Subtab item 7 section |
| 68 |
</Tab> |
| 69 |
<Tab eventKey={27} title={<TabTitleText>Subtab item 8</TabTitleText>}> |
| 70 |
Subtab item 8 section |
| 71 |
</Tab> |
| 72 |
</Tabs> |
| 73 |
</Tab> |
| 74 |
<Tab eventKey={1} title={<TabTitleText>Containers</TabTitleText>}> |
| 75 |
Containers |
| 76 |
</Tab> |
| 77 |
<Tab eventKey={2} title={<TabTitleText>Database</TabTitleText>}> |
| 78 |
Database |
| 79 |
</Tab> |
| 80 |
<Tab eventKey={3} title={<TabTitleText>Server</TabTitleText>}> |
| 81 |
Server |
| 82 |
</Tab> |
| 83 |
<Tab eventKey={4} title={<TabTitleText>System</TabTitleText>}> |
| 84 |
System |
| 85 |
</Tab> |
| 86 |
<Tab eventKey={6} title={<TabTitleText>Network</TabTitleText>}> |
| 87 |
Network |
| 88 |
</Tab> |
| 89 |
<Tab eventKey={7} title={<TabTitleText>Tab item 7</TabTitleText>}> |
| 90 |
Tab 7 section |
| 91 |
</Tab> |
| 92 |
<Tab eventKey={8} title={<TabTitleText>Tab item 8</TabTitleText>}> |
| 93 |
Tab 8 section |
| 94 |
</Tab> |
| 95 |
<Tab eventKey={9} title={<TabTitleText>Tab item 9</TabTitleText>}> |
| 96 |
Tab 9 section |
| 97 |
</Tab> |
| 98 |
<Tab eventKey={10} title={<TabTitleText>Tab item 10</TabTitleText>}> |
| 99 |
Tab 10 section |
| 100 |
</Tab> |
| 101 |
<Tab eventKey={11} title={<TabTitleText>Tab item 11</TabTitleText>}> |
| 102 |
Tab 11 section |
| 103 |
</Tab> |
| 104 |
</Tabs> |
| 105 |
<div style={{ marginTop: '20px' }}> |
| 106 |
<Checkbox |
| 107 |
label="isBox" |
| 108 |
isChecked={isBox} |
| 109 |
onChange={(_event, checked) => toggleBox(checked)} |
| 110 |
aria-label="show box variation checkbox with sub tabs" |
| 111 |
id="toggle-box-subtab" |
| 112 |
name="toggle-box-subtab" |
| 113 |
/> |
| 114 |
</div> |
| 115 |
</div> |
| 116 |
); |
| 117 |
}; |