react-reflex-grid
Version:
React implementation for Reflex-Grid library.
22 lines (16 loc) • 674 B
JavaScript
const checker = /^(xs|sm|md|lg|xlg)-\d{1,2}$/;
export default function responsiveOrderValidator(props, propName, componentName) {
const propValue = props[propName];
if (!propValue) {
return;
}
if (typeof propValue !== 'string') {
return new Error(`${propName} should be String!`);
}
const breakpoints = propValue.split(',').map((bp) => bp.trim());
const isValid = breakpoints.every(bp => checker.test(bp));
if (!isValid) {
const failedValue = breakpoints.find(bp => !checker.test(bp));
return new Error(`${failedValue} is not valid value for property ${propName} of ${componentName} component!`);
}
}