Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-themeable

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-themeable

Utility for making React components easily themeable

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
265K
decreased by-17.28%
Maintainers
1
Weekly downloads
 
Created
Source

react-themeable

Utility for making React components easily themeable.

This project is still experimental, so feedback from component authors would be greatly appreciated!

Why?

The React community is highly fragmented when it comes to styling. How do we write components that can happily co-exist with all of these competing approaches?

With react-themeable, you can support custom themes provided by CSS Modules, Radium, React Style, or even plain old style objects as easily as this:

<MyComponent theme={theme} />

Install

npm install --save react-themeable

Usage

react-themeable exposes just a single function.

This function is designed to accept a theme prop inside of your render method. This then returns a small helper function that accepts a key and a series of classes/style names.

This helper function detects whether a theme is class or style based, and creates the appropriate attributes for you.

For example:

import React, { Component } from 'react';
import themeable from 'react-themeable';

class MyComponent extends Component {
  render() {
    const theme = themeable(this.props.theme);

    return (
      <div {...theme(1, 'root')}>
        <div {...theme(2, 'foo', 'bar')}>Foo Bar</div>
        <div {...theme(3, 'baz')}>Baz</div>
      </div>
    );
  }
}

A theme can now be passed to your component like so:

CSS Modules

.foo { color: red; }
.foo:hover { color: green; }
.bar { color: blue; }
import theme from './MyComponentTheme.css';
...
<MyComponent theme={theme} />

Radium

import Radium from 'radium';

const theme = {
  foo: {
    color: 'red',
    ':hover': {
      color: 'green'
    }
  },
  bar: {
    color: 'blue'
  }
};

const ThemedMyComponent = Radium(MyComponent);
...
<ThemedMyComponent theme={theme} />

React Style

import StyleSheet from 'react-style';

const theme = StyleSheet.create({
  foo: {
    color: 'red'
  },
  bar: {
    color: 'blue'
  }
});
...
<MyComponent theme={theme} />

Plain style objects

const theme = {
  foo: {
    color: 'red'
  },
  bar: {
    color: 'blue'
  }
};
...
<MyComponent theme={theme} />

License

MIT

FAQs

Package last updated on 07 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc