1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 15x 15x 15x | // @flow import React, { Component } from 'react'; import values from 'ramda/src/values'; import HOC from './validation-component'; type Props = { children: any, getErrors: Function }; class DisabledOnErrors extends Component { static defaultProps = { children: null }; props: Props; render() { const { children, getErrors } = this.props; const errors = getErrors(); return React.cloneElement(children, { disabled: Boolean(values(errors).length) }); } } export default HOC(DisabledOnErrors); |