Skip to content

Commit

Permalink
Use tippy.js for context popup
Browse files Browse the repository at this point in the history
By appending the tooltips to document.body, we can avoid any stacking context issues caused by surrounding element's CSS.

I wasn't able to get this portalling to work with Fomantic popups, so this uses tippy.js instead of Fomantic popups. We should aim to replace all Fomantic popups with this eventually.

Fixes: #20377
  • Loading branch information
silverwind committed Jul 17, 2022
1 parent 17ce5f8 commit ba0212f
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 11 deletions.
31 changes: 31 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 @@ -29,6 +29,7 @@
"pretty-ms": "7.0.1",
"sortablejs": "1.15.0",
"swagger-ui-dist": "4.11.1",
"tippy.js": "6.3.7",
"tributejs": "5.1.3",
"uint8-to-base64": "0.2.0",
"vue": "2.6.14",
Expand Down
22 changes: 11 additions & 11 deletions web_src/js/features/contextpopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import $ from 'jquery';
import Vue from 'vue';
import ContextPopup from '../components/ContextPopup.vue';
import {parseIssueHref} from '../utils.js';
import tippy from 'tippy.js';

export default function initContextPopups() {
const refIssues = $('.ref-issue');
Expand All @@ -16,7 +17,6 @@ export default function initContextPopups() {
if (!owner) return;

const el = document.createElement('div');
el.className = 'ui custom popup hidden';
el.innerHTML = '<div></div>';
this.parentNode.insertBefore(el, this.nextSibling);

Expand All @@ -33,17 +33,17 @@ export default function initContextPopups() {
el.textContent = 'ContextPopup failed to load';
}

$(this).popup({
variation: 'wide',
delay: {
show: 250
},
tippy(this, {
appendTo: () => document.body,
placement: 'top-start',
delay: 250,
content: el,
allowHTML: true,
interactive: true,
arrow: `<svg width="16" height="6"><path d="m0 6 8-6 8 6Z" class="tippy-svg-arrow"/><path d="m0 7 8-6 8 6Z" class="tippy-svg-arrow-content"/></svg>`,
onShow: () => {
view.$emit('load-context-popup', {owner, repo, index}, () => {
$(this).popup('reposition');
});
},
popup: $(el),
view.$emit('load-context-popup', {owner, repo, index});
}
});
});
}
87 changes: 87 additions & 0 deletions web_src/less/features/tippy.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
.tippy-box[data-animation="fade"][data-state="hidden"] {
opacity: 0;
}

[data-tippy-root] {
max-width: calc(100vw - 10px);
}

.tippy-box {
position: relative;
background-color: var(--color-body);
color: var(--color-secondary-dark-6);
border: 1px solid var(--color-secondary);
border-radius: var(--border-radius);
padding: .5em;
font-size: 1rem;
transition-property: transform, visibility, opacity;
}

.tippy-box[data-inertia][data-state="visible"] {
transition-timing-function: cubic-bezier(0.54, 1.5, 0.38, 1.11);
}

.tippy-content {
position: relative;
padding: 5px 9px;
z-index: 1;
}

.tippy-svg-arrow {
fill: var(--color-secondary);
}

.tippy-svg-arrow-content {
fill: var(--color-body);
}

.tippy-box[data-placement^="top"] > .tippy-svg-arrow {
bottom: 0;
}

.tippy-box[data-placement^="top"] > .tippy-svg-arrow:after,
.tippy-box[data-placement^="top"] > .tippy-svg-arrow > svg {
top: 16px;
transform: rotate(180deg);
}

.tippy-box[data-placement^="bottom"] > .tippy-svg-arrow {
top: 0;
}

.tippy-box[data-placement^="bottom"] > .tippy-svg-arrow > svg {
bottom: 16px;
}

.tippy-box[data-placement^="left"] > .tippy-svg-arrow {
right: 0;
}

.tippy-box[data-placement^="left"] > .tippy-svg-arrow:after,
.tippy-box[data-placement^="left"] > .tippy-svg-arrow > svg {
transform: rotate(90deg);
top: calc(50% - 3px);
left: 11px;
}

.tippy-box[data-placement^="right"] > .tippy-svg-arrow {
left: 0;
}

.tippy-box[data-placement^="right"] > .tippy-svg-arrow:after,
.tippy-box[data-placement^="right"] > .tippy-svg-arrow > svg {
transform: rotate(-90deg);
top: calc(50% - 3px);
right: 11px;
}

.tippy-svg-arrow {
width: 16px;
height: 16px;
text-align: initial;
}

.tippy-svg-arrow,
.tippy-svg-arrow > svg {
position: absolute;
}
1 change: 1 addition & 0 deletions web_src/less/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@import "./features/imagediff.less";
@import "./features/codeeditor.less";
@import "./features/projects.less";
@import "./features/tippy.less";
@import "./markup/content.less";
@import "./markup/codecopy.less";
@import "./code/linebutton.less";
Expand Down

0 comments on commit ba0212f

Please sign in to comment.