Skip to content

Commit 26bf5e2

Browse files
authored
[chore] Migrate Sass global built-in functions to module system (#7601)
1 parent 95d4506 commit 26bf5e2

File tree

26 files changed

+137
-102
lines changed

26 files changed

+137
-102
lines changed

packages/core/src/_typography.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2015 Palantir Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0.
33

4+
@use "sass:list";
45
@import "common/variables";
56
@import "common/variables-extended";
67
@import "common/mixins";
@@ -62,8 +63,8 @@ $headings: (
6263

6364
@each $tag, $props in $headings {
6465
%#{$tag} {
65-
font-size: nth($props, 1);
66-
line-height: nth($props, 2);
66+
font-size: list.nth($props, 1);
67+
line-height: list.nth($props, 2);
6768
}
6869

6970
#{$tag}.#{$ns}-heading {

packages/core/src/common/_mixins.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright 2015 Palantir Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0.
33

4+
@use "sass:map";
45
@use "sass:math";
6+
@use "sass:meta";
57
@import "@blueprintjs/colors/lib/scss/colors";
68
@import "flex";
79

@@ -34,7 +36,7 @@ $pt-dark-intent-text-colors: (
3436
) !default;
3537

3638
@mixin intent-color($intentName) {
37-
color: map-get($pt-intent-colors, $intentName);
39+
color: map.get($pt-intent-colors, $intentName);
3840
}
3941

4042
@mixin position-all($position, $value) {
@@ -101,15 +103,15 @@ $pt-dark-intent-text-colors: (
101103
// returns the padding necessary to center text in a container of the given height.
102104
// default line-height is that of base typography, 18px assuming 14px font-size.
103105

104-
@function centered-text($height, $line-height: floor($pt-font-size * $pt-line-height)) {
105-
@return floor(($height - $line-height) * 0.5);
106+
@function centered-text($height, $line-height: math.floor($pt-font-size * $pt-line-height)) {
107+
@return math.floor(($height - $line-height) * 0.5);
106108
}
107109

108110
// Removes the unit from a Sass numeric value (if present): `strip-unit(12px) => 12`
109111
// @see https://css-tricks.com/snippets/sass/strip-unit-function/
110112

111113
@function strip-unit($number) {
112-
@if type-of($number) == "number" and not unitless($number) {
114+
@if meta.type-of($number) == "number" and not math.is-unitless($number) {
113115
@return math.div($number, $number * 0 + 1);
114116
}
115117

packages/core/src/common/_react-transition.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright 2016 Palantir Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0.
33

4+
@use "sass:list";
5+
@use "sass:map";
6+
47
/*
58
A mixin to generate the classes for a React CSSTransition which animates any number of CSS
69
properties at once.
@@ -93,7 +96,7 @@ If `exit` phase is given then property values are animated in reverse, from fina
9396
@include each-prop($properties, $end-index);
9497
transition-delay: $delay;
9598
transition-duration: $duration;
96-
transition-property: map-keys($properties);
99+
transition-property: map.keys($properties);
97100
/* stylelint-disable-next-line declaration-block-no-redundant-longhand-properties */
98101
transition-timing-function: $easing;
99102
}
@@ -107,7 +110,7 @@ Example: `each-prop((opacity: 0 1), 2)` will print "opacity: 1"
107110
*/
108111
@mixin each-prop($properties, $index) {
109112
@each $prop, $values in $properties {
110-
#{$prop}: nth($values, $index);
113+
#{$prop}: list.nth($values, $index);
111114
}
112115
}
113116

packages/core/src/components/button/_button-group.scss

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2015 Palantir Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0.
33

4+
@use "sass:list";
45
@import "../../common/variables";
56
@import "../forms/common";
67
@import "./common";
@@ -12,50 +13,50 @@
1213
// ensure button can never be smaller than its default size
1314
flex: 0 0 auto;
1415
position: relative;
15-
z-index: index($control-group-stack, "button-default");
16+
z-index: list.index($control-group-stack, "button-default");
1617

1718
// the ordering of these z-index CSS rules is particular because of CSS
1819
// selector specificity. specifically, disabled styles should have
1920
// precedence over hover and active styles to prevent mouse interactions on
2021
// disabled buttons from reordering elements in the stack.
2122

2223
&:focus {
23-
z-index: index($control-group-stack, "button-focus");
24+
z-index: list.index($control-group-stack, "button-focus");
2425
}
2526

2627
&:hover {
27-
z-index: index($control-group-stack, "button-hover");
28+
z-index: list.index($control-group-stack, "button-hover");
2829
}
2930

3031
&:active,
3132
&.#{$ns}-active {
32-
z-index: index($control-group-stack, "button-active");
33+
z-index: list.index($control-group-stack, "button-active");
3334
}
3435

3536
&:disabled,
3637
&.#{$ns}-disabled {
37-
z-index: index($control-group-stack, "button-disabled");
38+
z-index: list.index($control-group-stack, "button-disabled");
3839
}
3940

4041
&[class*="#{$ns}-intent-"] {
41-
z-index: index($control-group-stack, "intent-button-default");
42+
z-index: list.index($control-group-stack, "intent-button-default");
4243

4344
&:focus {
44-
z-index: index($control-group-stack, "intent-button-focus");
45+
z-index: list.index($control-group-stack, "intent-button-focus");
4546
}
4647

4748
&:hover {
48-
z-index: index($control-group-stack, "intent-button-hover");
49+
z-index: list.index($control-group-stack, "intent-button-hover");
4950
}
5051

5152
&:active,
5253
&.#{$ns}-active {
53-
z-index: index($control-group-stack, "intent-button-active");
54+
z-index: list.index($control-group-stack, "intent-button-active");
5455
}
5556

5657
&:disabled,
5758
&.#{$ns}-disabled {
58-
z-index: index($control-group-stack, "intent-button-disabled");
59+
z-index: list.index($control-group-stack, "intent-button-disabled");
5960
}
6061
}
6162
}

packages/core/src/components/button/_common.scss

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2015 Palantir Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0.
33

4+
@use "sass:map";
45
@import "../../common/mixins";
56
@import "../../common/variables";
67
@import "../../common/variables-extended";
@@ -401,12 +402,12 @@ $dark-minimal-active-text-colors: (
401402
);
402403

403404
@mixin pt-button-minimal-intent($intent) {
404-
$intent-color: map-get($pt-intent-colors, $intent);
405-
$text-color: map-get($pt-intent-text-colors, $intent);
406-
$active-text-color: map-get($pt-intent-active-text-colors, $intent);
407-
$dark-text-color: map-get($pt-dark-intent-text-colors, $intent);
408-
$dark-active-text-color: map-get($dark-minimal-active-text-colors, $intent);
409-
$dark-hover-text-color: map-get($dark-minimal-hover-text-colors, $intent);
405+
$intent-color: map.get($pt-intent-colors, $intent);
406+
$text-color: map.get($pt-intent-text-colors, $intent);
407+
$active-text-color: map.get($pt-intent-active-text-colors, $intent);
408+
$dark-text-color: map.get($pt-dark-intent-text-colors, $intent);
409+
$dark-active-text-color: map.get($dark-minimal-active-text-colors, $intent);
410+
$dark-hover-text-color: map.get($dark-minimal-hover-text-colors, $intent);
410411

411412
color: $text-color;
412413

@@ -499,8 +500,8 @@ $dark-minimal-active-text-colors: (
499500
@each $intent, $colors in $button-intents {
500501
&.#{$ns}-intent-#{$intent} {
501502
@include pt-button-outlined-intent(
502-
map-get($pt-intent-text-colors, $intent),
503-
map-get($pt-dark-intent-text-colors, $intent)
503+
map.get($pt-intent-text-colors, $intent),
504+
map.get($pt-dark-intent-text-colors, $intent)
504505
);
505506
}
506507
}

packages/core/src/components/callout/_callout.scss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2015 Palantir Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0.
33

4+
@use "sass:map";
45
@import "../../common/variables-extended";
56

67
$callout-padding: $pt-spacing * 4;
@@ -85,7 +86,7 @@ $callout-padding-compact: $pt-spacing * 2;
8586

8687
@each $intent, $color in $pt-intent-colors {
8788
&.#{$ns}-intent-#{$intent} {
88-
color: map-get($pt-intent-text-colors, $intent);
89+
color: map.get($pt-intent-text-colors, $intent);
8990

9091
&:not(.#{$ns}-minimal) {
9192
background-color: rgba($color, 0.1);
@@ -98,11 +99,11 @@ $callout-padding-compact: $pt-spacing * 2;
9899
&[class*="#{$ns}-icon-"]::before,
99100
> .#{$ns}-icon:first-child,
100101
.#{$ns}-heading {
101-
color: map-get($pt-intent-text-colors, $intent);
102+
color: map.get($pt-intent-text-colors, $intent);
102103
}
103104

104105
.#{$ns}-dark & {
105-
color: map-get($pt-dark-intent-text-colors, $intent);
106+
color: map.get($pt-dark-intent-text-colors, $intent);
106107

107108
&:not(.#{$ns}-minimal) {
108109
background-color: rgba($color, 0.2);
@@ -111,7 +112,7 @@ $callout-padding-compact: $pt-spacing * 2;
111112
&[class*="#{$ns}-icon-"]::before,
112113
> .#{$ns}-icon:first-child,
113114
.#{$ns}-heading {
114-
color: map-get($pt-dark-intent-text-colors, $intent);
115+
color: map.get($pt-dark-intent-text-colors, $intent);
115116
}
116117
}
117118
}

packages/core/src/components/card/_card.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2015 Palantir Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0.
33

4+
@use "sass:list";
45
@import "./card-variables";
56

67
.#{$ns}-card {
@@ -25,13 +26,13 @@
2526
}
2627
}
2728

28-
@for $index from 1 through length($elevation-shadows) {
29+
@for $index from 1 through list.length($elevation-shadows) {
2930
.#{$ns}-elevation-#{$index - 1} {
30-
box-shadow: nth($elevation-shadows, $index);
31+
box-shadow: list.nth($elevation-shadows, $index);
3132

3233
&.#{$ns}-dark,
3334
.#{$ns}-dark & {
34-
box-shadow: nth($dark-elevation-shadows, $index);
35+
box-shadow: list.nth($dark-elevation-shadows, $index);
3536
}
3637

3738
@media (forced-colors: active) and (prefers-color-scheme: dark) {

packages/core/src/components/entity-title/_entity-title.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2024 Palantir Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0.
33

4+
@use "sass:list";
45
@import "../../common/variables";
56
@import "../../common/variables-extended";
67

@@ -72,7 +73,7 @@
7273
align-items: center;
7374
display: flex;
7475
// Aligning icon which has unknown dimensions on the title size
75-
height: nth($props, 2);
76+
height: list.nth($props, 2);
7677
}
7778
}
7879

0 commit comments

Comments
 (0)