2.0 KB69 lines
Blame
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
8import * as stylex from '@stylexjs/stylex';
9import {Button} from 'isl-components/Button';
10import {Icon} from 'isl-components/Icon';
11import {Kbd} from 'isl-components/Kbd';
12import {KeyCode, Modifier} from 'isl-components/KeyboardShortcuts';
13import {Tooltip} from 'isl-components/Tooltip';
14import {useAtom} from 'jotai';
15import {colors} from '../../components/theme/tokens.stylex';
16import {Column} from './ComponentUtils';
17import {useCommand} from './ISLShortcuts';
18import {tracker} from './analytics';
19import {focusMode} from './atoms/FocusModeState';
20import {T} from './i18n';
21
22const styles = stylex.create({
23 focused: {
24 backgroundColor: colors.blue,
25 color: 'white',
26 },
27});
28
29export function FocusModeToggle() {
30 const [focused, setFocused] = useAtom(focusMode);
31
32 const toggleFocus = () => {
33 const shouldFocus = !focused;
34 tracker.track('SetFocusMode', {extras: {focus: shouldFocus}});
35 setFocused(shouldFocus);
36 };
37
38 useCommand('ToggleFocusMode', toggleFocus);
39
40 const shortcut = <Kbd keycode={KeyCode.F} modifiers={[Modifier.ALT]} />;
41 return (
42 <Tooltip
43 placement="bottom"
44 title={
45 <Column alignStart>
46 <div>
47 {focused ? (
48 <T replace={{$shortcut: shortcut}}>
49 Focus Mode is enabled. Click to disable. ($shortcut)
50 </T>
51 ) : (
52 <T replace={{$shortcut: shortcut}}>Click to enable Focus Mode. ($shortcut)</T>
53 )}
54 </div>
55 <T>In Focus Mode, commits outside your current stack are hidden.</T>
56 </Column>
57 }>
58 <Button
59 icon
60 xstyle={focused && styles.focused}
61 onClick={toggleFocus}
62 data-focus-mode={focused}
63 data-testid="focus-mode-toggle">
64 <Icon icon={focused ? 'screen-normal' : 'screen-full'} />
65 </Button>
66 </Tooltip>
67 );
68}
69