-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(color.palette-get-keys()): add
palette.get-keys()
to find keys…
… using `name.index()`.
- Loading branch information
1 parent
c1e203b
commit a7c63cf
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Sass. | ||
@use 'sass:list'; | ||
@use 'sass:map'; | ||
|
||
// Functions. | ||
@use '../../list/remove'; | ||
@use '../../map/map.get.function' as *; | ||
@use '../name/name.index.function' as name; | ||
|
||
// Status: DONE | ||
// The `palette.get-keys()` function returns palette variant. | ||
// @param `$palette` Color palettes to get variant or variant color. | ||
// @param `$key` | ||
// @arbitrary `$keys...` | ||
// @returns The returned value is palette variants or variant colors . | ||
@function get-keys($palette, $key, $keys...) { | ||
@if $key { | ||
@each $current-key, $value in $palette { | ||
@if index($current-key, $key) { | ||
@if type-of($value) == map { | ||
$value: map.set( | ||
$value, | ||
result, | ||
list.append(get($palette, result, get($value, result) or ()), $current-key) | ||
); | ||
} | ||
@if list.length($keys) > 0 { | ||
@return get-keys($value, list.nth($keys, 1), remove.nth($keys, 1)...); | ||
} @else { | ||
@return map.get($value, result); | ||
} | ||
} | ||
} | ||
} | ||
@return $palette; | ||
} | ||
|
||
// Examples. | ||
$example: ( | ||
test basic: ( | ||
basic two: ( | ||
hue saturation: ( | ||
lightness alpha: hsla(15deg, 30%, 35%, 1) | ||
) | ||
), | ||
|
||
extended: ( | ||
accent: ( | ||
secondary: () | ||
) | ||
) | ||
) | ||
); | ||
|
||
// nested 2 | ||
// @debug get-keys($example, test, two); // (test basic) (basic two) | ||
// @debug get-keys($example, basic, extended); // (test basic) extended | ||
|
||
// nested 3 | ||
// @debug get-keys($example, test, two, saturation); |