Skip to content

Instantly share code, notes, and snippets.

@wescopeland
Created March 13, 2021 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wescopeland/a4843305b52236f7655eba8b67038660 to your computer and use it in GitHub Desktop.
Save wescopeland/a4843305b52236f7655eba8b67038660 to your computer and use it in GitHub Desktop.
Current breakpoint HUD component
// Obviously, don't ship this to production. I have this behind an environment flag in _app.tsx, like so:
/*
import dynamic from "next/dynamic";
let DynamicCurrentBreakpointDisplay;
if (process.env.NODE_ENV === "development") {
DynamicCurrentBreakpointDisplay = dynamic(() =>
import("../../app/core/components/CurrentBreakpointDisplay").then(
(m) => m.CurrentBreakpointDisplay
)
);
} else {
DynamicCurrentBreakpointDisplay = () => <></>;
}
return (
{/* _app.tsx stuff */}
<DynamicCurrentBreakpointDisplay />
);
*/
import { Box, useMediaQuery, useTheme, Typography } from "@material-ui/core";
export const CurrentBreakpointDisplay = () => {
const theme = useTheme();
const isXs = useMediaQuery(theme.breakpoints.only("xs"));
const isSm = useMediaQuery(theme.breakpoints.only("sm"));
const isMd = useMediaQuery(theme.breakpoints.only("md"));
const isLg = useMediaQuery(theme.breakpoints.only("lg"));
const isXl = useMediaQuery(theme.breakpoints.only("xl"));
return (
<Box
sx={{
position: "fixed",
bottom: 3,
left: 3,
backgroundColor: "black",
color: "white",
}}
>
{isXs && <Typography>XS</Typography>}
{isSm && <Typography>SM</Typography>}
{isMd && <Typography>MD</Typography>}
{isLg && <Typography>LG</Typography>}
{isXl && <Typography>XL</Typography>}
</Box>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment