| 1 |
import { useState } from 'react'; |
| 2 |
import { Tabs, Tab, TabTitleText, TabTitleIcon, Checkbox } from '@patternfly/react-core'; |
| 3 |
import RhUiUsersFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-users-fill-icon'; |
| 4 |
import RhUiContainerFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-container-fill-icon'; |
| 5 |
import DatabaseIcon from '@patternfly/react-icons/dist/esm/icons/database-icon'; |
| 6 |
|
| 7 |
export const TabsFilledWithIcons: React.FunctionComponent = () => { |
| 8 |
const [activeTabKey, setActiveTabKey] = useState<string | number>(0); |
| 9 |
const [isBox, setIsBox] = useState<boolean>(false); |
| 10 |
// Toggle currently active tab |
| 11 |
const handleTabClick = ( |
| 12 |
event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent, |
| 13 |
tabIndex: string | number |
| 14 |
) => { |
| 15 |
setActiveTabKey(tabIndex); |
| 16 |
}; |
| 17 |
|
| 18 |
const toggleBox = (checked: boolean) => { |
| 19 |
setIsBox(checked); |
| 20 |
}; |
| 21 |
|
| 22 |
return ( |
| 23 |
<div> |
| 24 |
<Tabs |
| 25 |
isFilled |
| 26 |
activeKey={activeTabKey} |
| 27 |
onSelect={handleTabClick} |
| 28 |
isBox={isBox} |
| 29 |
aria-label="Tabs in the filled with icons example" |
| 30 |
role="region" |
| 31 |
> |
| 32 |
<Tab |
| 33 |
eventKey={0} |
| 34 |
title={ |
| 35 |
<> |
| 36 |
<TabTitleIcon> |
| 37 |
<RhUiUsersFillIcon /> |
| 38 |
</TabTitleIcon>{' '} |
| 39 |
<TabTitleText>Users</TabTitleText>{' '} |
| 40 |
</> |
| 41 |
} |
| 42 |
aria-label="filled tabs with icons content users" |
| 43 |
> |
| 44 |
Users |
| 45 |
</Tab> |
| 46 |
<Tab |
| 47 |
eventKey={1} |
| 48 |
title={ |
| 49 |
<> |
| 50 |
<TabTitleIcon> |
| 51 |
<RhUiContainerFillIcon /> |
| 52 |
</TabTitleIcon>{' '} |
| 53 |
<TabTitleText>Containers</TabTitleText>{' '} |
| 54 |
</> |
| 55 |
} |
| 56 |
> |
| 57 |
Containers |
| 58 |
</Tab> |
| 59 |
<Tab |
| 60 |
eventKey={2} |
| 61 |
title={ |
| 62 |
<> |
| 63 |
<TabTitleIcon> |
| 64 |
<DatabaseIcon /> |
| 65 |
</TabTitleIcon>{' '} |
| 66 |
<TabTitleText>Database</TabTitleText>{' '} |
| 67 |
</> |
| 68 |
} |
| 69 |
> |
| 70 |
Database |
| 71 |
</Tab> |
| 72 |
</Tabs> |
| 73 |
<div style={{ marginTop: '20px' }}> |
| 74 |
<Checkbox |
| 75 |
label="isBox" |
| 76 |
isChecked={isBox} |
| 77 |
onChange={(_event, checked) => toggleBox(checked)} |
| 78 |
aria-label="show box variation checkbox with filled icon tabs" |
| 79 |
id="toggle-box-filled-icon" |
| 80 |
name="toggle-box-filled-icon" |
| 81 |
/> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
); |
| 85 |
}; |