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

react-theme-provider

v0.1.3

Published

The part of 'React Theming' project

Downloads

1,169

Readme

React Theme Provider

https://github.com/sm-react/react-theme-provider

What is React Theme Provider?

A generic theme provider and (very) simple CSS styler

now it is under development, see live demo, and this README

scheme

Use React Theme Provider in follow cases:

if you don't use Material-UI:

  1. Provide the theme data to your React Components via context. You don't need to have Material-UI in dependencies if you just want to pass your created theme to your non Material-UI components.
  2. Add style to your html elements - it will be based on your theme settings.
  3. Switch your created themes via API.

if you use Material-UI:

  1. Add simple style to you non material html elements. They will have same appearance with the marerial ones if wrapped in this provider.
  2. Override some part of your app with another theme.
  3. Have an API to switch themes on the client side.

What is Theme?

It's just plain javascript object, typically with two levels of nesting.

Primer:

const greyTheme = {
    themeName: 'Grey Theme',
    themeFile: 'greyTheme.json',
    palette: {
        primary1Color: '#00bcd4',
        alternateTextColor: '#4a4a4a',
        canvasColor: '#616161',
        textColor: '#bdbdbd',
        secondaryTextColor: 'rgba(255, 255, 255, 0.54)',
        disabledColor: '#757575',
        accent1Color: '#607d8b',
    },
};

You can develop your own themes with this tool (or see Live Demo)

What is CSSrule?

a string containing CSS rules. Typically it's a template string with passed theme props:

.themed div {
    color: ${palette.textColor};
    background-color: ${palette.canvasColor};
}

.themed a {
    color: ${palette.primary1Color};
}

Demo

Explore this live demo project:

Live demo

API

<ThemeProvider
  themes={[greyTheme, altTheme]}
  themeInd={1}
  override
  setCSS={CSSrule}
>
  <ThemedComponent />
</ThemeProvider>

themes - array with themes created in storybook-addon-material-ui. not required

themeInd - to set the current theme from themes. not required

override - if you use it inside of MuiThemeProvider (Material-UI) it will override theme. not required

setCSS - your custom CSS style function. You can set your own rules for CSS styling based on the theme setting. not required

if you use it without any props inside the MuiThemeProvider, it will provide CSS style for your html elements based on the current theme

if you use it without any props outside the MuiThemeProvider, it will provide CSS style for your html elements based on the default theme and pass this theme to your components via context same way as MuiThemeProvider.

by default you will have follow CSS settings:

.${className} div {
    color: ${palette.textColor};
    background-color: ${palette.canvasColor};
    border-width: 1px;
    border-color: ${palette.borderColor};
}

.${className} a {
    color: ${palette.primary1Color};
}

.${className} span {
    color: ${palette.accent1Color};
}

.${className} ::selection {
    background: ${palette.primary2Color};
}

Usage

  • install
npm i react-theme-provider --save
  • import
import ThemeProvider from 'react-theme-provider';
  • wrap
<ThemeProvider>
  <YourThemedComponentOrPlainHTML />
</ThemeProvider>

more examples see in Live demo