mirror of
https://github.com/material-components/material-web.git
synced 2026-03-09 00:09:23 +08:00
52 lines
1.5 KiB
SCSS
52 lines
1.5 KiB
SCSS
//
|
|
// Copyright 2022 Google LLC
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
// go/keep-sorted start
|
|
@use 'sass:map';
|
|
// go/keep-sorted end
|
|
|
|
/// Picks only specified items in a map.
|
|
///
|
|
/// @example - scss
|
|
/// @debug pick((one: 1, two: 2, three: 3), (two, three));
|
|
/// // (two: 2, three: 3)
|
|
///
|
|
/// @param {Map} $map - Map input to pick.
|
|
/// @param {List} $list - List containing items to pick.
|
|
/// @return {Map} Returns a map containing items specified in `$list`.
|
|
@function pick($map, $list) {
|
|
$result: ();
|
|
@each $key in $list {
|
|
$value: map.get($map, $key);
|
|
$result: map.set($result, $key, $value);
|
|
}
|
|
|
|
@return $result;
|
|
}
|
|
|
|
/// Duplicates a key in the map with a new name.
|
|
///
|
|
/// Throws an error if key is not in map.
|
|
///
|
|
/// @example - scss
|
|
/// @debug duplicate-key((width: 2, height: 3), width, container-width);
|
|
/// // (width: 2, height: 3, container-width: 2)
|
|
///
|
|
/// @example - scss
|
|
/// @debug duplicate-key((width: 2, height: 3), width, height);
|
|
/// // (width: 2, height: 2)
|
|
///
|
|
/// @param {Map} $map - Map input to duplicate key.
|
|
/// @param {String} $name - Name of key to duplicate.
|
|
/// @param {String} $new-name - Name of duplicated key.
|
|
/// @return {Map} Returns a map containing the duplicated key.
|
|
@function duplicate-key($map, $name, $new-name) {
|
|
$value: map.get($map, $name);
|
|
@if not map.has-key($map, $name) {
|
|
@error "Key " + $name + " does not exist in map " + $map;
|
|
}
|
|
@return map.set($map, $new-name, $value);
|
|
}
|