1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.checkPropType = checkPropType;
|
9 | exports.caseSensitiveType = caseSensitiveType;
|
10 | exports.deprecated = deprecated;
|
11 | exports.defaultInputValueType = defaultInputValueType;
|
12 | exports.defaultSelectedType = defaultSelectedType;
|
13 | exports.highlightOnlyResultType = highlightOnlyResultType;
|
14 | exports.ignoreDiacriticsType = ignoreDiacriticsType;
|
15 | exports.inputPropsType = inputPropsType;
|
16 | exports.isRequiredForA11y = isRequiredForA11y;
|
17 | exports.labelKeyType = labelKeyType;
|
18 | exports.selectedType = selectedType;
|
19 | exports.optionType = exports.sizeType = void 0;
|
20 |
|
21 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
22 |
|
23 | var _utils = require("./utils");
|
24 |
|
25 | var _constants = require("./constants");
|
26 |
|
27 | var INPUT_PROPS_BLACKLIST = [{
|
28 | alt: 'onBlur',
|
29 | prop: 'onBlur'
|
30 | }, {
|
31 | alt: 'onInputChange',
|
32 | prop: 'onChange'
|
33 | }, {
|
34 | alt: 'onFocus',
|
35 | prop: 'onFocus'
|
36 | }, {
|
37 | alt: 'onKeyDown',
|
38 | prop: 'onKeyDown'
|
39 | }];
|
40 |
|
41 | var sizeType = _propTypes["default"].oneOf((0, _utils.values)(_constants.SIZE));
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | exports.sizeType = sizeType;
|
48 |
|
49 | function checkPropType(validator, callback) {
|
50 | return function (props, propName, componentName) {
|
51 | var _PropTypes$checkPropT;
|
52 |
|
53 | _propTypes["default"].checkPropTypes((_PropTypes$checkPropT = {}, _PropTypes$checkPropT[propName] = validator, _PropTypes$checkPropT), props, 'prop', componentName);
|
54 |
|
55 | (0, _utils.isFunction)(callback) && callback(props, propName, componentName);
|
56 | };
|
57 | }
|
58 |
|
59 | function caseSensitiveType(props, propName, componentName) {
|
60 | var caseSensitive = props.caseSensitive,
|
61 | filterBy = props.filterBy;
|
62 | (0, _utils.warn)(!caseSensitive || typeof filterBy !== 'function', 'Your `filterBy` function will override the `caseSensitive` prop.');
|
63 | }
|
64 |
|
65 | function deprecated(validator, reason) {
|
66 | return function (props, propName, componentName) {
|
67 | var _PropTypes$checkPropT2;
|
68 |
|
69 | if (props[propName] != null) {
|
70 | (0, _utils.warn)(false, "The `" + propName + "` prop is deprecated. " + reason);
|
71 | }
|
72 |
|
73 | return _propTypes["default"].checkPropTypes((_PropTypes$checkPropT2 = {}, _PropTypes$checkPropT2[propName] = validator, _PropTypes$checkPropT2), props, 'prop', componentName);
|
74 | };
|
75 | }
|
76 |
|
77 | function defaultInputValueType(props, propName, componentName) {
|
78 | var defaultInputValue = props.defaultInputValue,
|
79 | defaultSelected = props.defaultSelected,
|
80 | multiple = props.multiple,
|
81 | selected = props.selected;
|
82 | var name = defaultSelected.length ? 'defaultSelected' : 'selected';
|
83 | (0, _utils.warn)(!(!multiple && defaultInputValue && (defaultSelected.length || selected && selected.length)), "`defaultInputValue` will be overridden by the value from `" + name + "`.");
|
84 | }
|
85 |
|
86 | function defaultSelectedType(props, propName, componentName) {
|
87 | var defaultSelected = props.defaultSelected,
|
88 | multiple = props.multiple;
|
89 | (0, _utils.warn)(multiple || defaultSelected.length <= 1, 'You are passing multiple options to the `defaultSelected` prop of a ' + 'Typeahead in single-select mode. The selections will be truncated to a ' + 'single selection.');
|
90 | }
|
91 |
|
92 | function highlightOnlyResultType(props, propName, componentName) {
|
93 | var allowNew = props.allowNew,
|
94 | highlightOnlyResult = props.highlightOnlyResult;
|
95 | (0, _utils.warn)(!(highlightOnlyResult && allowNew), '`highlightOnlyResult` will not work with `allowNew`.');
|
96 | }
|
97 |
|
98 | function ignoreDiacriticsType(props, propName, componentName) {
|
99 | var filterBy = props.filterBy,
|
100 | ignoreDiacritics = props.ignoreDiacritics;
|
101 | (0, _utils.warn)(ignoreDiacritics || typeof filterBy !== 'function', 'Your `filterBy` function will override the `ignoreDiacritics` prop.');
|
102 | }
|
103 |
|
104 | function inputPropsType(props, propName, componentName) {
|
105 | var inputProps = props.inputProps;
|
106 |
|
107 | if (!(inputProps && Object.prototype.toString.call(inputProps) === '[object Object]')) {
|
108 | return;
|
109 | }
|
110 |
|
111 |
|
112 | INPUT_PROPS_BLACKLIST.forEach(function (_ref) {
|
113 | var alt = _ref.alt,
|
114 | prop = _ref.prop;
|
115 | var msg = alt ? " Use the top-level `" + alt + "` prop instead." : null;
|
116 | (0, _utils.warn)(!inputProps[prop], "The `" + prop + "` property of `inputProps` will be ignored." + msg);
|
117 | });
|
118 | }
|
119 |
|
120 | function isRequiredForA11y(props, propName, componentName) {
|
121 | (0, _utils.warn)(props[propName] != null, "The prop `" + propName + "` is required to make `" + componentName + "` " + 'accessible for users of assistive technologies such as screen readers.');
|
122 | }
|
123 |
|
124 | function labelKeyType(props, propName, componentName) {
|
125 | var allowNew = props.allowNew,
|
126 | labelKey = props.labelKey;
|
127 | (0, _utils.warn)(!((0, _utils.isFunction)(labelKey) && allowNew), '`labelKey` must be a string when `allowNew={true}`.');
|
128 | }
|
129 |
|
130 | var optionType = _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].string]);
|
131 |
|
132 | exports.optionType = optionType;
|
133 |
|
134 | function selectedType(props, propName, componentName) {
|
135 | var multiple = props.multiple,
|
136 | onChange = props.onChange,
|
137 | selected = props.selected;
|
138 | (0, _utils.warn)(multiple || !selected || selected.length <= 1, 'You are passing multiple options to the `selected` prop of a Typeahead ' + 'in single-select mode. This may lead to unexpected behaviors or errors.');
|
139 | (0, _utils.warn)(!selected || selected && (0, _utils.isFunction)(onChange), 'You provided a `selected` prop without an `onChange` handler. If you ' + 'want the typeahead to be uncontrolled, use `defaultSelected`. ' + 'Otherwise, set `onChange`.');
|
140 | } |
\ | No newline at end of file |