From a2c5c67b5cac34f925c1d844125cf80a582dd263 Mon Sep 17 00:00:00 2001 From: Alexey Kulakov Date: Mon, 16 Nov 2026 12:38:00 -0700 Subject: [PATCH] fix(sass): replace the remaining legacy if() calls Sass 1.95 deprecates the legacy if() function, so builds on it warn for every call left in `@carbon/motion`, `@carbon/styles` and the action set web component. Use `or` for the fallbacks in motion's error messages and @if/@else elsewhere, which every supported Sass version understands. The compiled CSS doesn't change. Signed-off-by: Alexey Kulakov --- packages/motion/__tests__/motion-test.js | 18 ++++++++ packages/motion/index.scss | 4 +- .../styles/scss/components/card/_card.scss | 5 ++- .../scss/components/popover/_popover.scss | 12 ++++-- .../scss/components/toggletip/_toggletip.scss | 26 +++++++----- .../scss/components/tooltip/_tooltip.scss | 42 +++++++++++++------ .../src/components/action-set/action-set.scss | 10 ++--- 7 files changed, 81 insertions(+), 36 deletions(-) diff --git a/packages/motion/__tests__/motion-test.js b/packages/motion/__tests__/motion-test.js index 77c4320bf602..984e6dedd319 100644 --- a/packages/motion/__tests__/motion-test.js +++ b/packages/motion/__tests__/motion-test.js @@ -326,6 +326,24 @@ describe('@carbon/motion', () => { ).rejects.toThrow( /Unable to find duration `slo-01` for the custom surface/ ); + + await expect( + render(` + @use '../index.scss' as motion; + + .surface { + @include motion.surface(( + kind: reveal, + enter: (opacity: 1), + exit: (opacity: 0), + enter-easing: (name: entrance, mode: expressive), + exit-easing: (name: exit, mode: expressive), + )); + } + `) + ).rejects.toThrow( + /Unable to find duration `nothing` for the custom surface/ + ); }); test('surface mixin rejects a malformed inline definition', async () => { diff --git a/packages/motion/index.scss b/packages/motion/index.scss index a2d515405cf8..7bdcb7938186 100644 --- a/packages/motion/index.scss +++ b/packages/motion/index.scss @@ -160,7 +160,7 @@ $-durations: ( } @if $kind != 'reveal' { - @error 'Expected the #{$label} to declare `kind: reveal`, but found `#{if($kind, $kind, 'nothing')}`.'; + @error 'Expected the #{$label} to declare `kind: reveal`, but found `#{$kind or 'nothing'}`.'; } @each $key in (enter, exit) { @@ -178,7 +178,7 @@ $-durations: ( $duration: map.get($definition, duration); @if not map.has-key($-durations, $duration) { - @error 'Unable to find duration `#{if($duration, $duration, 'nothing')}` for the #{$label}. Expected one of: #{map.keys($-durations)}.'; + @error 'Unable to find duration `#{$duration or 'nothing'}` for the #{$label}. Expected one of: #{map.keys($-durations)}.'; } @each $key in (enter-easing, exit-easing) { diff --git a/packages/styles/scss/components/card/_card.scss b/packages/styles/scss/components/card/_card.scss index ac48c7df7db4..0ac8232da558 100644 --- a/packages/styles/scss/components/card/_card.scss +++ b/packages/styles/scss/components/card/_card.scss @@ -608,7 +608,10 @@ position: absolute; display: block; - border-radius: if(enabled('enable-v12-release'), $border-radius-08, null); + @if enabled('enable-v12-release') { + border-radius: $border-radius-08; + } + block-size: 100%; box-shadow: inset 0 -80px 70px -65px $ai-inner-shadow; content: ''; diff --git a/packages/styles/scss/components/popover/_popover.scss b/packages/styles/scss/components/popover/_popover.scss index dd8754d226ad..cbb4562ccaf9 100644 --- a/packages/styles/scss/components/popover/_popover.scss +++ b/packages/styles/scss/components/popover/_popover.scss @@ -62,10 +62,14 @@ $popover-border-color: custom-property.get-var( ); // The border radius value for the popover container -$popover-border-radius: custom-property.get-var( - 'popover-border-radius', - if(enabled('enable-v12-release'), $border-radius-08, 2px) -); +$popover-border-radius: custom-property.get-var('popover-border-radius', 2px); + +@if enabled('enable-v12-release') { + $popover-border-radius: custom-property.get-var( + 'popover-border-radius', + $border-radius-08 + ); +} // The text color used for text placed inside of the popover $popover-text-color: custom-property.get-var( diff --git a/packages/styles/scss/components/toggletip/_toggletip.scss b/packages/styles/scss/components/toggletip/_toggletip.scss index aa09cedb88b0..765092b8b06a 100644 --- a/packages/styles/scss/components/toggletip/_toggletip.scss +++ b/packages/styles/scss/components/toggletip/_toggletip.scss @@ -55,18 +55,22 @@ } .#{$prefix}--toggletip { - @include custom-property.declaration( - 'popover-offset', - if( - enabled('enable-v12-release'), - convert.to-rem(4px), + @if enabled('enable-v12-release') { + @include custom-property.declaration( + 'popover-offset', + convert.to-rem(4px) + ); + @include custom-property.declaration( + 'popover-border-radius', + $border-radius-04 + ); + } @else { + @include custom-property.declaration( + 'popover-offset', convert.to-rem(13px) - ) - ); - @include custom-property.declaration( - 'popover-border-radius', - if(enabled('enable-v12-release'), $border-radius-04, 2px) - ); + ); + @include custom-property.declaration('popover-border-radius', 2px); + } } .#{$prefix}--toggletip-content { diff --git a/packages/styles/scss/components/tooltip/_tooltip.scss b/packages/styles/scss/components/tooltip/_tooltip.scss index d586872a5bd7..4a64e87534dc 100644 --- a/packages/styles/scss/components/tooltip/_tooltip.scss +++ b/packages/styles/scss/components/tooltip/_tooltip.scss @@ -20,9 +20,16 @@ $tooltip-padding-block: custom-property.get-var( 'tooltip-padding-block', - if(enabled('enable-v12-release'), spacing.$spacing-02, spacing.$spacing-05) + spacing.$spacing-05 ); +@if enabled('enable-v12-release') { + $tooltip-padding-block: custom-property.get-var( + 'tooltip-padding-block', + spacing.$spacing-02 + ); +} + $tooltip-padding-inline: custom-property.get-var( 'tooltip-padding-inline', spacing.$spacing-05 @@ -30,14 +37,19 @@ $tooltip-padding-inline: custom-property.get-var( @mixin tooltip { .#{$prefix}--tooltip { - @include custom-property.declaration( - 'popover-offset', - if(enabled('enable-v12-release'), convert.to-rem(4px), 12px) - ); - @include custom-property.declaration( - 'popover-border-radius', - if(enabled('enable-v12-release'), $border-radius-04, 2px) - ); + @if enabled('enable-v12-release') { + @include custom-property.declaration( + 'popover-offset', + convert.to-rem(4px) + ); + @include custom-property.declaration( + 'popover-border-radius', + $border-radius-04 + ); + } @else { + @include custom-property.declaration('popover-offset', 12px); + @include custom-property.declaration('popover-border-radius', 2px); + } } .#{$prefix}--tooltip-content { @@ -69,10 +81,14 @@ $tooltip-padding-inline: custom-property.get-var( } .#{$prefix}--definition-tooltip { - @include custom-property.declaration( - 'popover-border-radius', - if(enabled('enable-v12-release'), $border-radius-04, 2px) - ); + @if enabled('enable-v12-release') { + @include custom-property.declaration( + 'popover-border-radius', + $border-radius-04 + ); + } @else { + @include custom-property.declaration('popover-border-radius', 2px); + } @include type.type-style('body-01'); padding: convert.to-rem(8px) convert.to-rem(16px); diff --git a/packages/web-components/src/components/action-set/action-set.scss b/packages/web-components/src/components/action-set/action-set.scss index ca4467db275e..05b3f7bf2701 100644 --- a/packages/web-components/src/components/action-set/action-set.scss +++ b/packages/web-components/src/components/action-set/action-set.scss @@ -26,11 +26,11 @@ $block-class: #{$prefix}--action-set; // Mixin for button separator styles @mixin button-separator($direction: horizontal) { - $shadow: if( - $direction == horizontal, - to-rem(-1px) 0 0 0 button-tokens.$button-separator, - 0 to-rem(-1px) 0 0 button-tokens.$button-separator - ); + $shadow: to-rem(-1px) 0 0 0 button-tokens.$button-separator; + + @if $direction != horizontal { + $shadow: 0 to-rem(-1px) 0 0 button-tokens.$button-separator; + } // Slotted buttons ::slotted(#{$prefix}-button:not(:first-of-type)) {