@lumx/react 3.1.4 → 3.1.5

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/package.json CHANGED
@@ -7,8 +7,8 @@
7
7
  },
8
8
  "dependencies": {
9
9
  "@juggle/resize-observer": "^3.2.0",
10
- "@lumx/core": "^3.1.4",
11
- "@lumx/icons": "^3.1.4",
10
+ "@lumx/core": "^3.1.5",
11
+ "@lumx/icons": "^3.1.5",
12
12
  "@popperjs/core": "^2.5.4",
13
13
  "body-scroll-lock": "^3.1.5",
14
14
  "classnames": "^2.2.6",
@@ -113,5 +113,5 @@
113
113
  "build:storybook": "cd storybook && ./build"
114
114
  },
115
115
  "sideEffects": false,
116
- "version": "3.1.4"
116
+ "version": "3.1.5"
117
117
  }
@@ -11,6 +11,7 @@ exports[`<AlertDialog> Snapshots and structure should render story 'Default' 1`]
11
11
  "role": "alertdialog",
12
12
  }
13
13
  }
14
+ disableBodyScroll={true}
14
15
  focusElement={
15
16
  {
16
17
  "current": null,
@@ -84,6 +85,7 @@ exports[`<AlertDialog> Snapshots and structure should render story 'Error' 1`] =
84
85
  "role": "alertdialog",
85
86
  }
86
87
  }
88
+ disableBodyScroll={true}
87
89
  focusElement={
88
90
  {
89
91
  "current": null,
@@ -157,6 +159,7 @@ exports[`<AlertDialog> Snapshots and structure should render story 'RichDescript
157
159
  "role": "alertdialog",
158
160
  }
159
161
  }
162
+ disableBodyScroll={true}
160
163
  focusElement={
161
164
  {
162
165
  "current": null,
@@ -243,6 +246,7 @@ exports[`<AlertDialog> Snapshots and structure should render story 'Success' 1`]
243
246
  "role": "alertdialog",
244
247
  }
245
248
  }
249
+ disableBodyScroll={true}
246
250
  focusElement={
247
251
  {
248
252
  "current": null,
@@ -316,6 +320,7 @@ exports[`<AlertDialog> Snapshots and structure should render story 'Warning' 1`]
316
320
  "role": "alertdialog",
317
321
  }
318
322
  }
323
+ disableBodyScroll={true}
319
324
  focusElement={
320
325
  {
321
326
  "current": null,
@@ -389,6 +394,7 @@ exports[`<AlertDialog> Snapshots and structure should render story 'WithCancel'
389
394
  "role": "alertdialog",
390
395
  }
391
396
  }
397
+ disableBodyScroll={true}
392
398
  focusElement={
393
399
  {
394
400
  "current": null,
@@ -470,6 +476,7 @@ exports[`<AlertDialog> Snapshots and structure should render story 'WithForwarde
470
476
  "role": "alertdialog",
471
477
  }
472
478
  }
479
+ disableBodyScroll={true}
473
480
  focusElement={
474
481
  {
475
482
  "current": null,
@@ -72,6 +72,18 @@ export const SimpleDialog = ({ theme }: any) => {
72
72
  );
73
73
  };
74
74
 
75
+ export const WithBodyScroll = ({ theme }: any) => {
76
+ const { button, buttonRef, closeDialog, isOpen } = useOpenButton(theme);
77
+ return (
78
+ <>
79
+ {button}
80
+ <Dialog isOpen={isOpen} onClose={closeDialog} parentElement={buttonRef} disableBodyScroll={false}>
81
+ {content}
82
+ </Dialog>
83
+ </>
84
+ );
85
+ };
86
+
75
87
  export const PreventDialogAutoClose = ({ theme }: any) => {
76
88
  const { button, buttonRef, closeDialog, isOpen } = useOpenButton(theme);
77
89
  return (
@@ -93,6 +105,48 @@ export const PreventDialogAutoClose = ({ theme }: any) => {
93
105
  );
94
106
  };
95
107
 
108
+ export const PreventDialogCloseOnEscape = ({ theme }: any) => {
109
+ const { button, buttonRef, closeDialog, isOpen } = useOpenButton(theme);
110
+ return (
111
+ <>
112
+ {button}
113
+ <Dialog preventCloseOnEscape isOpen={isOpen} onClose={closeDialog} parentElement={buttonRef}>
114
+ {content}
115
+ <footer>
116
+ <Toolbar
117
+ after={
118
+ <Button onClick={closeDialog} emphasis={Emphasis.low}>
119
+ Close
120
+ </Button>
121
+ }
122
+ />
123
+ </footer>
124
+ </Dialog>
125
+ </>
126
+ );
127
+ };
128
+
129
+ export const PreventDialogCloseOnClick = ({ theme }: any) => {
130
+ const { button, buttonRef, closeDialog, isOpen } = useOpenButton(theme);
131
+ return (
132
+ <>
133
+ {button}
134
+ <Dialog preventCloseOnClick isOpen={isOpen} onClose={closeDialog} parentElement={buttonRef}>
135
+ {content}
136
+ <footer>
137
+ <Toolbar
138
+ after={
139
+ <Button onClick={closeDialog} emphasis={Emphasis.low}>
140
+ Close
141
+ </Button>
142
+ }
143
+ />
144
+ </footer>
145
+ </Dialog>
146
+ </>
147
+ );
148
+ };
149
+
96
150
  export const DialogWithAlertDialog = ({ theme }: any) => {
97
151
  const { button, buttonRef, closeDialog, isOpen } = useOpenButton(theme);
98
152
  const { openDialog: openAlertDialog, closeDialog: closeAlertDialog, isOpen: isAlertDialogOpen } = useOpenButton(
@@ -76,6 +76,14 @@ describe(`<${Dialog.displayName}>`, () => {
76
76
  document.body.dispatchEvent(keyDown('Escape'));
77
77
  expect(onClose).not.toHaveBeenCalled();
78
78
  });
79
+
80
+ it('should not trigger `onClose` when pressing `escape` key with `preventCloseOnEscape` set to `true`', () => {
81
+ const onClose = jest.fn();
82
+ setup({ isOpen: true, onClose, preventCloseOnEscape: true }, false);
83
+
84
+ document.body.dispatchEvent(keyDown('Escape'));
85
+ expect(onClose).not.toHaveBeenCalled();
86
+ });
79
87
  });
80
88
 
81
89
  // 4. Test conditions (i.e. things that display or not in the UI based on props).
@@ -43,6 +43,10 @@ export interface DialogProps extends GenericProps {
43
43
  focusElement?: RefObject<HTMLElement>;
44
44
  /** Whether to keep the dialog open on clickaway or escape press. */
45
45
  preventAutoClose?: boolean;
46
+ /** Whether to keep the dialog open on escape press. */
47
+ preventCloseOnEscape?: boolean;
48
+ /** Whether to keep the dialog open on clickaway. */
49
+ preventCloseOnClick?: boolean;
46
50
  /** Size variant. */
47
51
  size?: DialogSizes;
48
52
  /** Z-axis position. */
@@ -53,6 +57,8 @@ export interface DialogProps extends GenericProps {
53
57
  onClose?(): void;
54
58
  /** Callback called when the open animation starts and the close animation finishes. */
55
59
  onVisibilityChange?(isVisible: boolean): void;
60
+ /** whether to disable the scroll on the body or not */
61
+ disableBodyScroll?: boolean;
56
62
  }
57
63
 
58
64
  export type DialogSizes = Extract<Size, 'tiny' | 'regular' | 'big' | 'huge'>;
@@ -75,6 +81,7 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
75
81
  */
76
82
  const DEFAULT_PROPS: Partial<DialogProps> = {
77
83
  size: Size.big,
84
+ disableBodyScroll: true,
78
85
  };
79
86
 
80
87
  /**
@@ -108,6 +115,9 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
108
115
  zIndex,
109
116
  dialogProps,
110
117
  onVisibilityChange,
118
+ disableBodyScroll,
119
+ preventCloseOnClick,
120
+ preventCloseOnEscape,
111
121
  ...forwardedProps
112
122
  } = props;
113
123
 
@@ -125,8 +135,10 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
125
135
  }
126
136
  }, [isOpen, parentElement]);
127
137
 
138
+ const shouldPreventCloseOnEscape = preventAutoClose || preventCloseOnEscape;
139
+
128
140
  // eslint-disable-next-line react-hooks/rules-of-hooks
129
- useCallbackOnEscape(onClose, isOpen && !preventAutoClose);
141
+ useCallbackOnEscape(onClose, isOpen && !shouldPreventCloseOnEscape);
130
142
 
131
143
  // eslint-disable-next-line react-hooks/rules-of-hooks
132
144
  const wrapperRef = useRef<HTMLDivElement>(null);
@@ -141,7 +153,7 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
141
153
  useFocusTrap(isOpen && wrapperRef.current, focusElement?.current);
142
154
 
143
155
  // eslint-disable-next-line react-hooks/rules-of-hooks
144
- useDisableBodyScroll(isOpen && localContentRef.current);
156
+ useDisableBodyScroll(disableBodyScroll && isOpen && localContentRef.current);
145
157
 
146
158
  // eslint-disable-next-line react-hooks/rules-of-hooks
147
159
  const [sentinelTop, setSentinelTop] = useState<Element | null>(null);
@@ -175,6 +187,8 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
175
187
  // eslint-disable-next-line react-hooks/rules-of-hooks
176
188
  const isVisible = useTransitionVisibility(rootRef, Boolean(isOpen), onVisibilityChange);
177
189
 
190
+ const shouldPreventCloseOnClickAway = preventAutoClose || preventCloseOnClick;
191
+
178
192
  return isOpen || isVisible
179
193
  ? createPortal(
180
194
  <div
@@ -196,7 +210,7 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
196
210
 
197
211
  <section className={`${CLASSNAME}__container`} role="dialog" aria-modal="true" {...dialogProps}>
198
212
  <ClickAwayProvider
199
- callback={!preventAutoClose && onClose}
213
+ callback={!shouldPreventCloseOnClickAway && onClose}
200
214
  childrenRefs={clickAwayRefs}
201
215
  parentRef={rootRef}
202
216
  >
@@ -11,6 +11,7 @@ exports[`<Dialog> Snapshots and structure should render story DialogFocusTrap 1`
11
11
  Open dialog
12
12
  </Button>
13
13
  <Dialog
14
+ disableBodyScroll={true}
14
15
  focusElement={
15
16
  {
16
17
  "current": null,
@@ -96,6 +97,7 @@ exports[`<Dialog> Snapshots and structure should render story DialogFocusTrap 1`
96
97
  Open date picker
97
98
  </Button>
98
99
  <Dialog
100
+ disableBodyScroll={true}
99
101
  isOpen={false}
100
102
  onClose={[Function]}
101
103
  parentElement={
@@ -242,6 +244,7 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithAlertDia
242
244
  Open dialog
243
245
  </Button>
244
246
  <Dialog
247
+ disableBodyScroll={true}
245
248
  isOpen={true}
246
249
  onClose={[Function]}
247
250
  parentElement={
@@ -318,6 +321,7 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithHeaderFo
318
321
  Open dialog
319
322
  </Button>
320
323
  <Dialog
324
+ disableBodyScroll={true}
321
325
  forceFooterDivider={true}
322
326
  forceHeaderDivider={true}
323
327
  isOpen={true}
@@ -372,6 +376,7 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithHeaderFo
372
376
  Open dialog
373
377
  </Button>
374
378
  <Dialog
379
+ disableBodyScroll={true}
375
380
  isOpen={true}
376
381
  onClose={[Function]}
377
382
  parentElement={
@@ -424,6 +429,7 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithHeaderFo
424
429
  Open dialog
425
430
  </Button>
426
431
  <Dialog
432
+ disableBodyScroll={true}
427
433
  footer="Footer prop"
428
434
  header="Header prop"
429
435
  isOpen={true}
@@ -468,6 +474,7 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithHeaderFo
468
474
  Open dialog
469
475
  </Button>
470
476
  <Dialog
477
+ disableBodyScroll={true}
471
478
  footer=" Footer prop"
472
479
  header=" Header prop"
473
480
  isOpen={true}
@@ -522,6 +529,7 @@ exports[`<Dialog> Snapshots and structure should render story LoadingDialog 1`]
522
529
  Open dialog
523
530
  </Button>
524
531
  <Dialog
532
+ disableBodyScroll={true}
525
533
  isLoading={true}
526
534
  isOpen={true}
527
535
  onClose={[Function]}
@@ -565,6 +573,7 @@ exports[`<Dialog> Snapshots and structure should render story PreventDialogAutoC
565
573
  Open dialog
566
574
  </Button>
567
575
  <Dialog
576
+ disableBodyScroll={true}
568
577
  isOpen={true}
569
578
  onClose={[Function]}
570
579
  parentElement={
@@ -611,6 +620,122 @@ tertiam. Cras mattis iudicium purus sit amet fermentum
611
620
  </Fragment>
612
621
  `;
613
622
 
623
+ exports[`<Dialog> Snapshots and structure should render story PreventDialogCloseOnClick 1`] = `
624
+ <Fragment>
625
+ <Button
626
+ emphasis="high"
627
+ onClick={[Function]}
628
+ size="m"
629
+ theme="light"
630
+ >
631
+ Open dialog
632
+ </Button>
633
+ <Dialog
634
+ disableBodyScroll={true}
635
+ isOpen={true}
636
+ onClose={[Function]}
637
+ parentElement={
638
+ {
639
+ "current": undefined,
640
+ }
641
+ }
642
+ preventCloseOnClick={true}
643
+ size="big"
644
+ >
645
+ <div
646
+ className="lumx-spacing-padding"
647
+ >
648
+
649
+ Nihil hic munitissimus habendi senatus locus, nihil horum? At nos hinc posthac, sitientis piros
650
+ Afros. Magna pars studiorum, prodita quaerimus. Integer legentibus erat a ante historiarum
651
+ dapibus. Praeterea iter est quasdam res quas ex communi. Ullamco laboris nisi ut aliquid ex ea
652
+ commodi consequat. Inmensae subtilitatis, obscuris et malesuada fames. Me non paenitet nullum
653
+ festiviorem excogitasse ad hoc. Cum ceteris in veneratione tui montes, nascetur mus. Etiam
654
+ habebis sem dicantur magna mollis euismod. Quis aute iure reprehenderit in voluptate velit esse.
655
+ Phasellus laoreet lorem vel dolor tempus vehicula. Ambitioni dedisse scripsisse iudicaretur.
656
+ Paullum deliquit, ponderibus modulisque suis ratio utitur. Ab illo tempore, ab est sed
657
+ immemorabili. Nec dubitamus multa iter quae et nos invenerat. Tu quoque, Brute, fili mi, nihil
658
+ timor populi, nihil! Morbi fringilla convallis sapien, id pulvinar odio volutpat. Cras mattis
659
+ iudicium purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus.
660
+ Quisque ut dolor gravida, placerat libero vel, euismod. Unam incolunt Belgae, aliam Aquitani,
661
+ tertiam. Cras mattis iudicium purus sit amet fermentum
662
+ </div>
663
+ <footer>
664
+ <Toolbar
665
+ after={
666
+ <Button
667
+ emphasis="low"
668
+ onClick={[Function]}
669
+ size="m"
670
+ theme="light"
671
+ >
672
+ Close
673
+ </Button>
674
+ }
675
+ />
676
+ </footer>
677
+ </Dialog>
678
+ </Fragment>
679
+ `;
680
+
681
+ exports[`<Dialog> Snapshots and structure should render story PreventDialogCloseOnEscape 1`] = `
682
+ <Fragment>
683
+ <Button
684
+ emphasis="high"
685
+ onClick={[Function]}
686
+ size="m"
687
+ theme="light"
688
+ >
689
+ Open dialog
690
+ </Button>
691
+ <Dialog
692
+ disableBodyScroll={true}
693
+ isOpen={true}
694
+ onClose={[Function]}
695
+ parentElement={
696
+ {
697
+ "current": undefined,
698
+ }
699
+ }
700
+ preventCloseOnEscape={true}
701
+ size="big"
702
+ >
703
+ <div
704
+ className="lumx-spacing-padding"
705
+ >
706
+
707
+ Nihil hic munitissimus habendi senatus locus, nihil horum? At nos hinc posthac, sitientis piros
708
+ Afros. Magna pars studiorum, prodita quaerimus. Integer legentibus erat a ante historiarum
709
+ dapibus. Praeterea iter est quasdam res quas ex communi. Ullamco laboris nisi ut aliquid ex ea
710
+ commodi consequat. Inmensae subtilitatis, obscuris et malesuada fames. Me non paenitet nullum
711
+ festiviorem excogitasse ad hoc. Cum ceteris in veneratione tui montes, nascetur mus. Etiam
712
+ habebis sem dicantur magna mollis euismod. Quis aute iure reprehenderit in voluptate velit esse.
713
+ Phasellus laoreet lorem vel dolor tempus vehicula. Ambitioni dedisse scripsisse iudicaretur.
714
+ Paullum deliquit, ponderibus modulisque suis ratio utitur. Ab illo tempore, ab est sed
715
+ immemorabili. Nec dubitamus multa iter quae et nos invenerat. Tu quoque, Brute, fili mi, nihil
716
+ timor populi, nihil! Morbi fringilla convallis sapien, id pulvinar odio volutpat. Cras mattis
717
+ iudicium purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus.
718
+ Quisque ut dolor gravida, placerat libero vel, euismod. Unam incolunt Belgae, aliam Aquitani,
719
+ tertiam. Cras mattis iudicium purus sit amet fermentum
720
+ </div>
721
+ <footer>
722
+ <Toolbar
723
+ after={
724
+ <Button
725
+ emphasis="low"
726
+ onClick={[Function]}
727
+ size="m"
728
+ theme="light"
729
+ >
730
+ Close
731
+ </Button>
732
+ }
733
+ />
734
+ </footer>
735
+ </Dialog>
736
+ </Fragment>
737
+ `;
738
+
614
739
  exports[`<Dialog> Snapshots and structure should render story ScrollableDialog 1`] = `
615
740
  <Fragment>
616
741
  <Button
@@ -622,6 +747,7 @@ exports[`<Dialog> Snapshots and structure should render story ScrollableDialog 1
622
747
  Open dialog
623
748
  </Button>
624
749
  <Dialog
750
+ disableBodyScroll={true}
625
751
  isOpen={true}
626
752
  onClose={[Function]}
627
753
  parentElement={
@@ -706,6 +832,7 @@ exports[`<Dialog> Snapshots and structure should render story ScrollableDialogWi
706
832
  Open dialog
707
833
  </Button>
708
834
  <Dialog
835
+ disableBodyScroll={true}
709
836
  isOpen={true}
710
837
  onClose={[Function]}
711
838
  parentElement={
@@ -800,6 +927,7 @@ exports[`<Dialog> Snapshots and structure should render story SimpleDialog 1`] =
800
927
  Open dialog
801
928
  </Button>
802
929
  <Dialog
930
+ disableBodyScroll={true}
803
931
  isOpen={true}
804
932
  onClose={[Function]}
805
933
  parentElement={
@@ -843,6 +971,7 @@ exports[`<Dialog> Snapshots and structure should render story Sizes 1`] = `
843
971
  </Button>
844
972
  Use the knobs to change the dialog size!
845
973
  <Dialog
974
+ disableBodyScroll={true}
846
975
  isOpen={true}
847
976
  onClose={[Function]}
848
977
  parentElement={
@@ -927,6 +1056,7 @@ exports[`<Dialog> Snapshots and structure should render story WithAnimationCallb
927
1056
  Open dialog
928
1057
  </Button>
929
1058
  <Dialog
1059
+ disableBodyScroll={true}
930
1060
  isOpen={true}
931
1061
  onClose={[Function]}
932
1062
  onVisibilityChange={[Function]}
@@ -958,3 +1088,46 @@ tertiam. Cras mattis iudicium purus sit amet fermentum
958
1088
  </Dialog>
959
1089
  </Fragment>
960
1090
  `;
1091
+
1092
+ exports[`<Dialog> Snapshots and structure should render story WithBodyScroll 1`] = `
1093
+ <Fragment>
1094
+ <Button
1095
+ emphasis="high"
1096
+ onClick={[Function]}
1097
+ size="m"
1098
+ theme="light"
1099
+ >
1100
+ Open dialog
1101
+ </Button>
1102
+ <Dialog
1103
+ disableBodyScroll={false}
1104
+ isOpen={true}
1105
+ onClose={[Function]}
1106
+ parentElement={
1107
+ {
1108
+ "current": undefined,
1109
+ }
1110
+ }
1111
+ size="big"
1112
+ >
1113
+ <div
1114
+ className="lumx-spacing-padding"
1115
+ >
1116
+
1117
+ Nihil hic munitissimus habendi senatus locus, nihil horum? At nos hinc posthac, sitientis piros
1118
+ Afros. Magna pars studiorum, prodita quaerimus. Integer legentibus erat a ante historiarum
1119
+ dapibus. Praeterea iter est quasdam res quas ex communi. Ullamco laboris nisi ut aliquid ex ea
1120
+ commodi consequat. Inmensae subtilitatis, obscuris et malesuada fames. Me non paenitet nullum
1121
+ festiviorem excogitasse ad hoc. Cum ceteris in veneratione tui montes, nascetur mus. Etiam
1122
+ habebis sem dicantur magna mollis euismod. Quis aute iure reprehenderit in voluptate velit esse.
1123
+ Phasellus laoreet lorem vel dolor tempus vehicula. Ambitioni dedisse scripsisse iudicaretur.
1124
+ Paullum deliquit, ponderibus modulisque suis ratio utitur. Ab illo tempore, ab est sed
1125
+ immemorabili. Nec dubitamus multa iter quae et nos invenerat. Tu quoque, Brute, fili mi, nihil
1126
+ timor populi, nihil! Morbi fringilla convallis sapien, id pulvinar odio volutpat. Cras mattis
1127
+ iudicium purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus.
1128
+ Quisque ut dolor gravida, placerat libero vel, euismod. Unam incolunt Belgae, aliam Aquitani,
1129
+ tertiam. Cras mattis iudicium purus sit amet fermentum
1130
+ </div>
1131
+ </Dialog>
1132
+ </Fragment>
1133
+ `;