Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): share one set of slide keyframes

Elian Doran19e5abf362c3
diff --git a/apps/client/src/widgets/react/Menu.css b/apps/client/src/widgets/react/Menu.css
index 13dd17d6ea..e74ddc505b 100644
--- a/apps/client/src/widgets/react/Menu.css
+++ b/apps/client/src/widgets/react/Menu.css
@@ -54,7 +54,7 @@ body.desktop .dropdown-submenu > .dropdown-menu.tn-menu.tn-menu-immediate {
/*
* On a phone, a submenu is a page that takes its menu's place (`SubmenuPage`), and the frame
* follows the height of the page on show. The level under a page keeps its rows and its scroll
- * position, hidden out of the flow. The slides are master_detail.css's.
+ * position, hidden out of the flow. The slides are slide_animations.css's.
*/
.tn-menu-page {
--tn-popup-padding: var(--padding, var(--menu-padding-size));
@@ -91,18 +91,18 @@ body.desktop .dropdown-submenu > .dropdown-menu.tn-menu.tn-menu-immediate {
&:has(+ .tn-menu-page-entering) {
visibility: visible;
- animation: tn-master-detail-out-start 0.35s ease-in-out forwards;
+ animation: tn-slide-out-to-left 0.35s ease-in-out forwards;
}
&:has(+ .tn-menu-page-leaving) {
- animation: tn-master-detail-in-start 0.35s ease-in-out forwards;
+ animation: tn-slide-in-from-left 0.35s ease-in-out forwards;
}
}
.dropdown-menu.tn-menu > .tn-menu-page-entering {
position: relative;
z-index: 1;
- animation: tn-master-detail-in-end 0.35s ease-in-out forwards;
+ animation: tn-slide-in-from-right 0.35s ease-in-out forwards;
}
.dropdown-menu.tn-menu > .tn-menu-page-leaving {
@@ -110,24 +110,24 @@ body.desktop .dropdown-submenu > .dropdown-menu.tn-menu.tn-menu-immediate {
inset: 0;
margin: 0;
z-index: 1;
- animation: tn-master-detail-out-end 0.35s ease-in-out forwards;
+ animation: tn-slide-out-to-right 0.35s ease-in-out forwards;
}
body[dir="rtl"] .dropdown-menu.tn-menu {
> :is(.tn-menu-scroll, .tn-menu-page):has(+ .tn-menu-page-entering) {
- animation-name: tn-master-detail-out-end;
+ animation-name: tn-slide-out-to-right;
}
> :is(.tn-menu-scroll, .tn-menu-page):has(+ .tn-menu-page-leaving) {
- animation-name: tn-master-detail-in-end;
+ animation-name: tn-slide-in-from-right;
}
> .tn-menu-page-entering {
- animation-name: tn-master-detail-in-start;
+ animation-name: tn-slide-in-from-left;
}
> .tn-menu-page-leaving {
- animation-name: tn-master-detail-out-start;
+ animation-name: tn-slide-out-to-left;
}
}
diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsx
index f9f15b294e..baccb2bd2a 100644
--- a/apps/client/src/widgets/react/Menu.tsx
+++ b/apps/client/src/widgets/react/Menu.tsx
@@ -1,4 +1,5 @@
import "./Menu.css";
+import "./slide_animations.css";
import clsx from "clsx";
import type { ComponentChildren } from "preact";
diff --git a/apps/client/src/widgets/react/SlidePages.css b/apps/client/src/widgets/react/SlidePages.css
index 9365b78059..1292222190 100644
--- a/apps/client/src/widgets/react/SlidePages.css
+++ b/apps/client/src/widgets/react/SlidePages.css
@@ -47,53 +47,33 @@
}
.slide-out-forward {
- animation-name: slide-out-left;
+ animation-name: tn-slide-out-to-left;
}
.slide-out-backward {
- animation-name: slide-out-right;
+ animation-name: tn-slide-out-to-right;
}
.slide-in-forward {
- animation-name: slide-in-right;
+ animation-name: tn-slide-in-from-right;
}
.slide-in-backward {
- animation-name: slide-in-left;
+ animation-name: tn-slide-in-from-left;
}
body[dir=rtl] .slide-out-forward {
- animation-name: slide-out-right;
+ animation-name: tn-slide-out-to-right;
}
body[dir=rtl] .slide-out-backward {
- animation-name: slide-out-left;
+ animation-name: tn-slide-out-to-left;
}
body[dir=rtl] .slide-in-forward {
- animation-name: slide-in-left;
+ animation-name: tn-slide-in-from-left;
}
body[dir=rtl] .slide-in-backward {
- animation-name: slide-in-right;
-}
-
-@keyframes slide-out-left {
- from { transform: translateX(0); opacity: 1; }
- to { transform: translateX(-100%); opacity: 0; }
-}
-
-@keyframes slide-out-right {
- from { transform: translateX(0); opacity: 1; }
- to { transform: translateX(100%); opacity: 0; }
-}
-
-@keyframes slide-in-right {
- from { transform: translateX(100%); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
-}
-
-@keyframes slide-in-left {
- from { transform: translateX(-100%); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
+ animation-name: tn-slide-in-from-right;
}
diff --git a/apps/client/src/widgets/react/SlidePages.tsx b/apps/client/src/widgets/react/SlidePages.tsx
index 0c879bf9ee..8691b3b351 100644
--- a/apps/client/src/widgets/react/SlidePages.tsx
+++ b/apps/client/src/widgets/react/SlidePages.tsx
@@ -1,3 +1,4 @@
+import "./slide_animations.css";
import "./SlidePages.css";
import clsx from "clsx";
diff --git a/apps/client/src/widgets/react/master_detail.css b/apps/client/src/widgets/react/master_detail.css
index ada577edad..c9299f26e4 100644
--- a/apps/client/src/widgets/react/master_detail.css
+++ b/apps/client/src/widgets/react/master_detail.css
@@ -68,42 +68,42 @@ body.mobile .modal.mobile-master-detail {
&.mobile-transition-to-page {
.tn-detail-pane {
- animation: tn-master-detail-in-end 0.35s ease-in-out forwards;
+ animation: tn-slide-in-from-right 0.35s ease-in-out forwards;
}
.tn-master-pane {
- animation: tn-master-detail-out-start 0.35s ease-in-out forwards;
+ animation: tn-slide-out-to-left 0.35s ease-in-out forwards;
}
}
&.mobile-transition-to-list {
.tn-detail-pane {
- animation: tn-master-detail-out-end 0.35s ease-in-out forwards;
+ animation: tn-slide-out-to-right 0.35s ease-in-out forwards;
}
.tn-master-pane {
- animation: tn-master-detail-in-start 0.35s ease-in-out forwards;
+ animation: tn-slide-in-from-left 0.35s ease-in-out forwards;
}
}
}
body[dir="rtl"].mobile .modal.mobile-master-detail.mobile-transition-to-page {
.tn-detail-pane {
- animation-name: tn-master-detail-in-start;
+ animation-name: tn-slide-in-from-left;
}
.tn-master-pane {
- animation-name: tn-master-detail-out-end;
+ animation-name: tn-slide-out-to-right;
}
}
body[dir="rtl"].mobile .modal.mobile-master-detail.mobile-transition-to-list {
.tn-detail-pane {
- animation-name: tn-master-detail-out-start;
+ animation-name: tn-slide-out-to-left;
}
.tn-master-pane {
- animation-name: tn-master-detail-in-end;
+ animation-name: tn-slide-in-from-right;
}
}
@@ -147,23 +147,3 @@ body[dir="rtl"].mobile .modal.mobile-master-detail.mobile-transition-to-list {
flex-grow: 0;
}
}
-
-@keyframes tn-master-detail-in-end {
- from { transform: translateX(100%); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
-}
-
-@keyframes tn-master-detail-in-start {
- from { transform: translateX(-100%); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
-}
-
-@keyframes tn-master-detail-out-end {
- from { transform: translateX(0); opacity: 1; }
- to { transform: translateX(100%); opacity: 0; }
-}
-
-@keyframes tn-master-detail-out-start {
- from { transform: translateX(0); opacity: 1; }
- to { transform: translateX(-100%); opacity: 0; }
-}
diff --git a/apps/client/src/widgets/react/master_detail.spec.tsx b/apps/client/src/widgets/react/master_detail.spec.tsx
index 7870225168..40531aba55 100644
--- a/apps/client/src/widgets/react/master_detail.spec.tsx
+++ b/apps/client/src/widgets/react/master_detail.spec.tsx
@@ -81,7 +81,7 @@ function renderHost() {
function endSlide() {
act(() => {
host()?.dispatchEvent(Object.assign(new Event("animationend", { bubbles: true }), {
- animationName: "tn-master-detail-slide-in"
+ animationName: "tn-slide-in-from-right"
}));
});
}
diff --git a/apps/client/src/widgets/react/master_detail.tsx b/apps/client/src/widgets/react/master_detail.tsx
index c93dd77768..dde2cadffb 100644
--- a/apps/client/src/widgets/react/master_detail.tsx
+++ b/apps/client/src/widgets/react/master_detail.tsx
@@ -1,4 +1,5 @@
import "./master_detail.css";
+import "./slide_animations.css";
import clsx from "clsx";
import { ComponentChildren, createContext, RefObject } from "preact";
@@ -21,8 +22,8 @@ import Modal, { ModalProps } from "./Modal";
* master-detail flow. */
export const MASTER_DETAIL_TABLET_MIN_WIDTH = 768;
-/** What every slide of the flow is named with, which is how a finished one is recognised. */
-const SLIDE_ANIMATION_PREFIX = "tn-master-detail-";
+/** What the slides of slide_animations.css are named with, which is how a finished one is recognized. */
+const SLIDE_ANIMATION_PREFIX = "tn-slide-";
export interface MobileMasterDetail {
/** True on narrow mobile viewports where the list and detail collapse into a master-detail flow. */
diff --git a/apps/client/src/widgets/react/slide_animations.css b/apps/client/src/widgets/react/slide_animations.css
new file mode 100644
index 0000000000..e5a4f62708
--- /dev/null
+++ b/apps/client/src/widgets/react/slide_animations.css
@@ -0,0 +1,26 @@
+/*
+ * The slides between two views that replace each other, such as a list and the page it leads to:
+ * `SlidePages`, the master-detail flow and a phone's submenu pages. Named by the physical direction
+ * they move in, so a right-to-left layout swaps which one a rule uses. `useMobileMasterDetail`
+ * recognizes their end by the `tn-slide-` prefix.
+ */
+
+@keyframes tn-slide-in-from-right {
+ from { transform: translateX(100%); opacity: 0; }
+ to { transform: translateX(0); opacity: 1; }
+}
+
+@keyframes tn-slide-in-from-left {
+ from { transform: translateX(-100%); opacity: 0; }
+ to { transform: translateX(0); opacity: 1; }
+}
+
+@keyframes tn-slide-out-to-right {
+ from { transform: translateX(0); opacity: 1; }
+ to { transform: translateX(100%); opacity: 0; }
+}
+
+@keyframes tn-slide-out-to-left {
+ from { transform: translateX(0); opacity: 1; }
+ to { transform: translateX(-100%); opacity: 0; }
+}