Types for generated variants using template literals for a token values #2103
Answered
by
astahmer
kiruushaaa
asked this question in
Q&A
-
I'm trying to put similar hardcoded variants differ only with a name of a semantic token. It does work but I have no idea how to type it correctly. import { cva } from "~/styled-system/css";
import type { RecipeVariantRecord } from "~/styled-system/types";
const variantObject = ["primary", "secondary"].reduce((variants, name) => {
variants[name] = {
bg: `token(colors.${name})`,
borderColor: `token(colors.${name})`,
_hoverEnabled: {
bg: `token(colors.${name}.hover)`,
borderColor: `token(colors.${name}.hover)`,
},
_activeEnabled: { ... },
_disabled: { ... }
};
return variants;
}, {} as RecipeVariantRecord);
export const button = cva({
base: { ... },
variants: {
...variantObject,
anotherVariant: { ... }
}
}); Typing error related to:
I was thinking about pregenerated color pallets but It will bring some logic for |
Beta Was this translation helpful? Give feedback.
Answered by
astahmer
Jan 28, 2024
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
kiruushaaa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
as Record<string, SystemStyleObject>
instead ofRecipeVariantRecord
should fix it I think ?