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

Refactored breakpoints #307

Closed
wants to merge 23 commits into from
Closed

Refactored breakpoints #307

wants to merge 23 commits into from

Conversation

DrShpongle
Copy link
Contributor

@DrShpongle DrShpongle commented Jan 19, 2021

Hopefully fixes this: #275

Used "mobile-first" approach to define breakpoints.
For CSS breakpoints (which we strive to use whenever it's possible) we use bpMinXX naming and I used isMinXX for the "js-defined" breakpoints.

Demo of how this approach works: https://share.getcloudapp.com/NQuKyD0r

@vercel
Copy link

vercel bot commented Jan 19, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/eggheadio/egghead-io-nextjs/62wh2w0pt
✅ Preview: https://egghead-io-nextjs-git-en-breakpoints-refactoring.eggheadio1.vercel.app

@DrShpongle
Copy link
Contributor Author

in process of refactoring...

@DrShpongle DrShpongle reopened this Jan 20, 2021
return keys
.map((key, ind) => ({['isMin' + key.toUpperCase()]: ind <= foundInd}))
.filter((_, ind) => ind)
.reduce((acc, cur) => ({...acc, ...cur}), {})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eventually we get the object like:
for the xl breakpoint

{
  isMinXS: true,
  isMinSM: true,
  isMinMD: true,
  isMinLG: true,
  isMinXL: true,
  isMin2XL: false,
  isMin3XL: false,
}

"only mobile" breakpoint could be considered as !isMinXS or !isMinSM (portrait/landscape)

so, if we want to show some component on mobiles only we want to !isMinXS && <Component />
if we want to show component on md and bigger (768+) we should to isMinMD && <Component />

const foundInd = keys.indexOf(breakpoint)
return keys
.map((key, ind) => ({['isMin' + key.toUpperCase()]: ind <= foundInd}))
.filter((_, ind) => ind)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idea here is to filter out first zero value, because it's like default class in tailwindcss (flex-row vs sm:flex-row)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants