Skip to content
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

fix: add grid w/container query for projects #8344

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

thomasheartman
Copy link
Contributor

@thomasheartman thomasheartman commented Oct 2, 2024

This PR is a work in progress, but the current state aims to suggest a direction. The main goals of this are:

  1. Make it so that the layout grid doesn't break on small screens
  2. Fix an issue where the border of the box didn't fit the outline
  3. (Bonus): make the layout of the info box depend on the box's size, not the screen size.

To achieve those goals, this PR:

  1. Switches to using a native CSS grid instead of MUI's grid component. This gives us more power over the layout in various different sizes.
  2. Switches from putting borders on the boxes inside the grid, instead makes the grid container the color of the border and uses gaps to create borders.
  3. If your browser supports it, it will use container queries to determine whether we should display the layout as a multi-column grid or in a single column.

Container query demo (both with the same screen sizes):

Sidebar closed:
image

Sidebar open:
image

Copy link

vercel bot commented Oct 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 3, 2024 6:59am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Oct 3, 2024 6:59am

Copy link
Contributor

github-actions bot commented Oct 2, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

Comment on lines +4 to +6
export const ContentGridContainer = styled('div')({
containerType: 'inline-size',
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need external containers to be able to use container queries. This contains the grid so we can check the size of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why only inline and not block+inline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That... I don't know. When playing with containers before, I've tried both, and I think this is usually the one that's worked out well for me. Must be something I don't quite get, but it works here, so 🤷🏼

(side note: if you read up on it and grok it proper, please let me know 😄 )

Comment on lines +17 to +19
'&>*': {
backgroundColor: theme.palette.background.paper,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure all direct children have a background color. This can be pushed to the gird items if we want.

Comment on lines 24 to 40
gridTemplateAreas: `
"title"
"onboarding"
"projects"
"box1"
"box2"
"owners"
`,

'@container (min-width: 1000px)': {
gridTemplateColumns: '1fr 1fr 1fr',
gridTemplateAreas: `
"title onboarding onboarding"
"projects box1 box2"
". owners owners"
`,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we use named areas in the items, that messes things up if we suddenly don't have any areas mentioned in the 1-column layout. As such, the workaround is to list them in all possible layouts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally (just thought of this): we could only use a grid layout when we're wider than X px, and use a flex layout otherwise. That's probably a cleaner option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer the grid/flex distinction depending on size

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree!

Comment on lines 42 to 50
'@supports not (container-type: inline-size)': {
[theme.breakpoints.up('lg')]: {
gridTemplateColumns: '1fr 1fr 1fr',
gridTemplateAreas: `
"title onboarding onboarding"
"projects box1 box2"
". owners owners"
`,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your browser doesn't support container queries AND we're on 'lg' screens, here's the fallback.

Comment on lines +58 to +70
export const EmptyGridItem = styled('div')(({ theme }) => ({
display: 'none',

'@container (min-width: 1000px)': {
display: 'block',
},

'@supports not (container-type: inline-size)': {
[theme.breakpoints.up('lg')]: {
display: 'block',
},
},
}));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an empty element to take up spaces in the grid when it's multi-column (the special . area). We hide it to avoid showing an empty div in the list when we collapse the grid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is mostly just indentation caused by the container element that I added. The only relevant change here is removing item, lg, and md props from the grid items and switching to using the new components instead. Also: add grid areas.

Copy link
Contributor

@kwasniew kwasniew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work!

@thomasheartman thomasheartman enabled auto-merge (squash) October 3, 2024 06:58
@thomasheartman thomasheartman merged commit 35a73a5 into main Oct 3, 2024
11 checks passed
@thomasheartman thomasheartman deleted the fix/1-2898-grid-layout-on-small-screens-breaks branch October 3, 2024 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants