From 365c56edcc36b5b92902bac01ce44b43d01e8685 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Fri, 18 Oct 2024 18:08:24 +0200 Subject: Refactoring --- src/_props.scss | 113 ++++++++++++-------------------------------------------- 1 file changed, 24 insertions(+), 89 deletions(-) (limited to 'src/_props.scss') diff --git a/src/_props.scss b/src/_props.scss index f7f54c5..ac1dfd5 100644 --- a/src/_props.scss +++ b/src/_props.scss @@ -1,105 +1,40 @@ @use 'sass:list'; @use 'sass:map'; @use 'sass:meta'; +@use 'themes'; +@use 'include-media/dist/include-media' as media; +@use 'iro-sass/src/iro-sass' as iro; -@use 'iro-sass/src/functions' as functions; +@forward 'iro-sass/src/props'; -@function is-prop-ref($value) { - @if meta.type-of($value) != 'list' { - @return false; +@mixin materialize($ref) { + @if meta.type-of($ref) == 'map' { + $ref: map.values($ref); } - @if list.length($value) != 3 { - @return false; - } - @if list.nth($value, 1) != 'prop-ref' { - @return false; - } - @return true; -} - -@function def($name, $value: ()) { - @return ('prop-ref' $name $value); -} - -@function merge($ref, $value) { - @if not is-prop-ref($ref) { - @return $ref; - } - - $v: list.nth($ref, 3); - $ref: list.set-nth($ref, 3, map.deep-merge($v, $value)); - @return $ref; -} - -@function get-deep($name, $value, $key: (), $keys...) { - @if is-prop-ref($value) { - // $value: list.nth($value, 3); - @return get($value, $key, $keys); - } - @if meta.type-of($value) == 'map' { - @if list.length($keys) == 0 { - @return #{$name}#{$key} map.get($value, $key); - } @else { - @return get-deep(#{$name}#{$key}, map.get($value, $key), $keys...); - } - } - @return $name $value; -} -@function map-to-vars($name, $map) { - @if meta.type-of($map) != 'map' { - @return var($name); - } - - $out: (); - - @each $key, $value in $map { - $out: map.set($out, $key, map-to-vars(#{$name}#{$key}, $value)); - } - - @return $out; -} - -@function get($ref, $key: (), $keys...) { - @if not is-prop-ref($ref) { - @return $ref; - } - - $name: list.nth($ref, 2); - $value: get(list.nth($ref, 3)); + :root { + @include iro.props-materialize($ref); - @if meta.type-of($value) == 'map' { - $res: get-deep($name, $value, $key, $keys...); - $name: list.nth($res, 1); - $value: list.nth($res, 2); - } @else if meta.type-of($value) == 'list' { - $i: 1; - @each $item in $value { - $value: list.set-nth($value, $i, get($item)); - $i: $i + 1; + @each $breakpoint in map.keys(media.$breakpoints) { + @include media.media('<=#{$breakpoint}') { + @include iro.props-materialize($ref, $breakpoint); + } } - } - @return map-to-vars($name, $value); -} - -@mixin declare-helper($name, $value) { - @if meta.type-of($value) == 'map' { - @each $key, $value in $value { - @include declare-helper(#{$name}#{$key}, $value); + @media (prefers-color-scheme: dark) { + @include iro.props-materialize($ref, 'dark'); } - } @else { - #{$name}: #{$value}; } -} - -@mixin materialize($refs) { - @each $ref in $refs { - @if is-prop-ref($ref) { - $name: list.nth($ref, 2); - $value: get(list.nth($ref, 3)); - @include declare-helper($name, $value); + @each $theme-name in map.keys(themes.$themes) { + @if $theme-name != themes.$theme-default { + @include iro.bem-theme($theme-name) { + @include iro.props-materialize($ref); + + @media (prefers-color-scheme: dark) { + @include iro.props-materialize($ref, 'dark'); + } + } } } } -- cgit v1.2.3-70-g09d2