Skip to content

Commit

Permalink
addFiles property seems missleading #4 (#5)
Browse files Browse the repository at this point in the history
* replaced addFiles property with addStyleFiles #4

* 1.1.0

* removed console.log
  • Loading branch information
BonneVoyager authored and flipace committed Nov 11, 2016
1 parent 8e32b36 commit b5b6963
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

### v1.1.0
- **enhanced** ```addFiles``` property replace with ```addStyleFiles```, as it's more self-explanatory (#4 by @BonneVoyager)

### v1.0.0
- **enhanced** ```addFiles``` now can actually handle multiple files (#3)
- **new** ```mergeContext``` option (#2)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default () => (
<MyComponent
theme="blue big italic"
styles={{ label: { textDecoration: 'underline' } }}
addFiles={cb => require(['./additionalStyles.less', './someMoreStyles.css'], cb) }
addStyleFiles={cb => require(['./additionalStyles.less', './someMoreStyles.css'], cb) }
/>
);
```
Expand All @@ -73,7 +73,7 @@ export default () => (
`})`

A component which is wrapped with *themeit* accepts these additional props:
- `addFiles` *(func)*: a function to pass additional theme classes to the component
- `addStyleFiles` *(func)*: a function to pass additional theme classes to the component
- `styles` *(object)*: additional js css styles to be passed to the component (will be processed with *aphrodite*)

The target component will receive the combined style classes in a property called `styles`.
Expand Down Expand Up @@ -137,9 +137,9 @@ You might want to define themes / style information for the keys
with themeit. If you were to use the calculator widget however,
you'd also want to pass new/additional style information for the keys to the calculator widget.

One way to deal with this would be to accept a separate prop like ```stylesForKeys``` or ```addFilesForKeys``` and pass these props down to each individual key. However, this sucks.
One way to deal with this would be to accept a separate prop like ```stylesForKeys``` or ```addStyleFilesForKeys``` and pass these props down to each individual key. However, this sucks.

Instead, you may just use the ```addFiles``` prop to pass style information for the whole widget + its themeable child components. And utilize the ```mergeContext``` option to merge all style information for the Key components.
Instead, you may just use the ```addStyleFiles``` prop to pass style information for the whole widget + its themeable child components. And utilize the ```mergeContext``` option to merge all style information for the Key components.

**b)** Ignore parent styles information and create a new styles context from the component

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-themeit",
"version": "1.0.0",
"version": "1.1.0",
"description": "themeit makes it easy to create and use different themes for your react components while using CSS Modules or JS style objects.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ storiesOf('Label', module)
.add('additional .css file', () => (
<Label
theme="blue"
addFiles={cb => require(['./additional.css'], cb)}
addStyleFiles={cb => require(['./additional.css'], cb)}
>Hello world.</Label>
));
4 changes: 2 additions & 2 deletions src/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ describe('themeit', () => {
expect(html.match(/boldText_/g)).to.have.length(1);
});

it('should accept multiple files passed by addFiles property function', () => {
it('should accept multiple files passed by addStyleFiles property function', () => {
const comp = mount(
<ComponentA
theme="black"
addFiles={cb => cb(
addStyleFiles={cb => cb(
require('./styles/test1'),
require('./styles/test2')
)}
Expand Down
13 changes: 10 additions & 3 deletions src/themeit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function themeit(opts) {
styles: PropTypes.object,
// optional css imports to be added
// (must be a function which calls cb(classMap1, classMap2))
addFiles: PropTypes.func,
addStyleFiles: PropTypes.func,
};

static defaultProps = {
Expand Down Expand Up @@ -129,8 +129,15 @@ export default function themeit(opts) {
// add styles from defined themes to our styles array
styles = styles.concat(parseThemes(theme, themes));

// if addFiles is defined, push the addFiles function to the styles array
if (props.addFiles) styles.push(props.addFiles);
// if addStyleFiles is defined, push the addStyleFiles function to the styles array
if (props.addStyleFiles) styles.push(props.addStyleFiles);

// if addStyleFiles is defined, push the addStyleFiles function to the styles array
if (props.addFiles) {
console.warn("(react-themeit) 'addFiles' is deprecated and will be removed " +
"in the next major version. Use 'addStyleFiles' instead.");
styles.push(props.addFiles);
}

// if a styles object is defined in props, add it also to our styles array
if (props.styles) styles.push(props.styles);
Expand Down

0 comments on commit b5b6963

Please sign in to comment.