feat(settings): 站点界面动画总开关与子开关
管理后台可关全站动画,并细调代码折叠、平滑滚动、装饰入场;统一 lib/motion,尊重系统减少动态效果。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
52
frontend/components/MotionProvider.tsx
Normal file
52
frontend/components/MotionProvider.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
import {
|
||||
applyMotionSiteConfig,
|
||||
getMotionSiteConfig,
|
||||
motionConfigFromSettings,
|
||||
type MotionSiteConfig,
|
||||
} from "@/lib/motion";
|
||||
import { realtime, RT_SETTINGS_CHANGED, type RtSettingsData } from "@/lib/realtime";
|
||||
|
||||
/**
|
||||
* 根布局注入:SSR 初值写入 motion 模块 + html class;settings:changed 热更新。
|
||||
*/
|
||||
export default function MotionProvider({
|
||||
initial,
|
||||
children,
|
||||
}: {
|
||||
initial: MotionSiteConfig;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
applyMotionSiteConfig(motionConfigFromSettings(initial));
|
||||
}, [initial]);
|
||||
|
||||
useEffect(() => {
|
||||
return realtime.on<RtSettingsData>(RT_SETTINGS_CHANGED, (data) => {
|
||||
if (!data) return;
|
||||
const cur = getMotionSiteConfig();
|
||||
applyMotionSiteConfig(
|
||||
motionConfigFromSettings({
|
||||
ui_animations:
|
||||
typeof data.ui_animations === "boolean"
|
||||
? data.ui_animations
|
||||
: cur.ui_animations,
|
||||
anim_code_fold:
|
||||
typeof data.anim_code_fold === "boolean"
|
||||
? data.anim_code_fold
|
||||
: cur.anim_code_fold,
|
||||
anim_smooth_scroll:
|
||||
typeof data.anim_smooth_scroll === "boolean"
|
||||
? data.anim_smooth_scroll
|
||||
: cur.anim_smooth_scroll,
|
||||
anim_chrome:
|
||||
typeof data.anim_chrome === "boolean" ? data.anim_chrome : cur.anim_chrome,
|
||||
})
|
||||
);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return children;
|
||||
}
|
||||
Reference in New Issue
Block a user