wix-style-react
Version:
24 lines (20 loc) • 1.2 kB
JavaScript
import PropTypes from 'prop-types';
import { StepType, MAX_STEPS, MIN_STEPS } from './constants';
export var validateStepsPropType = function validateStepsPropType(props, propName, componentName, location) {
var steps = props[propName];
var activeStep = props.activeStep;
if (Array.isArray(steps)) {
if (steps.length < MIN_STEPS || steps.length > MAX_STEPS) {
return new Error("The prop `".concat(propName, "` in `").concat(componentName, "` has to be an array with a length between ").concat(MIN_STEPS, " and ").concat(MAX_STEPS, "."));
}
if (typeof activeStep === 'number' && steps[activeStep].type === StepType.Disabled) {
return new Error("Invalid prop `".concat(propName, "[").concat(activeStep, "].type` of value `").concat(steps[activeStep].type, "` supplied to `").concat(componentName, "`. Active step cannot be disabled, will use default `").concat(StepType.Normal, "` type."));
}
} // Validate default steps array shape
PropTypes.checkPropTypes({
steps: PropTypes.arrayOf(PropTypes.shape({
text: PropTypes.string.isRequired,
type: PropTypes.oneOf(Object.values(StepType))
})).isRequired
}, props, location, componentName);
};