| 1 |
import { useState } from 'react'; |
| 2 |
import { ToggleGroup, ToggleGroupItem } from '@patternfly/react-core'; |
| 3 |
import UndoIcon from '@patternfly/react-icons/dist/esm/icons/undo-icon'; |
| 4 |
import RhUiCopyFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-copy-fill-icon'; |
| 5 |
import ShareSquareIcon from '@patternfly/react-icons/dist/esm/icons/share-square-icon'; |
| 6 |
|
| 7 |
export const ToggleGroupIcon: React.FunctionComponent = () => { |
| 8 |
const [isSelected, setIsSelected] = useState({ |
| 9 |
'text-icons-1': false, |
| 10 |
'text-icons-2': false, |
| 11 |
'text-icons-3': true |
| 12 |
}); |
| 13 |
const handleItemClick = (event, isSelected: boolean) => { |
| 14 |
const id = event.currentTarget.id; |
| 15 |
setIsSelected((prevIsSelected) => ({ ...prevIsSelected, [id]: isSelected })); |
| 16 |
}; |
| 17 |
return ( |
| 18 |
<> |
| 19 |
<ToggleGroup aria-label="Text and icon toggle group with icons at start"> |
| 20 |
<ToggleGroupItem |
| 21 |
icon={<RhUiCopyFillIcon />} |
| 22 |
text="Copy" |
| 23 |
buttonId="toggle-group-text-icons-1" |
| 24 |
isSelected={isSelected['toggle-group-text-icons-1']} |
| 25 |
onChange={handleItemClick} |
| 26 |
/> |
| 27 |
<ToggleGroupItem |
| 28 |
icon={<UndoIcon />} |
| 29 |
text="Undo" |
| 30 |
buttonId="toggle-group-text-icons-2" |
| 31 |
isSelected={isSelected['toggle-group-text-icons-2']} |
| 32 |
onChange={handleItemClick} |
| 33 |
/> |
| 34 |
<ToggleGroupItem |
| 35 |
icon={<ShareSquareIcon />} |
| 36 |
text="Share" |
| 37 |
buttonId="toggle-group-text-icons-3" |
| 38 |
isSelected={isSelected['toggle-group-text-icons-3']} |
| 39 |
onChange={handleItemClick} |
| 40 |
/> |
| 41 |
</ToggleGroup> |
| 42 |
<br /> |
| 43 |
<ToggleGroup aria-label="Text and icon toggle group with icons at end"> |
| 44 |
<ToggleGroupItem |
| 45 |
icon={<RhUiCopyFillIcon />} |
| 46 |
iconPosition="end" |
| 47 |
text="Copy" |
| 48 |
buttonId="toggle-group-text-icons-4" |
| 49 |
isSelected={isSelected['toggle-group-text-icons-4']} |
| 50 |
onChange={handleItemClick} |
| 51 |
/> |
| 52 |
<ToggleGroupItem |
| 53 |
icon={<UndoIcon />} |
| 54 |
iconPosition="end" |
| 55 |
text="Undo" |
| 56 |
buttonId="toggle-group-text-icons-5" |
| 57 |
isSelected={isSelected['toggle-group-text-icons-5']} |
| 58 |
onChange={handleItemClick} |
| 59 |
/> |
| 60 |
<ToggleGroupItem |
| 61 |
icon={<ShareSquareIcon />} |
| 62 |
iconPosition="end" |
| 63 |
text="Share" |
| 64 |
buttonId="toggle-group-text-icons-6" |
| 65 |
isSelected={isSelected['toggle-group-text-icons-6']} |
| 66 |
onChange={handleItemClick} |
| 67 |
/> |
| 68 |
</ToggleGroup> |
| 69 |
</> |
| 70 |
); |
| 71 |
}; |