main
js 49 lines 1.29 KB
Raw
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 const isMac =
34 typeof navigator !== 'undefined' &&
35 navigator.platform.toUpperCase().indexOf('MAC') >= 0;
36 const shortcut = isMac ? '⌘E' : 'Ctrl+E';
37 const title = `${isProfiling ? 'Stop' : 'Start'} profiling - ${shortcut}`;
38
39 return (
40 <Button
41 className={className}
42 disabled={disabled}
43 onClick={isProfiling ? stopProfiling : startProfiling}
44 testName="ProfilerToggleButton"
45 title={title}>
46 <ButtonIcon type="record" />
47 </Button>
48 );
49 }