Skip to content

Commit 74afda1

Browse files
authored
refactor(ThemeMode): update view-transition style (#5580)
* feat: 增加 calcCenterPosition 工具方法 * refactor: 更新样式
1 parent edfdbe1 commit 74afda1

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

src/BootstrapBlazor.Server/Components/Components/ThemeMode.razor.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTheme, switchTheme } from "../../_content/BootstrapBlazor/modules/utility.js"
1+
import { getTheme, switchTheme, calcCenterPosition } from "../../_content/BootstrapBlazor/modules/utility.js"
22
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js"
33

44
export function init(id) {
@@ -12,7 +12,9 @@ export function init(id) {
1212
else {
1313
theme = 'dark';
1414
}
15-
switchTheme(theme, window.innerWidth, window.innerHeight);
15+
16+
const rect = calcCenterPosition(el);
17+
switchTheme(theme, rect.x, rect.y);
1618
});
1719
}
1820
}

src/BootstrapBlazor/Components/ThemeProvider/ThemeProvider.razor.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPreferredTheme, setTheme, switchTheme } from "../../modules/utility.js"
1+
import { getPreferredTheme, setTheme, switchTheme, calcCenterPosition } from "../../modules/utility.js"
22
import EventHandler from "../../modules/event-handler.js"
33
import Data from "../../modules/data.js"
44

@@ -25,7 +25,9 @@ export function init(id, invoke, themeValue, callback) {
2525
EventHandler.on(el, 'click', '.dropdown-item', e => {
2626
const activeTheme = e.delegateTarget.getAttribute('data-bb-theme-value');
2727
theme.currentTheme = activeTheme;
28-
switchTheme(activeTheme, window.innerWidth, 0);
28+
29+
const rect = calcCenterPosition(el);
30+
switchTheme(activeTheme, rect.x, rect.y);
2931
if (callback) {
3032
invoke.invokeMethodAsync(callback, activeTheme);
3133
}

src/BootstrapBlazor/wwwroot/modules/utility.js

+8
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,14 @@ export function setTitle(title) {
841841
document.title = title;
842842
}
843843

844+
export function calcCenterPosition(el) {
845+
const rect = el.getBoundingClientRect();
846+
return {
847+
x: rect.left + el.offsetWidth / 2,
848+
y: rect.top + el.offsetHeight / 2
849+
}
850+
}
851+
844852
export {
845853
autoAdd,
846854
autoRemove,

src/BootstrapBlazor/wwwroot/scss/root.scss

+38-13
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,48 @@ a, a:hover, a:focus {
7676
--bs-popover-body-padding-y: 0.5rem;
7777
}
7878

79-
::view-transition-old(root) {
79+
::view-transition-old(*) {
80+
mix-blend-mode: normal;
8081
animation: none;
82+
z-index: 1;
8183
}
8284

83-
::view-transition-new(root) {
85+
::view-transition-new(*) {
8486
mix-blend-mode: normal;
85-
animation: clip .3s ease-in;
87+
animation: clip .3s ease-in-out;
88+
z-index: 9999;
89+
}
90+
91+
@keyframes clip {
92+
from {
93+
clip-path: circle(0% at var(--bb-theme-x) var(--bb-theme-y));
94+
}
95+
96+
to {
97+
clip-path: circle(100% at var(--bb-theme-x) var(--bb-theme-y));
98+
}
99+
}
100+
101+
[data-bs-theme='dark'] {
102+
&::view-transition-old(*) {
103+
animation: clip2 .3s ease-in-out;
104+
z-index: 9999;
105+
}
106+
107+
&::view-transition-new(*) {
108+
animation: none;
109+
z-index: 1;
110+
}
111+
}
112+
113+
@keyframes clip2 {
114+
from {
115+
clip-path: circle(100% at var(--bb-theme-x) var(--bb-theme-y));
116+
}
117+
118+
to {
119+
clip-path: circle(0% at var(--bb-theme-x) var(--bb-theme-y));
120+
}
86121
}
87122

88123
body:before {
@@ -125,13 +160,3 @@ body:before {
125160
content: "extraExtraLarge";
126161
}
127162
}
128-
129-
@keyframes clip {
130-
from {
131-
clip-path: circle(0% at var(--bb-theme-x) var(--bb-theme-y));
132-
}
133-
134-
to {
135-
clip-path: circle(100% at var(--bb-theme-x) var(--bb-theme-y));
136-
}
137-
}

0 commit comments

Comments
 (0)