Sha256: f04a17601cf2889fd1698d0bdb99b74a40984ed79fd4bb0850ebe9126a23232d

Contents?: true

Size: 1.76 KB

Versions: 8

Compression:

Stored size: 1.76 KB

Contents

// Remove the unit and return the integer
@function strip-unit($value) {
    @return ($value / ($value * 0 + 1));
}

// Convert a unit value to a pixel while using $base-size as the reference
@function to-pixel($from) {
    $from-unit: unit($from);

    @if $from-unit == "px" {
        @return $from;

    } @else if $from-unit == "%" or $from-unit == "em" or $from-unit == "rem" {
        @return (strip-unit($from) * $base-size);

    } @else {
        @warn "Unknown pixel conversion unit type.";
    }

    @return $from;
}

// Convert a unit value to a percentage while using $base-size as the reference
@function to-percent($from) {
    $from-unit: unit($from);

    @if $from-unit == "%" {
        @return $from;

    } @else if $from-unit == "px" or $from-unit == "em" or $from-unit == "rem" {
        @return percentage((to-pixel($from) / $base-size) / 100);

    } @else {
        @warn "Unknown percentage conversion unit type.";
    }

    @return $from;
}

// Convert a unit value to a rem unit while using $base-size as the reference
@function to-rem($from) {
    $from-unit: unit($from);

    @if $from-unit == "rem" {
        @return $from;

    } @else if $from-unit == "px" or $from-unit == "%" or $from-unit == "em" {
        @return (to-pixel($from) / $base-size) * 1rem;

    } @else {
        @warn "Unknown rem conversion unit type.";
    }

    @return $from;
}

// Convert a unit value to an em unit while using $base-size as the reference
@function to-em($from) {
    $from-unit: unit($from);

    @if $from-unit == "em" {
        @return $from;

    } @else if $from-unit == "px" or $from-unit == "%" or $from-unit == "rem" {
        @return (to-pixel($from) / $base-size) * 1em;

    } @else {
        @warn "Unknown em conversion unit type.";
    }

    @return $from;
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
titon-toolkit-2.1.9 scss/toolkit/mixins/_unit.scss
titon-toolkit-2.1.8 scss/toolkit/mixins/_unit.scss
titon-toolkit-2.1.7 scss/toolkit/mixins/_unit.scss
titon-toolkit-2.1.6 scss/toolkit/mixins/_unit.scss
titon-toolkit-2.1.5 scss/toolkit/mixins/_unit.scss
titon-toolkit-2.1.4 scss/toolkit/mixins/_unit.scss
titon-toolkit-2.1.3 scss/toolkit/mixins/_unit.scss
titon-toolkit-2.1.2 scss/toolkit/mixins/_unit.scss