Designing a responsive Grid with breakpoint props
abstracting responsive CSS behind a clean API.
accept per-breakpoint column props, map them to CSS Grid and media queries or container queries, expose a gap prop.
leaking raw media-query CSS to every consumer.
WHAT THIS TESTS This checks whether you can design a declarative layout API that abstracts responsive CSS, so consumers describe intent (columns per breakpoint) rather than writing media queries themselves.
A GOOD ANSWER COVERS The Grid should accept a responsive column specification, for example a columns prop that is either a single number or an object mapping breakpoints like mobile, tablet, and desktop to column counts. Internally it uses CSS Grid, setting grid-template-columns to repeat the requested count, and applies the per-breakpoint values via media queries or, better, container queries so the grid responds to its own container rather than the viewport. Expose a gap prop wired to the design system spacing scale for consistent gutters. Children are passed as-is and flow into the grid tracks, so consumers do not manage placement. The key is that all the responsive CSS lives inside the component; the consumer only declares how many columns they want at each size. Optionally support spanning by pairing with a GridItem that accepts its own breakpoint span.
COMMON WRONG ANSWERS Hardcoding one column count with no responsiveness. Making consumers write their own media queries, which defeats the abstraction. Using floats or manual width math instead of CSS Grid. Tying gap to arbitrary pixels instead of the spacing tokens.
LIKELY FOLLOW-UPS Container queries versus viewport media queries, and when each is appropriate. How do you support items that span multiple columns? How do you keep generated CSS small with many breakpoints?
ONE CONCRETE EXAMPLE A consumer writes Grid with columns set to one on mobile, two on tablet, and four on desktop, plus a gap token of md. The component emits CSS Grid rules that switch grid-template-columns at each breakpoint, and the children reflow from a single column on phones to four across on desktop, with the consumer never touching a media query.
Read the original → mui.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.