-
Notifications
You must be signed in to change notification settings - Fork 221
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
feat(labs): Theming (react) #272
Conversation
|
||
return ( | ||
<ThemeProvider theme={theme}> | ||
<InputProvider>{children}</InputProvider> |
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.
CanvasProvider
would provide both the theme and the input type to avoid multiple HOCs.
It would be cool if this automatically loaded the fonts module and injected the global style if a flag for that was passed as well.
modules/banner/react/lib/Banner.tsx
Outdated
backgroundColor: | ||
error === ErrorType.Error ? theme.palette.error.main : theme.palette.alert.main, | ||
color: error === ErrorType.Error ? theme.palette.error.contrast : colors.blackPepper400, | ||
'&:hover': { |
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.
Note: I realized we don't have active states for our Banner
component. The color/contrast gets pretty terrible based on our current system, so we should consider this.
3d4a544
to
a57b54c
Compare
49dba6f
to
d7b081f
Compare
d6f8db3
to
e4eb9db
Compare
Update on the conflict with |
Summary
Spent last week working through how theming will work in Canvas Kit. This is a functional POC, but still needs some work. It also only adds theming to one existing component as a test.
Note 1: This does not have any breaking changes 🎉
Note 2: Since I've put the theming work in labs (to allow for updates to the API/theme object), we now need to depend on
@workday/canvas-kit-labs-react-core
if we want to start adding theming support to our components.Note 3: This does not address CSS theming. The implementation of that is still up in the air.
Implementation
This adds a new
CanvasProvider
(which includes anInputProvider
) that provides a theme using Emotion'sThemeProvider
. You can pass a custom theme using thecreateCanvasTheme
function:createCanvasTheme
will expand a partial theme into a full one based on the default theme. If you only pass a main shade, all other shades will be generated automatically based on that.CanvasTheme
also contains breakpoints (zero, s, m, l, xl) that can be accessed with the context. It also includes functions that return media queries based on the breakpoints (e.g.theme.breakpoints.up('m')
will return'@media (min-width:960px)'
by default).Finally, since this is all based on React Contexts, we have an issue if anyone is not able to use contexts. This can be true for teams with multiple small React trees. To handle this,
CanvasProvider
can accept thesetThemeGlobal
prop. This sets the theme onwindow.wdCanvas.theme
. Whenever we access the theme, we use theuseTheme
hook, which first looks for a context theme, then for a window theme, before falling back to the default. I added an override/wrapper to Emotion'sstyled
function which callsuseTheme
behind the scenes.Checklist
yarn test
passespackage.json
canvas-kit-react
and/orcanvas-kit-css
universal modules, ifapplicable