From c0d7d041b48d691896d31985ac76df3e740eb9d8 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 25 Jan 2023 10:28:10 +0800 Subject: [PATCH] refactor: cssinjs --- .../_util/cssinjs/hooks/useStyleRegister.tsx | 18 +-- components/alert/index.tsx | 45 +++---- components/theme/internal.ts | 4 +- .../theme/util/genComponentStyleHook.ts | 112 +++++++++--------- 4 files changed, 91 insertions(+), 88 deletions(-) diff --git a/components/_util/cssinjs/hooks/useStyleRegister.tsx b/components/_util/cssinjs/hooks/useStyleRegister.tsx index f70e3e14e..86def3f1d 100644 --- a/components/_util/cssinjs/hooks/useStyleRegister.tsx +++ b/components/_util/cssinjs/hooks/useStyleRegister.tsx @@ -21,6 +21,7 @@ import { supportLayer } from '../util'; import useGlobalCache from './useGlobalCache'; import canUseDom from '../../canUseDom'; import { removeCSS, updateCSS } from '../../../vc-util/Dom/dynamicCSS'; +import type { Ref } from 'vue'; import { computed } from 'vue'; import type { VueNode } from '../../type'; @@ -286,20 +287,20 @@ function Empty() { * Register a style to the global style sheet. */ export default function useStyleRegister( - info: { + info: Ref<{ theme: Theme; token: any; path: string[]; hashId?: string; layer?: string; - }, + }>, styleFn: () => CSSInterpolation, ) { const styleContext = useStyleInject(); - const tokenKey = computed(() => info.token._tokenKey as string); + const tokenKey = computed(() => info.value.token._tokenKey as string); - const fullPath = computed(() => [tokenKey.value, ...info.path]); + const fullPath = computed(() => [tokenKey.value, ...info.value.path]); // Check if need insert style let isMergedClientSide = isClientSide; @@ -315,7 +316,7 @@ export default function useStyleRegister( () => { const styleObj = styleFn(); const { hashPriority, container, transformers, linters } = styleContext; - const { path, hashId, layer } = info; + const { path, hashId, layer } = info.value; const [parsedStyle, effectStyle] = parseStyle(styleObj, { hashId, hashPriority, @@ -371,17 +372,16 @@ export default function useStyleRegister( return (node: VueNode) => { let styleNode: VueNode; - if (!styleContext.ssrInline || isMergedClientSide || !styleContext.defaultCache) { styleNode = ; } else { styleNode = (