tdesign-react
Version:
TDesign Component for React
17 lines (16 loc) • 727 B
TypeScript
/**
* useVariables Hook - 监听CSS变量变化并返回实时值
* @param variables CSS 变量名对象,键为返回对象的属性名,值为CSS变量名(带--前缀)
* @param targetElement 监听的元素,默认为 document?.documentElement
* @returns 包含每个变量当前值的ref对象
* @example
* const { textColor, brandColor } = useVariables({
* textColor: '--td-text-color-primary',
* brandColor: '--td-brand-color',
* });
*
* // 使用变量值
* console.log(textColor.current); // 获取当前文本颜色
*/
declare function useVariables<T extends Record<string, string>>(variables: T, targetElement?: HTMLElement): Record<keyof T, string>;
export default useVariables;