@mackin.com/styleguide 9.1.0 → 9.2.0

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.
Files changed (3) hide show
  1. package/index.d.ts +40 -1
  2. package/index.js +98 -0
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1090,4 +1090,43 @@ 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
- export { Accordian, AccordianProps, Alignment, Autocomplete, 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 };
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
+ /** Extracted logic around autocomplete functionality for Autocomplete.tsx. */
1101
+ declare class AutocompleteController {
1102
+ constructor(getOptions: (value: string | undefined) => Promise<string[]>, config?: AutoCompleteConfig);
1103
+ get value(): string | undefined;
1104
+ get options(): string[];
1105
+ onChange(newValue: string | undefined): Promise<void>;
1106
+ onPick(newValue: string | undefined): void;
1107
+ private readonly getOptions;
1108
+ private readonly _minChars;
1109
+ private _value;
1110
+ private _options;
1111
+ }
1112
+
1113
+ /** Extracted logic around autocomplete functionality for Autocomplete.tsx that supports Entity (id/name) mapping. */
1114
+ declare class AutocompleteEntityController<T extends string | number> {
1115
+ constructor(getOptions: (value: string | undefined) => Promise<Entity<T>[]>, config?: AutoCompleteConfig);
1116
+ get entity(): Entity<T> | undefined;
1117
+ get entities(): Entity<T>[];
1118
+ get value(): string | undefined;
1119
+ get options(): string[];
1120
+ onChange(newValue: string | undefined): Promise<void>;
1121
+ onPick(newValue: string | undefined): void;
1122
+ private _ctrl;
1123
+ private _pickedEntity;
1124
+ private _options;
1125
+ private trySyncCtrlOptions;
1126
+ }
1127
+ interface Entity<T extends string | number> {
1128
+ id: T;
1129
+ name: string;
1130
+ }
1131
+
1132
+ 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,106 @@ const TabContainer = (p) => {
4655
4655
  }), p.contentClassName) }, p.tabs[tabIndex].getContent())));
4656
4656
  };
4657
4657
 
4658
+ const defaultMinChars = 3;
4659
+ /** Extracted logic around autocomplete functionality for Autocomplete.tsx. */
4660
+ class AutocompleteController {
4661
+ constructor(getOptions, config) {
4662
+ var _a;
4663
+ this._value = undefined;
4664
+ this._options = [];
4665
+ this._minChars = (_a = config === null || config === void 0 ? void 0 : config.minChars) !== null && _a !== void 0 ? _a : defaultMinChars;
4666
+ if (config === null || config === void 0 ? void 0 : config.debounceMs) {
4667
+ this.getOptions = lodash.debounce(getOptions, config.debounceMs, {
4668
+ leading: false,
4669
+ trailing: true
4670
+ });
4671
+ }
4672
+ else {
4673
+ this.getOptions = getOptions;
4674
+ }
4675
+ }
4676
+ get value() {
4677
+ return this._value;
4678
+ }
4679
+ get options() {
4680
+ return this._options;
4681
+ }
4682
+ async onChange(newValue) {
4683
+ var _a;
4684
+ // don't make getOptions calls if the value hasn't changed.
4685
+ if (newValue === this.value) {
4686
+ return;
4687
+ }
4688
+ // nullish should not make the getOptions call and instead clear everything.
4689
+ if (!newValue) {
4690
+ this._value = newValue;
4691
+ this._options = [];
4692
+ return;
4693
+ }
4694
+ // sub min chars should clear everything and not attempt the getOptions call.
4695
+ if (newValue.length < this._minChars) {
4696
+ this._value = newValue;
4697
+ this._options = [];
4698
+ return;
4699
+ }
4700
+ try {
4701
+ this._value = newValue;
4702
+ // debounce (if used) will return undefined until the actual function is executed.
4703
+ // after that it will return the result of the last execution.
4704
+ this._options = (_a = (await this.getOptions(newValue))) !== null && _a !== void 0 ? _a : [];
4705
+ }
4706
+ catch (err) {
4707
+ // the getOptions method needs to handle it's own errors
4708
+ }
4709
+ }
4710
+ onPick(newValue) {
4711
+ this._value = newValue;
4712
+ this._options = [];
4713
+ }
4714
+ }
4715
+
4716
+ /** Extracted logic around autocomplete functionality for Autocomplete.tsx that supports Entity (id/name) mapping. */
4717
+ class AutocompleteEntityController {
4718
+ constructor(getOptions, config) {
4719
+ this._options = [];
4720
+ const getStringOptions = async (value) => {
4721
+ this._options = await getOptions(value);
4722
+ return this._options.map(o => o.name);
4723
+ };
4724
+ this._ctrl = new AutocompleteController(getStringOptions, config);
4725
+ }
4726
+ get entity() {
4727
+ return this._pickedEntity;
4728
+ }
4729
+ get entities() {
4730
+ return this._options;
4731
+ }
4732
+ get value() {
4733
+ return this._ctrl.value;
4734
+ }
4735
+ get options() {
4736
+ return this._options.map(o => o.name);
4737
+ }
4738
+ async onChange(newValue) {
4739
+ await this._ctrl.onChange(newValue);
4740
+ this.trySyncCtrlOptions();
4741
+ }
4742
+ onPick(newValue) {
4743
+ this._ctrl.onPick(newValue);
4744
+ this._pickedEntity = this._options.find(o => o.name === this._ctrl.value);
4745
+ this.trySyncCtrlOptions();
4746
+ }
4747
+ trySyncCtrlOptions() {
4748
+ if (!this._ctrl.options.length) {
4749
+ this._options = [];
4750
+ }
4751
+ }
4752
+ }
4753
+
4658
4754
  exports.Accordian = Accordian;
4659
4755
  exports.Autocomplete = Autocomplete;
4756
+ exports.AutocompleteController = AutocompleteController;
4757
+ exports.AutocompleteEntityController = AutocompleteEntityController;
4660
4758
  exports.Backdrop = Backdrop$1;
4661
4759
  exports.Backdrop2 = Backdrop;
4662
4760
  exports.BoundMemoryPager = BoundMemoryPager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mackin.com/styleguide",
3
- "version": "9.1.0",
3
+ "version": "9.2.0",
4
4
  "description": "",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",