theme-change.scss 799 Bytes
$themes: (
  theme-white: (
    black: #000,
    text: #314659,
    border: #e8e8e8,
    border-light: rgba(#e8e8e8, 0.2),
    background: #fff,
  ),
  theme-black: (
    black: #fff,
    text: #D8D9DA,
    border: #343434,
    border-light: rgba(#343434, 0.2),
    background: #161719,
  ),
);

@mixin themify($themes: $themes) {
  @each $theme-name, $map in $themes {
    // & 表示父级元素
    // !global 表示覆盖原来的
    .#{$theme-name} & {
      $theme-map: () !global;
      // 循环合并键值对
      @each $key, $value in $map {
        $theme-map: map-merge($theme-map, ($key: $value)) !global;
      }
      // 表示包含 下面函数 themed()
      @content;
      $theme-map: null !global;
    }
  }
}

@function themed($key) {
  @return map-get($theme-map, $key);
}