| 1 |
import { useState } from 'react'; |
| 2 |
import { Tabs, Tab, TabTitleText, Checkbox } from '@patternfly/react-core'; |
| 3 |
|
| 4 |
export const TabsInset: React.FunctionComponent = () => { |
| 5 |
const [activeTabKey, setActiveTabKey] = useState<string | number>(0); |
| 6 |
const [isBox, setIsBox] = useState<boolean>(false); |
| 7 |
// Toggle currently active tab |
| 8 |
const handleTabClick = ( |
| 9 |
event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent, |
| 10 |
tabIndex: string | number |
| 11 |
) => { |
| 12 |
setActiveTabKey(tabIndex); |
| 13 |
}; |
| 14 |
|
| 15 |
const toggleBox = (checked: boolean) => { |
| 16 |
setIsBox(checked); |
| 17 |
}; |
| 18 |
|
| 19 |
return ( |
| 20 |
<div> |
| 21 |
<Tabs |
| 22 |
activeKey={activeTabKey} |
| 23 |
onSelect={handleTabClick} |
| 24 |
inset={{ |
| 25 |
default: 'insetNone', |
| 26 |
md: 'insetSm', |
| 27 |
xl: 'insetLg', |
| 28 |
'2xl': 'inset2xl' |
| 29 |
}} |
| 30 |
isBox={isBox} |
| 31 |
aria-label="Tabs in the inset example" |
| 32 |
role="region" |
| 33 |
> |
| 34 |
<Tab eventKey={0} title={<TabTitleText>Users</TabTitleText>} aria-label="Inset example content users"> |
| 35 |
Users |
| 36 |
</Tab> |
| 37 |
<Tab eventKey={1} title={<TabTitleText>Containers</TabTitleText>}> |
| 38 |
Containers |
| 39 |
</Tab> |
| 40 |
<Tab eventKey={2} title={<TabTitleText>Database</TabTitleText>}> |
| 41 |
Database |
| 42 |
</Tab> |
| 43 |
<Tab eventKey={3} title={<TabTitleText>Server</TabTitleText>}> |
| 44 |
Server |
| 45 |
</Tab> |
| 46 |
<Tab eventKey={4} title={<TabTitleText>System</TabTitleText>}> |
| 47 |
System |
| 48 |
</Tab> |
| 49 |
<Tab eventKey={6} title={<TabTitleText>Network</TabTitleText>}> |
| 50 |
Network |
| 51 |
</Tab> |
| 52 |
</Tabs> |
| 53 |
<div style={{ marginTop: '20px' }}> |
| 54 |
<Checkbox |
| 55 |
label="isBox" |
| 56 |
isChecked={isBox} |
| 57 |
onChange={(_event, checked) => toggleBox(checked)} |
| 58 |
aria-label="show box variation checkbox with inset" |
| 59 |
id="toggle-box-inset" |
| 60 |
name="toggle-box-inset" |
| 61 |
/> |
| 62 |
</div> |
| 63 |
</div> |
| 64 |
); |
| 65 |
}; |