-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Custom breakpoints typing and Grid support #170
Comments
Closed via 0f7daa6 |
Thanks for the fix, but it seems to me this only fixes the typing, not the implementation? I may not have been clear in my original issue but I believe the implementation of lg: false,
md: false,
sm: false, |
But that lines are for the dummy https://stackblitz.com/edit/angular-t9udkq?file=src%2FApp.tsx (SUID) import { Grid, useMediaQuery } from '@suid/material';
import { createTheme, ThemeProvider } from '@suid/material/styles';
declare module '@suid/material/styles' {
interface BreakpointOverrides {
xs: false;
sm: false;
md: false;
lg: false;
xl: false;
mobile: true;
tablet: true;
laptop: true;
desktop: true;
}
}
const theme = createTheme({
breakpoints: {
keys: ['mobile', 'tablet', 'laptop', 'desktop'],
values: {
mobile: 0,
tablet: 600,
laptop: 900,
desktop: 1200,
},
},
});
export default function BreakpointsExample() {
const mediaQuery: {
[K in keyof typeof theme.breakpoints.keys[number]]: () => boolean;
} = {} as any;
theme.breakpoints.keys.forEach(
(key) => (mediaQuery[key] = useMediaQuery(theme.breakpoints.up(key)))
);
const breakpoint = () =>
theme.breakpoints.keys
.map((key) => mediaQuery[key]() && key)
.filter((v) => !!v)
.slice(-1);
return (
<ThemeProvider theme={theme}>
<Grid container>
<Grid
item
height={100}
border={1}
borderColor="black"
mobile={12}
tablet={6}
laptop={3}
desktop={1}
>
{breakpoint()}
</Grid>
</Grid>
</ThemeProvider>
);
} So there are two issues:
|
I wanted to customize the breakpoints (as MUI normally supports this). It slightly differs from how you do it in MUI, and at least one component does not support it (
Grid
). First of all, I found out you have to augment a different module to adjust theBreakpoint
type, as follows:This is enough to make
styled
work, for example with[theme.breakpoints.up('tiny')]: {...}
. It would be nice if the documentation specified this.As for
Grid
, the breakpoints are hardcoded into the code. I'm not sure how to get around this. I've fixed the types (see below) but it's the implementation itself that has the breakpoints hardcoded. I'm not sure how I can adjust the many hardcoded values. And I certainly wouldn't know how to do this automatically from MUI source (as this is the overall goal of SUID).Any help would be appreciated :)
Fixed `@suid/material/Grid/GridProps.d.ts`
The text was updated successfully, but these errors were encountered: