2-mixins-and-functions edit

mixin-breakpoints  edit

Used to output consistent breakpoint css

Breakpoint function
Creates @media css from specified breakpoints
Usage:

.class {
  @include breakpoint($mobile-to-desktop-breakpoint) {
    display: block;
  }
}

outputs:
@media (min-width: 930px) {
  .class {
    display: block;
  }
}

or create a one-time use breakpoint:
.class {
  @include breakpoint(1200px, max) {
    display: block;
  }
}

Go to breakpoint variables and breakpoint map



/* scss/2-mixins-and-functions/_mixin-breakpoints.scss */

// BREAKPOINT MIXIN USAGE
// Outputs breakpoint for specified width
// can be used anywhere, not just at the bottom of the page
//
// use breakpoints from the map in 3-variables/_wm-breakpoints.scss
// map of breakpoints and breakpoint variables are in 3-variables/_wm-colors.scss
//
// default is min but can add max as second parameter
//
// .class {
//   @include breakpoint($mobile-to-desktop-breakpoint) {
//       display: block;
//   }
// }
// outputs:
// @media (min-width: 930px) {
//   .class {
//       display: block;
//   }
// }
//
// or create a one-time use breakpoint:
// .class {
//   @include breakpoint(1200px, max) {
//       display: block;
//   }
// }
// https://rimdev.io/making-media-query-mixins-with-sass/

@mixin breakpoint($breakpoint, $direction: min) {
  @if map-has-key($breakpoints, $breakpoint) {
    // Get the breakpoint value.
    $breakpoint-value: map-get($breakpoints, $breakpoint);

    @if $direction == max {
      @media (max-width: ($breakpoint-value - 1)) {
        @content;
      }
    } @else if $direction == min {
      @media (min-width: $breakpoint-value) {
        @content;
      }
    } @else {
      @media ($direction: $breakpoint-value) {
        @content;
      }
    }

    // If the breakpoint doesn't exist in the map.
  } @else {
    @if $direction == max {
      @media (max-width: $breakpoint) {
        @content;
      }
    } @else if $direction == min {
      @media (min-width: $breakpoint) {
        @content;
      }
    } @else {
      @media ($direction: $breakpoint) {
        @content;
      }
    }
  }
}

@function breakpoint($breakpoint) {
  // Get the breakpoint value.
  $breakpoint-value: map-get($breakpoints, $breakpoint);
  @return $breakpoint-value;
}
Copy
Edit
<!-- components/2-mixins-and-functions/mixin-breakpoints.php --> <p> <strong>Breakpoint function </strong><br> Creates @media css from specified breakpoints<br> Usage: <BR> <code> <br>.class { <br> &nbsp;&nbsp;@include breakpoint($mobile-to-desktop-breakpoint) { <br> &nbsp;&nbsp;&nbsp;&nbsp;display: block; <br> &nbsp;&nbsp;} <br>} </code><br> outputs: <code> <br> @media (min-width: 930px) { <br>&nbsp;&nbsp;.class { <br>&nbsp;&nbsp;&nbsp;&nbsp;display: block; <br>&nbsp;&nbsp;} <br>} <br></code> <br> or create a one-time use breakpoint: <code> <br>.class { <br>&nbsp;&nbsp;@include breakpoint(1200px, max) { <br>&nbsp;&nbsp;&nbsp;&nbsp;display: block; <br>&nbsp;&nbsp;} <br>} </code> <br> <a href="../wm/atomic-core/?cat=3-variables#wm-breakpoints">Go to breakpoint variables and breakpoint map</a> </p> <br><br> <pre><code class="language-css"><?php echo outputFile('../scss/2-mixins-and-functions/_mixin-breakpoints.scss'); ?> </code></pre>
Copy
Copy
Edit
/* scss/2-mixins-and-functions/_mixin-breakpoints.scss */ // BREAKPOINT MIXIN USAGE // Outputs breakpoint for specified width // can be used anywhere, not just at the bottom of the page // // use breakpoints from the map in 3-variables/_wm-breakpoints.scss // map of breakpoints and breakpoint variables are in 3-variables/_wm-colors.scss // // default is min but can add max as second parameter // // .class { // @include breakpoint($mobile-to-desktop-breakpoint) { // display: block; // } // } // outputs: // @media (min-width: 930px) { // .class { // display: block; // } // } // // or create a one-time use breakpoint: // .class { // @include breakpoint(1200px, max) { // display: block; // } // } // https://rimdev.io/making-media-query-mixins-with-sass/ @mixin breakpoint($breakpoint, $direction: min) { @if map-has-key($breakpoints, $breakpoint) { // Get the breakpoint value. $breakpoint-value: map-get($breakpoints, $breakpoint); @if $direction == max { @media (max-width: ($breakpoint-value - 1)) { @content; } } @else if $direction == min { @media (min-width: $breakpoint-value) { @content; } } @else { @media ($direction: $breakpoint-value) { @content; } } // If the breakpoint doesn't exist in the map. } @else { @if $direction == max { @media (max-width: $breakpoint) { @content; } } @else if $direction == min { @media (min-width: $breakpoint) { @content; } } @else { @media ($direction: $breakpoint) { @content; } } } } @function breakpoint($breakpoint) { // Get the breakpoint value. $breakpoint-value: map-get($breakpoints, $breakpoint); @return $breakpoint-value; }