| 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 | |
| 8 | import * as stylex from '@stylexjs/stylex'; |
| 9 | import {Button} from 'isl-components/Button'; |
| 10 | import {Icon} from 'isl-components/Icon'; |
| 11 | import {Kbd} from 'isl-components/Kbd'; |
| 12 | import {KeyCode, Modifier} from 'isl-components/KeyboardShortcuts'; |
| 13 | import {Tooltip} from 'isl-components/Tooltip'; |
| 14 | import {useAtom} from 'jotai'; |
| 15 | import {colors} from '../../components/theme/tokens.stylex'; |
| 16 | import {Column} from './ComponentUtils'; |
| 17 | import {useCommand} from './ISLShortcuts'; |
| 18 | import {tracker} from './analytics'; |
| 19 | import {focusMode} from './atoms/FocusModeState'; |
| 20 | import {T} from './i18n'; |
| 21 | |
| 22 | const styles = stylex.create({ |
| 23 | focused: { |
| 24 | backgroundColor: colors.blue, |
| 25 | color: 'white', |
| 26 | }, |
| 27 | }); |
| 28 | |
| 29 | export 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 | |