UNPKG

4.34 kBJavaScriptView Raw
1import _defineProperty from "@babel/runtime/helpers/defineProperty";
2import PropTypes from 'prop-types';
3import { SIZES } from './constants';
4import { isFunction, warn } from './utils';
5var 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}];
18export var sizeType = PropTypes.oneOf(SIZES);
19
20/**
21 * Allows additional warnings or messaging related to prop validation.
22 */
23export 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}
29export 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}
34export 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}
43export 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}
51export 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}
56export function highlightOnlyResultType(_ref) {
57 var allowNew = _ref.allowNew,
58 highlightOnlyResult = _ref.highlightOnlyResult;
59 warn(!(highlightOnlyResult && allowNew), '`highlightOnlyResult` will not work with `allowNew`.');
60}
61export 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}
66export function inputPropsType(_ref2) {
67 var inputProps = _ref2.inputProps;
68
69 if (!(inputProps && Object.prototype.toString.call(inputProps) === '[object Object]')) {
70 return;
71 } // Blacklisted properties.
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}
81export 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}
84export 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}
89export var optionType = PropTypes.oneOfType([PropTypes.object, PropTypes.string]);
90export 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