-
Hi, I'm creating a system with a few different themes, these themes can be composed of modular chunks using const vars = createThemeContract({
space: {...},
radius: {...},
fontSize: {...},
lineHeight: {...},
})
const base = assignVars(
{ space: vars.space, radius: vars.radius},
{
space: {...},
radius: {...},
}
)
const typefaceA = assignVars(
vars.typography,
{
fontSize: {...},
lineHeight: {...},
}
)
const typefaceB = assignVars(
vars.typography,
{...} // same as typefaceB but different values
)
const themeA = style({
vars: {
...base,
...typefaceA,
}
})
const themeB = style({
vars: {
...base,
...typefaceB,
}
}) Is there a way I can verify that variables assigned to my theme class meet the entire theme contract? Ideally if someone (me) composes an incomplete theme, this is flagged as a TS error. To continue the example: const themeC = style({
vars: {
...base
}
}) // => !! You're missing "fontSize" and "lineHeight" !! Any thoughts from the community welcome! |
Beta Was this translation helpful? Give feedback.
Answered by
askoufis
Oct 15, 2023
Replies: 1 comment 4 replies
-
You can use const vars = createThemeContract({
space: {...},
radius: {...},
fontSize: {...},
lineHeight: {...},
})
const base = assignVars(
{ space: vars.space, radius: vars.radius},
{
space: {...},
radius: {...},
}
)
const themeC = style({
// !! You're missing "fontSize" and "lineHeight" !!
vars: assignVars(vars, base)
}) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, I think we've both just been circling around the
createTheme
API, which is really just a wrapper around creating a style withassignVars
anyway, with the option to pass a contract if you want. I feel like it would be simpler to just derive some types from partial theme objects and then stitch themes together withcreateTheme
, rather than passing objects ofCSSVarFunction
s around: