diff --git a/src/helpers/aspectRatioType.js b/src/helpers/aspectRatioType.js new file mode 100644 index 00000000..452c83e1 --- /dev/null +++ b/src/helpers/aspectRatioType.js @@ -0,0 +1,28 @@ +function aspectRatioType(props, propName, componentName = 'ANONYMOUS') { + if (props[propName]) { + const value = props[propName]; + + if (typeof value === 'string') { + const vList = value.split(':'); + + if ( + value === 'inherit' || + (vList.length === 2 && !isNaN(Number(vList[0])) && !isNaN(Number(vList[1]))) + ) { + return null; + } + + return new Error( + `Invalid prop \`${propName}\` of value \`${value}\` supplied to ${componentName}, expected a value of \`Number:Number\``, + ); + } + + return new Error( + `Invalid prop \`${propName}\` of type ${typeof value} supplied to ${componentName}, expected a value of type \`string\``, + ); + } + + return null; +} + +export default aspectRatioType; diff --git a/src/player-prop-types.js b/src/player-prop-types.js index de82be6f..13b38981 100644 --- a/src/player-prop-types.js +++ b/src/player-prop-types.js @@ -1,7 +1,8 @@ import PropTypes from 'prop-types'; +import aspectRatioType from './helpers/aspectRatioType'; const propTypes = { - aspectRatio: PropTypes.oneOf(['inherit', '1:1', '16:9']), + aspectRatio: aspectRatioType, className: PropTypes.string, customProps: PropTypes.object, file: PropTypes.string,