Skip to content

Commit

Permalink
Merge pull request #406 from BeAPI/fix/scss
Browse files Browse the repository at this point in the history
Fix/scss
  • Loading branch information
francoistibo authored Jun 3, 2024
2 parents 9cbf635 + efbd58c commit 248b400
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/scss/02-tools/_f-to-number.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@use "sass:map";
@use "sass:math";
@use "sass:string";

/**
* To number - convert string to number
*
* @author: Stackoverflow - https://stackoverflow.com/questions/47630616/scss-arithmetic-operation-with-string
*
* @param string $value
*
* Examples :
* @for $i from 1 through 6 {
* &[data-per-line="#{$i}"] {
* .card {
* width: column(to-number(#{math.div(12, $i + 1)}));
* }
* }
* }
*/

@function to-number($value) {
@if type-of($value) == "number" {
@return $value;
} @else if type-of($value) != "string" {
@error "Value for `to-number` should be a number or a string.";
}

$result: 0;
$digits: 0;
$minus: string.slice($value, 1, 1) == "-";
$numbers: ("0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9);

@for $i from if($minus, 2, 1) through str-length($value) {
$character: string.slice($value, $i, $i);

@if (index(map-keys($numbers), $character) or $character == ".") {
@if $character == "." {
$digits: 1;
} @else if $digits == 0 {
$result: $result * 10 + map.get($numbers, $character);
} @else {
$digits: $digits * 10;
$result: $result + math.div(map.get($numbers, $character), $digits);
}
}
}

@return if($minus, -$result, $result);
}
2 changes: 2 additions & 0 deletions src/scss/02-tools/_m-sr-only.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

@mixin sr-only($focusable: false) {
position: absolute;
top: auto !important;
left: -10000px !important;
width: 1px !important;
height: 1px !important;
padding: 0 !important;
Expand Down

0 comments on commit 248b400

Please sign in to comment.