Skip to content

Commit

Permalink
feat(variant.update): add sub module update to modify variant item …
Browse files Browse the repository at this point in the history
…and property.
  • Loading branch information
sciborrudnicki committed Oct 1, 2023
1 parent 2b05573 commit 6a7c2fe
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions variant/_index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@forward 'update' as update-*;
@forward 'variant.create.function';
@forward 'variant.modify.function';
2 changes: 2 additions & 0 deletions variant/update/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@forward 'update.item.function';
@forward 'update.property.function';
48 changes: 48 additions & 0 deletions variant/update/_update.item.function.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Sass.
@use 'sass:list';
@use 'sass:meta';

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

// Status: DONE
// The `update.item()` function.
// @param `$item`
// @param `$class`
// @param `$property`
// @param `$key`
// @returns
@function item($item, $class: null, $property: null, $key: base) {
$result: ();
@if type-of($item) == map {
@each $-class, $prop in $item {
$result: (
if(
meta.type-of($class) == map,
class.affix-add($-class, $class),
$-class
): map.get($property, $key, $property) or $prop
);
}
} @else {
$class: if(
meta.type-of($class) == map,
class.affix-add($item, $class),
$class or $item
);
@if $property {
$result: (
$class: map.get($property, $key, $property)
);
} @else {
@return $class;
}
}
@return $result;
}

// Examples.
// @debug modify((primary: primary light), (prefix: p, suffix: s));
// @debug modify((primary: primary light), (prefix: spectre, suffix: end));
50 changes: 50 additions & 0 deletions variant/update/_update.property.function.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Sass.
@use 'sass:list';

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

// Status: TODO:
// The `update.property()` function.
// @param `$property`
// @param `$modifier`
// @param `$attribute`
// @returns
@function property($property, $modifier, $attribute: null) {
$property: if(
map.has-keys($modifier, (property, middle)),
map.get($modifier, (property, middle)),
$property
);
@if list.separator($property) == comma {
$i: 1;
@each $base in $property {
$property: list.set-nth(
$property,
$i,
values.join(
(separator: space),
map.get-any($modifier, (property, base), (property, name), null),
$base,
$attribute,
map.get-any($modifier, (property, attribute), (property, end), null),
)
);
$i: $i + 1;
}
} @else {
$property: values.join(
(separator: space),
map.get-any($modifier, (property, base), (property, name), null),
$property,
$attribute,
map.get-any($modifier, (property, attribute), (property, end), null),
);
}
@return $property;
}

// Examples.


0 comments on commit 6a7c2fe

Please sign in to comment.