Last active
January 25, 2018 02:09
-
-
Save Jahans3/3990f8af5c89743829ebe7d702ec7a19 to your computer and use it in GitHub Desktop.
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
// WithWrapper.js | |
const withWrapper = (Component, name) => ({ wrapper, ...props }) => { | |
if (wrapper) { | |
return ( | |
<div className={`${name}_wrapper`}> | |
<Component {...props} /> | |
</div> | |
) | |
} | |
return <Component {...props} /> | |
} | |
// Alert.js | |
import withWrapper from './withWrapper' | |
const name = 'alert' | |
const Alert = withWrapper(({ success, bar, wrapper, children }) => { | |
let CSSClass = name | |
if (success) CSSClass = CSSClass + '-success' | |
if (bar) CSSClass = CSSClass + '-bar' | |
return ( | |
<div className={CSSClass}>{children}</div> | |
) | |
}, name) | |
// SomeComponent.js | |
<Alert wrapper> | |
<Alert success bar /> | |
<Alert success bar /> | |
</Alert> | |
<Alert success bar /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment