-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix media merge with variants and compound variants #33
Fix media merge with variants and compound variants #33
Conversation
Feat/merge media
984eac0
to
d440978
Compare
Thank you for these PRs! On a quick glance they look very good 👍🏻 I'll try to find some time to review and test them locally 🙂 It looks like these three PRs build on top of each other so I'm wondering if it would be easier for me to review just the latest PR that contains all the fixes 🤔 They are all related to responsive styles so it wouldn't be too bad to review all the fixes as one big PR. Is it okay to you if I just review and test this PR and close the other two? |
Yes, of course. |
Thank you for setting up the Expo Web support in the example app! 🙌🏻 I noticed that running the example app in iOS Simulator doesn't seem to be working anymore because it's not able to resolve I wonder why the web version is working but not the native one 🤔 |
Sorry for this pitfall. It may be caused by expo and react-native latest versions. |
I think we can have both metro and webpack configs in the example Expo app. Metro will be used for native and webpack for web. I took a look at this RN library called Zeego that has both config files in the example app. I will play around with the bundler setup today and see if I can get it to work. |
Ah... I see. I certainly removed metro.config.js. The reason is mentioned in #31. But, you're right, we must use metro or repack as native module bundler. Especially I don't know whether we can use repack with expo so we should use metro. Thank you for investigation and I'll try to fix it too, though no problem as if you finish to work earlier than me. |
I think I got it working with both webpack and metro. Can you give me rights to push to your PR branch? |
@Temzasse Thank you, I worked just restoring metro.config.js, too. If you do another way and want more fix, could you do after merging my code? |
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 the first review round for the example app related changes.
Next I will take a look at the lib changes.
Sure that works too 👍🏻 |
@Temzasse |
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.
All in all changes to the internals look very good 👍🏻
Found a few places where we can cleanup the code a bit.
I will still test the implementation a bit more in order to make sure all different cases of media styles work as expected.
src/internals/utils.js
Outdated
@@ -103,16 +118,41 @@ export function processTheme(theme) { | |||
return { definition, values }; | |||
} | |||
|
|||
const THEME_PRIORITIZED_KEYS = [ |
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.
There is no need for priority ordering for these keys - they can be in any order. This means that you can derive them from the THEME_VALUES
object from constants.ts
:
const THEME_KEYS = Object.keys(THEME_VALUES);
src/internals/utils.js
Outdated
...acc, | ||
...processStyles({ styles: utils[key](val), theme, config }), | ||
}; | ||
// NOTE: Deepmerge for media propeties. |
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.
NIT: typo popeties
-> properties
src/internals/utils.js
Outdated
'letterSpacings', | ||
]; | ||
|
||
function searchHaveTokenConfigKey(theme, themeMap, key) { |
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.
NIT: a better name for this function would be something like getThemeScaleKey
and instead of using variable called configKey
in various places in this file a more accurate name would be scaleKey
.
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.
Okey, but colors key is also included. So, I'll rename getThemeKey and themeKey.
@@ -159,6 +177,8 @@ export function processStyles({ styles, theme, config }) { | |||
} else if (typeof val === 'object' && val.value !== undefined) { | |||
// Handle cases where the value comes from the `theme` returned by `createStitches` | |||
acc[key] = val.value; | |||
} else if (typeof acc[key] === 'object' && typeof val === 'object') { |
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.
Could you add a comment for this case so that it's easier to understand what is happening here when I or someone else comes back to this codebase after some time 😄
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.
DONE
src/internals/index.js
Outdated
Object.entries(config.media).forEach(([key, val]) => { | ||
const breakpoint = `@${key}`; | ||
|
||
if (breakpoint) { |
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 if could be merged with the below if to reduce the number of ifs:
if (breakpoint && propValue[breakpoint] !== undefined) {}
if (match) { | ||
styleSheetKey = `${prop}_${propValue[breakpoint]}`; | ||
} | ||
styleSheetKey = `${prop}_${propValue[breakpoint]}`; |
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 can also be simplified so that there is only one if:
if (val === true || typeof val === 'string') {
styleSheetKey = `${prop}_${propValue[breakpoint]}`;
}
@tkow Thank you for being patient with my many reviews 🙏🏻 After making the changes requested in my last review round I can merge this PR and fix anything else that comes up on my own 🙂 |
@Temzasse By the way, I don't know why, but this instruction can't be applied.(UI doesn't exist) So, in already our repository public you may be able to push without any setting. If you can't do so and need to do, I'll suggest another way after fixing the your review points. |
da7f5b8
to
ed1456d
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.
Awesome job! Thank you very much for this 🙌🏻 ✨
I will merge this after I have had the time to test it a bit more 🙂
…compoundVariables example * fix: Temzasse#34 * chore: compound variants example
defaultVariants: {
heading: 'h1',
underlined: true,
},
As I'm already using these new features as private git submodules. So, when I find something wrong and it's mission critical for our development, I may work for this library. Stitches and it for the native, really most awesome library as I have ever seen especially in the point of cross platform availability while it may be hard with streaming SSR , and I want to keep using them for long. I appreciate your nice work public. |
@tkow thank you so much for these fixes! 👏🏻 Let's not add any more fixes outside of the media styles related bug fixes or improvements into this PR so that that I'm able to review things more efficiently. I will try to merge this as soon as possible so that you can get these fixes from the npm instead of your git submodule 🙂 |
Closes #34
Check after #31 , #32.
I fixed media properties can be used with variants and compound variants styles.
I removed these code, because it's been ever ignored and not worked due to
key
format is used instead of@key
. In addition, now media properties must be kept as media variants style for work.I add new examples of this features.