@mackin.com/styleguide 7.9.0 → 7.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +2 -0
- package/index.js +16 -12
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ interface AutocompleteProps {
|
|
|
27
27
|
/** The minimum characters before 'getOptions' is called. No default. */
|
|
28
28
|
minChars?: number;
|
|
29
29
|
inputAriaAttributes?: React.AriaAttributes;
|
|
30
|
+
/** Defaults to 0ms. */
|
|
31
|
+
getOptionsDebounceMs?: number;
|
|
30
32
|
onChange: (value: string) => void;
|
|
31
33
|
getOptions: (value: string) => Promise<AutocompleteValue[]>;
|
|
32
34
|
onPick: (value: AutocompleteValue) => void;
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
3
|
var css = require('@emotion/css');
|
|
4
|
+
var lodash = require('lodash');
|
|
4
5
|
var React = require('react');
|
|
5
6
|
var nanoid = require('nanoid');
|
|
6
7
|
var proRegularSvgIcons = require('@fortawesome/pro-regular-svg-icons');
|
|
@@ -8,7 +9,6 @@ var proSolidSvgIcons = require('@fortawesome/pro-solid-svg-icons');
|
|
|
8
9
|
var proLightSvgIcons = require('@fortawesome/pro-light-svg-icons');
|
|
9
10
|
var reactFontawesome = require('@fortawesome/react-fontawesome');
|
|
10
11
|
var dateFns = require('date-fns');
|
|
11
|
-
var lodash = require('lodash');
|
|
12
12
|
var reactDom = require('react-dom');
|
|
13
13
|
var reactTinyPopover = require('react-tiny-popover');
|
|
14
14
|
var reactRouterDom = require('react-router-dom');
|
|
@@ -877,6 +877,7 @@ const getAutocompleteValueId = (v) => {
|
|
|
877
877
|
};
|
|
878
878
|
//TB: will need to use the new input
|
|
879
879
|
const Autocomplete = (p) => {
|
|
880
|
+
var _a;
|
|
880
881
|
const element = React__namespace.useRef(null);
|
|
881
882
|
const input = React__namespace.useRef(null);
|
|
882
883
|
const list = React__namespace.useRef(null);
|
|
@@ -886,6 +887,19 @@ const Autocomplete = (p) => {
|
|
|
886
887
|
var _a;
|
|
887
888
|
return values.slice(0, (_a = p.maxShownValues) !== null && _a !== void 0 ? _a : DEFAULT_MAX_SHOWN_VALUES);
|
|
888
889
|
}, [values]);
|
|
890
|
+
const onChangeForOptions = React__namespace.useRef(lodash.debounce((value) => {
|
|
891
|
+
if (!p.minChars || value.length >= p.minChars) {
|
|
892
|
+
p.getOptions(value)
|
|
893
|
+
.then(vals => {
|
|
894
|
+
setValues(vals);
|
|
895
|
+
}).catch(err => {
|
|
896
|
+
// ignore it
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
else {
|
|
900
|
+
setValues([]);
|
|
901
|
+
}
|
|
902
|
+
}, (_a = p.getOptionsDebounceMs) !== null && _a !== void 0 ? _a : 0, { leading: true, trailing: true }));
|
|
889
903
|
const theme = useThemeSafely();
|
|
890
904
|
const baseClass = css.css `
|
|
891
905
|
label: Autocomplete;
|
|
@@ -949,17 +963,7 @@ const Autocomplete = (p) => {
|
|
|
949
963
|
React__namespace.createElement(Input, { inputAriaAttributes: p.inputAriaAttributes, ref: input, debounceMs: 0, type: "text", value: getAutocompleteValueText(p.value), round: p.round, rounded: p.rounded, rightControl: p.rightControl, placeholder: p.placeholder, id: p.id, disabled: p.disabled, className: p.className, inputClassName: css.cx(inputClass, p.inputClassName), maxLength: p.maxLength, required: p.required, onChange: v => {
|
|
950
964
|
const value = v;
|
|
951
965
|
p.onChange(value);
|
|
952
|
-
|
|
953
|
-
p.getOptions(value)
|
|
954
|
-
.then(vals => {
|
|
955
|
-
setValues(vals);
|
|
956
|
-
}).catch(err => {
|
|
957
|
-
// ignore it
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
else {
|
|
961
|
-
setValues([]);
|
|
962
|
-
}
|
|
966
|
+
onChangeForOptions.current(value);
|
|
963
967
|
}, onKeyDown: e => {
|
|
964
968
|
var _a, _b;
|
|
965
969
|
if (showValues) {
|