feat(appearance): add AppearanceProvider and use-appearance hooks
新增 React Context 管理 themeColor 和 zoomLevel state,与 next-themes 正交, 通过 localStorage 持久化并支持跨标签页同步。提供语义化 hook useThemeColor / useZoomLevel 供调用点按需使用。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
24
src/hooks/use-appearance.ts
Normal file
24
src/hooks/use-appearance.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { useContext } from "react"
|
||||
import { AppearanceContext } from "@/components/appearance-provider"
|
||||
|
||||
export function useAppearance() {
|
||||
const ctx = useContext(AppearanceContext)
|
||||
if (!ctx) {
|
||||
throw new Error("useAppearance must be used within AppearanceProvider")
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
/** 语义化包装:只关心主题色的调用点用这个 */
|
||||
export function useThemeColor() {
|
||||
const { themeColor, setThemeColor } = useAppearance()
|
||||
return { themeColor, setThemeColor }
|
||||
}
|
||||
|
||||
/** 语义化包装:只关心缩放档位的调用点用这个 */
|
||||
export function useZoomLevel() {
|
||||
const { zoomLevel, setZoomLevel } = useAppearance()
|
||||
return { zoomLevel, setZoomLevel }
|
||||
}
|
||||
Reference in New Issue
Block a user