Giter Club home page Giter Club logo

Comments (8)

mattboon avatar mattboon commented on May 18, 2024

+1 for the future.

Usually use em for media queries but am willing to switch to px for this project as this lib is awesome!

from include-media.

eduardoboucas avatar eduardoboucas commented on May 18, 2024

So right now I'd say that we have partial support for EMs. For example, you can do this:

$breakpoints: (phone: 20em, tablet: 48em, desktop: 64em);

@include media(">=phone") {
}

/* Generates: */

@media (min-width: 20em) {
}

The one thing that doesn't work properly right now is when you use greater-than or less-than operators. By default, it adds or subtracts 1 pixel when you use those operators.

Example:

  • px: >phone means >320px so it translates to (min-width: 321px).
  • em: >phone means >20em so it translates to (min-width: 21em) (not what we want).

So maybe we need to add a different factor for each unit? So if you're dealing with pixels it adds 1px, but if you have EMs it adds 0.01em or something?

Let me know your thoughts guys, and thanks for the feedback!

from include-media.

eduardoboucas avatar eduardoboucas commented on May 18, 2024

I think that the good thing about this mixin is its flexibility and how it allows developers to use in many different ways. For that reason, I don't think it is a good idea to convert the breakpoints from pixels to ems - if you define $breakpoints in pixels, then it's because you want to use pixels and I don't think we should force EMs.

What I do think is that we need to support it properly, and the implementation is actually quite simple. Something like this:

@function _get-interval-for-unit($value) {
  $intervals: ("px": 1, "em": 0.0625);

  @return map-get($intervals, unit($value));
}

This will establish the intervals that should be used for each unit, so:

$breakpoints: (phone: 30em, tablet: 48em, desktop: 64em);

@include media(">phone") {
}

/* Generates: */

@media (min-width: 30.0625em) {
}

How does that sound?

from include-media.

KittyGiraudel avatar KittyGiraudel commented on May 18, 2024

Sass-MQ uses -.01em.

Or I suppose you could use calc() but I don't know if it works fine within Media Queries.

@media (min-width: calc(28em - 1px)) {
  /* ... */
}

from include-media.

eduardoboucas avatar eduardoboucas commented on May 18, 2024

Yes, I saw that Sass-MQ was doing this already and I quite liked it.

My thoughts behind creating a separate function (and a map) instead of hard-coding a value for ems was that it becomes easier and cleaner if we want to support other units, even though pixels and ems will most likely cover the majority of use cases.

calc() doesn't seem to work within a media query expression.

from include-media.

KittyGiraudel avatar KittyGiraudel commented on May 18, 2024

My thoughts behind creating a separate function (and a map) instead of hard-coding a value for ems was that it becomes easier and cleaner if we want to support other units, even though pixels and ems will most likely cover the majority of use cases.

Makes sense. You might want to support rem as well.

from include-media.

eduardoboucas avatar eduardoboucas commented on May 18, 2024

I've created a new branch (add-intervals) with this stuff in it.

I'll keep doing some testing (feel free to pull and test on your end as well if you fancy it) and if nothing blows up I'll merge this in.

Thanks for the feedback guys!

from include-media.

eduardoboucas avatar eduardoboucas commented on May 18, 2024

Added in #19.

from include-media.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.