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

Add unit selection to between mixin #586

Open
grind-t opened this issue Jul 24, 2021 · 1 comment
Open

Add unit selection to between mixin #586

grind-t opened this issue Jul 24, 2021 · 1 comment

Comments

@grind-t
Copy link

grind-t commented Jul 24, 2021

Summary

between mixin returns a CSS calc formula for linear interpolation of a property between two values. The value of the calc formula will change when any relative value changes. Therefore, is it possible to add a choice of other relative units besides vw?

Basic Example

A simple solution would be to add an optional parameter with a relative unit to be used in the formula.

width: ${between('30px', '70px', '18px', '36px', 'em')};

Reasoning

Let's say that the header icon width should be 30px at a font size of 18px and 70px at 36px. Then, instead of changing both properties in media queries, you can simply use interpolation:

const Icon = styled.img`
  /* width: calc(-10px + 2.22em) */
  width: ${between('30px', '70px', '18px', '36px', 'em')};
`

const Header = styled.header`
  @media screen and (min-width: 768px) {
    /* width: calc(-10px + 2.22 * 18px) ≈ 30px */
    font-size: 18px;
  }

  @media screen and (min-width: 2560px) {
    /* width: calc(-10px + 2.22 * 36px) ≈ 70px */
    font-size: 36px;
  }
`
@developerits
Copy link

developerits commented Aug 4, 2021

The solution was found, It was written by author.

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

No branches or pull requests

3 participants