-
Notifications
You must be signed in to change notification settings - Fork 32
feat(ThemeProvider): Adds GamutThemeProvider component and initial Global styles #1444
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
Conversation
| const createMediaQuery = (size: MediaSize, direction: 'min' | 'max') => | ||
| `@media only screen and (${direction}-width: ${breakpoints[size]})`; |
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.
This removes new line characters from gunking up the strings. This is a no op.
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.
imo, a small comment/warning about that would be helpful for future us's
MattSchiller
left a comment
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.
I am perhaps highly biased, being in the discussions about this since Christian's PRs, but I think this is a fantastic first PR. I'm curious/excited to see where this goes, how it evolves, and where it takes us.
Thanks, Aaron!
| const createMediaQuery = (size: MediaSize, direction: 'min' | 'max') => | ||
| `@media only screen and (${direction}-width: ${breakpoints[size]})`; |
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.
imo, a small comment/warning about that would be helpful for future us's
JoshuaKGoldberg
left a comment
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.
🌮
(will post comment requests soon, we're still pairing)
christian-dinh
left a comment
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.
ya this is sick gg 🥇
casey-speer
left a comment
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.
So to handle say, LE dark vs light mode, we'd want our theme to be something like
const theme = {
leDarkMode: {
bgColor: 'black'
},
leLightMode: {
bgColor: 'white'
}
}And do
createThemeVars(theme, ['leDarkMode', 'leLightMode']);to serialize?
In our use case, would we want to keep this outside gamut for the near term (ie, create our own LEThemeProvider or add a vars argument to withEmotion or some other similar approach) or is the idea to start adding all vars in gamut?
Another question — if for whatever reason we wanted to provide extensions / variations of a theme somewhere in the monolith component tree, is it acceptable to nest <ThemeProvider>s ? (Not sure if emotion/styled system has any special support for that).
Aside from the small comments here, looks good to me overall.
|
I've updated this to 2 separate methods:
For your use case you will want to use import { createVariables } from '@codecademy/gamut-styles';
import styled from '@emotion/styled';
const ColorMode = styled.div(({ mode, theme }) => css(createVariables(theme[mode])));
const Scene = ({ children }) => <ColorMode mode="light">{children}</ColorMode> |
|
I regret to inform everyone that this concept is now a Mark Dalgleish joke tweet https://twitter.com/markdalgleish/status/1366629835880075267 |
slin12
left a comment
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.
😍
📬Published Alpha Packages:@codecademy/gamut-illustrations@0.7.5-alpha.c3d839.0 |
Codecov Report
@@ Coverage Diff @@
## main #1444 +/- ##
===========================================
+ Coverage 40.31% 83.01% +42.70%
===========================================
Files 331 336 +5
Lines 2704 2755 +51
Branches 696 709 +13
===========================================
+ Hits 1090 2287 +1197
+ Misses 1434 415 -1019
+ Partials 180 53 -127
|
|
🚀 Styleguide deploy preview ready! |
Overview
Our styling needs are becoming a bit more complex in the near term. There are current use cases for global css variables and near term uses for different Color Palettes (LE colors) + Modes (light and dark) that are going to be tricky to scale.
This PR Introduces them in a controlled way by creating a single point of entry for any
Globalstyles through a new component that wraps the default emotionThemeProvider. While also adding the first CSS vars to the themeheaderHeight.Adding support for CSS variables has a few huge advantages:
4remcan mean a lot of things butvar(--headerHeight)cannot.Adding any new pattern like this is dangerous, and I'm suggesting we consider using the following best practices:
To ensure we can safely introducing these this PR adds variable serialization through
createThemeVariablesandcreateVariables.createThemeVariablesUsageBasic example:
Contrived example:
The returned theme object will include valid references to these global variables to be used through out the app without any knowledge of their complexity. End usage of these variables remains the same down stream. For almost all use cases this provides a more flexible + robust method of distributing styles combining the typesafety and dynamism of TS and the performance + flexibility of CSS Variables
createVariablesusageTakes any object and returns a CSSObject with variable definitions along any selector.
Real world:
createThemeVariablesandcreateVariablesfor simple CSS Variable serialization.PR Checklist