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