如何在SASS中有条件地调整SLECTOR规则?

发布于 2025-02-01 09:10:10 字数 698 浏览 3 评论 0原文

我是SCSS的新手,我想使用SCSS实现主题,我编写了Mixins和功能,该功能在父类中返回颜色值。即“主题光”或“主题黑暗”相应退出。如果父类不存在,如何编写返回默认值的选择器?

@mixin themed() {
    @each $theme, $map in $themes {
      .theme-#{$theme} & {
        $theme-map: () !global;
        @each $key, $submap in $map {
          $value: map-get(map-get($themes, $theme), '#{$key}');
          $theme-map: map-merge($theme-map, ($key: $value)) !global;
        }
        @content;
        $theme-map: null !global;
      }

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

用例:实际上,我想在我的React应用程序中实现主题。基于所选主题,要么暗/光模式,应用程序的整个主题将被更改。

I'm new to scss, I want to implement theming using scss, I wrote mixins and function that returns a color value if parent class. i.e "theme-light" or "theme-dark" exits accordingly. How can I write a selector that returns a default value if the parent class doesn't exist?

@mixin themed() {
    @each $theme, $map in $themes {
      .theme-#{$theme} & {
        $theme-map: () !global;
        @each $key, $submap in $map {
          $value: map-get(map-get($themes, $theme), '#{$key}');
          $theme-map: map-merge($theme-map, ($key: $value)) !global;
        }
        @content;
        $theme-map: null !global;
      }

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

Use case: actually, I want to implement theming in my react app. based upon the selected theme either dark/light mode the whole theme for the app would be changed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文