@zohodesk/components 1.0.0-temp-220.10 → 1.0.0-temp-229

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 (48) hide show
  1. package/.cli/config/variables/variableMapping.json +8 -1
  2. package/.cli/propValidation_report.html +1 -1
  3. package/README.md +13 -0
  4. package/assets/Appearance/dark/mode/Component_v1_DarkMode.module.css +11 -0
  5. package/assets/Appearance/light/mode/Component_v1_LightMode.module.css +11 -0
  6. package/assets/Appearance/pureDark/mode/Component_v1_PureDarkMode.module.css +11 -0
  7. package/es/AppContainer/AppContainer.js +5 -4
  8. package/es/Card/Card.js +35 -8
  9. package/es/Card/props/defaultProps.js +2 -1
  10. package/es/Card/props/propTypes.js +2 -1
  11. package/es/Popup/Popup.js +92 -200
  12. package/es/Provider/Config.js +1 -2
  13. package/es/Provider/LibraryContext.js +7 -3
  14. package/es/deprecated/Switch/Switch.js +94 -0
  15. package/es/deprecated/Switch/props/defaultProps.js +11 -0
  16. package/es/deprecated/Switch/props/propTypes.js +28 -0
  17. package/es/v1/Switch/Switch.js +122 -78
  18. package/es/v1/Switch/__tests__/Switch.spec.js +30 -0
  19. package/es/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +135 -0
  20. package/es/v1/Switch/contants/index.js +24 -0
  21. package/es/v1/Switch/css/Switch_v1.module.css +134 -0
  22. package/es/v1/Switch/css/cssJSLogic.js +48 -0
  23. package/es/v1/Switch/props/defaultProps.js +8 -8
  24. package/es/v1/Switch/props/propTypes.js +30 -22
  25. package/es/v1/Switch/useSwitch.js +33 -0
  26. package/lib/AppContainer/AppContainer.js +7 -6
  27. package/lib/Card/Card.js +50 -23
  28. package/lib/Card/props/defaultProps.js +2 -1
  29. package/lib/Card/props/propTypes.js +2 -1
  30. package/lib/Popup/Popup.js +147 -272
  31. package/lib/Provider/Config.js +1 -2
  32. package/lib/Provider/LibraryContext.js +7 -3
  33. package/lib/deprecated/Switch/Switch.js +108 -0
  34. package/lib/deprecated/Switch/props/defaultProps.js +18 -0
  35. package/lib/deprecated/Switch/props/propTypes.js +39 -0
  36. package/lib/v1/Switch/Switch.js +130 -79
  37. package/lib/v1/Switch/__tests__/Switch.spec.js +37 -0
  38. package/lib/v1/Switch/__tests__/__snapshots__/Switch.spec.js.snap +135 -0
  39. package/lib/v1/Switch/contants/index.js +34 -0
  40. package/lib/v1/Switch/css/Switch_v1.module.css +134 -0
  41. package/lib/v1/Switch/css/cssJSLogic.js +37 -0
  42. package/lib/v1/Switch/props/defaultProps.js +10 -10
  43. package/lib/v1/Switch/props/propTypes.js +32 -24
  44. package/lib/v1/Switch/useSwitch.js +56 -0
  45. package/package.json +10 -6
  46. package/es/Popup/Registry.js +0 -37
  47. package/lib/Popup/Registry.js +0 -47
  48. package/result.json +0 -1
package/es/Popup/Popup.js CHANGED
@@ -12,10 +12,11 @@ import { addIntersectionObserver, removeIntersectionObserver } from "./intersect
12
12
  import { positionMapping } from "../DropBox/DropBoxPositionMapping.js";
13
13
  import isMobilePopover from "../DropBox/utils/isMobilePopover.js";
14
14
  import selectn from 'selectn';
15
- import Registry from "./Registry.js";
15
+ let lastOpenedGroup = [];
16
+ let popups = {};
16
17
 
17
18
  global.closeGroupPopups = function (groupName) {
18
- const groupPopups = Registry.popups[groupName] || [];
19
+ const groupPopups = popups[groupName] || [];
19
20
  groupPopups.forEach(popup => {
20
21
  popup.state.isPopupOpen && popup.setState({
21
22
  isPopupOpen: false,
@@ -37,51 +38,6 @@ const defaultState = {
37
38
  //{height: ‘’, width: ‘’,}
38
39
  isAbsolutePositioningNeeded: true
39
40
  };
40
- const SCROLL_BLOCK_EVENTS = Object.freeze([{
41
- name: 'wheel',
42
- handlerName: 'handleBlockScroll',
43
- options: {
44
- capture: true,
45
- passive: false
46
- }
47
- }, {
48
- name: 'touchmove',
49
- handlerName: 'handleBlockScroll',
50
- options: {
51
- capture: true,
52
- passive: false
53
- }
54
- }, {
55
- name: 'scroll',
56
- handlerName: 'handlePositionChange',
57
- options: {
58
- capture: true,
59
- passive: false
60
- }
61
- }, {
62
- name: 'keydown',
63
- handlerName: 'preventKeyboardScroll',
64
- options: {
65
- capture: true,
66
- passive: false
67
- }
68
- }]);
69
- const IFRAME_SCROLL_BLOCK_EVENTS = Object.freeze(SCROLL_BLOCK_EVENTS.filter(event => event.name !== 'keydown'));
70
- const CLICK_EVENTS = Object.freeze([{
71
- name: 'click',
72
- handlerName: 'documentClickHandler',
73
- options: {
74
- capture: false,
75
- passive: false
76
- }
77
- }, {
78
- name: 'click',
79
- handlerName: 'documentClickHandler1',
80
- options: {
81
- capture: true,
82
- passive: false
83
- }
84
- }]);
85
41
  /* eslint-disable react/no-deprecated */
86
42
 
87
43
  /* eslint-disable react/prop-types */
@@ -143,11 +99,8 @@ const Popup = function (Component) {
143
99
  this.handleBlockScroll = this.handleBlockScroll.bind(this);
144
100
  this.handlePositionChange = this.handlePositionChange.bind(this);
145
101
  this.preventKeyboardScroll = this.preventKeyboardScroll.bind(this);
146
- this.updateListeners = this.updateListeners.bind(this);
147
102
  this.addScrollBlockListeners = this.addScrollBlockListeners.bind(this);
148
103
  this.removeScrollBlockListeners = this.removeScrollBlockListeners.bind(this);
149
- this.addScrollToUpdateListeners = this.addScrollToUpdateListeners.bind(this);
150
- this.removeScrollToUpdateListeners = this.removeScrollToUpdateListeners.bind(this);
151
104
  this.handleAddingScrollBlock = this.handleAddingScrollBlock.bind(this);
152
105
  this.handleRemovingScrollBlock = this.handleRemovingScrollBlock.bind(this);
153
106
  this.handleIntersectionObserver = this.handleIntersectionObserver.bind(this);
@@ -157,10 +110,8 @@ const Popup = function (Component) {
157
110
  this.setContainerDynamicPositioning = this.setContainerDynamicPositioning.bind(this);
158
111
  this.updatePopupState = this.updatePopupState.bind(this);
159
112
  this.handleScrollAndBlockEvents = this.handleScrollAndBlockEvents.bind(this);
160
- this.handleIframeEventListeners = this.handleIframeEventListeners.bind(this);
161
113
  this.handleDropElementStyleUpdate = this.handleDropElementStyleUpdate.bind(this);
162
114
  this.positionRef = /*#__PURE__*/React.createRef();
163
- this.rootElement = Registry.getRootElement();
164
115
  this.popupObserver = new ResizeObserver(this.handlePopupResize); //dropBoxSize
165
116
 
166
117
  this.size = null;
@@ -177,15 +128,16 @@ const Popup = function (Component) {
177
128
 
178
129
  componentDidMount() {
179
130
  const group = this.getGroup();
180
- const groupPopups = Registry.popups[group] || [];
131
+ const groupPopups = popups[group] || [];
181
132
  groupPopups.push(this);
182
- Registry.popups[group] = groupPopups;
133
+ popups[group] = groupPopups;
183
134
 
184
- if (Object.keys(Registry.popups).length === 1 && groupPopups.length === 1) {
185
- this.updateListeners(true, CLICK_EVENTS, document);
135
+ if (Object.keys(popups).length === 1 && groupPopups.length === 1) {
136
+ document.addEventListener('click', this.documentClickHandler, false);
186
137
  document.addEventListener('keyup', this.documentKeyupHandler, false); // document.addEventListener('scroll', this.handleScroll, true);
187
138
 
188
139
  window.addEventListener('resize', this.handleResize);
140
+ document.addEventListener('click', this.documentClickHandler1, true);
189
141
  document.addEventListener('mousedown', this.handleDocumentMouseDown, true);
190
142
  document.addEventListener('focus', this.handleDocumentFocus, true);
191
143
  }
@@ -204,8 +156,8 @@ const Popup = function (Component) {
204
156
  }
205
157
  }
206
158
 
207
- handleScrollAndBlockEvents(shouldAdd) {
208
- if (shouldAdd) {
159
+ handleScrollAndBlockEvents(isPopupReady, isMobile) {
160
+ if (isPopupReady && !isMobile) {
209
161
  this.handleAddingScrollBlock();
210
162
  this.handleAddingScrollToUpdatePosition();
211
163
  } else {
@@ -214,16 +166,6 @@ const Popup = function (Component) {
214
166
  }
215
167
  }
216
168
 
217
- handleIframeEventListeners(shouldAdd, eventList) {
218
- this.rootElement.querySelectorAll('iframe').forEach(frame => {
219
- const frameDocument = frame.contentDocument;
220
-
221
- if (frameDocument) {
222
- this.updateListeners(shouldAdd, eventList, frameDocument);
223
- }
224
- });
225
- }
226
-
227
169
  componentDidUpdate(prevProps, prevState) {
228
170
  const {
229
171
  isPopupReady,
@@ -250,31 +192,28 @@ const Popup = function (Component) {
250
192
  }
251
193
 
252
194
  if (oldStateOpen !== isPopupReady && !isMobile || oldIsMobileState !== isMobile) {
253
- const shouldAdd = isPopupReady && !isMobile;
254
- this.handleScrollAndBlockEvents(shouldAdd);
255
- this.handleIframeEventListeners(shouldAdd, CLICK_EVENTS);
195
+ this.handleScrollAndBlockEvents(isPopupReady, isMobile);
256
196
  }
257
197
  }
258
198
 
259
199
  componentWillUnmount() {
260
200
  const group = this.getGroup();
261
- Registry.popups = Object.keys(Registry.popups).reduce((res, groupName) => {
201
+ popups = Object.keys(popups).reduce((res, groupName) => {
262
202
  if (groupName === group) {
263
- const groupPopups = Registry.popups[group];
203
+ const groupPopups = popups[group];
264
204
  const newGroupPopups = groupPopups.filter(popup => popup !== this);
265
- newGroupPopups.length === 0 && Registry.lastOpenedGroup.indexOf(group) >= 0 && Registry.lastOpenedGroup.splice(Registry.lastOpenedGroup.indexOf(group), 1);
205
+ newGroupPopups.length === 0 && lastOpenedGroup.indexOf(group) >= 0 && lastOpenedGroup.splice(lastOpenedGroup.indexOf(group), 1);
266
206
  res[group] = newGroupPopups;
267
207
  }
268
208
 
269
209
  return res;
270
- }, Registry.popups);
210
+ }, popups);
271
211
  this.handleRemovingScrollBlock();
272
212
  this.handleRemovingScrollToUpdatePosition();
273
- this.handleIframeEventListeners(false, CLICK_EVENTS);
274
213
  let noPopups = true;
275
214
 
276
- for (const i in Registry.popups) {
277
- if (Registry.popups[i].length >= 1) {
215
+ for (const i in popups) {
216
+ if (popups[i].length >= 1) {
278
217
  noPopups = false;
279
218
  break;
280
219
  }
@@ -285,10 +224,11 @@ const Popup = function (Component) {
285
224
  }
286
225
 
287
226
  if (noPopups) {
288
- this.updateListeners(false, CLICK_EVENTS, document);
227
+ document.removeEventListener('click', this.documentClickHandler);
289
228
  document.removeEventListener('keyup', this.documentKeyupHandler); // document.removeEventListener('scroll', this.handleScroll);
290
229
 
291
230
  window.removeEventListener('resize', this.handleResize);
231
+ document.removeEventListener('click', this.documentClickHandler1, true);
292
232
  document.removeEventListener('mousedown', this.handleDocumentMouseDown, true);
293
233
  document.removeEventListener('focus', this.handleDocumentFocus, true);
294
234
  }
@@ -320,13 +260,10 @@ const Popup = function (Component) {
320
260
 
321
261
  if (!isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
322
262
  addIntersectionObserver(this.placeHolderElement, this.updateVisibilityOnIntersection);
323
- const shouldAddScrollToUpdatePositionListeners = Registry.getScrollablePopups().length === 1 && !Registry.isScrollToUpdatePositionListenersAdded;
324
-
325
- if (shouldAddScrollToUpdatePositionListeners) {
326
- Registry.scrollableThisHandler = this;
327
- Registry.scrollableThisHandler.addScrollToUpdateListeners();
328
- Registry.isScrollToUpdatePositionListenersAdded = true;
329
- }
263
+ document.addEventListener('scroll', this.updatePositionOnScroll, {
264
+ capture: true,
265
+ passive: false
266
+ });
330
267
  }
331
268
  }
332
269
 
@@ -336,13 +273,10 @@ const Popup = function (Component) {
336
273
 
337
274
  if (!isOutsideScrollBlocked && !isAbsolutePositioningNeeded) {
338
275
  removeIntersectionObserver(this.placeHolderElement, this.updateVisibilityOnIntersection);
339
- const shouldRemoveScrollToUpdatePositionListeners = Registry.getScrollablePopups().length === 0 && Registry.isScrollToUpdatePositionListenersAdded;
340
-
341
- if (shouldRemoveScrollToUpdatePositionListeners) {
342
- Registry.scrollableThisHandler.removeScrollToUpdateListeners();
343
- Registry.isScrollToUpdatePositionListenersAdded = false;
344
- Registry.scrollableThisHandler = undefined;
345
- }
276
+ document.removeEventListener('scroll', this.updatePositionOnScroll, {
277
+ capture: true,
278
+ passive: false
279
+ });
346
280
  }
347
281
  }
348
282
 
@@ -401,125 +335,83 @@ const Popup = function (Component) {
401
335
  }
402
336
 
403
337
  updatePositionOnScroll(e) {
404
- const scrollablePopups = Registry.getScrollablePopups(); // Check if the event target is outside all dropElements
405
-
406
- scrollablePopups.forEach(_ref2 => {
407
- let {
408
- placeHolderElement,
409
- defaultPosition,
410
- isTargetElementVisible,
411
- handlePopupPosition
412
- } = _ref2;
413
-
414
- if (e.target.contains(placeHolderElement) && isTargetElementVisible) {
415
- handlePopupPosition(defaultPosition, true);
416
- }
417
- });
418
- }
338
+ const {
339
+ placeHolderElement,
340
+ defaultPosition,
341
+ isTargetElementVisible
342
+ } = this;
419
343
 
420
- updateListeners() {
421
- let add = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
422
- let eventList = arguments.length > 1 ? arguments[1] : undefined;
423
- let element = arguments.length > 2 ? arguments[2] : undefined;
424
- const method = add ? 'addEventListener' : 'removeEventListener';
425
- eventList.forEach(_ref3 => {
426
- let {
427
- name,
428
- handlerName,
429
- options
430
- } = _ref3;
431
- const handler = this[handlerName];
432
-
433
- if (handler) {
434
- element[method](name, handler, options);
435
- }
436
- });
344
+ if (e.target.contains(placeHolderElement) && isTargetElementVisible) {
345
+ this.handlePopupPosition(defaultPosition, true);
346
+ }
437
347
  }
438
348
 
439
349
  addScrollBlockListeners() {
440
- // Only add scroll block listeners if at least one open popup needs outside scroll blocked
441
- const shouldAddScrollBlockListeners = Registry.getScrollBlockedPopups().length === 1 && !Registry.isScrollBlockListenersAdded;
442
-
443
- if (shouldAddScrollBlockListeners) {
444
- Registry.scrollBlockedThisHandler = this; // Main document
445
-
446
- Registry.scrollBlockedThisHandler.updateListeners(true, SCROLL_BLOCK_EVENTS, document); // Attach event listeners to all iframes within rootElement
447
-
448
- Registry.scrollBlockedThisHandler.handleIframeEventListeners(true, IFRAME_SCROLL_BLOCK_EVENTS);
449
- Registry.isScrollBlockListenersAdded = true;
450
- }
350
+ document.addEventListener('wheel', this.handleBlockScroll, {
351
+ capture: true,
352
+ passive: false
353
+ });
354
+ document.addEventListener('touchmove', this.handleBlockScroll, {
355
+ capture: true,
356
+ passive: false
357
+ });
358
+ document.addEventListener('scroll', this.handlePositionChange, {
359
+ capture: true,
360
+ passive: false
361
+ });
362
+ document.addEventListener('keydown', this.preventKeyboardScroll, {
363
+ capture: true,
364
+ passive: false
365
+ });
451
366
  }
452
367
 
453
368
  removeScrollBlockListeners() {
454
- // Only remove scroll block listeners if at least one open popup needs outside scroll blocked
455
- const shouldRemoveScrollBlockListeners = Registry.getScrollBlockedPopups().length === 0 && Registry.isScrollBlockListenersAdded;
456
-
457
- if (shouldRemoveScrollBlockListeners) {
458
- Registry.scrollBlockedThisHandler.updateListeners(false, SCROLL_BLOCK_EVENTS, document);
459
- Registry.scrollBlockedThisHandler.handleIframeEventListeners(false, IFRAME_SCROLL_BLOCK_EVENTS);
460
- Registry.isScrollBlockListenersAdded = false;
461
- Registry.scrollBlockedThisHandler = undefined;
462
- }
463
- }
464
-
465
- addScrollToUpdateListeners() {
466
- document.addEventListener('scroll', this.updatePositionOnScroll, {
369
+ document.removeEventListener('wheel', this.handleBlockScroll, {
467
370
  capture: true,
468
371
  passive: false
469
372
  });
470
- }
471
-
472
- removeScrollToUpdateListeners() {
473
- document.removeEventListener('scroll', this.updatePositionOnScroll, {
373
+ document.removeEventListener('touchmove', this.handleBlockScroll, {
374
+ capture: true,
375
+ passive: false
376
+ });
377
+ document.removeEventListener('scroll', this.handlePositionChange, {
378
+ capture: true,
379
+ passive: false
380
+ });
381
+ document.removeEventListener('keydown', this.preventKeyboardScroll, {
474
382
  capture: true,
475
383
  passive: false
476
384
  });
477
385
  }
478
386
 
479
387
  handleBlockScroll(event) {
480
- const scrollBlockedPopups = Registry.getScrollBlockedPopups(); // Check if the event target is outside all dropElements
481
-
482
- const isOutsideAllDropElements = scrollBlockedPopups.every(_ref4 => {
483
- let {
484
- dropElement
485
- } = _ref4;
486
- return dropElement && dropElement !== event.target && !dropElement.contains(event.target);
487
- });
488
-
489
- if (isOutsideAllDropElements) {
388
+ // const targetElement = this.placeHolderElement;
389
+ const containerElement = this.dropElement;
390
+
391
+ if (containerElement && containerElement !== event.target && !containerElement.contains(event.target)) {
392
+ // --- Scroll exclude Target & Container elements --- For reference. Will adopt in future
393
+ // if(
394
+ // (containerElement && (containerElement !== event.target && !containerElement.contains(event.target)))
395
+ // && (targetElement && (targetElement !== event.target && !targetElement.contains(event.target)))
396
+ // ) {
490
397
  event.preventDefault();
491
398
  }
492
399
  }
493
400
 
494
401
  handlePositionChange(event) {
495
- const scrollBlockedPopups = Registry.getScrollBlockedPopups();
496
- scrollBlockedPopups.forEach(_ref5 => {
497
- let {
498
- placeHolderElement,
499
- dropElement,
500
- handlePopupPosition,
501
- state
502
- } = _ref5;
503
-
504
- if (dropElement && dropElement !== event.target && !dropElement.contains(event.target) && placeHolderElement && placeHolderElement !== event.target && !placeHolderElement.contains(event.target) && event.target.contains(placeHolderElement)) {
505
- handlePopupPosition(state.position, true);
506
- }
507
- });
402
+ const targetElement = this.placeHolderElement;
403
+ const containerElement = this.dropElement;
404
+
405
+ if (containerElement && containerElement !== event.target && !containerElement.contains(event.target) && targetElement && targetElement !== event.target && !targetElement.contains(event.target) && event.target.contains(targetElement)) {
406
+ this.handlePopupPosition(this.state.position, true); // this.closePopupOnly(event);
407
+ }
508
408
  }
509
409
 
510
410
  preventKeyboardScroll(event) {
411
+ const containerElement = this.dropElement;
511
412
  const keys = [32, 37, 38, 39, 40]; // Space, Arrow keys
512
413
 
513
- const scrollBlockedPopups = Registry.getScrollBlockedPopups(); // Check if the event target is outside all dropElements
514
-
515
- const isOutsideAllDropElements = scrollBlockedPopups.every(_ref6 => {
516
- let {
517
- dropElement
518
- } = _ref6;
519
- return dropElement && dropElement !== event.target && !dropElement.contains(event.target) && keys.includes(event.keyCode);
520
- });
521
-
522
- if (isOutsideAllDropElements) {
414
+ if (containerElement && containerElement !== event.target && !containerElement.contains(event.target) && keys.includes(event.keyCode)) {
523
415
  event.preventDefault();
524
416
  }
525
417
  }
@@ -618,9 +510,9 @@ const Popup = function (Component) {
618
510
  const {
619
511
  isPopupOpen
620
512
  } = this.state;
621
- const groupPopups = Registry.popups[group] || [];
622
- Registry.lastOpenedGroup = !isPopupOpen && Registry.lastOpenedGroup.indexOf(group) === -1 ? [group, ...Registry.lastOpenedGroup] : Registry.lastOpenedGroup;
623
- isPopupOpen && Registry.lastOpenedGroup.splice(0, 1);
513
+ const groupPopups = popups[group] || [];
514
+ lastOpenedGroup = !isPopupOpen && lastOpenedGroup.indexOf(group) === -1 ? [group, ...lastOpenedGroup] : lastOpenedGroup;
515
+ isPopupOpen && lastOpenedGroup.splice(0, 1);
624
516
  groupPopups.forEach(popup => {
625
517
  if (popup !== this && popup.state.isPopupOpen) {
626
518
  popup.setState({
@@ -643,18 +535,18 @@ const Popup = function (Component) {
643
535
  openPopupOnly(e, defaultPosition) {
644
536
  const group = this.getGroup();
645
537
  this.removeClose(e);
646
- Registry.lastOpenedGroup = Registry.lastOpenedGroup.indexOf(group) === -1 ? [group, ...Registry.lastOpenedGroup] : Registry.lastOpenedGroup;
538
+ lastOpenedGroup = lastOpenedGroup.indexOf(group) === -1 ? [group, ...lastOpenedGroup] : lastOpenedGroup;
647
539
  this.handlePopupPosition(defaultPosition);
648
540
  }
649
541
 
650
542
  closePopupOnly(e) {
651
543
  this.removeClose(e);
544
+ lastOpenedGroup.splice(0, 1);
652
545
  const {
653
546
  isPopupOpen
654
547
  } = this.state;
655
548
 
656
549
  if (isPopupOpen) {
657
- Registry.lastOpenedGroup.splice(0, 1);
658
550
  this.setState({
659
551
  isPopupOpen: false,
660
552
  isPopupReady: false
@@ -663,8 +555,8 @@ const Popup = function (Component) {
663
555
  }
664
556
 
665
557
  handleCloseLastOpenedGroup() {
666
- const groupPopups = Registry.lastOpenedGroup.length ? Registry.popups[Registry.lastOpenedGroup[0]] || [] : [];
667
- Registry.lastOpenedGroup.splice(0, 1);
558
+ const groupPopups = lastOpenedGroup.length ? popups[lastOpenedGroup[0]] || [] : [];
559
+ lastOpenedGroup.splice(0, 1);
668
560
  groupPopups.forEach(popup => {
669
561
  popup.state.isPopupOpen && popup.setState({
670
562
  isPopupOpen: false,
@@ -692,11 +584,11 @@ const Popup = function (Component) {
692
584
  handleGetNeedPrevent(e) {
693
585
  let needPrevent = false;
694
586
 
695
- if (Registry.lastOpenedGroup.length > 1) {
587
+ if (lastOpenedGroup.length > 1) {
696
588
  const {
697
589
  target
698
590
  } = e;
699
- const groupPopups = Registry.lastOpenedGroup.length ? Registry.popups[Registry.lastOpenedGroup[0]] : [];
591
+ const groupPopups = lastOpenedGroup.length ? popups[lastOpenedGroup[0]] : [];
700
592
  let openedPopup = null; // eslint-disable-next-line guard-for-in
701
593
 
702
594
  for (const i in groupPopups) {
@@ -742,8 +634,8 @@ const Popup = function (Component) {
742
634
 
743
635
  documentClickHandler() {
744
636
  try {
745
- Object.keys(Registry.popups).forEach(groupName => {
746
- const groupPopups = Registry.popups[groupName] || [];
637
+ Object.keys(popups).forEach(groupName => {
638
+ const groupPopups = popups[groupName] || [];
747
639
  groupPopups.forEach(popup => {
748
640
  popup.state.isPopupOpen && (!popup.props.checkBeforeClose || popup.props.checkBeforeClose && popup.props.checkBeforeClose()) && !isTextSelected() && popup.setState({
749
641
  isPopupOpen: false,
@@ -751,7 +643,7 @@ const Popup = function (Component) {
751
643
  });
752
644
  });
753
645
  });
754
- Registry.lastOpenedGroup = [];
646
+ lastOpenedGroup = [];
755
647
  } catch (e) {// eslint-disable-next-line no-console
756
648
  //console.error('popup component not unmounted properly', e);
757
649
  }
@@ -871,8 +763,8 @@ const Popup = function (Component) {
871
763
  }
872
764
 
873
765
  handleOpenPopupPositionChange() {
874
- Object.keys(Registry.popups).forEach(groupName => {
875
- const groupPopups = Registry.popups[groupName] || [];
766
+ Object.keys(popups).forEach(groupName => {
767
+ const groupPopups = popups[groupName] || [];
876
768
  groupPopups.forEach(popup => {
877
769
  if (popup.state.isPopupOpen) {
878
770
  const {
@@ -8,8 +8,7 @@ let id = {
8
8
  direction: 'ltr',
9
9
  tooltipDebounce: 175,
10
10
  getTooltipContainer: () => {},
11
- autoComplete: false,
12
- getRootElement: () => {}
11
+ autoComplete: false
13
12
  };
14
13
  export function getLibraryConfig(key) {
15
14
  return id[key];
@@ -9,13 +9,15 @@ const LibraryContextProvider = _ref => {
9
9
  direction,
10
10
  coloredTagVariant,
11
11
  hasTagColorInheritedToText,
12
+ shouldIndicateSwitchState,
12
13
  children
13
14
  } = _ref;
14
15
  const [value, setValue] = useState({
15
16
  isReducedMotion,
16
17
  direction,
17
18
  coloredTagVariant,
18
- hasTagColorInheritedToText
19
+ hasTagColorInheritedToText,
20
+ shouldIndicateSwitchState
19
21
  });
20
22
 
21
23
  function setGlobalContext(key, data) {
@@ -38,12 +40,14 @@ LibraryContextProvider.propTypes = {
38
40
  isReducedMotion: PropTypes.bool,
39
41
  coloredTagVariant: PropTypes.oneOf(['bold', 'subtle', 'minimal']),
40
42
  hasTagColorInheritedToText: PropTypes.bool,
41
- direction: PropTypes.string
43
+ direction: PropTypes.string,
44
+ shouldIndicateSwitchState: PropTypes.bool
42
45
  };
43
46
  LibraryContextProvider.defaultProps = {
44
47
  isReducedMotion: getLibraryConfig('isReducedMotion'),
45
48
  direction: getLibraryConfig('direction'),
46
49
  coloredTagVariant: 'bold',
47
- hasTagColorInheritedToText: true
50
+ hasTagColorInheritedToText: true,
51
+ shouldIndicateSwitchState: false
48
52
  };
49
53
  export default LibraryContextProvider;
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import { defaultProps } from "./props/defaultProps";
3
+ import { propTypes } from "./props/propTypes";
4
+ import { Container, Box } from "../../v1/Layout";
5
+ import Label from "../../v1/Label/Label";
6
+ import style from "../../Switch/Switch.module.css";
7
+
8
+ const Switch = props => {
9
+ let {
10
+ id,
11
+ name,
12
+ value,
13
+ checked,
14
+ disabled,
15
+ isReadOnly,
16
+ size,
17
+ text,
18
+ labelSize,
19
+ labelPalette,
20
+ title,
21
+ disableTitle,
22
+ dataId,
23
+ dataSelectorId,
24
+ customClass,
25
+ customProps
26
+ } = props;
27
+
28
+ function onChange(e) {
29
+ const {
30
+ onChange
31
+ } = props;
32
+ onChange && onChange(!checked, e);
33
+ }
34
+
35
+ let {
36
+ SwitchProps = {},
37
+ LabelProps = {}
38
+ } = customProps;
39
+ let {
40
+ customSwitchWrap = '',
41
+ customSwitch = '',
42
+ customSwitchSize = '',
43
+ customLabel = ''
44
+ } = customClass;
45
+ size !== 'small' ? size = 'switch_medium' : size = 'switch_small';
46
+ return /*#__PURE__*/React.createElement(Container, {
47
+ align: "vertical",
48
+ isCover: false,
49
+ alignBox: "row",
50
+ isInline: true,
51
+ className: `${style.container} ${customSwitchWrap} ${disabled ? style.disabled : isReadOnly ? style.readonly : style.effect}`,
52
+ "data-title": disabled ? disableTitle : title,
53
+ "aria-checked": checked,
54
+ role: "switch",
55
+ dataSelectorId: dataSelectorId,
56
+ ...SwitchProps
57
+ }, /*#__PURE__*/React.createElement(Box, {
58
+ className: `${style[size]} ${customSwitchSize}`
59
+ }, /*#__PURE__*/React.createElement("input", {
60
+ type: "checkbox",
61
+ id: id,
62
+ className: `${style.input} ${checked ? style.checked : ''}`,
63
+ name: name,
64
+ value: value,
65
+ checked: checked,
66
+ disabled: disabled,
67
+ readOnly: isReadOnly,
68
+ onClick: !disabled || !isReadOnly ? onChange : null
69
+ }), /*#__PURE__*/React.createElement("label", {
70
+ htmlFor: id,
71
+ "data-id": dataId,
72
+ "data-test-id": dataId,
73
+ className: `${style.label} ${style[`${size}Label`]} ${customSwitch}`,
74
+ tabIndex: isReadOnly || disabled ? '-1' : '0'
75
+ })), text && /*#__PURE__*/React.createElement(Label, {
76
+ text: text,
77
+ palette: labelPalette,
78
+ id: id,
79
+ size: labelSize,
80
+ type: "subtitle",
81
+ onClick: !disabled || !isReadOnly ? onChange : null,
82
+ customClass: customLabel,
83
+ ...LabelProps
84
+ }));
85
+ };
86
+
87
+ Switch.defaultProps = defaultProps;
88
+ Switch.propTypes = propTypes;
89
+ export default Switch; // if (__DOCS__) {
90
+ // Switch.docs = {
91
+ // componentGroup: 'Form Elements',
92
+ // folderName: 'Style Guide'
93
+ // };
94
+ // }
@@ -0,0 +1,11 @@
1
+ export const defaultProps = {
2
+ checked: false,
3
+ disabled: false,
4
+ labelPalette: 'primary',
5
+ labelSize: 'medium',
6
+ size: 'medium',
7
+ isReadOnly: false,
8
+ customClass: {},
9
+ customProps: {},
10
+ dataSelectorId: 'switch'
11
+ };
@@ -0,0 +1,28 @@
1
+ import PropTypes from 'prop-types';
2
+ export const propTypes = {
3
+ checked: PropTypes.bool,
4
+ dataId: PropTypes.string,
5
+ dataSelectorId: PropTypes.string,
6
+ disableTitle: PropTypes.string,
7
+ disabled: PropTypes.bool,
8
+ id: PropTypes.string.isRequired,
9
+ isReadOnly: PropTypes.bool,
10
+ labelPalette: PropTypes.oneOf(['default', 'primary', 'secondary', 'danger', 'mandatory']),
11
+ labelSize: PropTypes.oneOf(['small', 'medium', 'large']),
12
+ name: PropTypes.string,
13
+ onChange: PropTypes.func,
14
+ size: PropTypes.oneOf(['small', 'medium']),
15
+ text: PropTypes.string,
16
+ title: PropTypes.string,
17
+ value: PropTypes.bool,
18
+ customClass: PropTypes.shape({
19
+ customSwitchWrap: PropTypes.string,
20
+ customSwitch: PropTypes.string,
21
+ customSwitchSize: PropTypes.string,
22
+ customLabel: PropTypes.string
23
+ }),
24
+ customProps: PropTypes.shape({
25
+ SwitchProps: PropTypes.object,
26
+ LabelProps: PropTypes.object
27
+ })
28
+ };