diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 82eed26b..df60caf6 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -109,7 +109,7 @@ const processStyleObject = ( /** Utils: */ if (isUtilProp) { // Resolve the util from the util function: - const resolvedUtils = config.utils[key](config)(val); + const resolvedUtils = config.utils[key](val, config); processStyleObject(resolvedUtils, config, valueMiddleware, [...currentNestingPath], false); continue; } diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 3c18fef6..521e85e1 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -65,7 +65,7 @@ export type TFlatUtils< T extends TConfig, UT = { [U in keyof T['utils']]?: T['utils'][U] extends TUtility - ? ReturnType extends (arg: infer A) => {} + ? T['utils'][U] extends (arg: infer A, config: T) => {} ? A : never : never; @@ -74,7 +74,7 @@ export type TFlatUtils< export type TTopUtils = { [U in keyof T['utils']]?: T['utils'][U] extends TUtility - ? ReturnType extends (arg: infer A) => {} + ? T['utils'][U] extends (arg: infer A, config: T) => {} ? A : never : never; @@ -86,7 +86,7 @@ export type TRecursiveUtils = [pseudo: string]: TRecursiveUtils; }; -export type TUtility = (config: T) => (arg: A) => TRecursiveCss; +export type TUtility = (arg: A, config: T) => TRecursiveCss; export type ICssPropToToken = T['tokens'] extends object ? { diff --git a/packages/core/tests/index.test.ts b/packages/core/tests/index.test.ts index 2d7b1483..2a6cf2c9 100644 --- a/packages/core/tests/index.test.ts +++ b/packages/core/tests/index.test.ts @@ -338,7 +338,7 @@ describe('createCss: mixed(SSR & Client)', () => { const css = createCss( { utils: { - marginX: () => (value: string) => ({ + marginX: (value: string, config) => ({ marginLeft: value, marginRight: value, }), @@ -353,7 +353,7 @@ describe('createCss: mixed(SSR & Client)', () => { const css = createCss( { utils: { - hover: () => (value) => ({ + hover: (value, config) => ({ ':hover': value, ':focus': value, }), @@ -926,7 +926,7 @@ describe('createCss: mixed(SSR & Client)', () => { const css = createCss( { utils: { - mx: (config) => (value) => ({ + mx: (value, config) => ({ marginLeft: value, marginRight: value, }),