Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify utils API #209

Merged
merged 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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