main
js 61 lines 1.62 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 {
12 LOCAL_STORAGE_OPEN_IN_EDITOR_URL,
13 LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET,
14 } from '../../../constants';
15 import {useLocalStorage} from '../hooks';
16 import {
17 getDefaultPreset,
18 getDefaultOpenInEditorURL,
19 } from 'react-devtools-shared/src/utils';
20
21 import styles from './SettingsShared.css';
22
23 export default function CodeEditorOptions({
24 environmentNames,
25 }: {
26 environmentNames: Promise<Array<string>>,
27 }): React.Node {
28 const [openInEditorURLPreset, setOpenInEditorURLPreset] = useLocalStorage<
29 'vscode' | 'custom',
30 >(LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET, getDefaultPreset());
31
32 const [openInEditorURL, setOpenInEditorURL] = useLocalStorage<string>(
33 LOCAL_STORAGE_OPEN_IN_EDITOR_URL,
34 getDefaultOpenInEditorURL(),
35 );
36
37 return (
38 <>
39 <select
40 value={openInEditorURLPreset}
41 onChange={({currentTarget}) => {
42 const selectedValue = currentTarget.value;
43 setOpenInEditorURLPreset(selectedValue);
44 }}>
45 <option value="vscode">VS Code</option>
46 <option value="custom">Custom</option>
47 </select>
48 {openInEditorURLPreset === 'custom' && (
49 <input
50 className={styles.Input}
51 type="text"
52 placeholder={getDefaultOpenInEditorURL()}
53 value={openInEditorURL}
54 onChange={event => {
55 setOpenInEditorURL(event.target.value);
56 }}
57 />
58 )}
59 </>
60 );
61 }