Skip to content

Commit 8ba8c69

Browse files
authored
Merge pull request javivelasco#27 from raveclassic/filter_themr_props
Filter themr props
2 parents 3c91ccc + 26aac97 commit 8ba8c69

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/components/themr.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
2727
/**
2828
* Themr decorator
2929
* @param {String|Number|Symbol} componentName - Component name
30-
* @param {TReactCSSThemrTheme} localTheme - Base theme
31-
* @param {{}} options - Themr options
30+
* @param {TReactCSSThemrTheme} [localTheme] - Base theme
31+
* @param {{}} [options] - Themr options
3232
* @returns {function(ThemedComponent:Function):Function} - ThemedComponent
3333
*/
3434
export default (componentName, localTheme, options = {}) => (ThemedComponent) => {
@@ -46,6 +46,9 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
4646
localTheme
4747
}
4848

49+
/**
50+
* @property {{wrappedInstance: *}} refs
51+
*/
4952
class Themed extends Component {
5053
static displayName = `Themed${ThemedComponent.name}`;
5154

@@ -134,16 +137,19 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
134137

135138
render() {
136139
let renderedElement
140+
//exclude themr-only props
141+
//noinspection JSUnusedLocalSymbols
142+
const { composeTheme, themeNamespace, ...props } = this.props //eslint-disable-line no-unused-vars
137143

138144
if (optionWithRef) {
139145
renderedElement = React.createElement(ThemedComponent, {
140-
...this.props,
146+
...props,
141147
ref: 'wrappedInstance',
142148
theme: this.theme_
143149
})
144150
} else {
145151
renderedElement = React.createElement(ThemedComponent, {
146-
...this.props,
152+
...props,
147153
theme: this.theme_
148154
})
149155
}
@@ -159,8 +165,8 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
159165

160166
/**
161167
* Merges two themes by concatenating values with the same keys
162-
* @param {TReactCSSThemrTheme} original - Original theme object
163-
* @param {TReactCSSThemrTheme} mixin - Mixing theme object
168+
* @param {TReactCSSThemrTheme} [original] - Original theme object
169+
* @param {TReactCSSThemrTheme} [mixin] - Mixing theme object
164170
* @returns {TReactCSSThemrTheme} - Merged resulting theme
165171
*/
166172
export function themeable(original = {}, mixin) {

test/components/themr.spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { themr, themeable } from '../../src/index'
99
describe('Themr decorator function', () => {
1010
class Passthrough extends Component {
1111
render() {
12-
return <div {...this.props} />
12+
const { theme, ...props } = this.props //eslint-disable-line no-unused-vars
13+
return <div {...props} />
1314
}
1415
}
1516

@@ -495,6 +496,25 @@ describe('Themr decorator function', () => {
495496
expect(spy.callCount === 4).toBe(true)
496497
}
497498
)
499+
500+
it('should not pass internal themr props to WrappedComponent', () => {
501+
@themr('Container')
502+
class Container extends Component {
503+
render() {
504+
return <Passthrough {...this.props} />
505+
}
506+
}
507+
508+
const tree = TestUtils.renderIntoDocument(
509+
<Container/>
510+
)
511+
512+
const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
513+
// expect(stub.props.theme).toEqual(containerTheme)
514+
expect(stub.props.themeNamespace).toNotExist()
515+
expect(stub.props.composeTheme).toNotExist()
516+
expect(stub.props.theme).toExist()
517+
})
498518
})
499519

500520
describe('themeable function', () => {

0 commit comments

Comments
 (0)