-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
import isFunction from 'lodash.isfunction' | ||
|
||
import extendReactClass from './css-modules/extendReactClass' | ||
import wrapStatelessFunction from './css-modules/wrapStatelessFunction' | ||
|
||
const isReactComponent = (maybeReactComponent) => | ||
'prototype' in maybeReactComponent && isFunction(maybeReactComponent.prototype.render) | ||
|
||
export default (styles, options) => Component => { | ||
let decoratedClass | ||
|
||
if (isReactComponent(Component)) { | ||
decoratedClass = extendReactClass(Component, styles, options) | ||
} else { | ||
decoratedClass = wrapStatelessFunction(Component, styles, options) | ||
} | ||
|
||
decoratedClass.displayName = Component.displayName || Component.name | ||
|
||
return decoratedClass | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import hoistNonReactStatics from 'hoist-non-react-statics' | ||
|
||
import linkElement from './linkElement' | ||
|
||
export default (Component, styles, options) => { | ||
class WrappedComponent extends Component { | ||
render() { | ||
const renderResult = super.render() | ||
|
||
if (renderResult) { | ||
return linkElement(renderResult, styles, options) | ||
} | ||
return renderResult | ||
} | ||
} | ||
|
||
return hoistNonReactStatics(WrappedComponent, Component) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Children, isValidElement, cloneElement } from 'react' | ||
import classNames from 'classnames/bind' | ||
|
||
const linkElement = (element, styles, options) => { | ||
const cx = classNames.bind(styles) | ||
let className | ||
let children | ||
|
||
if (isValidElement(element.props.children)) { | ||
children = linkElement(element.props.children, styles, options) | ||
} else { | ||
children = Children.map(element.props.children, (node) => { | ||
if (isValidElement(node)) { | ||
return linkElement(node, styles, options) | ||
} | ||
return node | ||
}) | ||
} | ||
|
||
if (element.props.styleName) { | ||
className = cx(element.props.styleName) | ||
|
||
if (element.props.className) { | ||
className = `${element.props.className} ${className}` | ||
} | ||
|
||
return cloneElement(element, { className }, children) | ||
} | ||
|
||
return element | ||
} | ||
|
||
export default linkElement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import linkElement from './linkElement' | ||
|
||
export default (Component, styles, options) => { | ||
const WrappedComponent = (props = {}, ...args) => { | ||
const renderResult = Component(props, ...args) | ||
|
||
if (renderResult) { | ||
return linkElement(renderResult, styles, options) | ||
} | ||
return renderResult | ||
} | ||
|
||
return WrappedComponent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters