1.0.1 • Published 3 years ago

util-darkmode v1.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

设备主题模式监听

npm.io Build Status Coverage Status npm.io

安装

# 安装
npm i util-darkmode
# 或者 yarn add util-darkmode

更新记录

说明

/* ----------类型说明----------*/
export enum Theme {
    DARK = 'dark', // 暗黑模式
    LIGHT = 'light', // 明亮模式
    NO_PREF = 'no-preference', // 未设置
    NO_SUPP = 'no-support', // 不支持
}
export type DarkMode = (
    config: (activeTheme: Theme, themes: typeof Theme) => void
) => { removeListeners: () => void }

/* ----------使用方式----------*/
import { darkmode } from 'util-darkmode'

// 注册监听
const dm = darkmode((theme, themes) => {
    // 处理业务,也可直接判断 theme === 'dark'
    if (theme === Theme.DARK) {
        // ...
    }
})

// 注销监听
dm.removeListeners()
1.0.1

3 years ago

1.0.0

3 years ago