Sass 支持多主题2019-09-25Θ
定义主题 theme.scss
:#
$themes: (light: (bd-bg: #f4f5f5,text-color: #555,),dark: (bd-bg: #181818,text-color: #fff,),);@mixin themify($themes: $themes) {@each $theme-name, $map in $themes {.theme-#{$theme-name} & {$theme-map: () !global;@each $key, $value in $map {$theme-map: map-merge($theme-map, ($key: $value)) !global;}@content;$theme-map: null !global;}}}@function themed($key) {@return map-get($theme-map, $key);}
引用#
@import 'xx/theme.scss';.Topbar {@include themify($themes) {color: themed('text-color');}}
相当于
.theme-light .Topbar {color: #555;}.theme-dark .Topbar {color: #fff;}