Skip to content
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

Merged
merged 20 commits into from
Oct 31, 2022

Conversation

tkow
Copy link
Contributor

@tkow tkow commented Oct 29, 2022

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.
スクリーンショット 2022-10-29 19 05 25

@tkow tkow force-pushed the fix/media-merge-with-variants branch from 984eac0 to d440978 Compare October 29, 2022 10:22
@Temzasse
Copy link
Owner

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?

@tkow
Copy link
Contributor Author

tkow commented Oct 29, 2022

@Temzasse

Is it okay to you if I just review and test this PR and close the other two?

Yes, of course.
Thank you for reaction and taking your time.

@Temzasse
Copy link
Owner

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 stitches-native. I think it's very nice to be able to test the lib in a web browser but the main target of this lib is native app development so it's very important to be able to test the app inside iOS/Android simulator.

I wonder why the web version is working but not the native one 🤔

@tkow
Copy link
Contributor Author

tkow commented Oct 30, 2022

Sorry for this pitfall. It may be caused by expo and react-native latest versions.
I will check tomorrow both android and iOS simulator. Let me share if I find the reason.

@Temzasse
Copy link
Owner

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.

@tkow
Copy link
Contributor Author

tkow commented Oct 30, 2022

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.

@Temzasse
Copy link
Owner

I think I got it working with both webpack and metro. Can you give me rights to push to your PR branch?

@tkow
Copy link
Contributor Author

tkow commented Oct 30, 2022

@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?

Copy link
Owner

@Temzasse Temzasse left a 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.

example/package.json Outdated Show resolved Hide resolved
example/webpack.config.js Outdated Show resolved Hide resolved
@tkow
Copy link
Contributor Author

tkow commented Oct 30, 2022

スクリーンショット 2022-10-31 0 12 19
I tested and worked in our local environment like this.

@Temzasse
Copy link
Owner

@Temzasse Thank you, I worked just restore metro.config.js, too. If you do another way and want more fix, could you do after merging my code?

Sure that works too 👍🏻

@tkow
Copy link
Contributor Author

tkow commented Oct 30, 2022

@Temzasse
Sorry, let you review many times.
If you still have problems to work, I will set permission my repository.

@tkow tkow requested a review from Temzasse October 30, 2022 15:38
Copy link
Owner

@Temzasse Temzasse left a 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.

@@ -103,16 +118,41 @@ export function processTheme(theme) {
return { definition, values };
}

const THEME_PRIORITIZED_KEYS = [
Copy link
Owner

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);

...acc,
...processStyles({ styles: utils[key](val), theme, config }),
};
// NOTE: Deepmerge for media propeties.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: typo popeties -> properties

'letterSpacings',
];

function searchHaveTokenConfigKey(theme, themeMap, key) {
Copy link
Owner

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.

Copy link
Contributor Author

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') {
Copy link
Owner

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 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE

Object.entries(config.media).forEach(([key, val]) => {
const breakpoint = `@${key}`;

if (breakpoint) {
Copy link
Owner

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]}`;
Copy link
Owner

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]}`;
}

@Temzasse
Copy link
Owner

@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 🙂

@tkow
Copy link
Contributor Author

tkow commented Oct 30, 2022

@Temzasse
Sure. Thank you for many advices. I can take time an hour now, fix them at least in an hour.

By the way, I don't know why, but this instruction can't be applied.(UI doesn't exist)

スクリーンショット 2022-10-31 0 52 00

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.

tkow added a commit to MOCHI-inc-JAPAN/stitches-native that referenced this pull request Oct 30, 2022
tkow added a commit to MOCHI-inc-JAPAN/stitches-native that referenced this pull request Oct 30, 2022
tkow added a commit to MOCHI-inc-JAPAN/stitches-native that referenced this pull request Oct 30, 2022
tkow added a commit to MOCHI-inc-JAPAN/stitches-native that referenced this pull request Oct 30, 2022
tkow added a commit to MOCHI-inc-JAPAN/stitches-native that referenced this pull request Oct 30, 2022
Copy link
Owner

@Temzasse Temzasse left a 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 🙂

@tkow
Copy link
Contributor Author

tkow commented Oct 31, 2022

Sorry, after review approved, but I found the type problem for #34 and, example's @type/react version's not compatible with installed react. Then, I add compoundVariants example for check.
These are not so much change and essentially bug fix, thus I'll merge it to PR.

See,

61d83b8

and

スクリーンショット 2022-10-31 16 22 29

…compoundVariables example

* fix: Temzasse#34

* chore: compound variants example
@tkow
Copy link
Contributor Author

tkow commented Oct 31, 2022

@Temzasse

In addition, I don't know why but found the bug defaultVariants combination doesn't match compoundVariants, though
the passed props work. If you want to check, please change my example.

defaultVariants: {
      heading: 'h1',
      underlined: true,
},

This bug may have ever been and not very serious because passing props explicitly so, could I ask you to get it out of scope in this PR?
I can fix it easily, so bring it to this PR. Now example looks that.

スクリーンショット 2022-10-31 17 52 15

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.

@Temzasse
Copy link
Owner

@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 🙂

@Temzasse Temzasse merged commit 60f5c35 into Temzasse:main Oct 31, 2022
@tkow tkow deleted the fix/media-merge-with-variants branch November 8, 2022 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Css function Composer type extends String type require length property is not needed
2 participants