From b8b9c9f680e03d4ccefaf169c4a71d286518a0cb Mon Sep 17 00:00:00 2001 From: Pedro Duarte Date: Thu, 10 Sep 2020 19:47:36 +0200 Subject: [PATCH] Update util API --- packages/core/src/index.ts | 2 +- packages/core/src/types.ts | 6 +++--- packages/core/tests/index.test.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7054e12a..d1786e69 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 67c66504..d0d1d9c4 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 f86bce82..23be8944 100644 --- a/packages/core/tests/index.test.ts +++ b/packages/core/tests/index.test.ts @@ -330,7 +330,7 @@ describe('createCss: mixed(SSR & Client)', () => { const css = createCss( { utils: { - marginX: () => (value: string) => ({ + marginX: (value: string, config) => ({ marginLeft: value, marginRight: value, }), @@ -345,7 +345,7 @@ describe('createCss: mixed(SSR & Client)', () => { const css = createCss( { utils: { - hover: () => (value) => ({ + hover: (value, config) => ({ ':hover': value, ':focus': value, }), @@ -901,7 +901,7 @@ describe('createCss: mixed(SSR & Client)', () => { const css = createCss( { utils: { - mx: (config) => (value) => ({ + mx: (value, config) => ({ marginLeft: value, marginRight: value, }),