Skip to content

Commit a7c63cf

Browse files
feat(color.palette-get-keys()): add palette.get-keys() to find keys using name.index().
1 parent c1e203b commit a7c63cf

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Sass.
2+
@use 'sass:list';
3+
@use 'sass:map';
4+
5+
// Functions.
6+
@use '../../list/remove';
7+
@use '../../map/map.get.function' as *;
8+
@use '../name/name.index.function' as name;
9+
10+
// Status: DONE
11+
// The `palette.get-keys()` function returns palette variant.
12+
// @param `$palette` Color palettes to get variant or variant color.
13+
// @param `$key`
14+
// @arbitrary `$keys...`
15+
// @returns The returned value is palette variants or variant colors .
16+
@function get-keys($palette, $key, $keys...) {
17+
@if $key {
18+
@each $current-key, $value in $palette {
19+
@if index($current-key, $key) {
20+
@if type-of($value) == map {
21+
$value: map.set(
22+
$value,
23+
result,
24+
list.append(get($palette, result, get($value, result) or ()), $current-key)
25+
);
26+
}
27+
@if list.length($keys) > 0 {
28+
@return get-keys($value, list.nth($keys, 1), remove.nth($keys, 1)...);
29+
} @else {
30+
@return map.get($value, result);
31+
}
32+
}
33+
}
34+
}
35+
@return $palette;
36+
}
37+
38+
// Examples.
39+
$example: (
40+
test basic: (
41+
basic two: (
42+
hue saturation: (
43+
lightness alpha: hsla(15deg, 30%, 35%, 1)
44+
)
45+
),
46+
47+
extended: (
48+
accent: (
49+
secondary: ()
50+
)
51+
)
52+
)
53+
);
54+
55+
// nested 2
56+
// @debug get-keys($example, test, two); // (test basic) (basic two)
57+
// @debug get-keys($example, basic, extended); // (test basic) extended
58+
59+
// nested 3
60+
// @debug get-keys($example, test, two, saturation);

0 commit comments

Comments
 (0)