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

@kwooshung/react-themes

v2.0.1

Published

It is more convenient to use svg as React theme, which has strong operability and high degree of freedom.

Downloads

23

Readme

@kwooshung/react-themes

A super convenient theme management component, you can set the theme color by yourself, add custom themes at will, and design templates by yourself. All data themes share the same state, support local storage settings, and can determine light or dark colors according to the system.

GitHub License GitHub Release Date - Published_At GitHub last commit GitHub code size in bytes GitHub top language GitHub pull requests GitHub issues Github Stars NPM Version Npm.js Downloads/Week Github CI/CD codecov Maintainability Gitee Repo

Why Develop It?

  • In today's world, can a website be called modern without a Change Theme feature? At the very least, it should have a Dark Mode, right?

What Pain Points Does It Solve?

  • Every time a website is developed, there's the hassle of writing a theme management system from scratch;
  • Why not use other third-party components?
    • They are often highly integrated with their own UI component libraries;
    • The functionality is too complex and not lightweight enough;
    • The lightweight component libraries, on the other hand, tend to be overly simplistic in features;

Why Use It?

  • Headless, no predefined styles, allows customizing the theme switch button or list;
  • Supports custom theme colors, with default support for 'light' and 'dark' themes;
  • Easy to use, simple operation, low learning curve, and high flexibility;
  • Shared state, all data themes share the same status;
  • Implemented with modern ES6 features;
  • Written in TypeScript for type safety;
  • Modular esm import on demand, naturally supports tree-shaking, no worries about the size after packaging;
  • Of course, this project also offers a commonjs (cjs) version;
  • 100% test coverage;

Demo

Installation

npm

npm install @kwooshung/react-themes

yarn

yarn add @kwooshung/react-themes

pnpm

pnpm add @kwooshung/react-themes

Usage

ThemesProvider 包裹的组件,都可以通过 Themes 获取到主题统一的状态。

ThemesProvider

import { ThemesProvider } from '@kwooshung/react-themes';
import Switch from './Switch';

/**
 * @zh 主题列表
 * @en Theme list
 */
const ThemeList = ['light', 'dark', 'blue', 'green'];

/**
 * @zh 全局布局
 * @en Global layout
 */
const Layout = () => {
  return (
    <ThemesProvider def='auto' list={ThemeList}>
      {/* <OtherComponents /> */}
      <Switch />
      {/* <OtherComponents /> */}
    </ThemesProvider>
  );
};

export default App;

Themes

import { IThemesContext, Themes } from '@kwooshung/react-themes';

const Demo = () => {
  const themes = (context: IThemesContext): ReactNode => {
    return (
      // Write your theme switching button or list here, and you can get the theme status through `context`;
    );
  };

  return <Themes>{themes}</Themes>;
};

export default Switch;

API

For interface type definition, you can also read the interfaces.d.ts source file;

IThemesProps

| Properties | Type | Default Value | Description | | ---------- | --------------------------------------------- | ------------- | ------------------------------- | | children | (themeContext: IThemesContext) => ReactNode | - | Subcomponent rendering function |

IThemesProviderProps

| Properties | Type | Default Value | Description | | ---------- | -------- | ------------- | ----------------------------------- | | def | string | auto | Default theme value, default auto | | list | string[] | - | Topic list |

IThemesContext

| Properties | Type | Default Value | Description | | ------------------ | ----------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------- | | value | string | auto | Current theme value, default auto | | name | string | auto | The current theme name, except auto, is the same as value. If value = auto, if the system is dark, then name=dark | | setTheme | (theme: string) => void | - | Topic list | | addThemes | (themes: string | string[]) => void | Add topic | | getValueTheme | () => string | - | Get the current topic value | | getNameTheme | () => string | - | Get the current topic name | | getAvailableThemes | () => string[] | - | Get a list of available themes |