Skip to content

Commit

Permalink
feat(propUtils): accept props in prop renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Jul 17, 2016
1 parent 1c1054d commit b6d9e94
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/utils/propUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,25 @@ export const getUnhandledProps = (Component, props) => {
// Many components share many props. Some of those props should be smart.
// These give all our components props consistent smart capabilities.
// ----------------------------------------
export const iconPropRenderer = (val) => _.isString(val) ? <Icon className={val} /> : val
export const imagePropRenderer = (val) => _.isString(val) ? <Image src={val} /> : val
export const iconPropRenderer = (val, props = {}) => {
if (_.isString(val)) {
return <Icon {...props} className={val} />
}

if (_.isObject(val)) {
return React.cloneElement(val, { ...val.props, ...props })
}
}

export const imagePropRenderer = (val, props = {}) => {
if (_.isString(val)) {
return <Image {...props} src={val} />
}

if (_.isObject(val)) {
return React.cloneElement(val, { ...val.props, ...props })
}
}

// ----------------------------------------
// Prop to className
Expand Down

0 comments on commit b6d9e94

Please sign in to comment.