From 1b739f15d10d68c5a7f85c2c403f2897f6ddfe50 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Mon, 7 Feb 2022 12:41:59 +0100 Subject: Further improved font handling --- src/_functions.scss | 127 +++++++++------------------------------------- src/objects/_heading.scss | 4 +- yarn.lock | 2 +- 3 files changed, 26 insertions(+), 107 deletions(-) diff --git a/src/_functions.scss b/src/_functions.scss index 9f6a789..f15ed0c 100644 --- a/src/_functions.scss +++ b/src/_functions.scss @@ -1,8 +1,7 @@ @use 'iro-sass/src/index' as iro; @function color($key, $tree: 'colors', $default: null, $global: false) { - $key: iro.fn-list-prepend($key, --colors); - @return iro.props-get($key, $tree, $default, $global); + @return iro.props-get(join(--colors, $key), $tree, $default, $global); } @function global-color($key, $tree: 'colors', $default: null, $global: true) { @@ -14,8 +13,7 @@ } @function dim($key, $tree: 'dims', $default: null, $global: false) { - $key: iro.fn-list-prepend($key, --dims); - @return iro.props-get($key, $tree, $default, $global); + @return iro.props-get(join(--dims, $key), $tree, $default, $global); } @function global-dim($key, $tree: 'dims', $default: null, $global: true) { @@ -26,108 +24,27 @@ @return iro.props-get(join($foreign-key --dims, $key), $tree, $default, $global); } -@function set-font($key, $overrides: ()) { - $font: iro.props-get-static(join(--dims --font, $key), 'dims', $global: true); - - $map: (); - - @if (map-has-key($overrides, --family)) { - $map: map-merge( - $map, ( - font-family: map-get($overrides, --family) - ) - ); - } @else if (map-has-key($font, --family)) { - $map: map-merge( - $map, ( - font-family: global-dim(--font $key --family) - ) - ); - } - - @if (map-has-key($overrides, --size)) { - $map: map-merge( - $map, ( - font-size: map-get($overrides, --size) - ) - ); - } @else if (map-has-key($font, --size)) { - $map: map-merge( - $map, ( - font-size: global-dim(--font $key --size) - ) - ); - } - - @if (map-has-key($overrides, --weight)) { - $map: map-merge( - $map, ( - font-weight: map-get($overrides, --weight) - ) - ); - } @else if (map-has-key($font, --weight)) { - $map: map-merge( - $map, ( - font-weight: global-dim(--font $key --weight) - ) - ); - } - - @if (map-has-key($overrides, --style)) { - $map: map-merge( - $map, ( - font-style: map-get($overrides, --style) - ) - ); - } @else if (map-has-key($font, --style)) { - $map: map-merge( - $map, ( - font-style: global-dim(--font $key --style) - ) - ); - } - - @if (map-has-key($overrides, --line-height)) { - $map: map-merge( - $map, ( - line-height: map-get($overrides, --line-height) - ) - ); - } @else if (map-has-key($font, --line-height)) { - $map: map-merge( - $map, ( - line-height: global-dim(--font $key --line-height) - ) - ); +@function font-prop($data, $overrides, $key, $prop) { + @if (map-has-key($overrides, $prop)) { + @return map-get($overrides, $prop); + } @else if (map-has-key($data, $prop)) { + @return global-dim(--font $key $prop); } + @return null; +} - @if (map-has-key($overrides, --transform)) { - $map: map-merge( - $map, ( - text-transform: map-get($overrides, --transform) - ) - ); - } @else if (map-has-key($font, --transform)) { - $map: map-merge( - $map, ( - text-transform: global-dim(--font $key --transform) - ) - ); - } +@function set-font($key, $overrides: ()) { + $font: iro.props-get-static(join(--dims --font, $key), 'dims', $global: true); - @if (map-has-key($overrides, --variant-alternates)) { - $map: map-merge( - $map, ( - font-variant-alternates: map-get($overrides, --variant-alternates) - ) - ); - } @else if (map-has-key($font, --variant-alternates)) { - $map: map-merge( - $map, ( - font-variant-alternates: global-dim(--font $key --variant-alternates) - ) - ); - } + $map: ( + font-family: font-prop($font, $overrides, $key, --family), + font-size: font-prop($font, $overrides, $key, --size), + font-weight: font-prop($font, $overrides, $key, --weight), + font-style: font-prop($font, $overrides, $key, --style), + line-height: font-prop($font, $overrides, $key, --line-height), + text-transform: font-prop($font, $overrides, $key, --transform), + font-variant-alternates: font-prop($font, $overrides, $key, --variant-alternates), + ); @return $map; } @@ -136,6 +53,8 @@ $values: set-font($basis, $values); @each $prop, $value in $values { - #{$prop}: $value; + @if $value != null { + #{$prop}: $value; + } } } diff --git a/src/objects/_heading.scss b/src/objects/_heading.scss index 2af8e19..cd91c61 100644 --- a/src/objects/_heading.scss +++ b/src/objects/_heading.scss @@ -51,7 +51,7 @@ } @include iro.bem-modifier('sm') { - @include fn.set-font(--standard, (--line-height: fn.global-dim(--font --headline --line-height))); + @include fn.set-font(--standard, (--line-height: null)); color: fn.color(--strong); font-size: fn.global-dim(--font-size --md); @@ -59,7 +59,7 @@ } @include iro.bem-modifier('xs') { - @include fn.set-font(--standard, (--line-height: fn.global-dim(--font --headline --line-height))); + @include fn.set-font(--standard, (--line-height: null)); color: fn.color(--light); font-size: fn.global-dim(--font-size --xs); diff --git a/yarn.lock b/yarn.lock index 9653150..2ab3c0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1260,7 +1260,7 @@ internal-slot@^1.0.3: "iro-sass@git+https://git.vulpes.one/git/iro-sass.git": version "1.0.2" - resolved "git+https://git.vulpes.one/git/iro-sass.git#9f1653f2ab64ef8cb4c545416da4241baa481557" + resolved "git+https://git.vulpes.one/git/iro-sass.git#4c9a427806b47b916849dbc98330fdbb469b659b" is-arrayish@^0.2.1: version "0.2.1" -- cgit v1.2.3-70-g09d2