Skip to content

Commit a019197

Browse files
committed
feat: 增加 setMemorialMode 方法
1 parent 0a7afef commit a019197

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/BootstrapBlazor/Extensions/JSModuleExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,12 @@ public static string GetTypeModuleName(this Type type)
170170
/// <param name="module">An instance of <see cref="JSModule"/></param>
171171
/// <returns></returns>
172172
public static ValueTask<string?> GetThemeAsync(this JSModule module) => module.InvokeAsync<string?>("getTheme");
173+
174+
/// <summary>
175+
/// Set memorial mode
176+
/// </summary>
177+
/// <param name="module">An instance of <see cref="JSModule"/></param>
178+
/// <param name="isMemorial">Whether it is memorial mode</param>
179+
/// <returns></returns>
180+
public static ValueTask SetMemorialModeAsync(this JSModule module, bool isMemorial) => module.InvokeVoidAsync("setMemorialMode", isMemorial);
173181
}

src/BootstrapBlazor/wwwroot/modules/utility.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,26 @@ export function calcCenterPosition(el) {
849849
}
850850
}
851851

852+
export function setMemorialMode(memorial) {
853+
const el = document.documentElement;
854+
if (memorial) {
855+
const theme = el.getAttribute('data-bs-theme');
856+
if (theme) {
857+
el.setAttribute('data-bs-original-theme', theme);
858+
}
859+
el.setAttribute('data-bs-theme', 'dark');
860+
el.setAttribute('data-bb-theme', 'memorial');
861+
}
862+
else {
863+
const theme = el.getAttribute('data-bs-original-theme');
864+
el.removeAttribute('data-bs-theme');
865+
el.removeAttribute('data-bb-theme');
866+
if (theme) {
867+
el.setAttribute('data-bs-theme', theme);
868+
}
869+
}
870+
}
871+
852872
export {
853873
autoAdd,
854874
autoRemove,

0 commit comments

Comments
 (0)