Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tool-tip component #762

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/fontra/client/web-components/tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { UnlitElement } from "/core/unlit.js";
import * as html from "/core/unlit.js";

export class Tooltip extends UnlitElement {
static styles = `
.tooltip {
background: #f2f2f2;
position: absolute;
width: 200px;
padding: 9px;
margin: 6px 0;
box-shadow: 0 0 4px 0 #686868;
}

.hidden {
display: none;
}
`;

constructor() {
super();
this.x = 0;
this.y = 0;
}

connectedCallback() {
const showFor = this.parentElement.querySelector(this.showFor);
const observer = new ResizeObserver(() => {
if (!this._element) {
return;
}
const boundingClientRect = showFor.getBoundingClientRect();
this.x = boundingClientRect.x;
this.y = boundingClientRect.y + boundingClientRect.height;
this._element.style.top = this.y + "px";
this._element.style.left = this.x + "px";
});
observer.observe(showFor);
showFor.addEventListener("mouseover", () => {
this._element.classList.remove("hidden");
});
showFor.addEventListener("mouseout", () => {
this._element.classList.add("hidden");
});
}

static properties = {
text: { type: String },
showFor: { type: String },
};

render() {
this._element = html.div(
{
class: "tooltip hidden",
},
this.text
);
return this._element;
}
}

customElements.define("tool-tip", Tooltip);
9 changes: 9 additions & 0 deletions src/fontra/views/editor/panel-designspace-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { showMenu } from "/web-components/menu-panel.js";
import { dialogSetup } from "/web-components/modal-dialog.js";
import { IconButton } from "/web-components/icon-button.js";
import { Tooltip } from "/web-components/tooltip.js";
import { NumberFormatter } from "/web-components/ui-list.js";
import Panel from "./panel.js";

Expand Down Expand Up @@ -83,13 +84,21 @@ export default class DesignspaceNavigationPanel extends Panel {
[]
),
html.div({ class: "axis-buttons-container" }, [
html.createDomElement("tool-tip", {
text: "Reset all axes",
showFor: "#reset-axes-button",
}),
html.createDomElement("icon-button", {
id: "reset-axes-button",
src: "/tabler-icons/refresh.svg",
onclick: (event) => this.resetAllAxesToDefault(event),
disabled: false,
hidden: true,
}),
html.createDomElement("tool-tip", {
text: "Edit local axes",
showFor: "#edit-local-axes-button",
}),
html.createDomElement("icon-button", {
id: "edit-local-axes-button",
src: "/tabler-icons/settings.svg",
Expand Down