Developer-DAO / DAO-job-board

A job board connecting DAOs with talent.
https://devdao-job-board.vercel.app/
82 stars 34 forks source link

refactor: clean up responsive object props #210

Closed with-heart closed 2 years ago

with-heart commented 2 years ago

This PR cleans up the way we're using responsive object props.

There are three types of cleanup involved here. I think it's easier to explain the responsive object prop syntax as a whole first, so that it's obvious why there are three types of cleanup.

How responsive object props syntax works

When specifying responsive objects, it's important to always start with a base value. The base is basically the default value for that prop.

() => (
  <div>
    {/* These are equivalent */}
    <Box fontSize="16px" />
    <Box fontSize={{ base: '16px' }} />
  </div>
)

To make this responsive, we can add keys for specific breakpoints. If a breakpoint isn't defined, it will use the value from the definition of the next smallest breakpoint that is defined. If there isn't a smaller breakpoint defined, the base value is used.

Essentially we can look at the priority like this:

base < definition for breakpoint smaller than user's breakpoint < exact definition for user's breakpoint

() => (
  <Box fontSize={{ base: '16px', md: '18px', xl: '24px' }} />
)

Here's the breakdown of the values at each breakpoint for the above example:

Breakpoint Size
< sm 16px
sm 16px
md 18px
lg 18px
xl 24px
2xl 24px

We didn't need to define values for sm, lg, or 2xl because they fall back to the definition of the next smallest defined breakpoint. sm falls back to base, lg falls back to md, and 2xl falls back to xl.

Types of cleanup

  1. Make sure all objects have a base key. Some of them started with sm which will break for screen sizes smaller than the sm breakpoint.
  2. Removing unnecessary breakpoint sizes. If an object defines identical values for base, sm and md, we only need to define base as sm and md will fall back to the base value.
  3. Removing unnecessary use of responsive objects. If a responsive object defines identical values for base and any other breakpoint, we don't need to use responsive syntax at all.
vercel[bot] commented 2 years ago

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/devdaojobboard/dao-job-board/DCDAea2m6jjD9pM31h15T8XpzJKG
✅ Preview: https://dao-job-board-git-clean-up-responsive-props-devdaojobboard.vercel.app