Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
left_sidebar: Refactor tooltip logic for left sidebar navigation list.
Pratik Chanda6c03d839f71a
diff --git a/web/src/tippyjs.ts b/web/src/tippyjs.tsindex afbc3aea4db..cf9e5cdb447 100644--- a/web/src/tippyjs.ts+++ b/web/src/tippyjs.ts@@ -188,6 +188,25 @@ export function initialize(): void {placement: "right",delay: EXTRA_LONG_HOVER_DELAY,appendTo: () => document.body,+ onShow(instance) {+ const $container = $(instance.popper).find(".views-tooltip-container");+ if ($container.attr("data-view-code") === user_settings.web_home_view) {+ $container.find(".views-tooltip-home-view-note").removeClass("hide");+ }++ // Since the tooltip is attached to the anchor tag which doesn't+ // include width of the ellipsis icon, we need to offset the+ // tooltip so that the tooltip is displayed to right of the+ // ellipsis icon.+ if (instance.reference.classList.contains("left-sidebar-navigation-label-container")) {+ instance.setProps({+ offset: [0, 40],+ });+ }+ },+ onHidden(instance) {+ instance.destroy();+ },popperOptions: {modifiers: [{@@ -221,44 +240,6 @@ export function initialize(): void {},});- // Variant of .tippy-left-sidebar-tooltip configuration. Here- // we need to dynamically check which view is the home view.- tippy.delegate("body", {- target: ".tippy-views-tooltip",- placement: "right",- delay: EXTRA_LONG_HOVER_DELAY,- appendTo: () => document.body,- onShow(instance) {- const $container = $(instance.popper).find(".views-tooltip-container");- if ($container.attr("data-view-code") === user_settings.web_home_view) {- $container.find(".views-tooltip-home-view-note").removeClass("hide");- }-- // Since the tooltip is attached the anchor tag which doesn't- // include with of the ellipsis icon, we need to offset the- // tooltip so that the tooltip is displayed to right of the- // ellipsis icon.- if (instance.reference.classList.contains("left-sidebar-navigation-label-container")) {- instance.setProps({- offset: [0, 40],- });- }- },- onHidden(instance) {- instance.destroy();- },- popperOptions: {- modifiers: [- {- name: "flip",- options: {- fallbackPlacements: "bottom",- },- },- ],- },- });-// The below definitions are for specific tooltips that require// custom JavaScript code or configuration. Note that since the// below specify the target directly, elements using those shoulddiff --git a/web/templates/left_sidebar.hbs b/web/templates/left_sidebar.hbsindex f1f22c721cb..14c0660b990 100644--- a/web/templates/left_sidebar.hbs+++ b/web/templates/left_sidebar.hbs@@ -6,7 +6,7 @@<h4 class="left-sidebar-title"><span class="views-tooltip-target">{{t 'VIEWS' }}</span></h4><ul id="left-sidebar-navigation-list-condensed" class="filters"><li class="top_left_inbox left-sidebar-navigation-condensed-item {{#if is_inbox_home_view}}selected-home-view{{/if}}">- <a href="#inbox" class="tippy-views-tooltip left-sidebar-navigation-icon-container" data-tooltip-template-id="inbox-tooltip-template">+ <a href="#inbox" class="tippy-left-sidebar-tooltip left-sidebar-navigation-icon-container" data-tooltip-template-id="inbox-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-inbox" aria-hidden="true"></i></span>@@ -14,7 +14,7 @@</a></li><li class="top_left_recent_view left-sidebar-navigation-condensed-item {{#if is_recent_view_home_view}}selected-home-view{{/if}}">- <a href="#recent" class="tippy-views-tooltip left-sidebar-navigation-icon-container" data-tooltip-template-id="recent-conversations-tooltip-template">+ <a href="#recent" class="tippy-left-sidebar-tooltip left-sidebar-navigation-icon-container" data-tooltip-template-id="recent-conversations-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-recent" aria-hidden="true"></i></span>@@ -22,7 +22,7 @@</a></li><li class="top_left_all_messages left-sidebar-navigation-condensed-item {{#if is_all_messages_home_view}}selected-home-view{{/if}}">- <a href="#feed" class="home-link tippy-views-tooltip left-sidebar-navigation-icon-container" data-tooltip-template-id="all-message-tooltip-template">+ <a href="#feed" class="home-link tippy-left-sidebar-tooltip left-sidebar-navigation-icon-container" data-tooltip-template-id="all-message-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-all-messages" aria-hidden="true"></i></span>@@ -38,7 +38,7 @@</a></li><li class="top_left_starred_messages left-sidebar-navigation-condensed-item">- <a href="#narrow/is/starred" class="tippy-left-sidebar-tooltip left-sidebar-navigation-icon-container" data-tooltip-template-id="starred-tooltip-template">+ <a href="#narrow/is/starred" class="tippy-left-sidebar-tooltip left-sidebar-navigation-icon-container" data-tooltip-template-id="starred-message-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-star" aria-hidden="true"></i></span>@@ -52,7 +52,7 @@</div><ul id="left-sidebar-navigation-list" class="left-sidebar-navigation-list filters"><li class="top_left_inbox top_left_row hidden-for-spectators {{#if is_inbox_home_view}}selected-home-view{{/if}}">- <a href="#inbox" class="left-sidebar-navigation-label-container tippy-views-tooltip" data-tooltip-template-id="inbox-tooltip-template">+ <a href="#inbox" class="left-sidebar-navigation-label-container tippy-left-sidebar-tooltip" data-tooltip-template-id="inbox-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-inbox" aria-hidden="true"></i></span>@@ -63,7 +63,7 @@<span class="arrow sidebar-menu-icon inbox-sidebar-menu-icon hidden-for-spectators"><i class="zulip-icon zulip-icon-more-vertical" aria-hidden="true"></i></span></li><li class="top_left_recent_view top_left_row {{#if is_recent_view_home_view}}selected-home-view{{/if}}">- <a href="#recent" class="left-sidebar-navigation-label-container tippy-views-tooltip" data-tooltip-template-id="recent-conversations-tooltip-template">+ <a href="#recent" class="left-sidebar-navigation-label-container tippy-left-sidebar-tooltip" data-tooltip-template-id="recent-conversations-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-recent" aria-hidden="true"></i></span>@@ -76,7 +76,7 @@</span></li><li class="top_left_all_messages top_left_row {{#if is_all_messages_home_view}}selected-home-view{{/if}}">- <a href="#feed" class="home-link left-sidebar-navigation-label-container tippy-views-tooltip" data-tooltip-template-id="all-message-tooltip-template">+ <a href="#feed" class="home-link left-sidebar-navigation-label-container tippy-left-sidebar-tooltip" data-tooltip-template-id="all-message-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-all-messages" aria-hidden="true"></i></span>@@ -99,7 +99,7 @@</a></li><li class="top_left_my_reactions top_left_row hidden-for-spectators">- <a class="left-sidebar-navigation-label-container tippy-views-tooltip" href="#narrow/has/reaction/sender/me" data-tooltip-template-id="my-reactions-tooltip-template">+ <a class="left-sidebar-navigation-label-container tippy-left-sidebar-tooltip" href="#narrow/has/reaction/sender/me" data-tooltip-template-id="my-reactions-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-smile" aria-hidden="true"></i></span>@@ -109,7 +109,7 @@</a></li><li class="top_left_starred_messages top_left_row hidden-for-spectators">- <a class="left-sidebar-navigation-label-container tippy-views-tooltip" href="#narrow/is/starred" data-tooltip-template-id="starred-message-tooltip-template">+ <a class="left-sidebar-navigation-label-container tippy-left-sidebar-tooltip" href="#narrow/is/starred" data-tooltip-template-id="starred-message-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-star" aria-hidden="true"></i></span>@@ -123,7 +123,7 @@<span class="arrow sidebar-menu-icon starred-messages-sidebar-menu-icon"><i class="zulip-icon zulip-icon-more-vertical" aria-hidden="true"></i></span></li><li class="top_left_drafts top_left_row hidden-for-spectators">- <a href="#drafts" class="left-sidebar-navigation-label-container tippy-views-tooltip" data-tooltip-template-id="drafts-tooltip-template">+ <a href="#drafts" class="left-sidebar-navigation-label-container tippy-left-sidebar-tooltip" data-tooltip-template-id="drafts-tooltip-template"><span class="filter-icon"><i class="zulip-icon zulip-icon-drafts" aria-hidden="true"></i></span>diff --git a/web/templates/tooltip_templates.hbs b/web/templates/tooltip_templates.hbsindex c20a667bc40..800cb1b1dc8 100644--- a/web/templates/tooltip_templates.hbs+++ b/web/templates/tooltip_templates.hbs@@ -124,7 +124,7 @@{{tooltip_hotkey_hints "T"}}</template><template id="starred-message-tooltip-template">- <div class="views-tooltip-container">+ <div class="views-tooltip-container" data-view-code="starred_message"><div>{{t 'Starred messages' }}</div></div>{{tooltip_hotkey_hints "*"}}@@ -142,7 +142,9 @@{{tooltip_hotkey_hints "Shift" "I"}}</template><template id="drafts-tooltip-template">- {{t 'Drafts' }}+ <div class="views-tooltip-container" data-view-code="drafts">+ <div>{{t 'Drafts' }}</div>+ </div>{{tooltip_hotkey_hints "D"}}</template><template id="show-all-direct-messages-template">@@ -150,10 +152,9 @@{{tooltip_hotkey_hints "Shift" "P"}}</template><template id="mentions-tooltip-template">- {{t 'Mentions' }}-</template>-<template id="starred-tooltip-template">- {{t 'Starred messages' }}+ <div class="views-tooltip-container" data-view-code="mentions">+ <div>{{t 'Mentions' }}</div>+ </div></template><template id="filter-streams-tooltip-template">{{t 'Filter channels' }}