-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
<Theme { ...args }> | ||
<Button variant="primary"> | ||
Inner theme (set via Storybook controls) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good clarification!
import type { ReactNode, CSSProperties } from 'react'; | ||
|
||
export type ThemeProps = { | ||
accent?: CSSProperties[ 'color' ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note in the README and validation via the isValid
function (including unit tests) in 0ac7a24
A few additional notes:
- writing tests for
isValid
actually flagged a bug in the code: named colors were supported in Storybook because other components also added the needed plugin, but theTheme
component didn't do it and therefore unit tests were failing! I fixed by adding thenamed
plugin explicitly in theTheme
component too - I've also added the
a11y
plugin 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writing tests for
isValid
actually 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
Theme
componentaccent
color exposed as a theme variablecolord
libraryButton
componentWhy?
This part of the initial exploration for allowing the
@wordpress/components
to be themeable (see #44116)Testing Instructions
Theme
component in Storybook:Button
in the "Default" example still has the same color as theButton
in theButton
storyButton
s in the "Nested" example should be blue (outer) and orange (inner)Button
element renders like ontrunk
in the editor and in its dedicated Storybook examplesScreenshots or screencast