_handle.scss 904 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. @import "./_themes.scss";
  2. //遍历主题map
  3. @mixin themeify {
  4. @each $theme-name, $theme-map in $themes {
  5. //!global 把局部变量强升为全局变量
  6. $theme-map: $theme-map !global;
  7. //判断html的data-theme的属性值 #{}是sass的插值表达式
  8. //& sass嵌套里的父容器标识 @content是混合器插槽,像vue的slot
  9. [data-theme="#{$theme-name}"] & {
  10. @content;
  11. }
  12. }
  13. }
  14. //声明一个根据Key获取颜色的function
  15. @function themed($key) {
  16. @return map-get($theme-map, $key);
  17. }
  18. //获取背景颜色
  19. @mixin background_color($color) {
  20. @include themeify {
  21. background-color: themed($color) !important;
  22. }
  23. }
  24. //获取字体颜色
  25. @mixin font_color($color) {
  26. @include themeify {
  27. color: themed($color) !important;
  28. }
  29. }
  30. //获取边框颜色
  31. @mixin border_color($color) {
  32. @include themeify {
  33. border-color: themed($color) !important;
  34. }
  35. }