-
Notifications
You must be signed in to change notification settings - Fork 24
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
feature request: exclude invalid breakpoints instead of failing #1138
Comments
Hi @bdefore I guessed that in the future there might be problems when combining with themes of third-party libraries. If I understood correctly, then the problem is that the breakpoints from the MUI theme overwrites the breakpoints from styled-breakpoints? To solve this problem i can add
const defaultOptions = {
errorPrefix: '[styled-breakpoints]: ',
- pathToMediaQueries: 'breakpoints',
+ pathToMediaQueries: 'styled-breakpoints.breakpoints',
defaultBreakpoints: {
xs: '0px',
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
xxl: '1400px',
},
}; export const createTheme = (theme) => {
return {
"styled-breakpoints": {
breakpoints: theme
}
};
};
import { createTheme } from 'styled-breakpoints';
const theme = createTheme({
tablet: '600px',
desktop: '1200px'
});
<ThemeProvider theme={theme}>
<Component>This is cool!</Component>
</ThemeProvider>; That do you think about it? |
I think that'd be wise, ad-hoc namespacing your library. Would you plan for backward support for users configured for placing their breakpoints at What you propose is good, but less of a full solution than surviving invalid values from wherever you source your breakpoints. |
@bdefore In the next couple of days I will release a new version that will contain not only a solution to your problem, but also design inaccuracies. You can wait? |
I can. Thanks. |
I've encountered an issue where styled-breakpoints is incompatible with latest Material UI and styled-components because MUI merges its theme into the styled theme provider, including helper functions into the
breakpoints
key. A description of how MUI suggests working with themes for both is here: mui/material-ui#28979 (comment)When setting up providers this way and using styled-breakpoints in a component, such as:
The following error occurs:
Note the last line about invalid breakpoints. The large output here is MUI's
up
helper, which styled-breakpoints accurately determines is not a valid breakpoint declaration.This could be mitigated if the
checkAllValuesHasPixels
were changed to agetValidBreakpoints
that filters out invalid ones determined by the check forpx
and proceeds with the ones that are valid instead of creating an invariant and failing. Related code: https://github.com/mg901/styled-breakpoints/blob/master/styled-breakpoints/styled-breakpoints.js#L49Another option is to expose
createStyledBreakpoints
from the export on the public package so thatpathToMediaQueries
could be overridden, but the friendly path is to be resilient when faced with a mix of valid and invalid options.The text was updated successfully, but these errors were encountered: