mirror of
https://github.com/black7375/Firefox-UI-Fix.git
synced 2026-02-04 06:20:37 -08:00
Add: SASS - utils/list
This commit is contained in:
parent
3d9e7987dc
commit
c85da8f526
2 changed files with 67 additions and 0 deletions
31
__tests__/list.test.scss
Normal file
31
__tests__/list.test.scss
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
@use 'true' as *;
|
||||
@use "../src/utils/list";
|
||||
|
||||
// TODO: Need more tests..
|
||||
$simpleList: (ab cd efgh ijk);
|
||||
$dupList: (ab cd efgh efgh efgh ijk);
|
||||
|
||||
@include test-module("Remove at list [fn]") {
|
||||
@include test("simple") {
|
||||
@include assert-equal(
|
||||
list.remove($simpleList, "cd"),
|
||||
(ab efgh ijk)
|
||||
);
|
||||
}
|
||||
|
||||
@include test("duplicate") {
|
||||
@include assert-equal(
|
||||
list.remove($dupList, "efgh"),
|
||||
(ab cd ijk)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@include test-module("Convert to str [fn]") {
|
||||
@include test("simple") {
|
||||
@include assert-equal(
|
||||
list.to-string($simpleList),
|
||||
(((null ab) cd) efgh) ijk
|
||||
);
|
||||
}
|
||||
}
|
||||
36
src/utils/_list.scss
Normal file
36
src/utils/_list.scss
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// https://kittygiraudel.com/2013/08/08/advanced-sass-list-functions/
|
||||
// https://gist.github.com/Jakobud/ec056b52f3673cc369dc97f2c2428424
|
||||
|
||||
@function remove($list, $value, $recursive: false) {
|
||||
$result: ();
|
||||
|
||||
@for $i from 1 through length($list) {
|
||||
@if type-of(nth($list, $i)) == list and $recursive {
|
||||
$result: append($result, remove(nth($list, $i), $value, $recursive));
|
||||
} @else if nth($list, $i) != $value {
|
||||
$result: append($result, nth($list, $i));
|
||||
}
|
||||
}
|
||||
|
||||
@return $result;
|
||||
}
|
||||
|
||||
@function to-string($list, $glue: '', $is-nested: false) {
|
||||
$result: null;
|
||||
|
||||
@for $i from 1 through length($list) {
|
||||
$e: nth($list, $i);
|
||||
|
||||
@if type-of($e) == list {
|
||||
$result: $result#{to-string($e, $glue, true)};
|
||||
} @else {
|
||||
$result: if(
|
||||
$i != length($list) or $is-nested,
|
||||
$result#{$e}#{$glue},
|
||||
$result#{$e}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@return $result;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue