styled-components / polished

A lightweight toolset for writing styles in JavaScript ✨
https://polished.js.org/
MIT License
7.63k stars 209 forks source link

modularScale accepts em but not rem #365

Closed caribou-code closed 6 years ago

caribou-code commented 6 years ago

When using the modularScale function it only seems to accept an em value for the base parameter. It seems to be good practice to use rem figures for typography to keep everything relative to a root figure.

Consider this (very contrived) example:

<header>
  <h1></h1>
  <div>
    <h1>hello</h1>
  </div>
</header>

body {
  font-size: 16px;
}

div {
  font-size: 1.5rem;
}

h1 {
  font-size: modularScale(2, '1rem');
}

I wouldn't do something as simple as the above in reality but you get the picture. The scenario has come up for me before.

I would want all my h1s to have a consistent font size but since 1rem is not accepted as a base figure, it uses 1em instead, resulting in an inconsistent font size for the h1s. Could the base parameter be changed to accept rem? Or is there a reason for this?

bhough commented 6 years ago

@caribou-code There is no reason that we couldn't expand this to accept other base units as the unit of measure is mostly irrelevant to how the helper works. It is something we could look into for V3.

bhough commented 6 years ago

Added to potential V3 Roadmap #354