Skip to content

Commit

Permalink
refactor(modifier): move modifier-retrieve() function to module `mo…
Browse files Browse the repository at this point in the history
…difier`.
  • Loading branch information
sciborrudnicki committed Dec 26, 2023
1 parent eb1b424 commit 15b13f1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 32 deletions.
32 changes: 0 additions & 32 deletions variant/_variant.modifier-retrieve.function.scss

This file was deleted.

1 change: 1 addition & 0 deletions variant/modifier/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward 'modifier.retrieve.function';
71 changes: 71 additions & 0 deletions variant/modifier/_modifier.retrieve.function.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Sass.
@use 'sass:list';

// Modules.
@use '../../map';

// Status: TODO:
// The `variant.modifier-retrieve()` function.
// @param `$modifier` A map type value from which `$key-fallback` are retrieved.
// @param `$type` String type `property` or `class` to retrieve from `$modifier`.
// @param `$level` Variant level from `1` to `4`.
// @arbitrary `$key-fallback...` List of keys to retrieve from `$modifier`.
// @returns The returned value is `map` with `$key-fallback` .
@function retrieve($modifier, $type, $level, $key-fallback...) {
$result: ();
@each $key in $key-fallback {
$attribute: if(list.length($key) > 1, list.nth($key, 1), $key);
$result: map.set(
$result,
$attribute,
map.get-any(
$modifier,
($level, $type, $attribute),
($type, $attribute),
if(list.length($key) > 1, list.nth($key, 2), null)
)
);
}
@return $result;
}

// Examples.
// $-modifier: (
// property: (
// 1: (
// base: null,
// middle: null,
// attribute: null,
// prop-attribute: null,
// ),
// base: null,
// middle: null,
// attribute: null,
// prop-attribute: null,
// ),
// class: (
// 4: (
// prefix: null,
// base: null,
// middle: top,
// pre-attribute: null,
// attribute: null,
// prop-attribute: null,
// last-attribute: null,
// value-class: null,
// suffix: null,
// ),
// prefix: null,
// base: null,
// middle: null,
// pre-attribute: null,
// attribute: null,
// prop-attribute: null,
// last-attribute: null,
// value-class: null,
// suffix: null,
// ),
// );

// @debug retrieve($-modifier, property, null, prefix, (base, outline)); // (prefix: null, base: outline)
// @debug retrieve($-modifier, property, 4, (middle, radius)); // (middle: radius)

0 comments on commit 15b13f1

Please sign in to comment.