This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Laaouatni/bugs-UI-tooltip
fix: #29 popup zIndex bug, and it go outside parentDiv
- Loading branch information
Showing
12 changed files
with
194 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
import Gsimulator from "../Gsimulator.js"; | ||
import GcodeAPI from "../../GcodeAPI_main/GcodeAPI.js"; | ||
// import Gsimulator from "../Gsimulator.js"; | ||
// import GcodeAPI from "../../GcodeAPI_main/GcodeAPI.js"; | ||
|
||
export default class Gcanvas extends Gsimulator { | ||
constructor(_GcanvasObj) { | ||
super(); | ||
// in this case we use || instead of ?? to exclude also 0 from being a size | ||
this.width = _GcanvasObj.width || _GcanvasObj.height || 500; | ||
this.height = _GcanvasObj.height || _GcanvasObj.width || 500; | ||
this.parentHtmlContainer = | ||
_GcanvasObj.parentHtmlContainer ?? | ||
document.querySelector("#app") ?? | ||
document.body; | ||
this.create(); | ||
} | ||
// export default class Gcanvas extends Gsimulator { | ||
// constructor(_GcanvasObj) { | ||
// super(); | ||
// // in this case we use || instead of ?? to exclude also 0 from being a size | ||
// this.width = _GcanvasObj.width || _GcanvasObj.height || 500; | ||
// this.height = _GcanvasObj.height || _GcanvasObj.width || 500; | ||
// this.parentHtmlContainer = | ||
// _GcanvasObj.parentHtmlContainer ?? | ||
// document.querySelector("#app") ?? | ||
// document.body; | ||
// this.create(); | ||
// } | ||
|
||
create() { | ||
this.canvasElement = document.createElement("canvas"); | ||
this.appendCanvasToParent(); | ||
this.changeSize(); | ||
this.reset(); | ||
} | ||
// create() { | ||
// this.canvasElement = document.createElement("canvas"); | ||
// this.appendCanvasToParent(); | ||
// this.changeSize(); | ||
// this.reset(); | ||
// } | ||
|
||
appendCanvasToParent() { | ||
this.parentHtmlContainer.appendChild(this.canvasElement); | ||
} | ||
// appendCanvasToParent() { | ||
// this.parentHtmlContainer.appendChild(this.canvasElement); | ||
// } | ||
|
||
changeSize() { | ||
this.canvasElement.width = this.width; | ||
this.canvasElement.height = this.height; | ||
} | ||
// changeSize() { | ||
// this.canvasElement.width = this.width; | ||
// this.canvasElement.height = this.height; | ||
// } | ||
|
||
reset() { | ||
this.ctx = this.canvasElement.getContext("2d"); | ||
this.ctx.beginPath(); | ||
} | ||
// reset() { | ||
// this.ctx = this.canvasElement.getContext("2d"); | ||
// this.ctx.beginPath(); | ||
// } | ||
|
||
drawLine(_obj) { | ||
this.ctx.lineTo(_obj.x, _obj.y); | ||
this.ctx.stroke(); | ||
} | ||
// drawLine(_obj) { | ||
// this.ctx.lineTo(_obj.x, _obj.y); | ||
// this.ctx.stroke(); | ||
// } | ||
|
||
generate() { | ||
GcodeAPI.array.forEach((pos) => { | ||
this.drawLine(pos); | ||
}); | ||
} | ||
} | ||
// generate() { | ||
// GcodeAPI.array.forEach((pos) => { | ||
// this.drawLine(pos); | ||
// }); | ||
// } | ||
// } |
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
31 changes: 31 additions & 0 deletions
31
...ethods/updatePopup/other/Methods/calcolatePopupArrowPos/x/calcolatePopupArrowXposition.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,31 @@ | ||
export default function calcolatePopupArrowXposition(_x, _this) { | ||
if (_x > _this.parentPosition.x) { | ||
if ( | ||
_this.parentPosition.x + _this.parentElement.offsetWidth < | ||
_x + _this.popup.offsetWidth | ||
) { | ||
return { | ||
popup: | ||
_this.parentPosition.x + | ||
_this.parentElement.offsetWidth - | ||
_this.popup.offsetWidth - | ||
_this.padding, | ||
arrow: _this.arrowX, | ||
}; | ||
} | ||
|
||
return { | ||
popup: _x, | ||
arrow: _this.arrowX, | ||
}; | ||
} else if (_x <= _this.parentPosition.x) { | ||
return { | ||
popup: _this.parentPosition.x + _this.padding, | ||
arrow: | ||
_this.arrowX - | ||
(_this.parentPosition.x - _x) + | ||
_this.padding + | ||
_this.radiusPopup, | ||
}; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ethods/updatePopup/other/Methods/calcolatePopupArrowPos/y/calcolatePopupArrowYposition.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,31 @@ | ||
export default function calcolatePopupArrowYposition(_y, _this) { | ||
if (_y > _this.parentPosition.y) { | ||
if ( | ||
_this.parentPosition.y + _this.parentElement.offsetHeight < | ||
_y + _this.popup.offsetHeight | ||
) { | ||
return { | ||
popup: | ||
_this.parentPosition.y + | ||
_this.parentElement.offsetHeight - | ||
_this.popup.offsetHeight - | ||
_this.padding, | ||
arrow: _this.arrowY, | ||
}; | ||
} | ||
|
||
return { | ||
popup: _y, | ||
arrow: _this.arrowY, | ||
}; | ||
} else if (_y < _this.parentPosition.y) { | ||
return { | ||
popup: _this.parentPosition.y + _this.padding, | ||
arrow: | ||
_this.arrowY - | ||
(_this.parentPosition.y - _y) + | ||
_this.padding + | ||
_this.radiusPopup | ||
}; | ||
} | ||
} |
106 changes: 72 additions & 34 deletions
106
...e/src/API/GcodeApi/Gsimulator/Gcss/CssFloatPopup/other/Methods/updatePopup/updatePopup.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 |
---|---|---|
@@ -1,37 +1,75 @@ | ||
import { computePosition, shift, offset, arrow, autoPlacement } from "@floating-ui/dom"; | ||
|
||
export default function updatePopup(_this) { | ||
computePosition(_this.button, _this.popup, { | ||
placement: "bottom", | ||
middleware: [ | ||
autoPlacement(), | ||
shift({ padding: 8 }), | ||
offset(8), | ||
arrow({ element: _this.arrow }), | ||
], | ||
}).then(({ x, y, placement, middlewareData }) => { | ||
Object.assign(_this.popup.style, { | ||
left: `${x}px`, | ||
top: `${y}px`, | ||
}); | ||
import { | ||
computePosition, | ||
shift, | ||
offset, | ||
arrow, | ||
autoPlacement, | ||
} from "@floating-ui/dom"; | ||
|
||
const { x: arrowX, y: arrowY } = middlewareData.arrow; | ||
|
||
const staticSide = { | ||
top: "bottom", | ||
right: "left", | ||
bottom: "top", | ||
left: "right", | ||
}[placement.split("-")[0]]; | ||
|
||
Object.assign(_this.arrow.style, { | ||
left: arrowX != null ? `${arrowX}px` : "", | ||
top: arrowY != null ? `${arrowY}px` : "", | ||
right: "", | ||
bottom: "", | ||
[staticSide]: "-4px", | ||
}); | ||
}); | ||
} | ||
import calcolatePopupArrowXposition from "./other/Methods/calcolatePopupArrowPos/x/calcolatePopupArrowXposition.js"; | ||
import calcolatePopupArrowYposition from "./other/Methods/calcolatePopupArrowPos/y/calcolatePopupArrowYposition.js"; | ||
export default class UpdatePopup { | ||
constructor(_this) { | ||
this.button = _this.button; | ||
this.popup = _this.popup; | ||
this.arrow = _this.arrow; | ||
|
||
this.parentElement = _this.parentElement; | ||
|
||
this.parentPosition = { | ||
x: this.parentElement.getBoundingClientRect().x, | ||
y: this.parentElement.getBoundingClientRect().y, | ||
}; | ||
|
||
this.padding = 8; | ||
this.radiusPopup = window.getComputedStyle(this.popup).borderRadius.split("px")[0] ?? 0; | ||
} | ||
|
||
update() { | ||
computePosition(this.button, this.popup, { | ||
middleware: [ | ||
autoPlacement(), | ||
shift({ padding: this.padding }), | ||
offset(this.padding), | ||
arrow({ element: this.arrow }), | ||
], | ||
}).then(({ x, y, placement, middlewareData }) => { | ||
({ x: this.arrowX, y: this.arrowY } = middlewareData.arrow); | ||
|
||
this.choosedPos = this.calcolatePosition(x, y); | ||
|
||
Object.assign(this.popup.style, { | ||
left: `${this.choosedPos.popup.x}px`, | ||
top: `${this.choosedPos.popup.y}px`, | ||
}); | ||
|
||
this.staticSide = { | ||
top: "bottom", | ||
right: "left", | ||
bottom: "top", | ||
left: "right", | ||
}[placement.split("-")[0]]; | ||
|
||
Object.assign(this.arrow.style, { | ||
left: this.arrowX != null ? `${this.choosedPos.arrow.x}px` : "", | ||
top: this.arrowY != null ? `${this.choosedPos.arrow.y}px` : "", | ||
right: "", | ||
bottom: "", | ||
[this.staticSide]: `${this.padding * -1}px`, | ||
}); | ||
}); | ||
} | ||
|
||
calcolatePosition(_x, _y) { | ||
return { | ||
popup: { | ||
x: calcolatePopupArrowXposition(_x, this).popup, | ||
y: calcolatePopupArrowYposition(_y, this).popup, | ||
}, | ||
arrow: { | ||
x: calcolatePopupArrowXposition(_x, this).arrow, | ||
y: calcolatePopupArrowYposition(_y, this).arrow, | ||
}, | ||
}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#arrow { | ||
border: 0.1rem solid var(--sky-200); | ||
background-color: var(--sky-50); | ||
border-radius: 0.2rem; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.Gline:hover::before { | ||
transform: scale(2) translateY(-25%); | ||
zoom: 1.5; | ||
} | ||
|
||
.Gline:hover { | ||
|
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
e00cf6b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gcode-js – ./
gcode-js.vercel.app
gcode-js-git-main-laaouatni.vercel.app
gcode-js-laaouatni.vercel.app