-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: tidy up highlighter creation (#989)
* chore: do not render invisible element highlights * chore: split element & bound highlighters * chore: remove unused function variable
- Loading branch information
Showing
5 changed files
with
68 additions
and
59 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
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
app/renderer/components/Inspector/HighlighterRectForBounds.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,22 @@ | ||
import React from 'react'; | ||
import InspectorCSS from './Inspector.css'; | ||
|
||
/** | ||
* Single absolute positioned div that overlays the app screenshot and highlights the bounding | ||
* box of the element found through element search | ||
*/ | ||
const HighlighterRectForBounds = ({ elSize, elLocation, scaleRatio, xOffset }) => ( | ||
<div className={`${InspectorCSS['highlighter-box']} ${InspectorCSS['inspected-element-box']}`} | ||
// Unique keys are assigned to elements by their x & y coordinates | ||
key={`searchedForElement{x: ${elLocation.x}, y: ${elLocation.y}}`} | ||
style={{ | ||
left: elLocation.x / scaleRatio + xOffset, | ||
top: elLocation.y / scaleRatio, | ||
width: elSize.width / scaleRatio, | ||
height: elSize.height / scaleRatio | ||
}}> | ||
<div></div> | ||
</div> | ||
); | ||
|
||
export default HighlighterRectForBounds; |
34 changes: 34 additions & 0 deletions
34
app/renderer/components/Inspector/HighlighterRectForElem.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,34 @@ | ||
import React from 'react'; | ||
import InspectorCSS from './Inspector.css'; | ||
|
||
/** | ||
* Absolute positioned divs that overlay the app screenshot and highlight the bounding | ||
* boxes of the elements in the app | ||
*/ | ||
const HighlighterRectForElem = (props) => { | ||
const { hoveredElement = {}, selectHoveredElement, unselectHoveredElement, | ||
selectedElement = {}, selectElement, unselectElement, dimensions, element } = props; | ||
|
||
const { width, height, left, top } = dimensions; | ||
const key = element.path; | ||
let highlighterClasses = [InspectorCSS['highlighter-box']]; | ||
|
||
// Add class + special classes to hovered and selected elements | ||
if (hoveredElement.path === element.path) { | ||
highlighterClasses.push(InspectorCSS['hovered-element-box']); | ||
} | ||
if (selectedElement.path === element.path) { | ||
highlighterClasses.push(InspectorCSS['inspected-element-box']); | ||
} | ||
|
||
return <div className={highlighterClasses.join(' ').trim()} | ||
onMouseOver={() => selectHoveredElement(key)} | ||
onMouseOut={unselectHoveredElement} | ||
onClick={() => key === selectedElement.path ? unselectElement() : selectElement(key)} | ||
key={key} | ||
style={{left: (left || 0), top: (top || 0), width: (width || 0), height: (height || 0)}}> | ||
<div></div> | ||
</div>; | ||
}; | ||
|
||
export default HighlighterRectForElem; |
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