Skip to content

Commit

Permalink
Merge pull request #209 from modulz/update-util-api
Browse files Browse the repository at this point in the history
Simplify utils API
  • Loading branch information
Pedro Duarte authored Sep 10, 2020
2 parents bef0c97 + e400438 commit f156210
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type TFlatUtils<
T extends TConfig,
UT = {
[U in keyof T['utils']]?: T['utils'][U] extends TUtility<any, any>
? ReturnType<T['utils'][U]> extends (arg: infer A) => {}
? T['utils'][U] extends (arg: infer A, config: T) => {}
? A
: never
: never;
Expand All @@ -74,7 +74,7 @@ export type TFlatUtils<

export type TTopUtils<T extends TConfig> = {
[U in keyof T['utils']]?: T['utils'][U] extends TUtility<any, any>
? ReturnType<T['utils'][U]> extends (arg: infer A) => {}
? T['utils'][U] extends (arg: infer A, config: T) => {}
? A
: never
: never;
Expand All @@ -86,7 +86,7 @@ export type TRecursiveUtils<T extends TConfig> =
[pseudo: string]: TRecursiveUtils<T>;
};

export type TUtility<A extends any, T extends TConfig> = (config: T) => (arg: A) => TRecursiveCss<T>;
export type TUtility<A extends any, T extends TConfig> = (arg: A, config: T) => TRecursiveCss<T>;

export type ICssPropToToken<T extends TConfig> = T['tokens'] extends object
? {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ describe('createCss: mixed(SSR & Client)', () => {
const css = createCss(
{
utils: {
marginX: () => (value: string) => ({
marginX: (value: string, config) => ({
marginLeft: value,
marginRight: value,
}),
Expand All @@ -353,7 +353,7 @@ describe('createCss: mixed(SSR & Client)', () => {
const css = createCss(
{
utils: {
hover: () => (value) => ({
hover: (value, config) => ({
':hover': value,
':focus': value,
}),
Expand Down Expand Up @@ -926,7 +926,7 @@ describe('createCss: mixed(SSR & Client)', () => {
const css = createCss(
{
utils: {
mx: (config) => (value) => ({
mx: (value, config) => ({
marginLeft: value,
marginRight: value,
}),
Expand Down

0 comments on commit f156210

Please sign in to comment.