_var.scss 1.8 KB

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