From d6ebc60d3d98d48959e6e1bd4eeea4d6e8be4366 Mon Sep 17 00:00:00 2001 From: ysds Date: Tue, 3 Sep 2019 20:18:44 +0300 Subject: [PATCH] Add add and subtract function --- scss/_functions.scss | 37 ++++++++++++++++++ scss/_modal.scss | 16 ++++---- scss/_popover.scss | 8 ++-- scss/_variables.scss | 23 +++++------ scss/forms/_form-range.scss | 2 +- scss/forms/_labels.scss | 12 +++--- .../docs/4.3/getting-started/theming.md | 38 +++++++++++++++++++ 7 files changed, 106 insertions(+), 30 deletions(-) diff --git a/scss/_functions.scss b/scss/_functions.scss index 79f988feb5..930232950b 100644 --- a/scss/_functions.scss +++ b/scss/_functions.scss @@ -108,3 +108,40 @@ @function shade-color($color, $level) { @return mix(black, $color, $level * $theme-color-interval); } + +// Return valid calc +@function add($value1, $value2, $return-calc: true) { + @if $value1 == null { + @return $value2; + } + + @if $value2 == null { + @return $value1; + } + + @if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) { + @return $value1 + $value2; + } + + @return if($return-calc == true, calc(#{$value1} + #{$value2}), #{$value1} + #{$value2}); +} + +@function subtract($value1, $value2, $return-calc: true) { + @if $value1 == null and $value2 == null { + @return null; + } + + @if $value1 == null { + @return -$value2; + } + + @if $value2 == null { + @return $value1; + } + + @if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) { + @return $value1 - $value2; + } + + @return if($return-calc == true, calc(#{$value1} - #{$value2}), #{$value1} - #{$value2}); +} diff --git a/scss/_modal.scss b/scss/_modal.scss index 381b0685e5..421e3e6400 100644 --- a/scss/_modal.scss +++ b/scss/_modal.scss @@ -57,10 +57,10 @@ .modal-dialog-scrollable { display: flex; // IE10/11 - max-height: calc(100% - #{$modal-dialog-margin * 2}); + max-height: subtract(100%, $modal-dialog-margin * 2); .modal-content { - max-height: calc(100vh - #{$modal-dialog-margin * 2}); // IE10/11 + max-height: subtract(100vh, $modal-dialog-margin * 2); // IE10/11 overflow: hidden; } @@ -77,12 +77,12 @@ .modal-dialog-centered { display: flex; align-items: center; - min-height: calc(100% - #{$modal-dialog-margin * 2}); + min-height: subtract(100%, $modal-dialog-margin * 2); // Ensure `modal-dialog-centered` extends the full height of the view (IE10/11) &::before { display: block; // IE10 - height: calc(100vh - #{$modal-dialog-margin * 2}); + height: subtract(100vh, $modal-dialog-margin * 2); content: ""; } @@ -204,18 +204,18 @@ } .modal-dialog-scrollable { - max-height: calc(100% - #{$modal-dialog-margin-y-sm-up * 2}); + max-height: subtract(100%, $modal-dialog-margin-y-sm-up * 2); .modal-content { - max-height: calc(100vh - #{$modal-dialog-margin-y-sm-up * 2}); + max-height: subtract(100vh, $modal-dialog-margin-y-sm-up * 2); } } .modal-dialog-centered { - min-height: calc(100% - #{$modal-dialog-margin-y-sm-up * 2}); + min-height: subtract(100%, $modal-dialog-margin-y-sm-up * 2); &::before { - height: calc(100vh - #{$modal-dialog-margin-y-sm-up * 2}); + height: subtract(100vh, $modal-dialog-margin-y-sm-up * 2); } } diff --git a/scss/_popover.scss b/scss/_popover.scss index 512a25fb39..6ebb2c3de8 100644 --- a/scss/_popover.scss +++ b/scss/_popover.scss @@ -39,7 +39,7 @@ margin-bottom: $popover-arrow-height; > .popover-arrow { - bottom: calc((#{$popover-arrow-height} + #{$popover-border-width}) * -1); + bottom: subtract(-$popover-arrow-height, $popover-border-width); &::before { bottom: 0; @@ -59,7 +59,7 @@ margin-left: $popover-arrow-height; > .popover-arrow { - left: calc((#{$popover-arrow-height} + #{$popover-border-width}) * -1); + left: subtract(-$popover-arrow-height, $popover-border-width); width: $popover-arrow-height; height: $popover-arrow-width; margin: $popover-border-radius 0; // make sure the arrow does not touch the popover's rounded corners @@ -82,7 +82,7 @@ margin-top: $popover-arrow-height; > .popover-arrow { - top: calc((#{$popover-arrow-height} + #{$popover-border-width}) * -1); + top: subtract(-$popover-arrow-height, $popover-border-width); &::before { top: 0; @@ -114,7 +114,7 @@ margin-right: $popover-arrow-height; > .popover-arrow { - right: calc((#{$popover-arrow-height} + #{$popover-border-width}) * -1); + right: subtract(-$popover-arrow-height, $popover-border-width); width: $popover-arrow-height; height: $popover-arrow-width; margin: $popover-border-radius 0; // make sure the arrow does not touch the popover's rounded corners diff --git a/scss/_variables.scss b/scss/_variables.scss index 2fe1478745..b0c60e63fe 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -616,13 +616,13 @@ $input-plaintext-color: $body-color !default; $input-height-border: $input-border-width * 2 !default; -$input-height-inner: calc(#{$input-line-height * 1em} + #{$input-padding-y * 2}) !default; -$input-height-inner-half: calc(#{$input-line-height * .5em} + #{$input-padding-y}) !default; -$input-height-inner-quarter: calc(#{$input-line-height * .25em} + #{$input-padding-y / 2}) !default; +$input-height-inner: add($input-line-height * 1em, $input-padding-y * 2) !default; +$input-height-inner-half: add($input-line-height * .5em, $input-padding-y) !default; +$input-height-inner-quarter: add($input-line-height * .25em, $input-padding-y / 2) !default; -$input-height: calc(#{$input-line-height * 1em} + #{$input-padding-y * 2} + #{$input-height-border}) !default; -$input-height-sm: calc(#{$input-line-height * 1em} + #{$input-btn-padding-y-sm * 2} + #{$input-height-border}) !default; -$input-height-lg: calc(#{$input-line-height * 1em} + #{$input-btn-padding-y-lg * 2} + #{$input-height-border}) !default; +$input-height: add($input-line-height * 1em, add($input-padding-y * 2, $input-height-border, false)) !default; +$input-height-sm: add($input-line-height * 1em, add($input-btn-padding-y-sm * 2, $input-height-border, false)) !default; +$input-height-lg: add($input-line-height * 1em, add($input-btn-padding-y-lg * 2, $input-height-border, false)) !default; $input-transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out !default; @@ -706,7 +706,8 @@ $form-select-indicator: url("data:image/svg+xml,