From bbee3c44e9236ca823c1c85ebd03087f78d29656 Mon Sep 17 00:00:00 2001 From: Jen Downs Date: Mon, 23 Dec 2019 16:29:19 -0600 Subject: [PATCH 1/2] 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; } From 6c1042e05fb93fc604757b355a1f5574010e2788 Mon Sep 17 00:00:00 2001 From: carbon-bot Date: Mon, 23 Dec 2019 22:40:37 +0000 Subject: [PATCH 2/2] chore(project): sync generated files --- packages/components/docs/sass.md | 10 ++++++++++ packages/elements/docs/sass.md | 10 ++++++++++ packages/layout/docs/sass.md | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/packages/components/docs/sass.md b/packages/components/docs/sass.md index e3a31a81d2cd..767c399c5729 100644 --- a/packages/components/docs/sass.md +++ b/packages/components/docs/sass.md @@ -2550,6 +2550,11 @@ Convert a given px unit to a rem unit ```scss @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; } ``` @@ -2579,6 +2584,11 @@ Convert a given px unit to a em unit ```scss @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; } ``` diff --git a/packages/elements/docs/sass.md b/packages/elements/docs/sass.md index 11c79e41efa3..aae30c75a745 100644 --- a/packages/elements/docs/sass.md +++ b/packages/elements/docs/sass.md @@ -2326,6 +2326,11 @@ Convert a given px unit to a rem unit ```scss @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; } ``` @@ -2354,6 +2359,11 @@ Convert a given px unit to a em unit ```scss @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; } ``` diff --git a/packages/layout/docs/sass.md b/packages/layout/docs/sass.md index 68fa9d47bfc1..79e92eae719d 100644 --- a/packages/layout/docs/sass.md +++ b/packages/layout/docs/sass.md @@ -733,6 +733,11 @@ Convert a given px unit to a rem unit ```scss @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; } ``` @@ -761,6 +766,11 @@ Convert a given px unit to a em unit ```scss @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; } ```