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

feat: plugin config param tooltips #30

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
43 changes: 36 additions & 7 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log"],
"ignorePaths": [
"**/*.json",
"**/*.css",
"node_modules",
"**/*.log"
],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir"],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"],
"ignoreWords": ["ubiquibot", "Supabase", "supabase", "SUPABASE", "sonarjs", "mischeck", "Typebox"]
}
"words": [
"dataurl",
"devpool",
"outdir",
"servedir"
],
"dictionaries": [
"typescript",
"node",
"software-terms"
],
"import": [
"@cspell/dict-typescript/cspell-ext.json",
"@cspell/dict-node/cspell-ext.json",
"@cspell/dict-software-terms"
],
"ignoreRegExpList": [
"[0-9a-fA-F]{6}"
],
"ignoreWords": [
"ubiquibot",
"Supabase",
"supabase",
"SUPABASE",
"sonarjs",
"mischeck",
"Typebox",
"tooltiptext"
]
}
30 changes: 30 additions & 0 deletions static/manifest-gui.css
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,36 @@ button#add:active::before {
content: "+++";
}

#manifest-gui pre {
margin: 0 0 16px;
}

.tooltip {
position: relative;
display: inline-block;
cursor: help;
padding-left: 8px;
}

.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #101010;
color: #fff;
text-align: center;
border-radius: 4px;
padding: 8px;
position: absolute;
z-index: 1;
opacity: 0;
transition: opacity 0.25s;
}

.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}

.picker-select {
width: 100%;
padding: 8px 16px;
Expand Down
4 changes: 3 additions & 1 deletion static/types/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface Uses {
}

export interface ManifestPreDecode extends Manifest {
manifest: Manifest;
actionUrl?: string;
workerUrl?: string;
error?: string;
Expand All @@ -31,7 +32,8 @@ export type Manifest = {
};
configuration: {
type: string;
default: object;
default: unknown;
description?: string;
items?: {
type: string;
};
Expand Down
36 changes: 36 additions & 0 deletions static/utils/element-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function createInputRow(
const headerCell = document.createElement("td");
headerCell.className = "table-data-header";
headerCell.textContent = key.replace(/([A-Z])/g, " $1");

createConfigParamTooltip(headerCell, prop);

row.appendChild(headerCell);

const valueCell = document.createElement("td");
Expand Down Expand Up @@ -111,3 +114,36 @@ export function createTextareaInput(key: string, defaultValue: object | unknown,

return inputElem;
}

function createConfigParamTooltip(headerCell: HTMLElement, prop: ManifestProps) {
if (!prop.description) return;

const tooltip = createElement("span", { class: "tooltip", textContent: "?" });
const tooltipText = createElement("span", { class: "tooltiptext", textContent: prop.description });

tooltip.appendChild(tooltipText);
headerCell.appendChild(tooltip);

tooltip.addEventListener("mouseenter", () => {
const tooltipRect = tooltip.getBoundingClientRect();
const tooltipTextRect = tooltipText.getBoundingClientRect();
const spaceAbove = tooltipRect.top;
const spaceBelow = window.innerHeight - tooltipRect.bottom;

if (spaceBelow < tooltipTextRect.height && spaceAbove > spaceBelow) {
tooltipText.style.bottom = `${tooltipRect.height}px`;
tooltipText.style.top = "auto";
} else {
tooltipText.style.top = `${tooltipRect.height}px`;
tooltipText.style.bottom = "auto";
}

tooltipText.style.visibility = "visible";
tooltipText.style.opacity = "1";
});

tooltip.addEventListener("mouseleave", () => {
tooltipText.style.visibility = "hidden";
tooltipText.style.opacity = "0";
});
}
Loading