Skip to content

Instantly share code, notes, and snippets.

@carlossaraiva
Created May 15, 2018 22:46
Show Gist options
  • Save carlossaraiva/79d816b2ed0094984b9f1b4bcbb63812 to your computer and use it in GitHub Desktop.
Save carlossaraiva/79d816b2ed0094984b9f1b4bcbb63812 to your computer and use it in GitHub Desktop.
A hoc to render components dynamically.
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