1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-04 01:27:20 +00:00

Fix stopwatch and introduce default tippy theme

This commit is contained in:
silverwind
2024-04-27 17:06:32 +02:00
parent 6d2a307ad8
commit a6e746adb3
8 changed files with 43 additions and 29 deletions

View File

@ -82,31 +82,33 @@
</div> </div>
<span class="only-mobile tw-ml-2">{{ctx.Locale.Tr "active_stopwatch"}}</span> <span class="only-mobile tw-ml-2">{{ctx.Locale.Tr "active_stopwatch"}}</span>
</a> </a>
<div class="active-stopwatch-popup item tippy-target tw-p-2"> <div class="active-stopwatch-popup tippy-target">
<div class="tw-flex tw-items-center"> <div class="tw-flex tw-items-center item tw-gap-2 tw-p-2">
<a class="stopwatch-link tw-flex tw-items-center" href="{{.ActiveStopwatch.IssueLink}}"> {{svg "octicon-issue-opened" 16}}
{{svg "octicon-issue-opened" 16 "tw-mr-2"}} <a class="stopwatch-link tw-flex muted" href="{{.ActiveStopwatch.IssueLink}}">
<span class="stopwatch-issue">{{.ActiveStopwatch.RepoSlug}}#{{.ActiveStopwatch.IssueIndex}}</span> <span class="stopwatch-issue">{{.ActiveStopwatch.RepoSlug}}#{{.ActiveStopwatch.IssueIndex}}</span>
<span class="ui primary label stopwatch-time tw-my-0 tw-mx-4" data-seconds="{{.ActiveStopwatch.Seconds}}">
{{if .ActiveStopwatch}}{{Sec2Time .ActiveStopwatch.Seconds}}{{end}}
</span>
</a> </a>
<form class="stopwatch-commit" method="post" action="{{.ActiveStopwatch.IssueLink}}/times/stopwatch/toggle"> <span class="ui primary label stopwatch-time" data-seconds="{{.ActiveStopwatch.Seconds}}">
{{.CsrfTokenHtml}} {{if .ActiveStopwatch}}{{Sec2Time .ActiveStopwatch.Seconds}}{{end}}
<button </span>
type="submit" <div class="tw-flex tw-gap-1">
class="ui button mini compact basic icon" <form class="stopwatch-commit" method="post" action="{{.ActiveStopwatch.IssueLink}}/times/stopwatch/toggle">
data-tooltip-content="{{ctx.Locale.Tr "repo.issues.stop_tracking"}}" {{.CsrfTokenHtml}}
>{{svg "octicon-square-fill"}}</button> <button
</form> type="submit"
<form class="stopwatch-cancel" method="post" action="{{.ActiveStopwatch.IssueLink}}/times/stopwatch/cancel"> class="ui button mini compact basic icon tw-mr-0"
{{.CsrfTokenHtml}} data-tooltip-content="{{ctx.Locale.Tr "repo.issues.stop_tracking"}}"
<button >{{svg "octicon-square-fill"}}</button>
type="submit" </form>
class="ui button mini compact basic icon" <form class="stopwatch-cancel" method="post" action="{{.ActiveStopwatch.IssueLink}}/times/stopwatch/cancel">
data-tooltip-content="{{ctx.Locale.Tr "repo.issues.cancel_tracking"}}" {{.CsrfTokenHtml}}
>{{svg "octicon-trash"}}</button> <button
</form> type="submit"
class="ui button mini compact basic icon tw-mr-0"
data-tooltip-content="{{ctx.Locale.Tr "repo.issues.cancel_tracking"}}"
>{{svg "octicon-trash"}}</button>
</form>
</div>
</div> </div>
</div> </div>
{{end}} {{end}}

View File

@ -16,8 +16,8 @@
.tippy-box { .tippy-box {
position: relative; position: relative;
background-color: var(--color-body); background-color: var(--color-menu);
color: var(--color-secondary-dark-6); color: var(--color-text);
border: 1px solid var(--color-secondary); border: 1px solid var(--color-secondary);
border-radius: var(--border-radius); border-radius: var(--border-radius);
font-size: 1rem; font-size: 1rem;
@ -25,7 +25,6 @@
.tippy-content { .tippy-content {
position: relative; position: relative;
padding: 1rem; /* if you need different padding, use different data-theme */
z-index: 1; z-index: 1;
} }

View File

@ -18,6 +18,7 @@ export function attachRefIssueContextPopup(refIssues) {
if (!owner) return; if (!owner) return;
const el = document.createElement('div'); const el = document.createElement('div');
el.classList.add('tw-p-3');
refIssue.parentNode.insertBefore(el, refIssue.nextSibling); refIssue.parentNode.insertBefore(el, refIssue.nextSibling);
const view = createApp(ContextPopup); const view = createApp(ContextPopup);
@ -30,6 +31,7 @@ export function attachRefIssueContextPopup(refIssues) {
} }
createTippy(refIssue, { createTippy(refIssue, {
theme: 'default',
content: el, content: el,
placement: 'top-start', placement: 'top-start',
interactive: true, interactive: true,

View File

@ -113,6 +113,7 @@ function showLineButton() {
btn.closest('.code-view').append(menu.cloneNode(true)); btn.closest('.code-view').append(menu.cloneNode(true));
createTippy(btn, { createTippy(btn, {
theme: 'menu',
trigger: 'click', trigger: 'click',
hideOnClick: true, hideOnClick: true,
content: menu, content: menu,

View File

@ -502,6 +502,7 @@ export function initRepoPullRequestReview() {
if ($reviewBtn.length && $panel.length) { if ($reviewBtn.length && $panel.length) {
const tippy = createTippy($reviewBtn[0], { const tippy = createTippy($reviewBtn[0], {
content: $panel[0], content: $panel[0],
theme: 'default',
placement: 'bottom', placement: 'bottom',
trigger: 'click', trigger: 'click',
maxWidth: 'none', maxWidth: 'none',

View File

@ -5,6 +5,8 @@ import {hideElem, showElem} from '../utils/dom.js';
const {appSubUrl, notificationSettings, enableTimeTracking, assetVersionEncoded} = window.config; const {appSubUrl, notificationSettings, enableTimeTracking, assetVersionEncoded} = window.config;
let stopwatchTippy;
export function initStopwatch() { export function initStopwatch() {
if (!enableTimeTracking) { if (!enableTimeTracking) {
return; return;
@ -19,13 +21,14 @@ export function initStopwatch() {
stopwatchEl.removeAttribute('href'); // intended for noscript mode only stopwatchEl.removeAttribute('href'); // intended for noscript mode only
createTippy(stopwatchEl, { stopwatchTippy = createTippy(stopwatchEl, {
content: stopwatchPopup, content: stopwatchPopup,
placement: 'bottom-end', placement: 'bottom-end',
trigger: 'click', trigger: 'click',
maxWidth: 'none', maxWidth: 'none',
interactive: true, interactive: true,
hideOnClick: true, hideOnClick: true,
theme: 'default',
}); });
// global stop watch (in the head_navbar), it should always work in any case either the EventSource or the PeriodicPoller is used. // global stop watch (in the head_navbar), it should always work in any case either the EventSource or the PeriodicPoller is used.
@ -161,6 +164,9 @@ function updateStopwatchTime(seconds) {
const delta = Date.now() - start; const delta = Date.now() - start;
const dur = prettyMilliseconds(secs * 1000 + delta, {compact: true}); const dur = prettyMilliseconds(secs * 1000 + delta, {compact: true});
if (stopwatch) stopwatch.textContent = dur; if (stopwatch) stopwatch.textContent = dur;
// refresh the tippy so that the triangle updates to the correct position
stopwatchTippy.hide();
stopwatchTippy.show();
}; };
updateUi(); updateUi();
updateTimeIntervalId = setInterval(updateUi, 1000); updateTimeIntervalId = setInterval(updateUi, 1000);

View File

@ -37,8 +37,10 @@ export function createTippy(target, opts = {}) {
return onShow?.(instance); return onShow?.(instance);
}, },
arrow: arrow || (theme === 'bare' ? false : arrowSvg), arrow: arrow || (theme === 'bare' ? false : arrowSvg),
role: role || 'menu', // HTML role attribute // HTML role attribute, ideally the default role would be "popover" but it does not exist
theme: theme || role || 'menu', // CSS theme, either "tooltip", "menu", "box-with-header" or "bare" role: role || 'menu',
// CSS theme, either "default", "tooltip", "menu", "box-with-header" or "bare"
theme: theme || role || 'default',
plugins: [followCursor], plugins: [followCursor],
...other, ...other,
}); });

View File

@ -117,6 +117,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
interactive: true, interactive: true,
placement: 'bottom-end', placement: 'bottom-end',
role: 'menu', role: 'menu',
theme: 'menu',
content: this.tippyContent, content: this.tippyContent,
onShow: () => { // FIXME: onShown doesn't work (never be called) onShow: () => { // FIXME: onShown doesn't work (never be called)
setTimeout(() => { setTimeout(() => {