Skip to content

Commit

Permalink
EasyField support ‘passUtil’ prop
Browse files Browse the repository at this point in the history
  • Loading branch information
qiqiboy committed Aug 27, 2018
1 parent e2f725e commit 5c02ef0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/EasyField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class EasyField extends Component {
blurPropName: PropTypes.string,

$parser: PropTypes.func,
$formatter: PropTypes.func
$formatter: PropTypes.func,

passUtil: PropTypes.string
};

static defaultProps = {
Expand Down Expand Up @@ -101,6 +103,7 @@ class EasyField extends Component {
$validators,
$asyncValidators,
validMessage,
passUtil,
__TYPE__,
...otherProps
} = fieldProps;
Expand Down Expand Up @@ -215,23 +218,23 @@ class EasyField extends Component {
}
};

const childPropsUtil = { ...childProps, $fieldutil: $util };
if (passUtil) {
childProps[passUtil] = $util;
}

if (TheComponent) {
return <TheComponent {...childPropsUtil} />;
return <TheComponent {...childProps} />;
}

if (isFunction(render)) {
return render(childPropsUtil);
return render(childProps);
}

if (isFunction(children)) {
return children(childPropsUtil);
return children(childProps);
}

return Children.map(children, child =>
cloneElement(child, child && isFunction(child.type) ? childPropsUtil : childProps)
);
return Children.map(children, child => cloneElement(child, childProps));
}}
</Field>
);
Expand Down

0 comments on commit 5c02ef0

Please sign in to comment.