@mackin.com/styleguide 9.1.0 → 9.2.2
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 +39 -1
- package/index.js +124 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1090,4 +1090,42 @@ declare const TabContainer: (p: TabContainerProps) => JSX.Element;
|
|
|
1090
1090
|
/** Add to fixed positioned elements so their contents do not jump around when scrolling is disabled. */
|
|
1091
1091
|
declare const modalScrollFixClassName = "modal-scroll-fix";
|
|
1092
1092
|
|
|
1093
|
-
|
|
1093
|
+
interface AutoCompleteConfig {
|
|
1094
|
+
/** Number of characters entered before getOptions is called. Defaults to 3. */
|
|
1095
|
+
minChars?: number;
|
|
1096
|
+
/** Number of ms to debounce prior to calling getOptions on change. Defaults to no debounce. */
|
|
1097
|
+
debounceMs?: number;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
declare class AutocompleteController {
|
|
1101
|
+
constructor(getOptions: (value: string | undefined) => Promise<string[]>, config?: AutoCompleteConfig);
|
|
1102
|
+
get value(): string | undefined;
|
|
1103
|
+
get options(): string[];
|
|
1104
|
+
onChange(newValue: string | undefined): Promise<void>;
|
|
1105
|
+
onPick(newValue: string | undefined): void;
|
|
1106
|
+
private readonly getOptions;
|
|
1107
|
+
private readonly _minChars;
|
|
1108
|
+
private _value;
|
|
1109
|
+
private _options;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/** Extracted logic around autocomplete functionality for Autocomplete.tsx that supports Entity (id/name) mapping. */
|
|
1113
|
+
declare class AutocompleteEntityController<T extends string | number> {
|
|
1114
|
+
constructor(getOptions: (value: string | undefined) => Promise<Entity<T>[]>, config?: AutoCompleteConfig);
|
|
1115
|
+
get entity(): Entity<T> | undefined;
|
|
1116
|
+
get entities(): Entity<T>[];
|
|
1117
|
+
get value(): string | undefined;
|
|
1118
|
+
get options(): string[];
|
|
1119
|
+
onChange(newValue: string | undefined): Promise<void>;
|
|
1120
|
+
onPick(newValue: string | undefined): void;
|
|
1121
|
+
private _ctrl;
|
|
1122
|
+
private _pickedEntity;
|
|
1123
|
+
private _options;
|
|
1124
|
+
private trySyncCtrlOptions;
|
|
1125
|
+
}
|
|
1126
|
+
interface Entity<T extends string | number> {
|
|
1127
|
+
id: T;
|
|
1128
|
+
name: string;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
export { Accordian, AccordianProps, Alignment, Autocomplete, AutocompleteController, AutocompleteEntityController, AutocompleteProps, Backdrop$1 as Backdrop, Backdrop as Backdrop2, BoundMemoryPager, BoundStaticPager, Button, ButtonProps, Calendar, CalendarProps, Checkbox, CheckboxProps, ConfirmModal, ConfirmModalProps, CopyButton, DateInput, DateInputProps, Divider, ErrorModal, FileUploader, Form, FormColumnRow, FormFlexRow, FormProps, GlobalStyles, Header, Highlight, ICONS, Icon, Image, ImageProps, InfoPanel, InfoTip, InfoTipProps, ItemPager, Label, LabelProps, Link, LinkProps, List, ListItem, ListItemProps, ListProps, MackinTheme, Modal, ModalProps, Nav, NormalizeCss, NumberInput, NumberInputProps, OmniLink, OmniLinkProps, PagedResult, Pager, PagerProps, Picker, PickerOption, PickerProps, PickerValue, Popover, ProgressBar, ProgressBarProps, SearchBox, SearchBoxProps, Slider, SliderProps, SliderValue, TabContainer, TabContainerProps, TabHeader, TabHeaderProps, TabLocker, Table, Td, TdCurrency, TdNumber, Text, TextArea, TextAreaProps, TextInput, TextInputProps, TextProps, Th, ThSort, ThemeProvider, ThemeRenderer, ToggleButton, ToggleButtonGroup, ToggleButtonGroupProps, ToggleButtonProps, TogglePasswordInput, Tr, WaitingIndicator, calcDynamicThemeProps, defaultTheme, enumToEntities, getCurrencyDisplay, getFileSizeDisplay, modalScrollFixClassName, useAccordianState, useBooleanChanged, useIgnoreMount, useMediaQuery, useScrollbarSize, useThemeSafely, useWaiting };
|
package/index.js
CHANGED
|
@@ -4655,8 +4655,132 @@ const TabContainer = (p) => {
|
|
|
4655
4655
|
}), p.contentClassName) }, p.tabs[tabIndex].getContent())));
|
|
4656
4656
|
};
|
|
4657
4657
|
|
|
4658
|
+
const defaultMinChars = 3;
|
|
4659
|
+
class AutocompleteController {
|
|
4660
|
+
constructor(getOptions, config) {
|
|
4661
|
+
var _a;
|
|
4662
|
+
this._value = undefined;
|
|
4663
|
+
this._options = [];
|
|
4664
|
+
this._minChars = (_a = config === null || config === void 0 ? void 0 : config.minChars) !== null && _a !== void 0 ? _a : defaultMinChars;
|
|
4665
|
+
if (config === null || config === void 0 ? void 0 : config.debounceMs) {
|
|
4666
|
+
this.getOptions = createDebouncedPromise(getOptions, config === null || config === void 0 ? void 0 : config.debounceMs);
|
|
4667
|
+
}
|
|
4668
|
+
else {
|
|
4669
|
+
this.getOptions = getOptions;
|
|
4670
|
+
}
|
|
4671
|
+
}
|
|
4672
|
+
get value() {
|
|
4673
|
+
return this._value;
|
|
4674
|
+
}
|
|
4675
|
+
get options() {
|
|
4676
|
+
return this._options;
|
|
4677
|
+
}
|
|
4678
|
+
async onChange(newValue) {
|
|
4679
|
+
// don't make getOptions calls if the value hasn't changed.
|
|
4680
|
+
if (newValue === this.value) {
|
|
4681
|
+
return;
|
|
4682
|
+
}
|
|
4683
|
+
// nullish should not make the getOptions call and instead clear everything.
|
|
4684
|
+
if (!newValue) {
|
|
4685
|
+
this._value = newValue;
|
|
4686
|
+
this._options = [];
|
|
4687
|
+
return;
|
|
4688
|
+
}
|
|
4689
|
+
// sub min chars should clear everything and not attempt the getOptions call.
|
|
4690
|
+
if (newValue.length < this._minChars) {
|
|
4691
|
+
this._value = newValue;
|
|
4692
|
+
this._options = [];
|
|
4693
|
+
return;
|
|
4694
|
+
}
|
|
4695
|
+
try {
|
|
4696
|
+
this._value = newValue;
|
|
4697
|
+
this._options = (await this.getOptions(newValue));
|
|
4698
|
+
}
|
|
4699
|
+
catch (err) {
|
|
4700
|
+
// this method will throw errors on debounce rejections. that is to be expected.
|
|
4701
|
+
// for actual getOptions exceptions, the owner of that function will need to handle errors.
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
onPick(newValue) {
|
|
4705
|
+
this._value = newValue;
|
|
4706
|
+
this._options = [];
|
|
4707
|
+
}
|
|
4708
|
+
}
|
|
4709
|
+
const createDebouncedPromise = (originalFunction, trailingTimeoutMs) => {
|
|
4710
|
+
let timer;
|
|
4711
|
+
let onCancel;
|
|
4712
|
+
return (value) => {
|
|
4713
|
+
if (timer) {
|
|
4714
|
+
clearTimeout(timer);
|
|
4715
|
+
}
|
|
4716
|
+
if (onCancel) {
|
|
4717
|
+
onCancel('Promise cancelled due to in-progress debounce call.');
|
|
4718
|
+
onCancel = undefined;
|
|
4719
|
+
}
|
|
4720
|
+
return new Promise((res, rej) => {
|
|
4721
|
+
onCancel = rej;
|
|
4722
|
+
timer = setTimeout(() => {
|
|
4723
|
+
originalFunction(value)
|
|
4724
|
+
.then(values => {
|
|
4725
|
+
res(values);
|
|
4726
|
+
})
|
|
4727
|
+
.catch(err => {
|
|
4728
|
+
rej(err);
|
|
4729
|
+
})
|
|
4730
|
+
.finally(() => {
|
|
4731
|
+
clearTimeout(timer);
|
|
4732
|
+
});
|
|
4733
|
+
}, trailingTimeoutMs);
|
|
4734
|
+
});
|
|
4735
|
+
};
|
|
4736
|
+
};
|
|
4737
|
+
|
|
4738
|
+
/** Extracted logic around autocomplete functionality for Autocomplete.tsx that supports Entity (id/name) mapping. */
|
|
4739
|
+
class AutocompleteEntityController {
|
|
4740
|
+
constructor(getOptions, config) {
|
|
4741
|
+
this._options = [];
|
|
4742
|
+
const getStringOptions = async (value) => {
|
|
4743
|
+
this._options = await getOptions(value);
|
|
4744
|
+
return this._options.map(o => o.name);
|
|
4745
|
+
};
|
|
4746
|
+
this._ctrl = new AutocompleteController(getStringOptions, config);
|
|
4747
|
+
}
|
|
4748
|
+
get entity() {
|
|
4749
|
+
return this._pickedEntity;
|
|
4750
|
+
}
|
|
4751
|
+
get entities() {
|
|
4752
|
+
return this._options;
|
|
4753
|
+
}
|
|
4754
|
+
get value() {
|
|
4755
|
+
return this._ctrl.value;
|
|
4756
|
+
}
|
|
4757
|
+
get options() {
|
|
4758
|
+
return this._options.map(o => o.name);
|
|
4759
|
+
}
|
|
4760
|
+
async onChange(newValue) {
|
|
4761
|
+
const clearEntity = newValue !== this._ctrl.value;
|
|
4762
|
+
await this._ctrl.onChange(newValue);
|
|
4763
|
+
if (clearEntity) {
|
|
4764
|
+
this._pickedEntity = undefined;
|
|
4765
|
+
}
|
|
4766
|
+
this.trySyncCtrlOptions();
|
|
4767
|
+
}
|
|
4768
|
+
onPick(newValue) {
|
|
4769
|
+
this._ctrl.onPick(newValue);
|
|
4770
|
+
this._pickedEntity = this._options.find(o => o.name === this._ctrl.value);
|
|
4771
|
+
this.trySyncCtrlOptions();
|
|
4772
|
+
}
|
|
4773
|
+
trySyncCtrlOptions() {
|
|
4774
|
+
if (!this._ctrl.options.length) {
|
|
4775
|
+
this._options = [];
|
|
4776
|
+
}
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
|
|
4658
4780
|
exports.Accordian = Accordian;
|
|
4659
4781
|
exports.Autocomplete = Autocomplete;
|
|
4782
|
+
exports.AutocompleteController = AutocompleteController;
|
|
4783
|
+
exports.AutocompleteEntityController = AutocompleteEntityController;
|
|
4660
4784
|
exports.Backdrop = Backdrop$1;
|
|
4661
4785
|
exports.Backdrop2 = Backdrop;
|
|
4662
4786
|
exports.BoundMemoryPager = BoundMemoryPager;
|