npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

umi-plugin-dynamic-theme-switch

v1.1.7

Published

umi theme switch

Downloads

4

Readme

umi-plugin-theme-switch

NPM version NPM downloads

基于css变量实现主题切换的umi插件

Umi plugin for theme switching based on css variables.

Install

# or yarn
$ npm install umi-plugin-theme-switch

Usage

Configure in .umirc.js,

export default {
  plugins: [
    ['umi-plugin-theme-switch', options],
  ],
}

Examples

Examples

Options


themes

Type: string | UmiPluginThemeItem Required: true

主题列表,类型为string时表示主题列表目录,目录下的.json|.js都会被解析成主题配置

examle: src/themes/dark.json

{
  "--bg-global": "#333",
  "--font-color": "#ddd"
}

.umirc.js

export default {
  plugins: [
    ['umi-plugin-theme-switch', {
      themes: 'src/themes'
    }],
  ],
}

也可以不用配置目录,example:

export default {
  plugins: [
    ['umi-plugin-theme-switch', {
      themes: [{
        name: 'light',
        variables: {
          '--bg-global': '#ddd'
          '--font-color': '#333'
        }
      }, {
        name: 'dark',
        variables: {
          '--bg-global': '#333'
          '--font-color': '#ddd'
        }
      }]
    }],
  ],
}

defaultTheme

Type: string

Default: 默认为上面themes数组的第一个主题

默认主题,不传的话默认为themes里第一项


scope

Type: string

Default: :root

主题作用域,建议使用:root或者body或者app的根节点例如#root,否则如果设置了remember或者autoDetectDarkMode,页面会在render之前设置主题,尚未渲染出的元素将不会生效


attribute

Type: string

Default: umi-theme

css变量的作用域是根据scope+属性选择器[umi-theme=theme]来确定的,如果想要自定义属性选择器的名字,可以更改此选项


remember

Type: boolean

Default: false

新打开页面时是否自动选用上次选择过的主题,每次切换时会写入 localStorage.setItem('umi_theme',theme)


autoDetectDarkMode

Default: null

自动检测浏览器的dark模式并设置主题

如果同时启用rememberautoDetectDarkMode,则只有首次打开页面时会自动检测

autoDetectDarkMode.enable

Type: boolean

启用自动检测浏览器的dark模式

autoDetectDarkMode.darkTheme

Type: string

Default: dark

浏览器dark模式对应的主题配置名称


Functions

import {getTheme, switchTheme} from 'umi-plugin-theme-switch';

getTheme(): string

获取当前的主题名

switchTheme(theme: string): void

切换主题

ENV

UMI_THEME_SCOPE : 主题作用域,为选择器字符串

UMI_THEME_ATTRIBUTE : 主题产生作用的属性,默认为 umi-theme

兼容性

caniuse

由于css变量不支持ie11,所以ie11可能需要一些解决方案 nuxodin/ie11CustomProperties

LICENSE

MIT