Skip to content
Merged
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
18 changes: 12 additions & 6 deletions src/components/themr.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
/**
* Themr decorator
* @param {String|Number|Symbol} componentName - Component name
* @param {TReactCSSThemrTheme} localTheme - Base theme
* @param {{}} options - Themr options
* @param {TReactCSSThemrTheme} [localTheme] - Base theme
* @param {{}} [options] - Themr options
* @returns {function(ThemedComponent:Function):Function} - ThemedComponent
*/
export default (componentName, localTheme, options = {}) => (ThemedComponent) => {
Expand All @@ -46,6 +46,9 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
localTheme
}

/**
* @property {{wrappedInstance: *}} refs
*/
class Themed extends Component {
static displayName = `Themed${ThemedComponent.name}`;

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

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

if (optionWithRef) {
renderedElement = React.createElement(ThemedComponent, {
...this.props,
...props,
ref: 'wrappedInstance',
theme: this.theme_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why theme prop itself is not a problem?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost everywhere it is extracted: const {theme, ...props} = this.props; return <input {...props}/>;

})
} else {
renderedElement = React.createElement(ThemedComponent, {
...this.props,
...props,
theme: this.theme_
})
}
Expand All @@ -159,8 +165,8 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>

/**
* Merges two themes by concatenating values with the same keys
* @param {TReactCSSThemrTheme} original - Original theme object
* @param {TReactCSSThemrTheme} mixin - Mixing theme object
* @param {TReactCSSThemrTheme} [original] - Original theme object
* @param {TReactCSSThemrTheme} [mixin] - Mixing theme object
* @returns {TReactCSSThemrTheme} - Merged resulting theme
*/
export function themeable(original = {}, mixin) {
Expand Down
22 changes: 21 additions & 1 deletion test/components/themr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { themr, themeable } from '../../src/index'
describe('Themr decorator function', () => {
class Passthrough extends Component {
render() {
return <div {...this.props} />
const { theme, ...props } = this.props //eslint-disable-line no-unused-vars
return <div {...props} />
}
}

Expand Down Expand Up @@ -495,6 +496,25 @@ describe('Themr decorator function', () => {
expect(spy.callCount === 4).toBe(true)
}
)

it('should not pass internal themr props to WrappedComponent', () => {
@themr('Container')
class Container extends Component {
render() {
return <Passthrough {...this.props} />
}
}

const tree = TestUtils.renderIntoDocument(
<Container/>
)

const stub = TestUtils.findRenderedComponentWithType(tree, Passthrough)
// expect(stub.props.theme).toEqual(containerTheme)
expect(stub.props.themeNamespace).toNotExist()
expect(stub.props.composeTheme).toNotExist()
expect(stub.props.theme).toExist()
})
})

describe('themeable function', () => {
Expand Down