Skip to content

Commit 7ee465a

Browse files
feat(list.each()): add mixin.
1 parent f87dccd commit 7ee465a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/lib/_index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Other.
1717
@forward "list.add.function";
1818
@forward "list.append.function";
19-
// @forward "list.each.mixin";
19+
@forward "list.each.mixin";
2020
@forward "list.empty.function";
2121
@forward "list.extract-map.function";
2222
@forward "list.first.function";

src/lib/_list.each.mixin.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Sass.
2+
@use 'sass:list';
3+
4+
// Todo
5+
// The `list.each()` mixin uses flow control `@each` to iterate `$list`.
6+
// @param `$list` A list to iterate.
7+
// @param `$comma` If `true` then force to iterate comma-separated list, by adding space-separated list into comma-separated.
8+
// @param `$index`
9+
@mixin each($list, $comma: true, $index: 1) {
10+
@each $element in if($comma, if(list.separator($list) == space, ($list,), $list), $list) {
11+
@content($element, $index);
12+
13+
$index: $index + 1;
14+
}
15+
}
16+
17+
// Examples.
18+
// @include each((a, b, c, d, e)) using($value) {
19+
// @debug $value;
20+
// }
21+
22+
// @include each((a b c d e), true) using($value) {
23+
// @debug $value;
24+
// }

0 commit comments

Comments
 (0)