Repository navigation
Custom ThemeProvider and Theme #2396
Answered
by
hasparus
TrevorRice
asked this question in
General
|
Hi all! I'm curious if there is a preferred or recommended approach for a component library or design system to expose its own wrappers around Theme UI's For example, suppose I want to enforce a specific interface Colors {
primary: string;
neutral: string;
success: string;
...
}
interface MyDesignSystemTheme {
...
colors: Colors;
...
}If interface MyDesignSystemThemeProviderProps {
children?: ReactNode;
theme: MyDesignSystemTheme;
}
export const MyDesignSystemThemeProvider = (props: MyDesignSystemThemeProviderProps) => {
return <ThemeProvider theme={props.theme}>{props.children}</ThemeProvider>;
};You'll receive the following TypeScript error: This can be seen in this CodeSandbox example. How would I be able to provide my own provider and theme interface that enforces a certain structure but doesn't result in a type mismatch when passing that theme to Theme UI's |
Answered by
hasparus
Feb 22, 2023
Replies: 1 comment 2 replies
You can solve this by changing |
2 replies
Answer selected by
hasparus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can solve this by changing
Colorsto atypefrominterface.TS Playground