1 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2 | import PropTypes from 'prop-types';
|
3 | import { SIZES } from './constants';
|
4 | import { isFunction, warn } from './utils';
|
5 | var INPUT_PROPS_BLACKLIST = [{
|
6 | alt: 'onBlur',
|
7 | prop: 'onBlur'
|
8 | }, {
|
9 | alt: 'onInputChange',
|
10 | prop: 'onChange'
|
11 | }, {
|
12 | alt: 'onFocus',
|
13 | prop: 'onFocus'
|
14 | }, {
|
15 | alt: 'onKeyDown',
|
16 | prop: 'onKeyDown'
|
17 | }];
|
18 | export var sizeType = PropTypes.oneOf(SIZES);
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export function checkPropType(validator, callback) {
|
24 | return function (props, propName, componentName) {
|
25 | PropTypes.checkPropTypes(_defineProperty({}, propName, validator), props, 'prop', componentName);
|
26 | isFunction(callback) && callback(props, propName, componentName);
|
27 | };
|
28 | }
|
29 | export function caseSensitiveType(props) {
|
30 | var caseSensitive = props.caseSensitive,
|
31 | filterBy = props.filterBy;
|
32 | warn(!caseSensitive || typeof filterBy !== 'function', 'Your `filterBy` function will override the `caseSensitive` prop.');
|
33 | }
|
34 | export function deprecated(validator, reason) {
|
35 | return function (props, propName, componentName) {
|
36 | if (props[propName] != null) {
|
37 | warn(false, "The `".concat(propName, "` prop is deprecated. ").concat(reason));
|
38 | }
|
39 |
|
40 | return PropTypes.checkPropTypes(_defineProperty({}, propName, validator), props, 'prop', componentName);
|
41 | };
|
42 | }
|
43 | export function defaultInputValueType(props) {
|
44 | var defaultInputValue = props.defaultInputValue,
|
45 | defaultSelected = props.defaultSelected,
|
46 | multiple = props.multiple,
|
47 | selected = props.selected;
|
48 | var name = defaultSelected.length ? 'defaultSelected' : 'selected';
|
49 | warn(!(!multiple && defaultInputValue && (defaultSelected.length || selected && selected.length)), "`defaultInputValue` will be overridden by the value from `".concat(name, "`."));
|
50 | }
|
51 | export function defaultSelectedType(props) {
|
52 | var defaultSelected = props.defaultSelected,
|
53 | multiple = props.multiple;
|
54 | 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.');
|
55 | }
|
56 | export function highlightOnlyResultType(_ref) {
|
57 | var allowNew = _ref.allowNew,
|
58 | highlightOnlyResult = _ref.highlightOnlyResult;
|
59 | warn(!(highlightOnlyResult && allowNew), '`highlightOnlyResult` will not work with `allowNew`.');
|
60 | }
|
61 | export function ignoreDiacriticsType(props) {
|
62 | var filterBy = props.filterBy,
|
63 | ignoreDiacritics = props.ignoreDiacritics;
|
64 | warn(ignoreDiacritics || typeof filterBy !== 'function', 'Your `filterBy` function will override the `ignoreDiacritics` prop.');
|
65 | }
|
66 | export function inputPropsType(_ref2) {
|
67 | var inputProps = _ref2.inputProps;
|
68 |
|
69 | if (!(inputProps && Object.prototype.toString.call(inputProps) === '[object Object]')) {
|
70 | return;
|
71 | }
|
72 |
|
73 |
|
74 | INPUT_PROPS_BLACKLIST.forEach(function (_ref3) {
|
75 | var alt = _ref3.alt,
|
76 | prop = _ref3.prop;
|
77 | var msg = alt ? " Use the top-level `".concat(alt, "` prop instead.") : null;
|
78 | warn(!inputProps[prop], "The `".concat(prop, "` property of `inputProps` will be ignored.").concat(msg));
|
79 | });
|
80 | }
|
81 | export function isRequiredForA11y(props, propName, componentName) {
|
82 | warn(props[propName] != null, "The prop `".concat(propName, "` is required to make `").concat(componentName, "` ") + 'accessible for users of assistive technologies such as screen readers.');
|
83 | }
|
84 | export function labelKeyType(_ref4) {
|
85 | var allowNew = _ref4.allowNew,
|
86 | labelKey = _ref4.labelKey;
|
87 | warn(!(isFunction(labelKey) && allowNew), '`labelKey` must be a string when `allowNew={true}`.');
|
88 | }
|
89 | export var optionType = PropTypes.oneOfType([PropTypes.object, PropTypes.string]);
|
90 | export function selectedType(_ref5) {
|
91 | var multiple = _ref5.multiple,
|
92 | onChange = _ref5.onChange,
|
93 | selected = _ref5.selected;
|
94 | 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.');
|
95 | warn(!selected || selected && isFunction(onChange), 'You provided a `selected` prop without an `onChange` handler. If you ' + 'want the typeahead to be uncontrolled, use `defaultSelected`. ' + 'Otherwise, set `onChange`.');
|
96 | } |
\ | No newline at end of file |