-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[@mantine/core] Separate handle breakpoints override in mergeTheme #4051
Conversation
Another approach would be:
Then you wouldn't need to specify all default breakpoints when overriding them. With your approach it's arguable that this is a breaking change as partial breakpoint overrides wouldn't work anymore and have to be adjusted to work again. |
@cyantree Yes, you are right, thanks! |
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.
Maybe also add a test for this in merge-theme.test.ts
.
@cyantree I'm not good in tests. |
It failed because there's an error in your change implementation. So your test caught this. 👍 Here's the fixed code (you need to merge with if (key === 'breakpoints' && themeOverride.breakpoints) {
const mergedBreakpoints = { ...currentTheme.breakpoints, ...themeOverride.breakpoints };
return {
...acc,
breakpoints: Object.fromEntries(
Object.entries(mergedBreakpoints).sort(
(a, b) => getBreakpointValue(a[1]) - getBreakpointValue(b[1])
)
),
};
} If you want to cover more cases test merging with multiple units and also define your custom breakpoints in descending order. Maybe also test what happens with your overriding an existing breakpoint. Here's an updated test for this: expect(
Object.entries(mergeTheme(themeBase, { breakpoints: { xxl: '999em', min: '1', xs: '10rem' } }).breakpoints)
).toStrictEqual(Object.entries({ min: '1', ...{ ...themeBase.breakpoints, xs: '10rem' }, xxl: '999em' })); I've also introduced // This passes but shouldn't in our case
expect({ a: 1, b: 1 }).toStrictEqual({ b: 1, a: 1 });
// This correctly fails
expect(Object.entries({ a: 1, b: 1 })).toStrictEqual(Object.entries({ b: 1, a: 1 })); |
@cyantree Yes, thank you very much for correcting the error and the tests! |
Thanks! |
Related issues:
#4050
Instead of merge breakpoints, use breakpoints from override if provided (with an additional check for required keys).