import React, {Component} from 'react';
import {View} from "react-native";
import {UIText} from "../../../../components";
import PropTypes from "prop-types";
class PropTypesComponent extends Component {
static propTypes = {
test1: PropTypes.array,
test2: PropTypes.bool,
test3: PropTypes.func,
test4: PropTypes.number,
test5: PropTypes.object,
test6: PropTypes.string,
test7: PropTypes.symbol,
test8: PropTypes.any,
test9: PropTypes.arrayOf(PropTypes.number),
test10: PropTypes.element,
test11: PropTypes.instanceOf(PropTypesComponent),
test111: PropTypes.node,
test12: PropTypes.objectOf(PropTypes.number),
test13: PropTypes.oneOf(['value1', 'value2']),
test14: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.number,
PropTypes.instanceOf(PropTypesComponent),
]),
test15: PropTypes.shape({
color: PropTypes.string,
fontSize: PropTypes.number,
}),
optionalObjectWithStrictShape: PropTypes.exact({
optionalProperty: PropTypes.string,
requiredProperty: PropTypes.number.isRequired
}),
A: PropTypes.string,
B(props) {
if (!props.A && !props.B) {
throw new Error('there is no "A", "B" is required')
}
if (typeof props.B !== "string") {
throw new Error('"B" required "string"')
}
},
customProp: function (props, propName, componentName) {
if (!/matchme/.test(props[propName])) {
return new Error(
'Invalid prop `' + propName + '` supplied to' +
' `' + componentName + '`. Validation failed.'
);
}
},
customArrayProp: PropTypes.arrayOf(function (propValue, key, componentName, location, propFullName) {
if (!/matchme/.test(propValue[key])) {
return new Error(
'Invalid prop `' + propFullName + '` supplied to' +
' `' + componentName + '`. Validation failed.'
);
}
}),
};
static defaultProps = {
test4: 20,
A: '20',
B: '20',
};
render() {
const {test4, A} = this.props;
return (
<View>
<UIText children={test4 + ''}/>
<UIText children={A + ''}/>
</View>
);
}
}
PropTypesComponent.propTypes = {
...PropTypesComponent.propTypes,
C: PropTypes.number
}
export default PropTypesComponent