Add smooth animations across WebUI for modern feel
- Tab panels: fade-in with subtle translateY on switch - Cards: hover lift (translateY -2px), staggered entrance animation - Modals: spring-curve entrance with backdrop blur - Buttons: press feedback (scale down on :active) - Toggle switches: spring overshoot on knob transition - Toast: smooth bounce-in replaces jarring shake - Sections: animated height collapse/expand with chevron rotation - Command palette: slide-down entrance animation - Theme switch: smooth color transitions on key elements - Dashboard: section collapse animation, target row hover - Respects prefers-reduced-motion globally Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -65,7 +65,7 @@ export class CardSection {
|
||||
const cardsHtml = items.map(i => i.html).join('');
|
||||
|
||||
const isCollapsed = !!_getCollapsedMap()[this.sectionKey];
|
||||
const chevron = isCollapsed ? '\u25B6' : '\u25BC';
|
||||
const chevronStyle = isCollapsed ? '' : ' style="transform:rotate(90deg)"';
|
||||
const contentDisplay = isCollapsed ? ' style="display:none"' : '';
|
||||
|
||||
const addCard = this.addCardOnclick
|
||||
@@ -75,7 +75,7 @@ export class CardSection {
|
||||
return `
|
||||
<div class="subtab-section" data-card-section="${this.sectionKey}">
|
||||
<div class="subtab-section-header cs-header" data-cs-toggle="${this.sectionKey}">
|
||||
<span class="cs-chevron">${chevron}</span>
|
||||
<span class="cs-chevron"${chevronStyle}>▶</span>
|
||||
<span class="cs-title">${t(this.titleKey)}</span>
|
||||
<span class="cs-count">${count}</span>
|
||||
<div class="cs-filter-wrap">
|
||||
@@ -154,6 +154,9 @@ export class CardSection {
|
||||
|
||||
// Tag card elements with their source HTML for future reconciliation
|
||||
this._tagCards(content);
|
||||
|
||||
// Stagger card entrance animation
|
||||
this._animateEntrance(content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,6 +219,19 @@ export class CardSection {
|
||||
}
|
||||
}
|
||||
|
||||
// Animate newly added cards
|
||||
if (added.size > 0 && this.keyAttr && !window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
||||
let delay = 0;
|
||||
for (const key of added) {
|
||||
const card = content.querySelector(`[${this.keyAttr}="${key}"]`);
|
||||
if (card) {
|
||||
card.style.animationDelay = `${delay}ms`;
|
||||
card.classList.add('card-enter');
|
||||
delay += 30;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Re-apply filter
|
||||
if (this._filterValue) {
|
||||
this._applyFilter(content, this._filterValue);
|
||||
@@ -239,7 +255,7 @@ export class CardSection {
|
||||
if (content) content.style.display = '';
|
||||
if (header) {
|
||||
const chevron = header.querySelector('.cs-chevron');
|
||||
if (chevron) chevron.textContent = '\u25BC';
|
||||
if (chevron) chevron.style.transform = 'rotate(90deg)';
|
||||
}
|
||||
}
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(map));
|
||||
@@ -255,7 +271,7 @@ export class CardSection {
|
||||
if (content) content.style.display = 'none';
|
||||
if (header) {
|
||||
const chevron = header.querySelector('.cs-chevron');
|
||||
if (chevron) chevron.textContent = '\u25B6';
|
||||
if (chevron) chevron.style.transform = '';
|
||||
}
|
||||
}
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(map));
|
||||
@@ -272,12 +288,22 @@ export class CardSection {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(map));
|
||||
content.style.display = '';
|
||||
const chevron = header.querySelector('.cs-chevron');
|
||||
if (chevron) chevron.textContent = '\u25BC';
|
||||
if (chevron) chevron.style.transform = 'rotate(90deg)';
|
||||
}
|
||||
}
|
||||
|
||||
// ── private ──
|
||||
|
||||
_animateEntrance(content) {
|
||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
||||
const selector = this.keyAttr ? `[${this.keyAttr}]` : '.card, .template-card:not(.add-template-card)';
|
||||
const cards = content.querySelectorAll(selector);
|
||||
cards.forEach((card, i) => {
|
||||
card.style.animationDelay = `${i * 30}ms`;
|
||||
card.classList.add('card-enter');
|
||||
});
|
||||
}
|
||||
|
||||
_tagCards(content) {
|
||||
if (!this.keyAttr || !this._lastItems) return;
|
||||
const htmlMap = new Map(this._lastItems.map(i => [i.key, i.html]));
|
||||
@@ -294,9 +320,45 @@ export class CardSection {
|
||||
map[this.sectionKey] = nowCollapsed;
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(map));
|
||||
|
||||
content.style.display = nowCollapsed ? 'none' : '';
|
||||
const chevron = header.querySelector('.cs-chevron');
|
||||
if (chevron) chevron.textContent = nowCollapsed ? '\u25B6' : '\u25BC';
|
||||
if (chevron) chevron.style.transform = nowCollapsed ? '' : 'rotate(90deg)';
|
||||
|
||||
// Cancel any running animation on this content
|
||||
if (content._csAnim) { content._csAnim.cancel(); content._csAnim = null; }
|
||||
|
||||
// Skip animation when user prefers reduced motion
|
||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
||||
content.style.display = nowCollapsed ? 'none' : '';
|
||||
return;
|
||||
}
|
||||
|
||||
if (nowCollapsed) {
|
||||
const h = content.offsetHeight;
|
||||
content.style.overflow = 'hidden';
|
||||
const anim = content.animate(
|
||||
[{ height: h + 'px', opacity: 1 }, { height: '0px', opacity: 0 }],
|
||||
{ duration: 200, easing: 'ease-in-out' }
|
||||
);
|
||||
content._csAnim = anim;
|
||||
anim.onfinish = () => {
|
||||
content.style.display = 'none';
|
||||
content.style.overflow = '';
|
||||
content._csAnim = null;
|
||||
};
|
||||
} else {
|
||||
content.style.display = '';
|
||||
content.style.overflow = 'hidden';
|
||||
const h = content.scrollHeight;
|
||||
const anim = content.animate(
|
||||
[{ height: '0px', opacity: 0 }, { height: h + 'px', opacity: 1 }],
|
||||
{ duration: 200, easing: 'ease-in-out' }
|
||||
);
|
||||
content._csAnim = anim;
|
||||
anim.onfinish = () => {
|
||||
content.style.overflow = '';
|
||||
content._csAnim = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
_applyFilter(content, query) {
|
||||
|
||||
@@ -38,7 +38,7 @@ export function navigateToCard(tab, subTab, sectionKey, cardAttr, cardValue) {
|
||||
if (content && content.style.display === 'none') {
|
||||
content.style.display = '';
|
||||
const chevron = header?.querySelector('.cs-chevron');
|
||||
if (chevron) chevron.textContent = '\u25BC';
|
||||
if (chevron) chevron.style.transform = 'rotate(90deg)';
|
||||
const map = JSON.parse(localStorage.getItem('sections_collapsed') || '{}');
|
||||
map[sectionKey] = false;
|
||||
localStorage.setItem('sections_collapsed', JSON.stringify(map));
|
||||
|
||||
@@ -304,21 +304,43 @@ export function toggleDashboardSection(sectionKey) {
|
||||
if (!header) return;
|
||||
const content = header.nextElementSibling;
|
||||
const chevron = header.querySelector('.dashboard-section-chevron');
|
||||
if (collapsed[sectionKey]) {
|
||||
content.style.display = 'none';
|
||||
chevron.textContent = '\u25B6';
|
||||
const nowCollapsed = collapsed[sectionKey];
|
||||
if (chevron) chevron.style.transform = nowCollapsed ? '' : 'rotate(90deg)';
|
||||
|
||||
// Animate collapse/expand unless reduced motion
|
||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
||||
content.style.display = nowCollapsed ? 'none' : '';
|
||||
return;
|
||||
}
|
||||
if (content._dsAnim) { content._dsAnim.cancel(); content._dsAnim = null; }
|
||||
if (nowCollapsed) {
|
||||
const h = content.offsetHeight;
|
||||
content.style.overflow = 'hidden';
|
||||
const anim = content.animate(
|
||||
[{ height: h + 'px', opacity: 1 }, { height: '0px', opacity: 0 }],
|
||||
{ duration: 200, easing: 'ease-in-out' }
|
||||
);
|
||||
content._dsAnim = anim;
|
||||
anim.onfinish = () => { content.style.display = 'none'; content.style.overflow = ''; content._dsAnim = null; };
|
||||
} else {
|
||||
content.style.display = '';
|
||||
chevron.textContent = '\u25BC';
|
||||
content.style.overflow = 'hidden';
|
||||
const h = content.scrollHeight;
|
||||
const anim = content.animate(
|
||||
[{ height: '0px', opacity: 0 }, { height: h + 'px', opacity: 1 }],
|
||||
{ duration: 200, easing: 'ease-in-out' }
|
||||
);
|
||||
content._dsAnim = anim;
|
||||
anim.onfinish = () => { content.style.overflow = ''; content._dsAnim = null; };
|
||||
}
|
||||
}
|
||||
|
||||
function _sectionHeader(sectionKey, label, count, extraHtml = '') {
|
||||
const collapsed = _getCollapsedSections();
|
||||
const isCollapsed = !!collapsed[sectionKey];
|
||||
const chevron = isCollapsed ? '\u25B6' : '\u25BC';
|
||||
const chevronStyle = isCollapsed ? '' : ' style="transform:rotate(90deg)"';
|
||||
return `<div class="dashboard-section-header" data-dashboard-section="${sectionKey}" onclick="toggleDashboardSection('${sectionKey}')">
|
||||
<span class="dashboard-section-chevron">${chevron}</span>
|
||||
<span class="dashboard-section-chevron"${chevronStyle}>▶</span>
|
||||
${label}
|
||||
<span class="dashboard-section-count">${count}</span>
|
||||
${extraHtml}
|
||||
|
||||
Reference in New Issue
Block a user