I started a component library, based on tsdx --template react-with-storybook
, added chakra-ui/react
as a dependency, then created components in it.
The components use colors from Chakra's default theme -- in particular, blue.700
.
In Storybook, I wrap the component in <ChakraProvider>
, and it works. I build the library and put it in npm.
Now in my application (based on create-react-app
), I install the library, import and apply the <ChakraProvider>
, use the component -- and it works, except for the styling.
In the HTML source I can see that the color is still the string "blue.700"
, so this wasn't translated to a color using the theme.
This Chakra UI bit:
<Box
boxSizing="border-box"
width={`calc(${width} + ${scrollbarWidth}px)`}
backgroundColor="blue.700"
color="gray.100"
>
Is turned into this CSS class that the resulting div has:
.css-p8523l {
box-sizing: border-box;
width: calc(1200px + 0px);
background-color: blue.700;
color: gray.100;
}
ChakraProvider clearly does things, for instance there are many CSS variables added to the page, including --chakra-colors-blue-700
.
I thought that maybe the ChakraProvider used in my app (from its own @chakra-ui/react
dependency) used a different React context than the one in the library, so I decided to add an export in the library (export { ChakraProvider } from '@chakra-ui/react';
) and now I import it from my library in the app; but that doesn't have an effect.
What could be going on? Does anyone have an idea how to debug this?