File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 11import React , { Component , PropTypes } from 'react' ;
2+ import { offsetMin , offsetMax } from '../utils/propValidation' ;
23
34export default class Parallax extends Component {
45
@@ -18,8 +19,8 @@ export default class Parallax extends Component {
1819 disabled : PropTypes . bool . isRequired ,
1920 offsetXMax : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
2021 offsetXMin : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
21- offsetYMax : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
22- offsetYMin : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] ) ,
22+ offsetYMax : offsetMax ,
23+ offsetYMin : offsetMin ,
2324 slowerScrollRate : PropTypes . bool . isRequired ,
2425 tag : PropTypes . string . isRequired ,
2526 } ;
Original file line number Diff line number Diff line change 1+ export function offsetMin ( props , propName , componentName ) {
2+ componentName = componentName || 'ANONYMOUS' ;
3+
4+ if ( ! typeof value === 'string' || ! typeof value === 'number' ) {
5+ return new Error ( `[${ propName } ] in ${ componentName } must be a string with with "%"" or "px" units or number` ) ;
6+ }
7+
8+ if ( props [ propName ] ) {
9+ let value = props [ propName ] ;
10+ if ( typeof value === 'string' ) {
11+ value = parseInt ( value , 10 ) ;
12+ }
13+ return value <= 0 ? null : new Error ( `[${ propName } ] in ${ componentName } is greater than zero. [${ propName } ] must be less than or equal to zero.` ) ;
14+ }
15+ return null ;
16+ }
17+
18+ export function offsetMax ( props , propName , componentName ) {
19+ componentName = componentName || 'ANONYMOUS' ;
20+
21+ if ( ! typeof value === 'string' || ! typeof value === 'number' ) {
22+ return new Error ( `[${ propName } ] in ${ componentName } must be a string with with "%"" or "px" units or number` ) ;
23+ }
24+
25+ if ( props [ propName ] ) {
26+ let value = props [ propName ] ;
27+ if ( typeof value === 'string' ) {
28+ value = parseInt ( value , 10 ) ;
29+ }
30+ return value >= 0 ? null : new Error ( `[${ propName } ] in ${ componentName } is less than zero. [${ propName } ] must be greater than or equal to zero.` ) ;
31+ }
32+ return null ;
33+ }
You can’t perform that action at this time.
0 commit comments