Repository navigation
Components: Try color theming - #44668
Conversation
|
Size Change: +235 B (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
848aa19 to
653dca3
Compare
5f5984f to
ce15b70
Compare
|
|
||
| <Theme { ...args }> | ||
| <Button variant="primary"> | ||
| Inner theme (set via Storybook controls) |
| import type { ReactNode, CSSProperties } from 'react'; | ||
|
|
||
| export type ThemeProps = { | ||
| accent?: CSSProperties[ 'color' ]; |
There was a problem hiding this comment.
We might want to document that some otherwise "valid" values cannot be parsed in this context, like currentColor or var(--some-css-var).
Doesn't have to be in this PR, but we can also check at runtime with .isValid() and throw a dev warning.
There was a problem hiding this comment.
Added a note in the README and validation via the isValid function (including unit tests) in 0ac7a24
A few additional notes:
- writing tests for
isValidactually flagged a bug in the code: named colors were supported in Storybook because other components also added the needed plugin, but theThemecomponent didn't do it and therefore unit tests were failing! I fixed by adding thenamedplugin explicitly in theThemecomponent too - I've also added the
a11yplugin while I was at it, since we will need it for contrast checking (it's already used in other components, so it shouldn't really make a difference in terms of bundle size) - I changed the type to
string, since theCSSProperties[ 'color' ]was including a bunch of values that we don't support. But let me know if you'd rather revert toCSSProperties[ 'color' ]!
Let me know if these changes LGTY and I will proceed with merging :)
There was a problem hiding this comment.
writing tests for
isValidactually flagged a bug in the code
Wonderful 😄
Looks great! I think we're good to merge. Maybe copy & paste the readme stuff into JSDoc so we get it in Storybook and IntelliSense.
There was a problem hiding this comment.
Cool, it turns out that the TS docs already had the README stuff (including Storybook and intellisense).
I'm going to merge once CI is ✅
Smoke testing in the editor is looking ok 🚢 |
|
Exciting! How close are we to using components on a dark background now? |
|
Hey @jasmussen , this was only the very first step of the process - we still have quite a few aspects to work on, but this PR was definitely a big step in the right direction! We have a tentative TODO list in #44116 (comment) |
|
Thanks for tackling! |
What?
Themecomponentaccentcolor exposed as a theme variablecolordlibraryButtoncomponentWhy?
This part of the initial exploration for allowing the
@wordpress/componentsto be themeable (see #44116)Testing Instructions
Themecomponent in Storybook:Buttonin the "Default" example still has the same color as theButtonin theButtonstoryButtons in the "Nested" example should be blue (outer) and orange (inner)Buttonelement renders like ontrunkin the editor and in its dedicated Storybook examplesScreenshots or screencast