From bcd5f215ee45ad8e35d96c6c9e6a652b89799beb Mon Sep 17 00:00:00 2001 From: npahlfer Date: Fri, 11 Mar 2022 14:57:42 +0100 Subject: [PATCH 1/2] Adds new helper: aspectRatioType --- src/helpers/aspectRatioType.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/helpers/aspectRatioType.js 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; From 9a9f81e80a2fc6e2dd8b0559a51aafb55e78b278 Mon Sep 17 00:00:00 2001 From: npahlfer Date: Fri, 11 Mar 2022 14:58:12 +0100 Subject: [PATCH 2/2] Changes aspectRatio propType to aspectRatioType --- src/player-prop-types.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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,