Added mouse hovered state when exploring tree
Summary: Added a mouse hover state to detail inspector. The hover state follows you into and out of the hierarchy. changelog: Added hover state to detail inspector Reviewed By: mweststrate Differential Revision: D36781553 fbshipit-source-id: eafbf119a81779bf07199142d305b06ad6b98c52
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ae0a89c580
commit
3412ddfb1b
@@ -37,8 +37,11 @@ export const RootDataContext = createContext<() => any>(() => ({}));
|
|||||||
|
|
||||||
export const contextMenuTrigger = ['contextMenu' as const];
|
export const contextMenuTrigger = ['contextMenu' as const];
|
||||||
|
|
||||||
const BaseContainer = styled.div<{depth?: number; disabled?: boolean}>(
|
const BaseContainer = styled.div<{
|
||||||
(props) => ({
|
depth?: number;
|
||||||
|
disabled?: boolean;
|
||||||
|
hovered: boolean;
|
||||||
|
}>((props) => ({
|
||||||
fontFamily: 'Menlo, monospace',
|
fontFamily: 'Menlo, monospace',
|
||||||
fontSize: 11,
|
fontSize: 11,
|
||||||
lineHeight: '17px',
|
lineHeight: '17px',
|
||||||
@@ -47,8 +50,8 @@ const BaseContainer = styled.div<{depth?: number; disabled?: boolean}>(
|
|||||||
paddingLeft: 10,
|
paddingLeft: 10,
|
||||||
userSelect: 'text',
|
userSelect: 'text',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
}),
|
backgroundColor: props.hovered ? '#f9f9f9' : '',
|
||||||
);
|
}));
|
||||||
BaseContainer.displayName = 'DataInspector:BaseContainer';
|
BaseContainer.displayName = 'DataInspector:BaseContainer';
|
||||||
|
|
||||||
const RecursiveBaseWrapper = styled.span({
|
const RecursiveBaseWrapper = styled.span({
|
||||||
@@ -177,6 +180,10 @@ type DataInspectorProps = {
|
|||||||
value: any,
|
value: any,
|
||||||
name?: string,
|
name?: string,
|
||||||
) => ReactElement[];
|
) => ReactElement[];
|
||||||
|
|
||||||
|
onMouseEnter?: () => void;
|
||||||
|
|
||||||
|
onMouseExit?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultValueExtractor: DataValueExtractor = (value: any) => {
|
const defaultValueExtractor: DataValueExtractor = (value: any) => {
|
||||||
@@ -308,11 +315,14 @@ export const DataInspectorNode: React.FC<DataInspectorProps> = memo(
|
|||||||
tooltips,
|
tooltips,
|
||||||
setValue: setValueProp,
|
setValue: setValueProp,
|
||||||
additionalContextMenuItems,
|
additionalContextMenuItems,
|
||||||
|
onMouseEnter,
|
||||||
|
onMouseExit,
|
||||||
}) {
|
}) {
|
||||||
const highlighter = useHighlighter();
|
const highlighter = useHighlighter();
|
||||||
const getRoot = useContext(RootDataContext);
|
const getRoot = useContext(RootDataContext);
|
||||||
const isUnitTest = useInUnitTest();
|
const isUnitTest = useInUnitTest();
|
||||||
|
|
||||||
|
const [hover, setHover] = useState(false);
|
||||||
const shouldExpand = useRef(false);
|
const shouldExpand = useRef(false);
|
||||||
const expandHandle = useRef(undefined as any);
|
const expandHandle = useRef(undefined as any);
|
||||||
const [renderExpanded, setRenderExpanded] = useState(false);
|
const [renderExpanded, setRenderExpanded] = useState(false);
|
||||||
@@ -418,6 +428,37 @@ export const DataInspectorNode: React.FC<DataInspectorProps> = memo(
|
|||||||
[onDelete],
|
[onDelete],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const thisOnMouseEnter = useCallback(
|
||||||
|
(e: SyntheticEvent) => {
|
||||||
|
onMouseEnter?.();
|
||||||
|
e.stopPropagation();
|
||||||
|
setHover(true);
|
||||||
|
},
|
||||||
|
[onMouseEnter],
|
||||||
|
);
|
||||||
|
|
||||||
|
const thisOnMouseLeave = useCallback(
|
||||||
|
(e: SyntheticEvent) => {
|
||||||
|
onMouseExit?.();
|
||||||
|
e.stopPropagation();
|
||||||
|
setHover(false);
|
||||||
|
},
|
||||||
|
[onMouseExit],
|
||||||
|
);
|
||||||
|
|
||||||
|
const childOnMouseEnter = useCallback(() => {
|
||||||
|
//when a child is hovered we are in both child and parents bounds so
|
||||||
|
//manually disable our own hover state so we focus on child
|
||||||
|
setHover(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const childOnMouseExit = useCallback(() => {
|
||||||
|
//If a child has been unhovered then it means we have left the childs bounds and mouse should still be in parents
|
||||||
|
//(current element's) bounds. However the mouse enter callback wont fire again in this element since we never left the bounds.
|
||||||
|
//Therefore we manually set hovered back to true
|
||||||
|
setHover(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RENDERING
|
* RENDERING
|
||||||
*/
|
*/
|
||||||
@@ -461,6 +502,8 @@ export const DataInspectorNode: React.FC<DataInspectorProps> = memo(
|
|||||||
const metaKey = key + index;
|
const metaKey = key + index;
|
||||||
const dataInspectorNode = (
|
const dataInspectorNode = (
|
||||||
<DataInspectorNode
|
<DataInspectorNode
|
||||||
|
onMouseEnter={childOnMouseEnter}
|
||||||
|
onMouseExit={childOnMouseExit}
|
||||||
parentAncestry={ancestry}
|
parentAncestry={ancestry}
|
||||||
extractValue={extractValue}
|
extractValue={extractValue}
|
||||||
setValue={setValue}
|
setValue={setValue}
|
||||||
@@ -623,6 +666,9 @@ export const DataInspectorNode: React.FC<DataInspectorProps> = memo(
|
|||||||
<Dropdown overlay={getContextMenu} trigger={contextMenuTrigger}>
|
<Dropdown overlay={getContextMenu} trigger={contextMenuTrigger}>
|
||||||
<BaseContainer
|
<BaseContainer
|
||||||
onContextMenu={stopPropagation}
|
onContextMenu={stopPropagation}
|
||||||
|
hovered={hover}
|
||||||
|
onMouseEnter={thisOnMouseEnter}
|
||||||
|
onMouseLeave={thisOnMouseLeave}
|
||||||
depth={depth}
|
depth={depth}
|
||||||
disabled={!!setValueProp && !!setValue === false}>
|
disabled={!!setValueProp && !!setValue === false}>
|
||||||
<PropertyContainer onClick={isExpandable ? handleClick : undefined}>
|
<PropertyContainer onClick={isExpandable ? handleClick : undefined}>
|
||||||
|
|||||||
Reference in New Issue
Block a user