tanghaolin
2025-02-13 2ec3046812762fa7e5fc75867165625c3e4abc14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@use 'sass:map';
@use 'sass:color';
 
@use 'function' as *;
@use '../common/var' as *;
 
 
// set css var value, because we need translate value to string
// for example:
// @include set-css-var-value(('color', 'primary'), red);
// --el-color-primary: red;
@mixin set-css-var-value($name, $value) {
    #{joinVarName($name)}: #{$value};
}
 
@mixin set-css-color-type($colors, $type) {
    @include set-css-var-value(('color', $type), map.get($colors, $type, 'base'));
 
    @each $i in (3, 5, 7, 8, 9) {
        @include set-css-var-value(('color', $type, 'light', $i), map.get($colors, $type, 'light-#{$i}'));
    }
 
    @include set-css-var-value(('color', $type, 'dark-2'), map.get($colors, $type, 'dark-2'));
}
 
// set all css var for component by map
@mixin set-component-css-var($name, $variables) {
    @each $attribute, $value in $variables {
        @if $attribute == 'default' {
            #{getCssVarName($name)}: #{$value};
        } @else {
            #{getCssVarName($name, $attribute)}: #{$value};
        }
    }
}
@mixin set-css-color-rgb($type) {
    $color: map.get($colors, $type, 'base');
    @include set-css-var-value(('color', $type, 'rgb'), #{color.channel($color, 'red'), color.channel($color, 'green'), color.channel($color, 'blue')});
}
// generate css var from existing css var
// for example:
// @include css-var-from-global(('button', 'text-color'), ('color', $type))
// --el-button-text-color: var(--el-color-#{$type});
@mixin css-var-from-global($var, $gVar) {
    $varName: joinVarName($var);
    $gVarName: joinVarName($gVar);
    #{$varName}: var(#{$gVarName});
}