addons/isl/src/FocusMode.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import * as stylex from '@stylexjs/stylex';
b69ab319import {Button} from 'isl-components/Button';
b69ab3110import {Icon} from 'isl-components/Icon';
b69ab3111import {Kbd} from 'isl-components/Kbd';
b69ab3112import {KeyCode, Modifier} from 'isl-components/KeyboardShortcuts';
b69ab3113import {Tooltip} from 'isl-components/Tooltip';
b69ab3114import {useAtom} from 'jotai';
b69ab3115import {colors} from '../../components/theme/tokens.stylex';
b69ab3116import {Column} from './ComponentUtils';
b69ab3117import {useCommand} from './ISLShortcuts';
b69ab3118import {tracker} from './analytics';
b69ab3119import {focusMode} from './atoms/FocusModeState';
b69ab3120import {T} from './i18n';
b69ab3121
b69ab3122const styles = stylex.create({
b69ab3123 focused: {
b69ab3124 backgroundColor: colors.blue,
b69ab3125 color: 'white',
b69ab3126 },
b69ab3127});
b69ab3128
b69ab3129export function FocusModeToggle() {
b69ab3130 const [focused, setFocused] = useAtom(focusMode);
b69ab3131
b69ab3132 const toggleFocus = () => {
b69ab3133 const shouldFocus = !focused;
b69ab3134 tracker.track('SetFocusMode', {extras: {focus: shouldFocus}});
b69ab3135 setFocused(shouldFocus);
b69ab3136 };
b69ab3137
b69ab3138 useCommand('ToggleFocusMode', toggleFocus);
b69ab3139
b69ab3140 const shortcut = <Kbd keycode={KeyCode.F} modifiers={[Modifier.ALT]} />;
b69ab3141 return (
b69ab3142 <Tooltip
b69ab3143 placement="bottom"
b69ab3144 title={
b69ab3145 <Column alignStart>
b69ab3146 <div>
b69ab3147 {focused ? (
b69ab3148 <T replace={{$shortcut: shortcut}}>
b69ab3149 Focus Mode is enabled. Click to disable. ($shortcut)
b69ab3150 </T>
b69ab3151 ) : (
b69ab3152 <T replace={{$shortcut: shortcut}}>Click to enable Focus Mode. ($shortcut)</T>
b69ab3153 )}
b69ab3154 </div>
b69ab3155 <T>In Focus Mode, commits outside your current stack are hidden.</T>
b69ab3156 </Column>
b69ab3157 }>
b69ab3158 <Button
b69ab3159 icon
b69ab3160 xstyle={focused && styles.focused}
b69ab3161 onClick={toggleFocus}
b69ab3162 data-focus-mode={focused}
b69ab3163 data-testid="focus-mode-toggle">
b69ab3164 <Icon icon={focused ? 'screen-normal' : 'screen-full'} />
b69ab3165 </Button>
b69ab3166 </Tooltip>
b69ab3167 );
b69ab3168}