@nice-digital/global-nav 4.1.734 → 4.1.735-GN-169-Dropdown-open

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/README.md CHANGED
@@ -42,6 +42,8 @@
42
42
  - [Header.skipLinkId](#headerskiplinkid)
43
43
  - [Header.onNavigating](#headeronnavigating)
44
44
  - [Header.onResize](#headeronresize)
45
+ - [Header.onDropdownOpen](#headerondropdownopen)
46
+ - [Header.onDropdownClose](#headerondropdownclose)
45
47
  - [Header.additionalSubMenuItems](#headeradditionalsubmenuitems)
46
48
  - [Header.search](#headersearch)
47
49
  - [Header.search.url](#headersearchurl)
@@ -408,6 +410,49 @@ var global_nav_config = {
408
410
  };
409
411
  ```
410
412
 
413
+ ###### Header.onDropdownOpen
414
+
415
+ - Type: `String`, `Function`
416
+ - Default: `null`
417
+
418
+ Pass an `onDropdownOpen` property to enable callback when dropdown is open.
419
+ Pass either a function, or the name of a function defined on `window`. E.g.:
420
+
421
+ ```js
422
+ window.onDropdownOpenHandler = function () {
423
+ // Define your implementation here e.g.:
424
+ document.querySelector("body").classList.add("global-nav__dropdown--open");
425
+ };
426
+
427
+ var global_nav_config = {
428
+ header: {
429
+ onDropdownOpen: 'onDropdownOpenHandler',
430
+ },
431
+ };
432
+ ```
433
+
434
+ ###### Header.onDropdownClose
435
+
436
+ - Type: `String`, `Function`
437
+ - Default: `null`
438
+
439
+ Pass an `onDropdownClose` property to enable callback when dropdown is closed.
440
+ Pass either a function, or the name of a function defined on `window`. E.g.:
441
+
442
+ ```js
443
+ window.onDropdownCloseHandler = function (e) {
444
+ // Define your implementation here e.g.:
445
+ document.querySelector("body").classList.remove("global-nav__dropdown--open")
446
+
447
+ };
448
+
449
+ var global_nav_config = {
450
+ header: {
451
+ onDropdownClose: 'onDropdownCloseHandler',
452
+ },
453
+ };
454
+ ```
455
+
411
456
  ###### Header.additionalSubMenuItems
412
457
 
413
458
  - Type: `null | Array`
@@ -103,12 +103,38 @@ var Header = /*#__PURE__*/function (_Component) {
103
103
  }
104
104
  };
105
105
 
106
+ _proto.checkForFunctionOrFunctionName = function checkForFunctionOrFunctionName(funcParam) {
107
+ return typeof funcParam === "function" ? funcParam : window[funcParam];
108
+ };
109
+
110
+ _proto.dropdownToggleHandler = function dropdownToggleHandler(idOfOpenDropdown) {
111
+ // If we've got an onDropdownOpen or onDropdownClose prop call the onDropdownOpen or onDropdownClose callback based on idOfOpenDropdown.
112
+ var _this$props = this.props,
113
+ onDropdownOpen = _this$props.onDropdownOpen,
114
+ onDropdownClose = _this$props.onDropdownClose;
115
+
116
+ if (onDropdownOpen && idOfOpenDropdown !== null) {
117
+ if (typeof this.checkForFunctionOrFunctionName(onDropdownOpen) === "function") {
118
+ onDropdownOpen();
119
+ return true;
120
+ }
121
+ }
122
+
123
+ if (onDropdownClose && idOfOpenDropdown == null) {
124
+ if (typeof this.checkForFunctionOrFunctionName(onDropdownClose) === "function") {
125
+ onDropdownClose();
126
+ return true;
127
+ }
128
+ }
129
+ };
130
+
106
131
  _proto.render = function render() {
107
132
  var _this3 = this;
108
133
 
109
134
  return this.props.enabled !== false && /*#__PURE__*/_react["default"].createElement(_HeaderContext.HeaderContextProvider, null, /*#__PURE__*/_react["default"].createElement(_HeaderContext.HeaderContext.Consumer, null, function (_ref) {
110
135
  (0, _newArrowCheck2["default"])(this, _this3);
111
136
  var idOfOpenDropdown = _ref.idOfOpenDropdown;
137
+ this.dropdownToggleHandler(idOfOpenDropdown);
112
138
  return /*#__PURE__*/_react["default"].createElement("span", {
113
139
  id: "scrim",
114
140
  className: idOfOpenDropdown !== null ? _HeaderModule["default"].scrim : undefined,
@@ -184,6 +210,8 @@ Header.propTypes = {
184
210
  auth: _propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].object]),
185
211
  onNavigating: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].string]),
186
212
  onResize: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].string]),
213
+ onDropdownOpen: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].string]),
214
+ onDropdownClose: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].string]),
187
215
  additionalSubMenuItems: _propTypes["default"].arrayOf(_propTypes["default"].object)
188
216
  };
189
217
  Header.defaultProps = {
@@ -70,7 +70,7 @@ var debounce = function debounce(func, execAsap, threshold, scope) {
70
70
  var maxResults = 5;
71
71
  /** Delay in millieconds before loading results */
72
72
 
73
- var rateLimitWait = 100;
73
+ var rateLimitWait = 300;
74
74
  exports.rateLimitWait = rateLimitWait;
75
75
 
76
76
  var inputValueTemplate = function inputValueTemplate(suggestion) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice-digital/global-nav",
3
- "version": "4.1.734",
3
+ "version": "4.1.735-GN-169-Dropdown-open",
4
4
  "description": "Global header and footer components for NICE digital services",
5
5
  "main": "lib/index.js",
6
6
  "types": "./types.d.ts",
package/types.d.ts CHANGED
@@ -72,6 +72,8 @@ declare module "@nice-digital/global-nav" {
72
72
  skipLinkId?: string;
73
73
  search?: false | SearchProps;
74
74
  auth?: NiceAccountsProviderProps | IdamProviderProps | false;
75
+ onDropdownOpen?: string | OnDropdownOpenCallback;
76
+ onDropdownClose?: string | OnDropdownCloseCallback;
75
77
  onNavigating?: string | OnNavigatingCallback;
76
78
  additionalSubMenuItems?: Array<AdditionalSubMenuItem>;
77
79
  };