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 tooltips using Tippy.js #456

Merged
merged 4 commits into from
Oct 17, 2023
Merged
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
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"lottie-web": "^5.9.5",
"notyf": "^3.9.0",
"sweetalert2": "^11.6.13",
"tippy.js": "^6.3.7",
"v8-compile-cache": "^2.3.0"
},
"devDependencies": {
Expand Down
7 changes: 0 additions & 7 deletions src/renderer/assets/css/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,6 @@ table.table-save-metadata {
font-size: 14px;
font-style: italic;
}

.info {
width: 18px;
height: 18px;
float: right;
}

.tooltipnew .tooltiptext {
visibility: hidden;
width: 400px;
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/assets/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
word-break: break-all;
}

/* Tippy */
.tippy-box[data-theme~="error"] {
background-color: hsl(0, 100%, 70%);
}

.tippy-box[data-theme~="warning"] {
background-color: hsl(57, 100%, 70%);
}

/* Global ---------------------------- */

* {
Expand Down
36 changes: 26 additions & 10 deletions src/renderer/src/stories/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import { errorHue, warningHue } from "./globals";
import { checkStatus } from "../validation";
import { emojiFontFamily } from "./globals";

import tippy from "tippy.js";
import "tippy.js/dist/tippy.css";

const maxRows = 20;

// Inject scoped stylesheet
const styles = `

${css}


.handsontable td[error] {
background: hsl(${errorHue}, 100%, 90%) !important;
}
Expand All @@ -37,11 +41,8 @@ const styles = `
padding-left: 20px
}

[title] .relative::after {
content: 'ℹ️';
display: inline-block;
.relative .info {
margin: 0px 5px;
text-align: center;
font-size: 80%;
font-family: ${emojiFontFamily}
}
Expand Down Expand Up @@ -283,7 +284,19 @@ export class Table extends LitElement {

const onAfterGetHeader = function (index, TH) {
const desc = entries[colHeaders[index]].description;
if (desc) TH.setAttribute("title", desc);
if (desc) {
const rel = TH.querySelector(".relative");
let span = rel.querySelector(".info");
if (!span) {
span = document.createElement("span");
span.classList.add("info");
span.innerText = "ℹ️";
rel.append(span);
}

if (span._tippy) span._tippy.destroy();
tippy(span, { content: `${desc}` });
}
};

const data = this.#getData();
Expand Down Expand Up @@ -425,17 +438,20 @@ export class Table extends LitElement {

if (cell) {
let title = "";
let theme = "";
if (warnings.length) {
cell.setAttribute("warning", "");
title = warnings.map((o) => o.message).join("\n");
(theme = "warning"), (title = warnings.map((o) => o.message).join("\n"));
} else cell.removeAttribute("warning");

if (errors.length) {
cell.setAttribute("error", "");
title = errors.map((o) => o.message).join("\n"); // Class switching handled automatically
(theme = "error"), (title = errors.map((o) => o.message).join("\n")); // Class switching handled automatically
} else cell.removeAttribute("error");

if (title) cell.title = title;
if (theme) cell.setAttribute(theme, "");

if (cell._tippy) cell._tippy.destroy();

if (title) tippy(cell, { content: title, theme });
}

this.#checkStatus(); // Check status after every validation update
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/stories/pages/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Page extends LitElement {
notify = (...args) => {
const ref = notify(...args);
this.#notifications.push(ref);
return ref
return ref;
};

to = async (transition) => {
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/src/stories/pages/settings/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class SettingsPage extends Page {

#openNotyf = (message, type) => {
if (this.#notification) notyf.dismiss(this.#notification);
return (this.#notification = this.notify(message,type));
return (this.#notification = this.notify(message, type));
};

beforeSave = () => {
Expand All @@ -60,8 +60,7 @@ export class SettingsPage extends Page {
const button = new Button({
label: "Save Changes",
onClick: async () => {
if (!this.unsavedUpdates)
return this.#openNotyf("All changes were already saved", "success");
if (!this.unsavedUpdates) return this.#openNotyf("All changes were already saved", "success");
this.save();
},
});
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/src/stories/pages/uploads/UploadsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ export async function uploadToDandi(info, type = "project" in info ? "project" :
},
{ title: "Uploading to DANDI" }
).catch((e) => {
this.notify(e.message, 'error');
this.notify(e.message, "error");
throw e;
});

if (result) this.notify(`${info.project ?? `${info[folderPathKey].length} filesystem entries`} successfully uploaded to Dandiset ${dandiset_id}`, "success");
if (result)
this.notify(
`${
info.project ?? `${info[folderPathKey].length} filesystem entries`
} successfully uploaded to Dandiset ${dandiset_id}`,
"success"
);

return result;
}
Expand Down
Loading