-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DevTools] Support for adding props | Improved state/props value edit…
…ing (#16700) * Extracted sanitizeForParse * Added canAddEntries flag to InspectedElementTree * Added EditableKey component. * Added support to add an additional entry. * Added support to add more complex data structures in the EditableValue component. Added support to change the dataType of the value that is being changed. * Fixed flow error. * Removed unneeded fragment. * Renamed EditableKey -> EditableName * Removed unneeded dependency * Removed problematic props to state hook. * Prettified changes. * Removed unused import. * Fixed shouldStringify check. * Removed testing props from EditableProps. * Made some inline tweaks
- Loading branch information
1 parent
4ef6387
commit 709baf1
Showing
11 changed files
with
307 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/react-devtools-shared/src/devtools/views/Components/EditableName.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.Input { | ||
flex: 0 1 auto; | ||
padding: 1px; | ||
box-shadow: 0px 1px 3px transparent; | ||
} | ||
.Input:focus { | ||
color: var(--color-text); | ||
box-shadow: 0px 1px 3px var(--color-shadow); | ||
} |
78 changes: 78 additions & 0 deletions
78
packages/react-devtools-shared/src/devtools/views/Components/EditableName.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import React, {useCallback, useState} from 'react'; | ||
import AutoSizeInput from './NativeStyleEditor/AutoSizeInput'; | ||
import styles from './EditableName.css'; | ||
|
||
type OverrideNameFn = (path: Array<string | number>, value: any) => void; | ||
|
||
type EditableNameProps = {| | ||
autoFocus?: boolean, | ||
initialValue?: string, | ||
overrideNameFn: OverrideNameFn, | ||
|}; | ||
|
||
export default function EditableName({ | ||
autoFocus = false, | ||
initialValue = '', | ||
overrideNameFn, | ||
}: EditableNameProps) { | ||
const [editableName, setEditableName] = useState(initialValue); | ||
const [isValid, setIsValid] = useState(false); | ||
|
||
const handleChange = useCallback( | ||
({target}) => { | ||
const value = target.value.trim(); | ||
|
||
if (value) { | ||
setIsValid(true); | ||
} else { | ||
setIsValid(false); | ||
} | ||
|
||
setEditableName(value); | ||
}, | ||
[overrideNameFn], | ||
); | ||
|
||
const handleKeyDown = useCallback( | ||
event => { | ||
// Prevent keydown events from e.g. change selected element in the tree | ||
event.stopPropagation(); | ||
|
||
switch (event.key) { | ||
case 'Enter': | ||
case 'Tab': | ||
if (isValid) { | ||
overrideNameFn(editableName); | ||
} | ||
break; | ||
case 'Escape': | ||
setEditableName(initialValue); | ||
break; | ||
default: | ||
break; | ||
} | ||
}, | ||
[editableName, setEditableName, isValid, initialValue, overrideNameFn], | ||
); | ||
|
||
return ( | ||
<AutoSizeInput | ||
autoFocus={autoFocus} | ||
className={styles.Input} | ||
onChange={handleChange} | ||
onKeyDown={handleKeyDown} | ||
placeholder="new prop" | ||
type="text" | ||
value={editableName} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.