feat(asset): animate asset detail drawer
This commit is contained in:
@@ -683,11 +683,21 @@
|
||||
max-height: 100dvh;
|
||||
border-radius: 14px 0 0 14px;
|
||||
overflow: auto;
|
||||
will-change: transform;
|
||||
}
|
||||
.am-drawer.am-closing {
|
||||
pointer-events: none;
|
||||
}
|
||||
.am-dialog::backdrop,
|
||||
.am-drawer::backdrop {
|
||||
background: #0004;
|
||||
}
|
||||
.am-drawer::backdrop {
|
||||
transition: background-color 220ms ease;
|
||||
}
|
||||
.am-drawer.am-closing::backdrop {
|
||||
background: #0000;
|
||||
}
|
||||
body:has(dialog[open]) {
|
||||
overflow: hidden;
|
||||
}
|
||||
@@ -1352,4 +1362,7 @@ body:has(dialog[open]) {
|
||||
.am-kpi {
|
||||
transition: none;
|
||||
}
|
||||
.am-drawer::backdrop {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
+81
-3
@@ -304,19 +304,71 @@
|
||||
await loadDashboard();
|
||||
await loadList();
|
||||
}
|
||||
let drawerAnimation = null;
|
||||
let drawerMotionId = 0;
|
||||
function moveDrawer(opening) {
|
||||
const drawer = $("am-detail"),
|
||||
motionId = ++drawerMotionId;
|
||||
// 진행 중인 위치에서 방향을 바꾸므로 빠른 열기·닫기에도 패널이 튀지 않습니다.
|
||||
const from =
|
||||
drawerAnimation || !opening
|
||||
? getComputedStyle(drawer).transform
|
||||
: "translateX(100%)";
|
||||
drawerAnimation?.cancel();
|
||||
drawerAnimation = null;
|
||||
drawer.classList.toggle("am-closing", !opening);
|
||||
const finish = () => {
|
||||
if (motionId !== drawerMotionId) return;
|
||||
if (!opening) drawer.close();
|
||||
drawer.classList.remove("am-closing");
|
||||
drawerAnimation?.cancel();
|
||||
drawerAnimation = null;
|
||||
};
|
||||
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
const animation = drawer.animate(
|
||||
[
|
||||
{ transform: from },
|
||||
{ transform: opening ? "translateX(0)" : "translateX(100%)" },
|
||||
],
|
||||
{
|
||||
duration: opening ? 280 : 220,
|
||||
easing: opening
|
||||
? "cubic-bezier(.22,1,.36,1)"
|
||||
: "cubic-bezier(.4,0,1,1)",
|
||||
fill: "both",
|
||||
},
|
||||
);
|
||||
animation.id = "asset-drawer";
|
||||
drawerAnimation = animation;
|
||||
animation.finished.then(finish, () => {});
|
||||
}
|
||||
function show(id) {
|
||||
$(id).showModal();
|
||||
const dialog = $(id);
|
||||
if (id === "am-detail") {
|
||||
if (!dialog.open) {
|
||||
dialog.showModal();
|
||||
moveDrawer(true);
|
||||
} else if (dialog.classList.contains("am-closing")) moveDrawer(true);
|
||||
return;
|
||||
}
|
||||
if (!dialog.open) dialog.showModal();
|
||||
}
|
||||
function close(id) {
|
||||
// 저장 중에는 창을 닫거나 다시 제출해서 요청을 겹치지 않게 합니다.
|
||||
if ($(id).querySelector('form[data-busy="true"]')) return;
|
||||
if (id === "am-detail") {
|
||||
if (!$(id).open || $(id).classList.contains("am-closing")) return;
|
||||
++state.detailSeq;
|
||||
state.detail = null;
|
||||
syncURL();
|
||||
moveDrawer(false);
|
||||
return;
|
||||
}
|
||||
if (id === "am-upload") ++state.previewSeq;
|
||||
$(id).close();
|
||||
if (id === "am-detail") syncURL();
|
||||
}
|
||||
function info(label, value, wide = false) {
|
||||
return `<div class="am-info-field${wide ? " am-wide" : ""}"><span>${esc(label)}</span><strong>${esc(value || "—")}</strong></div>`;
|
||||
@@ -410,7 +462,7 @@
|
||||
const seq = ++state.detailSeq;
|
||||
state.tab = tab;
|
||||
state.reportView = null;
|
||||
if (!$("am-detail").open) show("am-detail");
|
||||
show("am-detail");
|
||||
$("am-detail-title").textContent = "자산 정보";
|
||||
$("am-detail-tag").textContent = "불러오는 중";
|
||||
$("am-detail-content").innerHTML =
|
||||
@@ -979,6 +1031,8 @@
|
||||
document.addEventListener("click", (event) => {
|
||||
const button = event.target.closest("button,a");
|
||||
if (!button) return;
|
||||
// 닫히는 동안 키보드로 이전 패널의 처리 버튼을 실행하지 않게 합니다.
|
||||
if (button.closest("#am-detail.am-closing")) return;
|
||||
if (button.dataset.close) {
|
||||
close(button.dataset.close);
|
||||
return;
|
||||
@@ -1102,6 +1156,30 @@
|
||||
event.preventDefault();
|
||||
close(id);
|
||||
});
|
||||
// 바깥에서 누르고 놓은 경우만 닫습니다. 패널 안에서 바깥으로 드래그하면 유지합니다.
|
||||
let drawerBackdropPressed = false;
|
||||
const outsideDrawer = (event) => {
|
||||
const drawer = $("am-detail"),
|
||||
rect = drawer.getBoundingClientRect();
|
||||
return (
|
||||
event.target === drawer &&
|
||||
(event.clientX < rect.left ||
|
||||
event.clientX >= rect.right ||
|
||||
event.clientY < rect.top ||
|
||||
event.clientY >= rect.bottom)
|
||||
);
|
||||
};
|
||||
$("am-detail").addEventListener("pointerdown", (event) => {
|
||||
drawerBackdropPressed = event.button === 0 && outsideDrawer(event);
|
||||
});
|
||||
$("am-detail").addEventListener("pointerup", (event) => {
|
||||
const dismiss = drawerBackdropPressed && outsideDrawer(event);
|
||||
drawerBackdropPressed = false;
|
||||
if (dismiss) close("am-detail");
|
||||
});
|
||||
$("am-detail").addEventListener("pointercancel", () => {
|
||||
drawerBackdropPressed = false;
|
||||
});
|
||||
$("am-filters").addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
state.page = 1;
|
||||
|
||||
Reference in New Issue
Block a user