fix: Fix custom theme token (#7180)

* fix: fix table column data is passed into chlidren is undefined or null errorr

* fix: fix custom theme token not take effect

* chore: reset button style

---------

Co-authored-by: undefined <undefined>
feat-4.1
yanyu 2023-12-18 15:20:24 +08:00 committed by GitHub
parent 73f0a29acf
commit 509ec682f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 16 deletions

View File

@ -90,7 +90,6 @@ export const getComputedToken = <DerivativeToken = object, DesignToken = Derivat
format?: (token: DesignToken) => DerivativeToken, format?: (token: DesignToken) => DerivativeToken,
) => { ) => {
const derivativeToken = theme.getDerivativeToken(originToken); const derivativeToken = theme.getDerivativeToken(originToken);
// Merge with override // Merge with override
let mergedDerivativeToken = { let mergedDerivativeToken = {
...derivativeToken, ...derivativeToken,
@ -150,7 +149,6 @@ export default function useCacheToken<DerivativeToken = object, DesignToken = De
const hashId = `${hashPrefix}-${hash(tokenKey)}`; const hashId = `${hashPrefix}-${hash(tokenKey)}`;
mergedDerivativeToken._hashId = hashId; // Not used mergedDerivativeToken._hashId = hashId; // Not used
return [mergedDerivativeToken, hashId]; return [mergedDerivativeToken, hashId];
}, },
cache => { cache => {

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
// import { StyleProvider } from '../../cssinjs'; // import { StyleProvider } from '../../cssinjs';
import { extractStyle } from '../index'; import { extractStyle } from '../index';
import { ConfigProvider } from '../../../components'; import { ConfigProvider } from '../../../components';
import { theme } from '../../../index';
const testGreenColor = '#008000'; const testGreenColor = '#008000';
describe('Static-Style-Extract', () => { describe('Static-Style-Extract', () => {
@ -26,6 +27,25 @@ describe('Static-Style-Extract', () => {
expect(cssText).toContain(testGreenColor); expect(cssText).toContain(testGreenColor);
expect(cssText).toMatchSnapshot(); expect(cssText).toMatchSnapshot();
}); });
it('should extract static styles with customTheme and customStyle', () => {
const cssText = extractStyle(node => {
return (
<ConfigProvider
theme={{
algorithm: theme.darkAlgorithm,
token: {
colorPrimary: testGreenColor,
},
}}
>
{node}
</ConfigProvider>
);
});
expect(cssText).toContain('#037003');
expect(cssText).toMatchSnapshot();
});
// it('with custom hashPriority', () => { // it('with custom hashPriority', () => {
// const cssText = extractStyle( // const cssText = extractStyle(
// (node) => ( // (node) => (

View File

@ -495,7 +495,6 @@ const genBlockButtonStyle: GenerateStyle<ButtonToken> = token => {
// ============================== Export ============================== // ============================== Export ==============================
export default genComponentStyleHook('Button', token => { export default genComponentStyleHook('Button', token => {
const { controlTmpOutline, paddingContentHorizontal } = token; const { controlTmpOutline, paddingContentHorizontal } = token;
const buttonToken = mergeToken<ButtonToken>(token, { const buttonToken = mergeToken<ButtonToken>(token, {
colorOutlineDefault: controlTmpOutline, colorOutlineDefault: controlTmpOutline,
buttonPaddingHorizontal: paddingContentHorizontal, buttonPaddingHorizontal: paddingContentHorizontal,

View File

@ -232,7 +232,6 @@ const ConfigProvider = defineComponent({
algorithm && (!Array.isArray(algorithm) || algorithm.length > 0) algorithm && (!Array.isArray(algorithm) || algorithm.length > 0)
? createTheme(algorithm) ? createTheme(algorithm)
: undefined; : undefined;
return { return {
...rest, ...rest,
theme: themeObj, theme: themeObj,

View File

@ -21,7 +21,7 @@ import statisticToken, { merge as mergeToken, statistic } from './util/statistic
import type { VueNode } from '../_util/type'; import type { VueNode } from '../_util/type';
import { objectType } from '../_util/type'; import { objectType } from '../_util/type';
import type { ComputedRef, InjectionKey, Ref } from 'vue'; import type { ComputedRef, InjectionKey, Ref } from 'vue';
import { defineComponent, provide, computed, inject, watchEffect, ref } from 'vue'; import { unref, defineComponent, provide, computed, inject, watchEffect, ref } from 'vue';
import { toReactive } from '../_util/toReactive'; import { toReactive } from '../_util/toReactive';
const defaultTheme = createTheme(defaultDerivative); const defaultTheme = createTheme(defaultDerivative);
@ -61,26 +61,30 @@ export interface DesignTokenContext {
hashed?: string | boolean; hashed?: string | boolean;
} }
//defaultConfig //defaultConfig
const DesignTokenContextKey: InjectionKey<DesignTokenContext> = Symbol('DesignTokenContext'); const DesignTokenContextKey: InjectionKey<ComputedRef<DesignTokenContext>> =
Symbol('DesignTokenContext');
export const globalDesignTokenApi = ref<DesignTokenContext>(); export const globalDesignTokenApi = ref<DesignTokenContext>();
export const useDesignTokenProvider = (value: DesignTokenContext) => { export const useDesignTokenProvider = (value: ComputedRef<DesignTokenContext>) => {
provide(DesignTokenContextKey, value); provide(DesignTokenContextKey, value);
watchEffect(() => { watchEffect(() => {
globalDesignTokenApi.value = value; globalDesignTokenApi.value = toReactive(value);
}); });
}; };
export const useDesignTokenInject = () => { export const useDesignTokenInject = () => {
return inject(DesignTokenContextKey, globalDesignTokenApi.value || defaultConfig); return inject(
DesignTokenContextKey,
computed(() => globalDesignTokenApi.value || defaultConfig),
);
}; };
export const DesignTokenProvider = defineComponent({ export const DesignTokenProvider = defineComponent({
props: { props: {
value: objectType<DesignTokenContext>(), value: objectType<DesignTokenContext>(),
}, },
setup(props, { slots }) { setup(props, { slots }) {
useDesignTokenProvider(toReactive(computed(() => props.value))); useDesignTokenProvider(computed(() => props.value));
return () => { return () => {
return slots.default?.(); return slots.default?.();
}; };
@ -92,9 +96,11 @@ export function useToken(): [
ComputedRef<GlobalToken>, ComputedRef<GlobalToken>,
ComputedRef<string>, ComputedRef<string>,
] { ] {
const designTokenContext = inject<DesignTokenContext>( const designTokenContext = unref(
DesignTokenContextKey, inject<ComputedRef<DesignTokenContext>>(
globalDesignTokenApi.value || defaultConfig, DesignTokenContextKey,
computed(() => globalDesignTokenApi.value || defaultConfig),
),
); );
const salt = computed(() => `${version}-${designTokenContext.hashed || ''}`); const salt = computed(() => `${version}-${designTokenContext.hashed || ''}`);