react-themeable

WebJar for react-themeable

Лицензия

Лицензия

MIT
Категории

Категории

React Взаимодействие с пользователем Веб-фреймворки
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

react-themeable
Последняя версия

Последняя версия

1.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

react-themeable
WebJar for react-themeable
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/markdalgleish/react-themeable

Скачать react-themeable

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/react-themeable/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>react-themeable</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/react-themeable/
implementation 'org.webjars.npm:react-themeable:1.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/react-themeable/
implementation ("org.webjars.npm:react-themeable:1.1.0")
'org.webjars.npm:react-themeable:jar:1.1.0'
<dependency org="org.webjars.npm" name="react-themeable" rev="1.1.0">
  <artifact name="react-themeable" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='react-themeable', version='1.1.0')
)
libraryDependencies += "org.webjars.npm" % "react-themeable" % "1.1.0"
[org.webjars.npm/react-themeable "1.1.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.webjars.npm : object-assign jar [3.0.0,4)

Модули Проекта

Данный проект не имеет модулей.

Build Status Coverage npm

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, Aphrodite, React Style, JSS, global CSS or inline styles 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 style names.

const theme = themeable(this.props.theme);
...
<div {...theme(key, ...styleNames)} />

Note: A unique key for each themed element is required for Radium to work correctly.

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} />

Aphrodite

import { StyleSheet, css } from 'aphrodite';

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

React Style

import StyleSheet from 'react-style';

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

JSS

import jss from 'jss';

const sheet = jss.createStyleSheet({
  foo: {
    color: 'red'
  },
  bar: {
    color: 'blue'
  }
}).attach();
...
<MyComponent theme={sheet.classes} />

Global CSS

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

Inline styles

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

License

MIT

Версии библиотеки

Версия
1.1.0
1.0.1