util-darkmode
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    设备主题模式监听

    Build Status Coverage Status

    安装

    # 安装
    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()

    Install

    npm i util-darkmode

    DownloadsWeekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    6.09 kB

    Total Files

    7

    Last publish

    Collaborators

    • ritj