Created
May 15, 2018 22:46
-
-
Save carlossaraiva/79d816b2ed0094984b9f1b4bcbb63812 to your computer and use it in GitHub Desktop.
A hoc to render components dynamically.
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
import React from 'react' | |
import PropTypes from 'prop-types' | |
import Wrapper from './wrapper' | |
import { Definition, Translation, Help, Normal } from './intents-templates' | |
const withIntent = Component => { | |
const Balon = ({ | |
intent = 'normal', | |
title, | |
position, | |
backgroundColor, | |
fulfillment, | |
...props | |
}) => ( | |
<Component backgroundColor={backgroundColor} title={title} position={position}> | |
{ | |
{ | |
'inquiry.help': <Help content={fulfillment.content} />, | |
'inquiry.definition': <Definition content={fulfillment.content} />, | |
'inquiry.translation': <Translation content={fulfillment.content} />, | |
normal: <Normal text={fulfillment.text} color={props.color} /> | |
}[intent] | |
} | |
</Component> | |
) | |
Balon.propTypes = { | |
color: PropTypes.string, | |
intent: PropTypes.string, | |
fulfillment: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | |
title: PropTypes.string, | |
position: PropTypes.string, | |
backgroundColor: PropTypes.string | |
} | |
return Balon | |
} | |
export const BallonWithIntent = withIntent(Wrapper) | |
export const Ballon = Wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment