Skip to content

Commit

Permalink
Merge ba16fa1 into ded4545
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor authored Aug 20, 2017
2 parents ded4545 + ba16fa1 commit 634fa84
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
},
"dependencies": {
"brcast": "^2.0.0",
"hoist-non-react-statics": "^2.3.0",
"is-function": "^1.0.1",
"is-plain-object": "^2.0.1",
"prop-types": "^15.5.8",
Expand Down
8 changes: 7 additions & 1 deletion src/create-with-theme.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import channel from './channel';
import createThemeListener from './create-theme-listener';
import hoist from 'hoist-non-react-statics';

const getDisplayName = Component =>
Component.displayName || Component.name || 'Component';

export default function createWithTheme(CHANNEL = channel) {
const themeListener = createThemeListener(CHANNEL);
return Component =>
return Component => {
class WithTheme extends React.Component {
static displayName = `WithTheme(${getDisplayName(Component)})`;
static contextTypes = themeListener.contextTypes;
Expand All @@ -31,4 +32,9 @@ export default function createWithTheme(CHANNEL = channel) {
return <Component theme={theme} {...this.props} />;
}
};

hoist(WithTheme, Component);

return WithTheme;
}
}
23 changes: 23 additions & 0 deletions src/create-with-theme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,26 @@ test(`withTheme(Comp) receives theme updates even through PureComponent`, t => {
`withTheme(Comp) should receive theme updates even through PureComponent`,
);
});

test(`withTheme(Comp) hoists non-react static class properties`, t => {
const withTheme = createWithTheme();

class ExampleComponent extends Component {
static displayName = 'foo';
static someSpecialStatic = 'bar';
}

const ComponentWithTheme = withTheme(ExampleComponent);

t.deepEqual(
ComponentWithTheme.displayName,
'WithTheme(foo)',
`withTheme(Comp) should not hoist react static properties`,
);

t.deepEqual(
ComponentWithTheme.someSpecialStatic,
ExampleComponent.someSpecialStatic,
`withTheme(Comp) should hoist non-react static properties`,
);
});

0 comments on commit 634fa84

Please sign in to comment.