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