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-component-theming

v1.1.1

Published

theming solution for react that aims to keep components independent.

Downloads

2

Readme

react-component-theming

Usually consistent theming across multiple components is achieved on an application level. In the best case this happens in a very generic way. For example:primary-color, accent-color, spacing(xs|sm|md|lg|xl). But in most cases this doesn't do the trick. A lot of exceptions for very component specific matters will end up in the central theme. Once these details change in the components itself, they often get forgotten and remain silently rotting in the central theme.

In order to avoid the above, this theming solution aims to separate the mentioned really specific parts from the central theme while keeping the good generic stuff in there. This is achieved by component themes which are, as the name suggests, themes on a component level and settings which are generic values on the application level.

Concepts

Settings

Settings are generic values that apply to the whole application. These should be as generic as possible and not contain any details of any specific component. The specific values contained in the settings of an application are different on an application basis and this library makes no assumptions about it. Recommended values for settings are values like primaryColor, accentColor, headingFontSize, textFontSize and a function that returns consistent spacing values for multiple sizes.

Theming Variant

A theming variant is a name for one specific settings object. Your application can contain a different settings object for each theming variant of the app. Examples for theming variants would be light and dark.

Settings Collection

The settings collection of your application is a mapping between all your theming variants and the corresponding settings.

Component Theme

A component theme is a theme for a specific component. Each component does define this theme for itself. Here you can be as specific as you want. This theme is based on the settings and the current theming variant making this approach really flexible since all edge cases can be handled in the component. Therefore, components continue to work in isolation.

Getting Started

This guide is based on the example provided by this repository.

Create your Settings Type

// src/Settings.ts

interface Settings {
  // Use here what you need
  textColor: string;
  backgroundColor: string;
  // ...
}

Create your Theming Variant Type

// src/ThemingVariant.ts

// Should be a union type of strings, like this one
type themingVariant = 'light' | 'dark';

Create your Settings Collection

// src/SettingsCollection.ts

const settingsCollection: SettingsCollection<Settings, ThemingVariant> = {
  light: {
    textColor: 'black',
    backgroundColor: 'white'
  },
  dark: {
    textColor: 'white',
    backgroundColor: 'black'
  }
};

Initialize the Context

// src/settingsContext.ts

const {
  SettingsProvider,
  useComponentTheme,
  useThemingVariant
} = initializeSettingsContext<Settings, ThemingVariant>({
  settingsCollection,
  initialThemingVariant: 'light'
});

Put the Provider into your Application

// src/pages/_app.tsx

const App: FunctionComponent<AppProps> = function ({ 
  Component,
  pageProps 
}): ReactElement {
  return (
    <SettingsProvider>
      <Component { ...pageProps } />;
    </SettingsProvider>
  );
};

Start using it :)

Have a look here.