Files
SnowLuma/.pnpm-store/v11/files/4a/61d790a6597de3cd09d2476bce2a8b8ff54bf6f297b62d52969b5798e13a0334134254dd1c0c6f1c54ddefaa9e03b0f8c47ebfb27884443e60bb7b24903ee4
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

45 lines
1.4 KiB
Plaintext

import { McpUiTheme } from "../types.js";
/**
* React hook that provides the current document theme reactively.
*
* Uses a `MutationObserver` to watch for changes to the `data-theme` attribute
* or `class` on `document.documentElement`. When the theme changes (e.g., from
* host context updates), the hook automatically re-renders your component with
* the new theme value.
*
* The `MutationObserver` is automatically disconnected when the component unmounts.
*
* @returns The current theme ("light" or "dark")
*
* @example Conditionally render based on theme
* ```tsx source="./useDocumentTheme.examples.tsx#useDocumentTheme_conditionalRender"
* function MyApp() {
* const theme = useDocumentTheme();
*
* return <div>{theme === "dark" ? <DarkIcon /> : <LightIcon />}</div>;
* }
* ```
*
* @example Use with theme-aware styling
* ```tsx source="./useDocumentTheme.examples.tsx#useDocumentTheme_themedButton"
* function ThemedButton() {
* const theme = useDocumentTheme();
*
* return (
* <button
* style={{
* background: theme === "dark" ? "#333" : "#fff",
* color: theme === "dark" ? "#fff" : "#333",
* }}
* >
* Click me
* </button>
* );
* }
* ```
*
* @see {@link getDocumentTheme `getDocumentTheme`} for the underlying function
* @see {@link applyDocumentTheme `applyDocumentTheme`} to set the theme
*/
export declare function useDocumentTheme(): McpUiTheme;