1 | import _typeof from 'babel-runtime/helpers/typeof';
|
2 | import * as PT from 'prop-types';
|
3 | import { DATE_PICKER_TYPE, DATE_INPUT_TYPE, DATE_PICKER_MODE } from './constant';
|
4 | import { datejs } from '../util';
|
5 |
|
6 | export var error = function error(propName, ComponentName) {
|
7 | return new Error('Invalid prop ' + propName + ' supplied to ' + ComponentName + '. Validation failed.');
|
8 | };
|
9 |
|
10 | function checkType(type) {
|
11 | return function (props, propName, componentName) {
|
12 | var value = props[propName];
|
13 | if (value) {
|
14 | if (!Array.isArray(value)) {
|
15 | value = [value];
|
16 | }
|
17 |
|
18 | if (!Array.isArray(type)) {
|
19 | type = [type];
|
20 | }
|
21 |
|
22 | if (!value.every(function (v) {
|
23 | return type.includes(typeof v === 'undefined' ? 'undefined' : _typeof(v));
|
24 | })) {
|
25 | throw error(propName, componentName);
|
26 | }
|
27 | }
|
28 | };
|
29 | }
|
30 |
|
31 | var SharedPT = {
|
32 | date: function date(props, propName, componentName) {
|
33 | if (propName in props && !datejs(props.propName).isValid()) {
|
34 | throw error(propName, componentName);
|
35 | }
|
36 | },
|
37 | value: function value(props, propName, componentName) {
|
38 | if (props[propName]) {
|
39 | var value = props[propName];
|
40 |
|
41 | if (props.type === DATE_PICKER_TYPE.RANGE && !Array.isArray(value)) {
|
42 | throw error(propName, componentName);
|
43 | } else if (!Array.isArray(value)) {
|
44 | value = [value];
|
45 | }
|
46 |
|
47 | if (!value.every(function (v) {
|
48 | return !v || datejs(v).isValid();
|
49 | })) {
|
50 | throw error(propName, componentName);
|
51 | }
|
52 | }
|
53 | },
|
54 |
|
55 | format: checkType(['string', 'function']),
|
56 | inputValue: checkType('string'),
|
57 | placeholder: checkType('string'),
|
58 | readOnly: checkType('boolean'),
|
59 | disabled: checkType('boolean'),
|
60 | disabledTime: checkType(['object', 'function']),
|
61 | ariaLabel: checkType('string'),
|
62 |
|
63 | render: PT.oneOfType([PT.node, PT.func]),
|
64 | mode: PT.oneOf(Object.values(DATE_PICKER_MODE)),
|
65 | type: PT.oneOf(Object.values(DATE_PICKER_TYPE)),
|
66 | inputType: PT.oneOf(Object.values(DATE_INPUT_TYPE)),
|
67 | size: PT.oneOf(['small', 'medium', 'large'])
|
68 | };
|
69 |
|
70 | export default SharedPT; |
\ | No newline at end of file |