Custom ThemeProvider and Theme #2396
-
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 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can solve this by changing |
Beta Was this translation helpful? Give feedback.
You can solve this by changing
Colors
to atype
frominterface
.TS Playground