Skip to content

Commit bbee3c4

Browse files
jendownsasudoh
authored andcommitted
fix(styles): add error handling for rem & em sass functions (#4931)
1 parent 2db756a commit bbee3c4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/components/src/globals/scss/_typography.scss

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ $base-font-size: 16px !default;
2222
/// @group global-typography
2323
/// @deprecated (For v10) Use `carbon--rem()`
2424
@function rem($px) {
25+
@if unit($px) != 'px' {
26+
// TODO: update to @error in v11
27+
@warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
28+
}
29+
2530
@return ($px / $base-font-size) * 1rem;
2631
}
2732

@@ -33,6 +38,11 @@ $base-font-size: 16px !default;
3338
/// @group global-typography
3439
/// @deprecated (For v10) Use `carbon--em()`
3540
@function em($px) {
41+
@if unit($px) != 'px' {
42+
// TODO: update to @error in v11
43+
@warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
44+
}
45+
3646
@return ($px / $base-font-size) * 1em;
3747
}
3848

packages/layout/scss/_convert.scss

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ $carbon--base-font-size: 16px !default;
1717
/// @access public
1818
/// @group @carbon/layout
1919
@function carbon--rem($px) {
20+
@if unit($px) != 'px' {
21+
// TODO: update to @error in v11
22+
@warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
23+
}
24+
2025
@return ($px / $carbon--base-font-size) * 1rem;
2126
}
2227

@@ -26,5 +31,10 @@ $carbon--base-font-size: 16px !default;
2631
/// @access public
2732
/// @group @carbon/layout
2833
@function carbon--em($px) {
34+
@if unit($px) != 'px' {
35+
// TODO: update to @error in v11
36+
@warn "Expected argument $px to be of type `px`, instead received: `#{unit($px)}`";
37+
}
38+
2939
@return ($px / $carbon--base-font-size) * 1em;
3040
}

0 commit comments

Comments
 (0)