From bbee3c44e9236ca823c1c85ebd03087f78d29656 Mon Sep 17 00:00:00 2001 From: Jen Downs Date: Mon, 23 Dec 2019 16:29:19 -0600 Subject: [PATCH] fix(styles): add error handling for rem & em sass functions (#4931) --- packages/components/src/globals/scss/_typography.scss | 10 ++++++++++ packages/layout/scss/_convert.scss | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/components/src/globals/scss/_typography.scss b/packages/components/src/globals/scss/_typography.scss index ad3932a18345..a1bcf9ea28d3 100644 --- a/packages/components/src/globals/scss/_typography.scss +++ b/packages/components/src/globals/scss/_typography.scss @@ -22,6 +22,11 @@ $base-font-size: 16px !default; /// @group global-typography /// @deprecated (For v10) Use `carbon--rem()` @function rem($px) { + @if unit($px) != 'px' { + // TODO: update to @error in v11 + @warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`"; + } + @return ($px / $base-font-size) * 1rem; } @@ -33,6 +38,11 @@ $base-font-size: 16px !default; /// @group global-typography /// @deprecated (For v10) Use `carbon--em()` @function em($px) { + @if unit($px) != 'px' { + // TODO: update to @error in v11 + @warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`"; + } + @return ($px / $base-font-size) * 1em; } diff --git a/packages/layout/scss/_convert.scss b/packages/layout/scss/_convert.scss index 339fc78e5257..7c5f5d98a69d 100644 --- a/packages/layout/scss/_convert.scss +++ b/packages/layout/scss/_convert.scss @@ -17,6 +17,11 @@ $carbon--base-font-size: 16px !default; /// @access public /// @group @carbon/layout @function carbon--rem($px) { + @if unit($px) != 'px' { + // TODO: update to @error in v11 + @warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`"; + } + @return ($px / $carbon--base-font-size) * 1rem; } @@ -26,5 +31,10 @@ $carbon--base-font-size: 16px !default; /// @access public /// @group @carbon/layout @function carbon--em($px) { + @if unit($px) != 'px' { + // TODO: update to @error in v11 + @warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`"; + } + @return ($px / $carbon--base-font-size) * 1em; }