-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy pathvalidate-props.js
40 lines (34 loc) · 1.19 KB
/
validate-props.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import invariant from "invariant";
import warning from "warning";
import { CONTROLLED_PROPS } from "./constants";
export function validateMaxLength(props) {
warning(
!props.maxLength || !props.mask,
"react-input-mask: maxLength property shouldn't be passed to the masked input. It breaks masking and unnecessary because length is limited by the mask length."
);
}
export function validateMaskPlaceholder(props) {
const { mask, maskPlaceholder } = props;
invariant(
!mask ||
!maskPlaceholder ||
maskPlaceholder.length === 1 ||
maskPlaceholder.length === mask.length,
"react-input-mask: maskPlaceholder should either be a single character or have the same length as the mask:\n" +
`mask: ${mask}\n` +
`maskPlaceholder: ${maskPlaceholder}`
);
}
export function validateChildren(props, inputElement) {
const conflictProps = CONTROLLED_PROPS.filter(
propId =>
inputElement.props[propId] != null &&
inputElement.props[propId] !== props[propId]
);
invariant(
!conflictProps.length,
`react-input-mask: the following props should be passed to the InputMask component, not to children: ${conflictProps.join(
","
)}`
);
}