Skip to content
Snippets Groups Projects
_mixins.scss 2.94 KiB
Newer Older
  • Learn to ignore specific revisions
  • Chris Lawton's avatar
    Chris Lawton committed
    // Media queries
    
    @mixin media-query($queries...) {
        @each $query in $queries {
            @each $breakpoint in $breakpoints {
                $name:        nth($breakpoint, 1);
                $declaration: nth($breakpoint, 2);
    
                @if $query == $name and $declaration {
                    @media only screen and #{$declaration} {
                        @content;
                    }
                }
            }
        }
    }
    
    
    Chris Lawton's avatar
    Chris Lawton committed
    //   Placeholder text
    
    @mixin placeholder-text {
        // sass-lint:disable no-vendor-prefixes
        &.placeholder { @content; }
        &:-moz-placeholder { @content; }
        &::-moz-placeholder { @content; }
        &:-ms-input-placeholder { @content; }
        &::-webkit-input-placeholder { @content; }
        // sass-lint:enddisable
    }
    
    
    Chris Lawton's avatar
    Chris Lawton committed
    // Hide text
    
    @mixin hidden {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(1px, 1px, 1px, 1px);
    }
    
    
    Chris Lawton's avatar
    Chris Lawton committed
    // iOS Native vertical scroll
    
    @mixin native-vertical-scroll {
        overflow-x: hidden;
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch; // sass-lint:disable-line no-misspelled-properties
    }
    
    
    Chris Lawton's avatar
    Chris Lawton committed
    // Output a rem and px fallback value for the given property
    
    @mixin rem($property, $values) {
    
        $px:  ();
        $rem: ();
    
        @each $value in $values {
            @if $value == 0 or $value == auto or $value == inherit {
                $px:  append($px, $value);
                $rem: append($rem, $value);
            } @else {
                $px:  append($px, $value);
                $rem: append($rem, rem(strip-unit($value)));
            }
        }
        // sass-lint:disable no-duplicate-properties
        #{$property}: $px;
        #{$property}: $rem;
        // sass-lint:enddisable
    }
    
    
    Chris Lawton's avatar
    Chris Lawton committed
    // Output a `font-size: [x]rem;` declaration for the given px value
    
    @mixin rem-font-size($font-size) {
        @include rem(font-size, $font-size);
    }
    
    
    Chris Lawton's avatar
    Chris Lawton committed
    // Font sizes
    
    @mixin font-size($keyword) {
        $size: map-get($font-sizes, $keyword);
    
        @if $size == null {
            @warn 'Font size ‘#{$keyword}’ does not exist';
        } @else {
            @include rem-font-size($size);
        }
    }
    
    Chris Lawton's avatar
    Chris Lawton committed
    
    // button mixin
    
    Chris Lawton's avatar
    Chris Lawton committed
        padding: 10px 60px;
    
        font-weight: $weight--bold;
    
    Chris Lawton's avatar
    Chris Lawton committed
        background: $bg;
        border: 1px solid $color--white;
    
        transition: color, background, border, $transition;
    
    Chris Lawton's avatar
    Chris Lawton committed
    
    
    Chris Lawton's avatar
    Chris Lawton committed
        &:active {
    
    Chris Lawton's avatar
    Chris Lawton committed
        }
    }
    
    
    // Viewport sized typography mixin that takes a min and max pixel-based value
    @mixin responsive-font-sizes($min, $max) {
    
        $vw-context: (1260 * 0.1) * 1px;
        $responsive: ($max / $vw-context) * 10vw;
    
        $responsive-unitless: $responsive / ($responsive - $responsive + 1);
        $dimension: if(unit($responsive) == 'vh', 'height', 'width');
        $min-breakpoint: $min / $responsive-unitless * 100;
    
        @media (max-#{$dimension}: #{$min-breakpoint}) {
            font-size: $min;
        }
    
        $max-breakpoint: $max / $responsive-unitless * 100;
    
        @media (min-#{$dimension}: #{$max-breakpoint}) {
            font-size: $max;
        }
    
        font-size: $responsive;
    }