|
| 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 | + |
1 | 21 | @mixin scope-custom-property( |
2 | 22 | $componentName, |
3 | 23 | $componentProp, |
4 | | - $responsively: false |
| 24 | + $responsively: false, |
| 25 | + $default: null |
5 | 26 | ) { |
6 | 27 | @if $responsively { |
7 | 28 | // 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')}; |
13 | 34 | } @else { |
14 | | - --pc-#{$componentName}-#{$componentProp}: initial; |
| 35 | + --pc-#{$componentName}-#{$componentProp}: #{get-default($default)}; |
15 | 36 | } |
16 | 37 | } |
17 | 38 |
|
18 | | -@mixin non-responsive-prop($componentName, $componentProp, $declarationProp) { |
| 39 | +@mixin non-responsive-prop( |
| 40 | + $componentName, |
| 41 | + $componentProp, |
| 42 | + $declarationProp, |
| 43 | + $default: null |
| 44 | +) { |
19 | 45 | @include scope-custom-property( |
20 | 46 | $componentName, |
21 | 47 | $componentProp, |
22 | | - $responsively = false |
| 48 | + false, |
| 49 | + $default |
23 | 50 | ); |
24 | 51 |
|
25 | 52 | #{$declarationProp}: var(--pc-#{$componentName}-#{$componentProp}); |
26 | 53 | } |
27 | 54 |
|
28 | | -@mixin responsive-props($componentName, $componentProp, $declarationProp) { |
| 55 | +@mixin responsive-props( |
| 56 | + $componentName, |
| 57 | + $componentProp, |
| 58 | + $declarationProp, |
| 59 | + $default: null |
| 60 | +) { |
29 | 61 | @include scope-custom-property( |
30 | 62 | $componentName, |
31 | 63 | $componentProp, |
32 | | - $responsively = true |
| 64 | + true, |
| 65 | + $default |
33 | 66 | ); |
34 | 67 |
|
35 | 68 | #{$declarationProp}: var(--pc-#{$componentName}-#{$componentProp}-xs); |
|
0 commit comments