Skip to content

Commit 28a12bc

Browse files
committed
Support default CSS variables beyond 'initial'
1 parent 413a80e commit 28a12bc

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

polaris-react/src/styles/shared/_responsive-props.scss

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,68 @@
1+
@function is-map($var) {
2+
@return type-of($var) == 'map';
3+
}
4+
5+
@function is-null($var) {
6+
@return type-of($var) == 'null';
7+
}
8+
9+
@function get-default($default: null, $key: null) {
10+
$value: null;
11+
@if is-map($default) {
12+
@if not is-null($key) {
13+
$value: map-get($default, $key);
14+
}
15+
} @else {
16+
$value: $default;
17+
}
18+
@return if(is-null($value), 'initial', $value);
19+
}
20+
121
@mixin scope-custom-property(
222
$componentName,
323
$componentProp,
4-
$responsively: false
24+
$responsively: false,
25+
$default: null
526
) {
627
@if $responsively {
728
// stylelint-disable -- Polaris component custom properties
8-
--pc-#{$componentName}-#{$componentProp}-xs: initial;
9-
--pc-#{$componentName}-#{$componentProp}-sm: initial;
10-
--pc-#{$componentName}-#{$componentProp}-md: initial;
11-
--pc-#{$componentName}-#{$componentProp}-lg: initial;
12-
--pc-#{$componentName}-#{$componentProp}-xl: initial;
29+
--pc-#{$componentName}-#{$componentProp}-xs: #{get-default($default, 'xs')};
30+
--pc-#{$componentName}-#{$componentProp}-sm: #{get-default($default, 'sm')};
31+
--pc-#{$componentName}-#{$componentProp}-md: #{get-default($default, 'md')};
32+
--pc-#{$componentName}-#{$componentProp}-lg: #{get-default($default, 'lg')};
33+
--pc-#{$componentName}-#{$componentProp}-xl: #{get-default($default, 'xl')};
1334
} @else {
14-
--pc-#{$componentName}-#{$componentProp}: initial;
35+
--pc-#{$componentName}-#{$componentProp}: #{get-default($default)};
1536
}
1637
}
1738

18-
@mixin non-responsive-prop($componentName, $componentProp, $declarationProp) {
39+
@mixin non-responsive-prop(
40+
$componentName,
41+
$componentProp,
42+
$declarationProp,
43+
$default: null
44+
) {
1945
@include scope-custom-property(
2046
$componentName,
2147
$componentProp,
22-
$responsively = false
48+
false,
49+
$default
2350
);
2451

2552
#{$declarationProp}: var(--pc-#{$componentName}-#{$componentProp});
2653
}
2754

28-
@mixin responsive-props($componentName, $componentProp, $declarationProp) {
55+
@mixin responsive-props(
56+
$componentName,
57+
$componentProp,
58+
$declarationProp,
59+
$default: null
60+
) {
2961
@include scope-custom-property(
3062
$componentName,
3163
$componentProp,
32-
$responsively = true
64+
true,
65+
$default
3366
);
3467

3568
#{$declarationProp}: var(--pc-#{$componentName}-#{$componentProp}-xs);

0 commit comments

Comments
 (0)