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 {useContext} from 'react';
    
  12. import Button from '../Button';
    
  13. import ButtonIcon from '../ButtonIcon';
    
  14. import {ProfilerContext} from './ProfilerContext';
    
  15. 
    
  16. import styles from './RecordToggle.css';
    
  17. 
    
  18. export type Props = {
    
  19.   disabled?: boolean,
    
  20. };
    
  21. 
    
  22. export default function RecordToggle({disabled}: Props): React.Node {
    
  23.   const {isProfiling, startProfiling, stopProfiling} =
    
  24.     useContext(ProfilerContext);
    
  25. 
    
  26.   let className = styles.InactiveRecordToggle;
    
  27.   if (disabled) {
    
  28.     className = styles.DisabledRecordToggle;
    
  29.   } else if (isProfiling) {
    
  30.     className = styles.ActiveRecordToggle;
    
  31.   }
    
  32. 
    
  33.   return (
    
  34.     <Button
    
  35.       className={className}
    
  36.       disabled={disabled}
    
  37.       onClick={isProfiling ? stopProfiling : startProfiling}
    
  38.       testName="ProfilerToggleButton"
    
  39.       title={isProfiling ? 'Stop profiling' : 'Start profiling'}>
    
  40.       <ButtonIcon type="record" />
    
  41.     </Button>
    
  42.   );
    
  43. }