I tried customProp. I got something like this:
function propTypeXOR(propType,excludedProps,includedProps){ return(props, propName, componentName) =>{ if(props[propName]){ if(typeof props[propName] !== propType){ return new Error("Failed propType: Invalid prop `"+propName+"` of type `"+propType+"` supplied to `"+componentName+"`, expected `number`"); }else{ excludedProps.map((excludedPropName) =>{ if(props[excludedPropName]){ return new Error("forbidden prop `"+excludedPropName+"` was specified in `"+componentName+"` when using the prop `"+propName+"`"); } }) if(includedProps){ includedProps.map((includedPropName) =>{ if(props[includedPropName]){ return new Error("required prop `"+includedPropName+"` was not specified in `"+componentName+"` when using the prop `"+propName+"`"); } }) } } }else{ if(excludedProps){ var error = ""; excludedProps.map((excludedPropName) =>{ if(!props[excludedPropName]){ error+="`"+excludedPropName+"`,"; } }) if(error!=""){ return new Error("required prop `"+propName+"` was not specified in `"+componentName+"`.It is required when props ["+error+"] are not defined."); } } } } } ResponsiveTable.propTypes = { width: propTypeXOR("number",["widthOffset","minWidth"]), widthOffset: propTypeXOR("number",["width"],["minWidth"]), minWidth: propTypeXOR("number",["width"],["widthOffset"]) };
It works: the user must declare either with width, or with widthOffset and minWidth. But I think that a more integrated solution will facilitate the announcement and improve the error that has occurred.
I post github responsiveness
source share