Closed mayank99 closed 1 year ago
Update Readme with new functionality. We need better docs for ThemeProvider.
the readme is actually more accurate now than it was previously, because the default behavior will work in most cases. does it make sense to clutter the readme with specific cases? i think the details should go in the documentation site.
i've tried to make the jsdoc very detailed for the applyBackground
prop. i can also improve the jsdoc for the ThemeProvider itself.
the readme is actually more accurate now than it was previously, because the default behavior will work in most cases. does it make sense to clutter the readme with specific cases? i think the details should go in the documentation site.
i've tried to make the jsdoc very detailed for the
applyBackground
prop. i can also improve the jsdoc for the ThemeProvider itself.
My main idea was to create more docs outside jsdoc. Some people might miss our exposed util components. Jsdoc is not visible unless you add component. This info should be added in website. Until that - where do people find what components we have?
My main idea was to create more docs outside jsdoc. Some people might miss our exposed util components. Jsdoc is not visible unless you add component. This info should be added in website. Until that - where do people find what components we have?
I agree jsdoc is not the only place we should document things. That's why we need to prioritize writing more useful docs for our website and deploy it. :)
Resolves #967.
What I did
Added an optional boolean
applyBackground
tothemeOptions
. When set to true, it will add theiui-root-background
class along withiui-root
. When false, it will not. The default behavior (when user doesn't pass anything) is to check if theme was already set either through context or on<body>
(similar to #963) and add this class if this is the first time setting theme.To achieve this, I refactored the parent theme check logic into a new hook called
useIsThemeAlreadySet
. I also had to move theiui-root
element above theProvider
, and then the code was getting messy so I moved all the complexity into a new internal component calledRoot
. This makes theThemeProvider
component simpler and more performant. (On the note of performance, I also memoized the context value since we are using this context in every component)Added unit test, and as an additional test that this actually works, I've also updated the vite playground (it was previously using
useTheme
instead ofThemeProvider
).What this means for the user
In most cases, the user can just do this without even thinking about this new prop:
And if the default behavior is not desirable, they will able to override it easily.