-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: CSS Rules - Lint and type at recipe #94
- Loading branch information
Showing
4 changed files
with
47 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
import { addRecipe } from '@vanilla-extract/css/recipe'; | ||
import { style, styleVariants } from '@vanilla-extract/css'; | ||
import { addFunctionSerializer } from "@vanilla-extract/css/functionSerializer"; | ||
import { style, styleVariants } from "@vanilla-extract/css"; | ||
|
||
import { createRuntimeFn } from './createRuntimeFn'; | ||
import { createRuntimeFn } from "./createRuntimeFn"; | ||
import type { | ||
PatternOptions, | ||
PatternResult, | ||
RuntimeFn, | ||
VariantGroups, | ||
VariantSelection, | ||
} from './types'; | ||
import { mapValues } from './utils'; | ||
VariantSelection | ||
} from "./types"; | ||
import { mapValues } from "./utils"; | ||
|
||
export type { RecipeVariants, RuntimeFn } from './types'; | ||
export type { RecipeVariants, RuntimeFn } from "./types"; | ||
|
||
export function recipe<Variants extends VariantGroups>( | ||
options: PatternOptions<Variants>, | ||
debugId?: string, | ||
debugId?: string | ||
): RuntimeFn<Variants> { | ||
const { | ||
variants = {}, | ||
defaultVariants = {}, | ||
compoundVariants = [], | ||
base, | ||
base | ||
} = options; | ||
|
||
let defaultClassName; | ||
|
||
if (!base || typeof base === 'string') { | ||
if (!base || typeof base === "string") { | ||
const baseClassName = style({}); | ||
defaultClassName = base ? `${baseClassName} ${base}` : baseClassName; | ||
} else { | ||
defaultClassName = style(base, debugId); | ||
} | ||
|
||
// @ts-expect-error | ||
const variantClassNames: PatternResult<Variants>['variantClassNames'] = | ||
// @ts-expect-error - Temporarily ignoring the error as the PatternResult type is not fully defined | ||
const variantClassNames: PatternResult<Variants>["variantClassNames"] = | ||
mapValues(variants, (variantGroup, variantGroupName) => | ||
styleVariants( | ||
variantGroup, | ||
(styleRule) => | ||
typeof styleRule === 'string' ? [styleRule] : styleRule, | ||
debugId ? `${debugId}_${variantGroupName}` : variantGroupName, | ||
), | ||
typeof styleRule === "string" ? [styleRule] : styleRule, | ||
debugId ? `${debugId}_${variantGroupName}` : variantGroupName | ||
) | ||
); | ||
|
||
const compounds: Array<[VariantSelection<Variants>, string]> = []; | ||
|
||
for (const { style: theStyle, variants } of compoundVariants) { | ||
compounds.push([ | ||
variants, | ||
typeof theStyle === 'string' | ||
typeof theStyle === "string" | ||
? theStyle | ||
: style(theStyle, `${debugId}_compound_${compounds.length}`), | ||
: style(theStyle, `${debugId}_compound_${compounds.length}`) | ||
]); | ||
} | ||
|
||
const config: PatternResult<Variants> = { | ||
defaultClassName, | ||
variantClassNames, | ||
defaultVariants, | ||
compoundVariants: compounds, | ||
compoundVariants: compounds | ||
}; | ||
|
||
return addRecipe(createRuntimeFn(config), { | ||
importPath: '@vanilla-extract/recipes/createRuntimeFn', | ||
importName: 'createRuntimeFn', | ||
// @ts-expect-error | ||
args: [config], | ||
return addFunctionSerializer(createRuntimeFn(config), { | ||
importPath: "@vanilla-extract/recipes/createRuntimeFn", | ||
importName: "createRuntimeFn", | ||
// @ts-expect-error - Mismatch between return type of createRuntimeFn and argument type of addFunctionSerializer | ||
args: [config] | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters