feat(ui): animate sidebar and toolbar interaction feedback

This commit is contained in:
zipg authored and GitHub committed 2026-08-31 16:37:51 +08:00
1 parent bcea953a50
commit 99c3bd0f42
14 files changed
+689 -100

No files matched your search

@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, shallowRef, computed, nextTick, watch, provide, onMounted, onUnmounted, type Component, type ComponentPublicInstance, type CSSProperties } from "vue";
import { useI18n } from "vue-i18n";
import { Search, X, SlidersHorizontal, ListOrdered, ArrowDownAZ, ArrowUpZA, LocateFixed, Server, Database, FolderTree, Table2, Eye, RotateCcw, Loader2, Unplug } from "@lucide/vue";
import { Search, X, ListOrdered, ArrowDownAZ, ArrowUpZA, Server, Database, FolderTree, Table2, Eye, RotateCcw, Loader2, Unplug } from "@lucide/vue";
import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore";
import { useSavedSqlStore } from "@/stores/savedSqlStore";
@@ -56,6 +56,9 @@ import { insertSidebarTableSearchControls, isSidebarTableSearchControlNode } fro
import { createSidebarTableSearchDebouncer, invalidateSidebarTableSearchBuild, loadOrBuildSidebarTableSearchIndex, scheduleExclusiveSidebarTableSearchDebounce } from "@/lib/sidebar/sidebarTableSearchIndex";
import TreeItem from "./TreeItem.vue";
import ActiveConnectionFilterButton from "./ActiveConnectionFilterButton.vue";
import SidebarListOptionsIcon from "./SidebarListOptionsIcon.vue";
import SidebarLocateButton from "./SidebarLocateButton.vue";
import SidebarRegexToggleButton from "./SidebarRegexToggleButton.vue";
import SidebarTreeRuntimeHost from "./SidebarTreeRuntimeHost.vue";
import SidebarTreeItemDialogs from "./SidebarTreeItemDialogs.vue";
import InstallExtensionDialog from "@/components/objects/InstallExtensionDialog.vue";
@@ -2430,16 +2433,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
<X class="h-3 w-3" />
</button>
<LightTooltip :text="t('sidebar.regexSearchTooltip')" side="top" :delay="300">
<button
type="button"
class="flex h-5 min-w-5 items-center justify-center rounded-sm px-0.5 text-[10px] font-mono text-muted-foreground hover:bg-accent hover:text-foreground"
:class="{ 'text-primary bg-primary/10': regexMode, 'text-destructive': regexMode && compileSearchRegex(searchQuery).invalid }"
:aria-label="t('sidebar.regexSearch')"
:aria-pressed="regexMode"
@click="regexMode = !regexMode"
>
.*
</button>
<SidebarRegexToggleButton :label="t('sidebar.regexSearch')" :pressed="regexMode" :invalid="regexMode && compileSearchRegex(searchQuery).invalid" @toggle="regexMode = !regexMode" />
</LightTooltip>
<LightTooltip :text="t('sidebar.globalLocalSearchTooltip')" side="top" :delay="300">
<Switch size="sm" :model-value="settingsStore.editorSettings.sidebarGlobalSearchLocal" :disabled="regexMode" :aria-label="t('sidebar.globalLocalSearch')" @update:model-value="settingsStore.updateEditorSettings({ sidebarGlobalSearchLocal: Boolean($event) })" />
@@ -2447,9 +2441,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
</div>
</div>
<LightTooltip :text="t('sidebar.locateActiveTab')" side="top" :delay="300" nowrap>
<button type="button" class="flex h-6 w-6 shrink-0 items-center justify-center rounded border border-border text-muted-foreground hover:bg-accent hover:text-foreground" :aria-label="t('sidebar.locateActiveTab')" @click="locateActiveTabInSidebar">
<LocateFixed class="h-3.5 w-3.5" />
</button>
<SidebarLocateButton :label="t('sidebar.locateActiveTab')" @locate="locateActiveTabInSidebar" />
</LightTooltip>
<LightTooltip :text="sidebarListOptionsLabel" side="top" :delay="300" nowrap>
<span class="inline-flex">
@@ -2458,9 +2450,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
:items="sidebarListOptionItems"
:selected-values="selectedSidebarListOptions"
:aria-label="sidebarListOptionsLabel"
:trigger-icon="SlidersHorizontal"
:trigger-class="['shrink-0 h-6 w-6 flex items-center justify-center rounded border border-border hover:bg-accent', hasCustomSidebarListOptions ? 'text-primary bg-primary/10 border-primary/30' : 'text-muted-foreground'].join(' ')"
trigger-icon-class="h-3.5 w-3.5"
item-icon-class="h-3.5 w-3.5"
content-class="w-max min-w-0"
selected-item-class="bg-primary/10 text-primary"
@@ -2470,7 +2460,11 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes, locateTabInSid
:close-on-select="false"
align="end"
@update:model-value="selectSidebarListOption"
/>
>
<template #trigger-icon="{ open }">
<SidebarListOptionsIcon :filtered="hasSearchScopeFilter" :open="open" />
</template>
</LightDropdown>
</span>
</LightTooltip>
<ActiveConnectionFilterButton :active-connection-count="store.connectedIds.size" :pressed="showConnectedConnectionsOnly" @toggle="showConnectedConnectionsOnly = !showConnectedConnectionsOnly" />
@@ -0,0 +1,91 @@
<script setup lang="ts">
import { ListFilter, SlidersHorizontal } from "@lucide/vue";
defineProps<{
filtered: boolean;
open: boolean;
}>();
</script>
<template>
<span data-sidebar-list-options-icon class="sidebar-list-options-icon relative block h-3.5 w-3.5" :class="{ 'sidebar-list-options-icon--filtered': filtered, 'sidebar-list-options-icon--open': open }" aria-hidden="true">
<Transition name="sidebar-filter-symbol">
<ListFilter v-if="filtered" key="filtered" data-sidebar-filtered-icon class="sidebar-filter-symbol absolute inset-0 h-3.5 w-3.5" />
<SlidersHorizontal v-else key="unfiltered" data-sidebar-unfiltered-icon class="sidebar-filter-symbol absolute inset-0 h-3.5 w-3.5" />
</Transition>
<span v-if="filtered" class="sidebar-filter-status-dot absolute -right-0.5 -top-0.5 h-1 w-1 rounded-full bg-primary" />
</span>
</template>
<style scoped>
.sidebar-list-options-icon {
transform: scale(1);
}
.sidebar-list-options-icon--open {
animation: sidebar-list-options-press 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
.sidebar-list-options-icon--filtered {
color: var(--primary);
}
.sidebar-filter-symbol-enter-active,
.sidebar-filter-symbol-leave-active {
transition:
opacity 180ms ease,
transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.sidebar-filter-symbol-enter-from {
opacity: 0;
transform: translateY(2px) scale(0.72);
}
.sidebar-filter-symbol-leave-to {
opacity: 0;
transform: translateY(-2px) scale(0.82);
}
.sidebar-filter-status-dot {
animation: sidebar-filter-dot-in 260ms cubic-bezier(0.2, 0.9, 0.25, 1.3) both;
box-shadow: 0 0 0 1px var(--background);
}
@keyframes sidebar-filter-dot-in {
0% {
opacity: 0;
transform: scale(0);
}
70% {
transform: scale(1.35);
}
100% {
opacity: 1;
transform: scale(1);
}
}
@keyframes sidebar-list-options-press {
0% {
transform: scale(1);
}
48% {
transform: scale(0.8);
}
100% {
transform: scale(1);
}
}
@media (prefers-reduced-motion: reduce) {
.sidebar-list-options-icon,
.sidebar-filter-symbol-enter-active,
.sidebar-filter-symbol-leave-active,
.sidebar-filter-status-dot {
animation: none;
transition: none;
transform: none;
}
}
</style>
@@ -0,0 +1,78 @@
<script setup lang="ts">
import { ref } from "vue";
import { LocateFixed } from "@lucide/vue";
defineProps<{
label: string;
}>();
const emit = defineEmits<{
locate: [];
}>();
const animationId = ref(0);
function locate() {
animationId.value += 1;
emit("locate");
}
</script>
<template>
<button type="button" data-sidebar-locate-button class="sidebar-locate-button relative flex h-6 w-6 shrink-0 items-center justify-center overflow-hidden rounded border border-border text-muted-foreground hover:bg-accent hover:text-foreground" :aria-label="label" @click="locate">
<LocateFixed :key="`locate-icon-${animationId}`" class="h-3.5 w-3.5" :class="{ 'sidebar-locate-icon--active': animationId > 0 }" />
<span v-if="animationId > 0" :key="`locate-pulse-${animationId}`" data-sidebar-locate-pulse class="sidebar-locate-pulse pointer-events-none absolute left-1/2 top-1/2 h-1.5 w-1.5 rounded-full border border-primary" aria-hidden="true" />
</button>
</template>
<style scoped>
.sidebar-locate-button:active {
transform: scale(0.94);
}
.sidebar-locate-icon--active {
animation: sidebar-locate-settle 420ms cubic-bezier(0.2, 0.85, 0.25, 1);
}
.sidebar-locate-pulse {
animation: sidebar-locate-pulse 440ms ease-out both;
}
@keyframes sidebar-locate-settle {
0% {
transform: rotate(-18deg) scale(0.78);
}
58% {
transform: rotate(5deg) scale(1.12);
color: var(--primary);
}
100% {
transform: rotate(0) scale(1);
}
}
@keyframes sidebar-locate-pulse {
0% {
opacity: 0.75;
transform: translate(-50%, -50%) scale(0.4);
}
100% {
opacity: 0;
transform: translate(-50%, -50%) scale(3.2);
}
}
@media (prefers-reduced-motion: reduce) {
.sidebar-locate-button,
.sidebar-locate-icon--active,
.sidebar-locate-pulse {
animation: none;
transition: none;
transform: none;
}
.sidebar-locate-pulse {
display: none;
}
}
</style>
@@ -0,0 +1,107 @@
<script setup lang="ts">
import { ref } from "vue";
defineProps<{
label: string;
pressed: boolean;
invalid: boolean;
}>();
const emit = defineEmits<{
toggle: [];
}>();
const animationId = ref(0);
function toggle() {
animationId.value += 1;
emit("toggle");
}
</script>
<template>
<button
type="button"
data-sidebar-regex-toggle
class="sidebar-regex-toggle relative flex h-5 min-w-5 items-center justify-center overflow-hidden rounded-sm px-0.5 font-mono text-[10px] text-muted-foreground hover:bg-accent hover:text-foreground"
:class="{ 'sidebar-regex-toggle--pressed text-primary bg-primary/10': pressed, 'text-destructive': invalid }"
:aria-label="label"
:aria-pressed="pressed"
@click="toggle"
>
<span :key="animationId" data-sidebar-regex-glyph class="sidebar-regex-glyph relative inline-flex h-3.5 w-4 items-center justify-center leading-none" :class="{ 'sidebar-regex-glyph--pressed': pressed, 'sidebar-regex-glyph--animated': animationId > 0 }" aria-hidden="true">.*</span>
</button>
</template>
<style scoped>
.sidebar-regex-toggle {
letter-spacing: 0;
transition:
color 160ms ease,
background-color 160ms ease,
transform 120ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sidebar-regex-toggle:active {
transform: scale(0.9);
}
.sidebar-regex-glyph {
font-weight: 400;
transform: scale(1);
transition:
font-weight 180ms ease,
transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
.sidebar-regex-glyph--pressed {
font-weight: 700;
transform: scale(1.08);
}
.sidebar-regex-glyph--animated.sidebar-regex-glyph--pressed {
animation: sidebar-regex-enable 300ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.sidebar-regex-glyph--animated:not(.sidebar-regex-glyph--pressed) {
animation: sidebar-regex-disable 300ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes sidebar-regex-enable {
0% {
font-weight: 400;
transform: scale(0.92);
}
56% {
font-weight: 700;
transform: scale(1.3);
}
100% {
font-weight: 700;
transform: scale(1.08);
}
}
@keyframes sidebar-regex-disable {
0% {
font-weight: 700;
transform: scale(1.08);
}
56% {
font-weight: 700;
transform: scale(1.26);
}
100% {
font-weight: 400;
transform: scale(1);
}
}
@media (prefers-reduced-motion: reduce) {
.sidebar-regex-toggle,
.sidebar-regex-glyph {
animation: none;
transition: none;
}
}
</style>
@@ -1478,7 +1478,19 @@ function onKeydown(event: KeyboardEvent) {
@keydown.escape.prevent="cancelRename"
@click.stop
/>
<span v-else ref="labelRef" :class="[labelWidthClass, { 'flex-1': node.type === 'connection' && !trailingComment, 'font-semibold': isLoginUserNode }]">{{ visibleLabel(node) }}</span>
<span
v-else
ref="labelRef"
:class="[
labelWidthClass,
{
'flex-1': node.type === 'connection' && !trailingComment,
'tree-connection-label': node.type === 'connection' || node.type === 'connection-group',
'font-semibold': isLoginUserNode,
},
]"
>{{ visibleLabel(node) }}</span
>
<span v-if="treeNodeSecondaryValue(node)" class="min-w-0 max-w-[55%] shrink truncate text-xs text-muted-foreground" :title="treeNodeSecondaryValue(node)">{{ treeNodeSecondaryValue(node) }}</span>
<button
v-if="canDragPinnedOrder()"
@@ -1635,6 +1647,10 @@ function onKeydown(event: KeyboardEvent) {
opacity: 1;
}
.tree-connection-label {
font-weight: 350;
}
.tree-item-connection-tint {
isolation: isolate;
background-color: transparent !important;
@@ -0,0 +1,116 @@
// @vitest-environment happy-dom
import { createApp, defineComponent, h, nextTick, reactive, type App, type Component } from "vue";
import { afterEach, describe, expect, it, vi } from "vitest";
import SidebarListOptionsIcon from "../SidebarListOptionsIcon.vue";
import SidebarLocateButton from "../SidebarLocateButton.vue";
import SidebarRegexToggleButton from "../SidebarRegexToggleButton.vue";
const mountedApps: App[] = [];
async function mount(component: Component) {
const container = document.createElement("div");
document.body.append(container);
const app = createApp(component);
mountedApps.push(app);
app.mount(container);
await nextTick();
return container;
}
afterEach(() => {
for (const app of mountedApps.splice(0)) app.unmount();
document.body.innerHTML = "";
});
describe("sidebar toolbar animations", () => {
it("restarts the locate pulse on every click without changing the button size", async () => {
const locate = vi.fn();
const container = await mount(
defineComponent({
setup: () => () => h(SidebarLocateButton, { label: "Locate", onLocate: locate }),
}),
);
const button = container.querySelector("[data-sidebar-locate-button]");
if (!(button instanceof HTMLButtonElement)) throw new Error("Locate button was not rendered");
expect(button.className).toContain("h-6 w-6");
expect(button.querySelector("[data-sidebar-locate-pulse]")).toBeNull();
button.click();
await nextTick();
const firstPulse = button.querySelector("[data-sidebar-locate-pulse]");
expect(firstPulse).not.toBeNull();
expect(locate).toHaveBeenCalledTimes(1);
button.click();
await nextTick();
expect(button.querySelector("[data-sidebar-locate-pulse]")).not.toBe(firstPulse);
expect(locate).toHaveBeenCalledTimes(2);
});
it("morphs the list options icon between unfiltered and filtered states", async () => {
const state = reactive({ filtered: false, open: false });
const container = await mount(
defineComponent({
setup: () => () => h(SidebarListOptionsIcon, { filtered: state.filtered, open: state.open }),
}),
);
const icon = container.querySelector("[data-sidebar-list-options-icon]");
expect(icon?.querySelector("[data-sidebar-unfiltered-icon]")).not.toBeNull();
expect(icon?.className).not.toContain("sidebar-list-options-icon--filtered");
state.filtered = true;
state.open = true;
await nextTick();
expect(icon?.querySelector("[data-sidebar-filtered-icon]")).not.toBeNull();
expect(icon?.className).toContain("sidebar-list-options-icon--filtered");
expect(icon?.className).toContain("sidebar-list-options-icon--open");
state.filtered = false;
state.open = false;
await nextTick();
expect(icon?.querySelector("[data-sidebar-unfiltered-icon]")).not.toBeNull();
expect(icon?.className).not.toContain("sidebar-list-options-icon--filtered");
});
it("replays a bold scale animation in both JavaScript regex states", async () => {
const state = reactive({ pressed: false, invalid: false });
const container = await mount(
defineComponent({
setup: () => () =>
h(SidebarRegexToggleButton, {
label: "JavaScript regex",
pressed: state.pressed,
invalid: state.invalid,
onToggle: () => {
state.pressed = !state.pressed;
},
}),
}),
);
const button = container.querySelector("[data-sidebar-regex-toggle]");
if (!(button instanceof HTMLButtonElement)) throw new Error("Regex button was not rendered");
expect(button.getAttribute("aria-pressed")).toBe("false");
expect(button.querySelector("[data-sidebar-regex-indicator]")).toBeNull();
const initialGlyph = button.querySelector("[data-sidebar-regex-glyph]");
button.click();
await nextTick();
expect(button.getAttribute("aria-pressed")).toBe("true");
expect(button.className).toContain("sidebar-regex-toggle--pressed");
const pressedGlyph = button.querySelector("[data-sidebar-regex-glyph]");
expect(pressedGlyph).not.toBe(initialGlyph);
expect(pressedGlyph?.className).toContain("sidebar-regex-glyph--pressed");
expect(pressedGlyph?.className).toContain("sidebar-regex-glyph--animated");
button.click();
await nextTick();
expect(button.getAttribute("aria-pressed")).toBe("false");
expect(button.className).not.toContain("sidebar-regex-toggle--pressed");
const releasedGlyph = button.querySelector("[data-sidebar-regex-glyph]");
expect(releasedGlyph).not.toBe(pressedGlyph);
expect(releasedGlyph?.className).not.toContain("sidebar-regex-glyph--pressed");
expect(releasedGlyph?.className).toContain("sidebar-regex-glyph--animated");
});
});