Skip to content

TypeScript rewrite #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
coverage
.nyc_output
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
src
coverage
.nyc_output
.eslintrc
.nycrc
20 changes: 20 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"require": ["ts-node/register"],
"check-coverage": true,
"extension": [
".ts",
".tsx"
],
"include": [
"src"
],
"reporter": [
"lcov"
],
"branches": 100,
"lines": 100,
"functions": 100,
"statements": 100
}
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- "0.10"
after_success:
npm run coverage
- 10
- 12
- 14
after_success: npm run coverage
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright © 2015 Mark Dalgleish

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54 changes: 26 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# react-themeable

Utility for making React components easily themeable.
Utility for making React components easily themeable, written in TypeScript for easier use.

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

Expand All @@ -24,11 +24,11 @@ With react-themeable, you can support custom themes provided by [CSS Modules](ht

`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.
This function is designed to accept a `theme` prop inside your `render` method. This then returns a small helper function that accepts a key, and a series of style names.

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

Expand All @@ -38,21 +38,19 @@ This helper function detects whether a theme is class or style based, and create

For example:

```js
import React, { Component } from 'react';
```tsx
import React, { VoidFunctionComponent } from 'react';
import themeable from 'react-themeable';

class MyComponent extends Component {
render() {
const theme = themeable(this.props.theme);
const MyComponent: VoidFunctionComponent = () => {
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>
);
}
return (
<div {...theme(1, 'root')}>
<div {...theme(2, 'foo', 'bar')}>Foo Bar</div>
<div {...theme(3, 'baz')}>Baz</div>
</div>
);
}
```

Expand All @@ -66,15 +64,15 @@ A theme can now be passed to your component like so:
.bar { color: blue; }
```

```js
```tsx
import theme from './MyComponentTheme.css';
...
// ...
<MyComponent theme={theme} />
```

### Radium

```js
```tsx
import Radium from 'radium';

const theme = {
Expand All @@ -90,13 +88,13 @@ const theme = {
};

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

### Aphrodite

```js
```tsx
import { StyleSheet, css } from 'aphrodite';

const theme = StyleSheet.create({
Expand All @@ -110,13 +108,13 @@ const theme = StyleSheet.create({
color: 'blue'
}
});
...
// ...
<MyComponent theme={[ theme, css ]} />
```

### React Style

```js
```tsx
import StyleSheet from 'react-style';

const theme = StyleSheet.create({
Expand All @@ -127,13 +125,13 @@ const theme = StyleSheet.create({
color: 'blue'
}
});
...
// ...
<MyComponent theme={theme} />
```

### JSS

```js
```tsx
import jss from 'jss';

const sheet = jss.createStyleSheet({
Expand All @@ -144,7 +142,7 @@ const sheet = jss.createStyleSheet({
color: 'blue'
}
}).attach();
...
// ...
<MyComponent theme={sheet.classes} />
```

Expand All @@ -161,7 +159,7 @@ const theme = {
foo: 'MyComponent__foo',
bar: 'MyComponent__bar'
};
...
// ...
<MyComponent theme={theme} />
```

Expand All @@ -176,7 +174,7 @@ const theme = {
color: 'blue'
}
};
...
// ...
<MyComponent theme={theme} />
```

Expand Down
Loading