How can I create my own theme? #1544
-
I'm trying to figure out how to create a custom theme, I've been reading the docs and the type definitions but I can't make it work, this is what I have so far:
Nothing is being displayed in the viewport, so it seems I didn't get it right, how would look a basic custom theme setting? I know here is a couple of examples but they don't show how to set the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @GhostOrder28 - sorry if this wasn't clear from the docs. We don't really support referencing design tokens like that at this time. If you wanted to use interface CustomTheme extends Theme {
colors: {
customColor: string;
};
}
const customTheme: CustomTheme & DefaultTheme = mergeTheme(defaultTheme, {
colors: {
customColor: "#2596be"
}
});
// app.tsx or equivalent 'root' component
const App = () => {
return (
<ThemeProvider value={customTheme}>
{...}
</ThemeProvider>
);
};
// Some custom components deeper in the tree
const CustomParagraph = (props) => {
const { colors } = useTheme<CustomTheme>();
const { children, ...rest } = props;
return (
<Paragraph color={colors.customColor} {...rest}>
{children}
</Paragraph>
);
}; I put together a small sandbox demoing this: https://codesandbox.io/s/evergreen-custom-theme-example-3ckblh?file=/src/App.tsx Let me know if you have any other questions or suggestions for improvements on the docs! |
Beta Was this translation helpful? Give feedback.
Hey @GhostOrder28 - sorry if this wasn't clear from the docs. We don't really support referencing design tokens like that at this time. If you wanted to use
customColor
in a component, you would need to reference the value directly from the theme (probably through theuseTheme
hook, which is generically typed)