Skip to content

Commit eb78651

Browse files
armediSTRML
andauthored
fix(prop-types): make width and height prop conditionally required (#196)
* make width and height propType conditionally required * Invert check for clarity Co-authored-by: Samuel Reed <[email protected]>
1 parent 4bb3b3a commit eb78651

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/propTypes.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ export const resizableProps: Object = {
8888
/*
8989
* Initial height
9090
* */
91-
height: PropTypes.number.isRequired,
91+
height: (...args) => {
92+
const [props] = args;
93+
// Required if resizing height or both
94+
if (props.axis === 'both' || props.axis === 'y') {
95+
return PropTypes.number.isRequired(...args);
96+
}
97+
return PropTypes.number(...args);
98+
},
9299
/*
93100
* Customize cursor resize handle
94101
* */
@@ -141,5 +148,12 @@ export const resizableProps: Object = {
141148
/*
142149
* Initial width
143150
*/
144-
width: PropTypes.number.isRequired,
151+
width: (...args) => {
152+
const [props] = args;
153+
// Required if resizing width or both
154+
if (props.axis === 'both' || props.axis === 'x') {
155+
return PropTypes.number.isRequired(...args);
156+
}
157+
return PropTypes.number(...args);
158+
},
145159
};

0 commit comments

Comments
 (0)