_function.scss 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * 辅助函数
  3. */
  4. @import 'config';
  5. $default-theme: #4d80f0 !default; // 正常色
  6. /* 转换成字符串 */
  7. @function selectorToString($selector) {
  8. $selector: inspect($selector);
  9. $selector: str-slice($selector, 2, -2);
  10. @return $selector;
  11. }
  12. /* 判断是否存在 Modifier */
  13. @function containsModifier($selector) {
  14. $selector: selectorToString($selector);
  15. @if str-index($selector, $modifierSeparator) {
  16. @return true;
  17. }
  18. @else {
  19. @return false;
  20. }
  21. }
  22. /* 判断是否存在伪类 */
  23. @function containsPseudo($selector) {
  24. $selector: selectorToString($selector);
  25. @if str-index($selector, ':') {
  26. @return true;
  27. }
  28. @else {
  29. @return false;
  30. }
  31. }
  32. /**
  33. * 主题色切换
  34. * @params $theme-color 主题色
  35. * @params $type 变暗’dark‘ 变亮 'light'
  36. * @params $mix-color 自己设置的混色
  37. */
  38. @function themeColor($theme-color, $type: "", $mix-color: "") {
  39. @if $default-theme !=#4d80f0 {
  40. @if $type=="dark" {
  41. @return darken($theme-color, 10%);
  42. }
  43. @else if $type=="light" {
  44. @return lighten($theme-color, 10%);
  45. }
  46. @else {
  47. @return $theme-color;
  48. }
  49. }
  50. @else {
  51. @return $mix-color;
  52. }
  53. }
  54. /**
  55. * 颜色结果切换, 如果开启线性渐变色 使用渐变色,如果没有开启,那么使用主题色
  56. * @params $open-linear 是否开启线性渐变色
  57. * @params $deg 渐变色角度
  58. * @params $theme-color 当前配色
  59. * @params [Array] $set 主题色明暗设置,与 $color-list 数量对应
  60. * @params [Array] $color-list 渐变色顺序, $color-list 和 $per-list 数量相同
  61. * @params [Array] $per-list 渐变色比例
  62. */
  63. @function resultColor($deg, $theme-color, $set, $color-list, $per-list) {
  64. // 开启渐变
  65. $len: length($color-list);
  66. $arg: $deg;
  67. @for $i from 1 through $len {
  68. $arg: $arg + ","+ themeColor($theme-color, nth($set, $i), nth($color-list, $i)) + " "+ nth($per-list, $i);
  69. }
  70. @return linear-gradient(unquote($arg));
  71. }