| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import * as React from 'react'; |
| 11 | import Button from '../Button'; |
| 12 | import ButtonIcon from '../ButtonIcon'; |
| 13 | |
| 14 | import styles from './ExpandCollapseToggle.css'; |
| 15 | |
| 16 | type ExpandCollapseToggleProps = { |
| 17 | disabled: boolean, |
| 18 | isOpen: boolean, |
| 19 | setIsOpen: Function, |
| 20 | }; |
| 21 | |
| 22 | export default function ExpandCollapseToggle({ |
| 23 | disabled, |
| 24 | isOpen, |
| 25 | setIsOpen, |
| 26 | }: ExpandCollapseToggleProps): React.Node { |
| 27 | return ( |
| 28 | <Button |
| 29 | className={styles.ExpandCollapseToggle} |
| 30 | disabled={disabled} |
| 31 | onClick={() => setIsOpen(prevIsOpen => !prevIsOpen)} |
| 32 | title={`${isOpen ? 'Collapse' : 'Expand'} prop value`}> |
| 33 | <ButtonIcon type={isOpen ? 'expanded' : 'collapsed'} /> |
| 34 | </Button> |
| 35 | ); |
| 36 | } |