_var.scss 1.7 KB

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