Skip to content

Commit

Permalink
feat(@clayui/css): Functions adds map-deep-get for getting values o…
Browse files Browse the repository at this point in the history
…f deeply nested Sass map items
  • Loading branch information
pat270 committed Jul 21, 2021
1 parent b387faa commit 2b80302
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/clay-css/src/scss/functions/_global-functions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,32 @@
// * SPDX-FileCopyrightText: © 2016 Hugo Giraudel <https://hugogiraudel.com/>
// *

/// A function that fetches deeply nested values from a Sass map.
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/deep-getset-maps/
/// @param {Map} $map - The Sass map to fetch from
/// @param {Arglist} $keys - The keys to loop through

@function map-deep-get($map, $keys...) {
$newMap: $map;

@each $key in $keys {
@if (type-of($newMap) == 'list' and length($newMap) == 0) or
(type-of($newMap) == 'null')
{
$newMap: map-new();
}

@if (type-of($newMap) != map) {
@error ('argument `$map: #{$map}` of `map-deep-get($map, $keys)` must be a map');
}

$newMap: map-get($newMap, $key);
}

@return $newMap;
}

/// A function to replace all instances of a specific character in a string.
/// @author Hugo Giraudel
/// @link https://www.sassmeister.com/gist/1b4f2da5527830088e4d
Expand Down

0 comments on commit 2b80302

Please sign in to comment.