mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-29 10:54:02 -05:00
52cbe2bdbc
- Show popover on hover/focus (tippy default) instead of click - If there is only one status, add href to trigger element - Increase tippy [interactiveBorder](https://atomiks.github.io/tippyjs/v6/all-props/#interactiveborder), making it easier to keep interactive tooltips open with sloppy mouse movement - Fix a overflow issue in the commit list Commit list before: <img width="459" alt="Screen Shot 2022-09-09 at 19 00 01" src="https://user-images.githubusercontent.com/115237/189405517-68de5a69-e312-4ea2-ab81-87629db6064b.png"> Commit List after: <img width="475" alt="Screen Shot 2022-09-09 at 19 01 43" src="https://user-images.githubusercontent.com/115237/189405574-13e84885-9073-4f86-9eeb-d008c1639647.png"> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
import tippy from 'tippy.js';
|
|
|
|
export function createTippy(target, opts = {}) {
|
|
const instance = tippy(target, {
|
|
appendTo: document.body,
|
|
placement: target.getAttribute('data-placement') || 'top-start',
|
|
animation: false,
|
|
allowHTML: false,
|
|
interactiveBorder: 30,
|
|
ignoreAttributes: true,
|
|
maxWidth: 500, // increase over default 350px
|
|
arrow: `<svg width="16" height="7"><path d="m0 7 8-7 8 7Z" class="tippy-svg-arrow-outer"/><path d="m0 8 8-7 8 7Z" class="tippy-svg-arrow-inner"/></svg>`,
|
|
...(opts?.role && {theme: opts.role}),
|
|
...opts,
|
|
});
|
|
|
|
// for popups where content refers to a DOM element, we use the 'tippy-target' class
|
|
// to initially hide the content, now we can remove it as the content has been removed
|
|
// from the DOM by tippy
|
|
if (opts.content instanceof Element) {
|
|
opts.content.classList.remove('tippy-target');
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
|
|
export function initTooltip(el, props = {}) {
|
|
const content = el.getAttribute('data-content') || props.content;
|
|
if (!content) return null;
|
|
return createTippy(el, {
|
|
content,
|
|
delay: 100,
|
|
role: 'tooltip',
|
|
...props,
|
|
});
|
|
}
|
|
|
|
export function showTemporaryTooltip(target, content) {
|
|
let tippy, oldContent;
|
|
if (target._tippy) {
|
|
tippy = target._tippy;
|
|
oldContent = tippy.props.content;
|
|
} else {
|
|
tippy = initTooltip(target, {content});
|
|
}
|
|
|
|
tippy.setContent(content);
|
|
tippy.show();
|
|
tippy.setProps({
|
|
onHidden: (tippy) => {
|
|
if (oldContent) {
|
|
tippy.setContent(oldContent);
|
|
} else {
|
|
tippy.destroy();
|
|
}
|
|
tippy.setProps({onHidden: undefined});
|
|
},
|
|
});
|
|
}
|