@mmb-digital/ds-lilly 0.6.3 → 0.7.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.
package/dist/ds-lilly.js CHANGED
@@ -98469,7 +98469,7 @@ var Autocomplete2_spreadArray = (undefined && undefined.__spreadArray) || functi
98469
98469
 
98470
98470
 
98471
98471
  var Autocomplete2 = function (_a) {
98472
- var _b = _a.asyncDelayMilliseconds, asyncDelayMilliseconds = _b === void 0 ? 200 : _b, _c = _a.canAlwaysCreateNewItem, canAlwaysCreateNewItem = _c === void 0 ? false : _c, disabledTooltip = _a.disabledTooltip, _d = _a.displayDetails, displayDetails = _d === void 0 ? false : _d, dropdownTheme = _a.dropdownTheme, emptyValueLabel = _a.emptyValueLabel, error = _a.error, _e = _a.filterMinimumLength, filterMinimumLength = _e === void 0 ? 2 : _e, _f = _a.hasFullWidthOptions, hasFullWidthOptions = _f === void 0 ? true : _f, help = _a.help, isDisabled = _a.isDisabled, isLazyLoaded = _a.isLazyLoaded, isLoading = _a.isLoading, _g = _a.items, inputItems = _g === void 0 ? [] : _g, label = _a.label, labelTooltip = _a.labelTooltip, loadItems = _a.loadItems, loadMoreItems = _a.loadMoreItems, name = _a.name, messages = _a.messages, _h = _a.newItemMinimumLength, newItemMinimumLength = _h === void 0 ? 2 : _h, onBlur = _a.onBlur, onChange = _a.onChange, onCreateNewItem = _a.onCreateNewItem, onFocus = _a.onFocus, placeholder = _a.placeholder, testId = _a.testId, theme = _a.theme, value = _a.value;
98472
+ var _b = _a.asyncDelayMilliseconds, asyncDelayMilliseconds = _b === void 0 ? 200 : _b, _c = _a.canAlwaysCreateNewItem, canAlwaysCreateNewItem = _c === void 0 ? false : _c, disabledTooltip = _a.disabledTooltip, _d = _a.displayDetails, displayDetails = _d === void 0 ? false : _d, dropdownTheme = _a.dropdownTheme, emptyValueLabel = _a.emptyValueLabel, error = _a.error, _e = _a.filterMinimumLength, filterMinimumLength = _e === void 0 ? 2 : _e, _f = _a.hasFullWidthOptions, hasFullWidthOptions = _f === void 0 ? true : _f, help = _a.help, isDisabled = _a.isDisabled, isLazyLoaded = _a.isLazyLoaded, isLoading = _a.isLoading, _g = _a.items, inputItems = _g === void 0 ? [] : _g, label = _a.label, labelTooltip = _a.labelTooltip, loadItems = _a.loadItems, loadMoreItems = _a.loadMoreItems, name = _a.name, messages = _a.messages, _h = _a.newItemMinimumLength, newItemMinimumLength = _h === void 0 ? 2 : _h, onBlur = _a.onBlur, onChange = _a.onChange, onCreateNewItem = _a.onCreateNewItem, onFocus = _a.onFocus, onItemFocus = _a.onItemFocus, placeholder = _a.placeholder, testId = _a.testId, theme = _a.theme, value = _a.value;
98473
98473
  var _j = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(false), isDropdownVisible = _j[0], setIsDropdownVisible = _j[1];
98474
98474
  var _k = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(null), buttonValue = _k[0], setButtonValue = _k[1];
98475
98475
  var _l = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(false), typingMode = _l[0], setTypingMode = _l[1];
@@ -98762,6 +98762,12 @@ var Autocomplete2 = function (_a) {
98762
98762
  var position = getItemIndexPosition({ item: item, category: category });
98763
98763
  setCurrentItemPosition(position);
98764
98764
  scrollToItem(item, category);
98765
+ if (onItemFocus && position !== currentItemPosition) {
98766
+ var focusedItem_1 = isCategorised(items)
98767
+ ? items[category].items[item]
98768
+ : items[item];
98769
+ onItemFocus(focusedItem_1);
98770
+ }
98765
98771
  };
98766
98772
  var handleCreateNewOption = function () {
98767
98773
  setButtonValue({ label: fulltextValue, value: fulltextValue });
@@ -107281,7 +107287,7 @@ var Select2_spreadArray = (undefined && undefined.__spreadArray) || function (to
107281
107287
 
107282
107288
  var Select2 = function (_a) {
107283
107289
  var _b;
107284
- var disabledTooltip = _a.disabledTooltip, _c = _a.displayDetails, displayDetails = _c === void 0 ? false : _c, dropdownTheme = _a.dropdownTheme, emptyValueLabel = _a.emptyValueLabel, error = _a.error, _d = _a.hasFullWidthOptions, hasFullWidthOptions = _d === void 0 ? true : _d, help = _a.help, isDisabled = _a.isDisabled, items = _a.items, label = _a.label, labelTooltip = _a.labelTooltip, name = _a.name, onBlur = _a.onBlur, onChange = _a.onChange, onFocus = _a.onFocus, placeholder = _a.placeholder, testId = _a.testId, theme = _a.theme, value = _a.value;
107290
+ var disabledTooltip = _a.disabledTooltip, _c = _a.displayDetails, displayDetails = _c === void 0 ? false : _c, dropdownTheme = _a.dropdownTheme, emptyValueLabel = _a.emptyValueLabel, error = _a.error, _d = _a.hasFullWidthOptions, hasFullWidthOptions = _d === void 0 ? true : _d, help = _a.help, isDisabled = _a.isDisabled, items = _a.items, label = _a.label, labelTooltip = _a.labelTooltip, name = _a.name, onBlur = _a.onBlur, onChange = _a.onChange, onFocus = _a.onFocus, onItemFocus = _a.onItemFocus, placeholder = _a.placeholder, testId = _a.testId, theme = _a.theme, value = _a.value;
107285
107291
  var _e = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(false), isDropdownVisible = _e[0], setIsDropdownVisible = _e[1];
107286
107292
  var _f = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(null), buttonValue = _f[0], setButtonValue = _f[1];
107287
107293
  var _g = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useState"])(-1), currentItemPosition = _g[0], setCurrentItemPosition = _g[1];
@@ -107351,12 +107357,19 @@ var Select2 = function (_a) {
107351
107357
  var itemIndexPosition = getItemIndexPosition(itemIndex);
107352
107358
  setCurrentItemPosition(itemIndexPosition);
107353
107359
  }, [isDropdownVisible, getItemIndexByValue, value, getItemIndexPosition]);
107354
- var scrollToItem = function (item, category) {
107355
- var _a;
107360
+ var scrollToItem = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useCallback"])(function (item, category) {
107361
+ var _a, _b, _c, _d, _e;
107356
107362
  if (category === void 0) { category = -1; }
107357
107363
  var itemElementId = isCategorised ? name + "_option-" + category + "-" + item : name + "_option-" + item;
107358
- (_a = document.getElementById(itemElementId)) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'nearest' });
107359
- };
107364
+ var dropdownId = name + "_dropdown";
107365
+ var dropdownHalfHeight = (((_a = document.getElementById(dropdownId)) === null || _a === void 0 ? void 0 : _a.clientHeight) || 0) / 2;
107366
+ var itemHalfHeight = (((_b = document.getElementById(itemElementId)) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0) / 2;
107367
+ var itemOffset = ((_c = document.getElementById(itemElementId)) === null || _c === void 0 ? void 0 : _c.offsetTop) || 0;
107368
+ if (itemOffset > dropdownHalfHeight) {
107369
+ (_d = document
107370
+ .getElementById(dropdownId)) === null || _d === void 0 ? void 0 : _d.scrollTo(0, (((_e = document.getElementById(itemElementId)) === null || _e === void 0 ? void 0 : _e.offsetTop) || 0) - dropdownHalfHeight + itemHalfHeight);
107371
+ }
107372
+ }, [isCategorised, name]);
107360
107373
  var handleComboBoxClick = function () {
107361
107374
  if (!isDropdownVisible) {
107362
107375
  setTimeout(function () {
@@ -107425,6 +107438,12 @@ var Select2 = function (_a) {
107425
107438
  var position = getItemIndexPosition({ item: item, category: category });
107426
107439
  setCurrentItemPosition(position);
107427
107440
  scrollToItem(item, category);
107441
+ if (onItemFocus && position !== currentItemPosition) {
107442
+ var focusedItem_1 = isCategorised
107443
+ ? items[category].items[item]
107444
+ : items[item];
107445
+ onItemFocus(focusedItem_1);
107446
+ }
107428
107447
  };
107429
107448
  var handleOptionKeyPress = function (event) {
107430
107449
  var key = event.key;
@@ -107521,7 +107540,7 @@ var Select2 = function (_a) {
107521
107540
  };
107522
107541
  return (external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(FormGroup2, Select2_assign({ theme: classBinder_cx({ 'f-group2--open': isDropdownVisible }, theme) }, fromGroupProps),
107523
107542
  external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(contexts_Select2Context.Provider, { value: select2context },
107524
- external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(Dropdown, { forceVisibility: isDropdownVisible, hasSameWidthAsTrigger: hasFullWidthOptions, placement: "bottom-start", theme: dropdownTheme, trigger: null, triggerComponent: external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("div", { className: "f-controlWrap", "data-testid": testId, role: "combobox" },
107543
+ external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(Dropdown, { dropdownId: name + "_dropdown", forceVisibility: isDropdownVisible, hasSameWidthAsTrigger: hasFullWidthOptions, placement: "bottom-start", theme: dropdownTheme, trigger: null, triggerComponent: external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("div", { className: "f-controlWrap", "data-testid": testId, role: "combobox" },
107525
107544
  external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("button", { "aria-expanded": isDropdownVisible, "aria-haspopup": "listbox", "aria-invalid": !!error, "aria-labelledby": name + "_label " + name, className: classBinder_cx('f-control2 f-control2--select', { 'f-control2--large': displayDetails }), disabled: isDisabled, id: name + "_button", name: name, type: "button", onClick: handleComboBoxClick, onFocus: onFocus, onKeyDown: handleButtonKeyPress },
107526
107545
  external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("span", { className: classBinder_cx("f-control2__" + (buttonValue ? 'value' : 'placeholder')) }, buttonValue ? buttonValue : placeholder),
107527
107546
  external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(Icon, { name: "arrowDown", size: "small", theme: "f-control2__selectIcon" }))), onVisibleChange: function (state) { return setIsDropdownVisible(state); } }, isCategorised ? external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(Select2CategorisedOptions, null) : external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(Select2Options, null)))));
@@ -43,6 +43,8 @@ export interface Autocomplete2PropsType extends FormField2PropsType {
43
43
  newItemMinimumLength?: number;
44
44
  /** A callback to create new item */
45
45
  onCreateNewItem?: (value?: string) => void;
46
+ /** A callback called on highlight dropdown item */
47
+ onItemFocus?: (item: ItemType | CategorisedItemType) => void;
46
48
  }
47
- export declare const Autocomplete2: ({ asyncDelayMilliseconds, canAlwaysCreateNewItem, disabledTooltip, displayDetails, dropdownTheme, emptyValueLabel, error, filterMinimumLength, hasFullWidthOptions, help, isDisabled, isLazyLoaded, isLoading, items: inputItems, label, labelTooltip, loadItems, loadMoreItems, name, messages, newItemMinimumLength, onBlur, onChange, onCreateNewItem, onFocus, placeholder, testId, theme, value }: Autocomplete2PropsType) => JSX.Element;
49
+ export declare const Autocomplete2: ({ asyncDelayMilliseconds, canAlwaysCreateNewItem, disabledTooltip, displayDetails, dropdownTheme, emptyValueLabel, error, filterMinimumLength, hasFullWidthOptions, help, isDisabled, isLazyLoaded, isLoading, items: inputItems, label, labelTooltip, loadItems, loadMoreItems, name, messages, newItemMinimumLength, onBlur, onChange, onCreateNewItem, onFocus, onItemFocus, placeholder, testId, theme, value }: Autocomplete2PropsType) => JSX.Element;
48
50
  //# sourceMappingURL=Autocomplete2.d.ts.map
@@ -11,6 +11,8 @@ export interface Select2PropsType extends FormField2PropsType {
11
11
  hasFullWidthOptions?: boolean;
12
12
  /** List of options to select. */
13
13
  items: ItemType[] | CategorisedItemType[];
14
+ /** A callback called on highlight dropdown item */
15
+ onItemFocus?: (item: ItemType | CategorisedItemType) => void;
14
16
  }
15
17
  export interface ItemType {
16
18
  /** Optional value for withAmount variant. */
@@ -32,5 +34,5 @@ export interface CategorisedItemType {
32
34
  label: string;
33
35
  items: ItemType[];
34
36
  }
35
- export declare const Select2: ({ disabledTooltip, displayDetails, dropdownTheme, emptyValueLabel, error, hasFullWidthOptions, help, isDisabled, items, label, labelTooltip, name, onBlur, onChange, onFocus, placeholder, testId, theme, value }: Select2PropsType) => JSX.Element;
37
+ export declare const Select2: ({ disabledTooltip, displayDetails, dropdownTheme, emptyValueLabel, error, hasFullWidthOptions, help, isDisabled, items, label, labelTooltip, name, onBlur, onChange, onFocus, onItemFocus, placeholder, testId, theme, value }: Select2PropsType) => JSX.Element;
36
38
  //# sourceMappingURL=Select2.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmb-digital/ds-lilly",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
4
  "description": "MMB LILLY design system",
5
5
  "license": "UNLICENSED",
6
6
  "sideEffects": false,