@thecb/components 10.5.0-beta.0 → 10.5.0-beta.2

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/index.cjs.js CHANGED
@@ -46304,14 +46304,25 @@ var Modal$1 = function Modal(_ref) {
46304
46304
  blurUnderlay = _ref$blurUnderlay === void 0 ? true : _ref$blurUnderlay;
46305
46305
  var _useContext = React.useContext(styled.ThemeContext),
46306
46306
  isMobile = _useContext.isMobile;
46307
- var modalContainerRef = React.useRef(null);
46307
+
46308
+ // `AriaModal` uses `focus-trap` as a transient dependency. It automatically looks
46309
+ // for a tabbable node when the modal mounts. When it doesn't find one, it looks to
46310
+ // the `fallbackFocus` option. However, React does not guarantee the ref supplied to
46311
+ // this option will be populated on initial render when `focus-trap` is checking
46312
+ // these option. When there are no buttons in the modal, this causes an error.
46313
+ // Because `focus-trap` cannot be disabled, the ref requires a dummy node to satisfy
46314
+ // `focus-trap` until React populates it with the real ref value.
46315
+ //
46316
+ // See:
46317
+ // - https://react.dev/reference/react/useRef#caveats
46318
+ // - https://github.com/davidtheclark/react-aria-modal/pull/103
46319
+ var modalContainerRef = React.useRef( /*#__PURE__*/React__default.createElement("div", null));
46308
46320
  return /*#__PURE__*/React__default.createElement("div", {
46309
46321
  ref: modalContainerRef,
46310
46322
  "data-qa": dataQa
46311
- }, modalOpen && /*#__PURE__*/React__default.createElement(reactAriaModal
46312
- // fallback to resolve Jest unit test errors when tabbable doesn't exist in jsdom https://github.com/focus-trap/focus-trap-react/issues/91
46313
- , {
46323
+ }, modalOpen && /*#__PURE__*/React__default.createElement(reactAriaModal, {
46314
46324
  focusTrapOptions: {
46325
+ // fallback to resolve Jest unit test errors when tabbable doesn't exist in jsdom https://github.com/focus-trap/focus-trap-react/issues/91
46315
46326
  fallbackFocus: modalContainerRef === null || modalContainerRef === void 0 ? void 0 : modalContainerRef.current
46316
46327
  },
46317
46328
  onExit: onExit,
@@ -46436,6 +46447,112 @@ var Modal$1 = function Modal(_ref) {
46436
46447
  }))))))))), children);
46437
46448
  };
46438
46449
 
46450
+ var ButtonLayoutWrapper = function ButtonLayoutWrapper(_ref) {
46451
+ var _ref$children = _ref.children,
46452
+ children = _ref$children === void 0 ? [] : _ref$children,
46453
+ _ref$isMobile = _ref.isMobile,
46454
+ isMobile = _ref$isMobile === void 0 ? false : _ref$isMobile;
46455
+ var safeChildren = Array.isArray(children) ? children : [children];
46456
+ var flexGrow = isMobile ? "flex-grow: 1;" : "";
46457
+ return /*#__PURE__*/React__default.createElement(Box, {
46458
+ padding: SPACING_NORMAL
46459
+ }, /*#__PURE__*/React__default.createElement(Stack, {
46460
+ childGap: "1rem",
46461
+ direction: "row",
46462
+ justify: "flex-end"
46463
+ }, safeChildren.map(function (child, index) {
46464
+ return /*#__PURE__*/React__default.createElement(Box, {
46465
+ padding: "0",
46466
+ extraStyles: flexGrow,
46467
+ key: index
46468
+ }, child);
46469
+ })));
46470
+ };
46471
+
46472
+ var CancelButton = function CancelButton(_ref) {
46473
+ var _ref$buttonExtraStyle = _ref.buttonExtraStyles,
46474
+ buttonExtraStyles = _ref$buttonExtraStyle === void 0 ? "" : _ref$buttonExtraStyle,
46475
+ _ref$cancelAction = _ref.cancelAction,
46476
+ cancelAction = _ref$cancelAction === void 0 ? noop : _ref$cancelAction,
46477
+ _ref$cancelButtonText = _ref.cancelButtonText,
46478
+ cancelButtonText = _ref$cancelButtonText === void 0 ? "" : _ref$cancelButtonText,
46479
+ _ref$hideModal = _ref.hideModal,
46480
+ hideModal = _ref$hideModal === void 0 ? noop : _ref$hideModal,
46481
+ _ref$isMobile = _ref.isMobile,
46482
+ isMobile = _ref$isMobile === void 0 ? false : _ref$isMobile;
46483
+ var fullWidth = isMobile ? "width: 100%;" : "";
46484
+ return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
46485
+ action: cancelAction ? cancelAction : hideModal,
46486
+ borderRadius: CORNER_STANDARD,
46487
+ className: "modal-cancel-button",
46488
+ dataQa: cancelButtonText,
46489
+ extraStyles: "".concat(buttonExtraStyles, "; margin: 0; ").concat(fullWidth),
46490
+ name: cancelButtonText,
46491
+ role: "button",
46492
+ text: cancelButtonText,
46493
+ variant: "secondary"
46494
+ });
46495
+ };
46496
+
46497
+ var CloseButton = function CloseButton(_ref) {
46498
+ var _ref$buttonExtraStyle = _ref.buttonExtraStyles,
46499
+ buttonExtraStyles = _ref$buttonExtraStyle === void 0 ? "" : _ref$buttonExtraStyle,
46500
+ _ref$closeButtonText = _ref.closeButtonText,
46501
+ closeButtonText = _ref$closeButtonText === void 0 ? "" : _ref$closeButtonText,
46502
+ _ref$hideModal = _ref.hideModal,
46503
+ hideModal = _ref$hideModal === void 0 ? noop : _ref$hideModal,
46504
+ _ref$isMobile = _ref.isMobile,
46505
+ isMobile = _ref$isMobile === void 0 ? false : _ref$isMobile;
46506
+ var fullWidth = isMobile ? "width: 100%;" : "";
46507
+ return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
46508
+ action: hideModal,
46509
+ borderRadius: CORNER_STANDARD,
46510
+ className: "modal-close-button",
46511
+ dataQa: closeButtonText,
46512
+ extraStyles: "".concat(buttonExtraStyles, "; margin: 0; ").concat(fullWidth),
46513
+ name: closeButtonText,
46514
+ role: "button",
46515
+ text: closeButtonText,
46516
+ variant: "primary"
46517
+ });
46518
+ };
46519
+
46520
+ var ContinueButton = function ContinueButton(_ref) {
46521
+ var _ref$buttonExtraStyle = _ref.buttonExtraStyles,
46522
+ buttonExtraStyles = _ref$buttonExtraStyle === void 0 ? "" : _ref$buttonExtraStyle,
46523
+ _ref$continueAction = _ref.continueAction,
46524
+ continueAction = _ref$continueAction === void 0 ? noop : _ref$continueAction,
46525
+ _ref$continueButtonTe = _ref.continueButtonText,
46526
+ continueButtonText = _ref$continueButtonTe === void 0 ? "" : _ref$continueButtonTe,
46527
+ _ref$continueURL = _ref.continueURL,
46528
+ continueURL = _ref$continueURL === void 0 ? "" : _ref$continueURL,
46529
+ _ref$isContinueAction = _ref.isContinueActionDisabled,
46530
+ isContinueActionDisabled = _ref$isContinueAction === void 0 ? false : _ref$isContinueAction,
46531
+ _ref$isLoading = _ref.isLoading,
46532
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
46533
+ _ref$isMobile = _ref.isMobile,
46534
+ isMobile = _ref$isMobile === void 0 ? false : _ref$isMobile,
46535
+ _ref$useDangerButton = _ref.useDangerButton,
46536
+ useDangerButton = _ref$useDangerButton === void 0 ? false : _ref$useDangerButton;
46537
+ var ContinueButtonAtom = continueURL ? ButtonWithLink : ButtonWithAction;
46538
+ var fullWidth = isMobile ? "width: 100%;" : "";
46539
+ return /*#__PURE__*/React__default.createElement(ContinueButtonAtom, {
46540
+ action: continueAction,
46541
+ borderRadius: CORNER_STANDARD,
46542
+ className: "modal-continue-button",
46543
+ dataQa: continueButtonText,
46544
+ disabled: isContinueActionDisabled,
46545
+ extraStyles: "".concat(buttonExtraStyles, "; margin: 0; ").concat(fullWidth),
46546
+ isLoading: isLoading,
46547
+ linkExtraStyles: "display: inline-block; ".concat(fullWidth),
46548
+ name: continueButtonText,
46549
+ role: "button",
46550
+ text: continueButtonText,
46551
+ url: continueURL,
46552
+ variant: useDangerButton ? "danger" : "primary"
46553
+ });
46554
+ };
46555
+
46439
46556
  /*
46440
46557
  Default Modal molecule
46441
46558
  Uses react-aria-modal behind the scenes for a11y purposes
@@ -46452,35 +46569,48 @@ var getApplicationNode$1 = function getApplicationNode() {
46452
46569
  var Modal$2 = function Modal(_ref) {
46453
46570
  var _ref$blurUnderlay = _ref.blurUnderlay,
46454
46571
  blurUnderlay = _ref$blurUnderlay === void 0 ? true : _ref$blurUnderlay,
46455
- buttonExtraStyles = _ref.buttonExtraStyles,
46456
- cancelAction = _ref.cancelAction,
46572
+ _ref$buttonExtraStyle = _ref.buttonExtraStyles,
46573
+ buttonExtraStyles = _ref$buttonExtraStyle === void 0 ? "" : _ref$buttonExtraStyle,
46574
+ _ref$cancelAction = _ref.cancelAction,
46575
+ cancelAction = _ref$cancelAction === void 0 ? noop : _ref$cancelAction,
46457
46576
  _ref$cancelButtonText = _ref.cancelButtonText,
46458
46577
  cancelButtonText = _ref$cancelButtonText === void 0 ? "Cancel" : _ref$cancelButtonText,
46459
- children = _ref.children,
46578
+ _ref$children = _ref.children,
46579
+ children = _ref$children === void 0 ? [] : _ref$children,
46460
46580
  _ref$closeButtonText = _ref.closeButtonText,
46461
46581
  closeButtonText = _ref$closeButtonText === void 0 ? "Close" : _ref$closeButtonText,
46462
- continueAction = _ref.continueAction,
46582
+ _ref$continueAction = _ref.continueAction,
46583
+ continueAction = _ref$continueAction === void 0 ? noop : _ref$continueAction,
46463
46584
  _ref$continueButtonTe = _ref.continueButtonText,
46464
46585
  continueButtonText = _ref$continueButtonTe === void 0 ? "Continue" : _ref$continueButtonTe,
46465
- customWidth = _ref.customWidth,
46586
+ _ref$continueURL = _ref.continueURL,
46587
+ continueURL = _ref$continueURL === void 0 ? "" : _ref$continueURL,
46588
+ _ref$customWidth = _ref.customWidth,
46589
+ customWidth = _ref$customWidth === void 0 ? "" : _ref$customWidth,
46466
46590
  _ref$dataQa = _ref.dataQa,
46467
46591
  dataQa = _ref$dataQa === void 0 ? null : _ref$dataQa,
46468
46592
  _ref$defaultWrapper = _ref.defaultWrapper,
46469
46593
  defaultWrapper = _ref$defaultWrapper === void 0 ? true : _ref$defaultWrapper,
46470
- hideModal = _ref.hideModal,
46594
+ _ref$hideModal = _ref.hideModal,
46595
+ hideModal = _ref$hideModal === void 0 ? noop : _ref$hideModal,
46471
46596
  _ref$initialFocusSele = _ref.initialFocusSelector,
46472
46597
  initialFocusSelector = _ref$initialFocusSele === void 0 ? "" : _ref$initialFocusSele,
46473
46598
  _ref$isContinueAction = _ref.isContinueActionDisabled,
46474
46599
  isContinueActionDisabled = _ref$isContinueAction === void 0 ? false : _ref$isContinueAction,
46475
- isLoading = _ref.isLoading,
46476
- maxHeight = _ref.maxHeight,
46600
+ _ref$isLoading = _ref.isLoading,
46601
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
46602
+ _ref$maxHeight = _ref.maxHeight,
46603
+ maxHeight = _ref$maxHeight === void 0 ? "" : _ref$maxHeight,
46477
46604
  _ref$modalBodyBg = _ref.modalBodyBg,
46478
46605
  modalBodyBg = _ref$modalBodyBg === void 0 ? ATHENS_GREY : _ref$modalBodyBg,
46479
- modalBodyText = _ref.modalBodyText,
46606
+ _ref$modalBodyText = _ref.modalBodyText,
46607
+ modalBodyText = _ref$modalBodyText === void 0 ? "" : _ref$modalBodyText,
46480
46608
  _ref$modalHeaderBg = _ref.modalHeaderBg,
46481
46609
  modalHeaderBg = _ref$modalHeaderBg === void 0 ? WHITE : _ref$modalHeaderBg,
46482
- modalHeaderText = _ref.modalHeaderText,
46483
- modalOpen = _ref.modalOpen,
46610
+ _ref$modalHeaderText = _ref.modalHeaderText,
46611
+ modalHeaderText = _ref$modalHeaderText === void 0 ? "" : _ref$modalHeaderText,
46612
+ _ref$modalOpen = _ref.modalOpen,
46613
+ modalOpen = _ref$modalOpen === void 0 ? false : _ref$modalOpen,
46484
46614
  _ref$noButtons = _ref.noButtons,
46485
46615
  noButtons = _ref$noButtons === void 0 ? false : _ref$noButtons,
46486
46616
  _ref$onExit = _ref.onExit,
@@ -46495,114 +46625,29 @@ var Modal$2 = function Modal(_ref) {
46495
46625
  useDangerButton = _ref$useDangerButton === void 0 ? false : _ref$useDangerButton;
46496
46626
  var _useContext = React.useContext(styled.ThemeContext),
46497
46627
  isMobile = _useContext.isMobile;
46498
- var modalContainerRef = React.useRef(null);
46499
- var AllButtons = function AllButtons() {
46500
- return isMobile ? /*#__PURE__*/React__default.createElement(Stack, {
46501
- childGap: "1rem",
46502
- direction: "row"
46503
- }, /*#__PURE__*/React__default.createElement(Box, {
46504
- width: "100%",
46505
- padding: "0"
46506
- }, /*#__PURE__*/React__default.createElement(ButtonWithAction, {
46507
- variant: "secondary",
46508
- action: cancelAction ? cancelAction : hideModal,
46509
- text: cancelButtonText,
46510
- dataQa: cancelButtonText,
46511
- extraStyles: buttonExtraStyles,
46512
- borderRadius: CORNER_STANDARD,
46513
- className: "modal-cancel-button",
46514
- role: "button",
46515
- name: cancelButtonText
46516
- })), /*#__PURE__*/React__default.createElement(Box, {
46517
- width: "100%",
46518
- padding: "0"
46519
- }, /*#__PURE__*/React__default.createElement(ButtonWithAction, {
46520
- variant: useDangerButton ? "danger" : "primary",
46521
- action: continueAction,
46522
- text: continueButtonText,
46523
- dataQa: continueButtonText,
46524
- isLoading: isLoading,
46525
- disabled: isContinueActionDisabled,
46526
- extraStyles: buttonExtraStyles,
46527
- borderRadius: CORNER_STANDARD,
46528
- className: "modal-continue-button",
46529
- role: "button",
46530
- name: continueButtonText
46531
- }))) : /*#__PURE__*/React__default.createElement(Stack, {
46532
- childGap: "1rem",
46533
- direction: "row",
46534
- justify: "flex-end"
46535
- }, /*#__PURE__*/React__default.createElement(ButtonWithAction, {
46536
- variant: "secondary",
46537
- action: cancelAction ? cancelAction : hideModal,
46538
- text: cancelButtonText,
46539
- dataQa: cancelButtonText,
46540
- extraStyles: buttonExtraStyles,
46541
- borderRadius: CORNER_STANDARD,
46542
- className: "modal-cancel-button",
46543
- role: "button",
46544
- name: cancelButtonText
46545
- }), /*#__PURE__*/React__default.createElement(ButtonWithAction, {
46546
- variant: useDangerButton ? "danger" : "primary",
46547
- action: continueAction,
46548
- text: continueButtonText,
46549
- dataQa: continueButtonText,
46550
- isLoading: isLoading,
46551
- disabled: isContinueActionDisabled,
46552
- extraStyles: buttonExtraStyles,
46553
- borderRadius: CORNER_STANDARD,
46554
- className: "modal-continue-button",
46555
- role: "button",
46556
- name: continueButtonText
46557
- }));
46558
- };
46559
- var CloseButton = function CloseButton() {
46560
- return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
46561
- action: hideModal,
46562
- variant: "primary",
46563
- text: closeButtonText,
46564
- dataQa: closeButtonText,
46565
- extraStyles: buttonExtraStyles,
46566
- borderRadius: CORNER_STANDARD,
46567
- className: "modal-close-button",
46568
- role: "button",
46569
- name: closeButtonText
46570
- });
46571
- };
46572
- var ContinueButton = function ContinueButton() {
46573
- return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
46574
- variant: useDangerButton ? "danger" : "primary",
46575
- action: continueAction,
46576
- text: continueButtonText,
46577
- dataQa: continueButtonText,
46578
- isLoading: isLoading,
46579
- disabled: isContinueActionDisabled,
46580
- extraStyles: buttonExtraStyles,
46581
- borderRadius: CORNER_STANDARD,
46582
- className: "modal-continue-button",
46583
- role: "button",
46584
- name: continueButtonText
46585
- });
46586
- };
46587
- var MaybeButtons = /*#__PURE__*/React.forwardRef(function () {
46588
- return /*#__PURE__*/React__default.createElement(React.Fragment, null);
46589
- });
46590
- if (!noButtons) {
46591
- if (onlyContinueButton) {
46592
- MaybeButtons = ContinueButton;
46593
- } else if (onlyCloseButton) {
46594
- MaybeButtons = CloseButton;
46595
- } else {
46596
- MaybeButtons = AllButtons;
46597
- }
46598
- }
46628
+
46629
+ // `AriaModal` uses `focus-trap` as a transient dependency. It automatically looks
46630
+ // for a tabbable node when the modal mounts. When it doesn't find one, it looks to
46631
+ // the `fallbackFocus` option. However, React does not guarantee the ref supplied to
46632
+ // this option will be populated on initial render when `focus-trap` is checking
46633
+ // these option. When there are no buttons in the modal, this causes an error.
46634
+ // Because `focus-trap` cannot be disabled, the ref requires a dummy node to satisfy
46635
+ // `focus-trap` until React populates it with the real ref value.
46636
+ //
46637
+ // See:
46638
+ // - https://react.dev/reference/react/useRef#caveats
46639
+ // - https://github.com/davidtheclark/react-aria-modal/pull/103
46640
+ var modalContainerRef = React.useRef( /*#__PURE__*/React__default.createElement("div", null));
46641
+ var hasCloseButton = onlyCloseButton && !noButtons;
46642
+ var hasCancelButton = !onlyContinueButton && !onlyCloseButton && !noButtons;
46643
+ var hasContinueButton = onlyContinueButton && !noButtons || !onlyCloseButton && !noButtons;
46599
46644
  return /*#__PURE__*/React__default.createElement("div", {
46600
46645
  ref: modalContainerRef,
46646
+ tabIndex: "-1",
46601
46647
  "data-qa": dataQa
46602
- }, modalOpen && /*#__PURE__*/React__default.createElement(reactAriaModal
46603
- // fallback to resolve Jest unit test errors when tabbable doesn't exist in jsdom https://github.com/focus-trap/focus-trap-react/issues/91
46604
- , {
46648
+ }, modalOpen && /*#__PURE__*/React__default.createElement(reactAriaModal, {
46605
46649
  focusTrapOptions: {
46650
+ // fallback to resolve Jest unit test errors when tabbable doesn't exist in jsdom https://github.com/focus-trap/focus-trap-react/issues/91
46606
46651
  fallbackFocus: modalContainerRef === null || modalContainerRef === void 0 ? void 0 : modalContainerRef.current
46607
46652
  },
46608
46653
  onExit: onExit,
@@ -46619,7 +46664,7 @@ var Modal$2 = function Modal(_ref) {
46619
46664
  },
46620
46665
  dialogStyle: {
46621
46666
  borderRadius: CORNER_STANDARD,
46622
- width: customWidth || "615px",
46667
+ width: isMobile ? "" : customWidth || "615px",
46623
46668
  overflow: "auto"
46624
46669
  },
46625
46670
  underlayClickExits: underlayClickExits,
@@ -46644,8 +46689,6 @@ var Modal$2 = function Modal(_ref) {
46644
46689
  }, modalHeaderText))), /*#__PURE__*/React__default.createElement(Box, {
46645
46690
  background: modalBodyBg,
46646
46691
  padding: "0"
46647
- }, /*#__PURE__*/React__default.createElement(Stack, {
46648
- childGap: SPACING_NORMAL
46649
46692
  }, /*#__PURE__*/React__default.createElement(Box, {
46650
46693
  padding: SPACING_NORMAL,
46651
46694
  borderWidthOverride: !noButtons && "0 0 ".concat(BORDER_THIN, " 0"),
@@ -46655,22 +46698,40 @@ var Modal$2 = function Modal(_ref) {
46655
46698
  variant: "p"
46656
46699
  }, modalBodyText) : /*#__PURE__*/React__default.createElement(Box, {
46657
46700
  padding: maxHeight ? "0 0 ".concat(SPACING_XS, " 0") : "0"
46658
- }, modalBodyText)), noButtons ? /*#__PURE__*/React__default.createElement(MaybeButtons, null) : /*#__PURE__*/React__default.createElement(Box, {
46659
- padding: "0 ".concat(SPACING_NORMAL, " ").concat(SPACING_NORMAL)
46660
- }, /*#__PURE__*/React__default.createElement(Stack, {
46661
- direction: "row",
46662
- justify: "flex-end",
46663
- align: "center",
46664
- childGap: "0rem"
46665
- }, /*#__PURE__*/React__default.createElement(MaybeButtons, null))))))), children);
46701
+ }, modalBodyText)), noButtons ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null) : /*#__PURE__*/React__default.createElement(ButtonLayoutWrapper, {
46702
+ isMobile: isMobile
46703
+ }, [hasCancelButton && /*#__PURE__*/React__default.createElement(CancelButton, {
46704
+ buttonExtraStyles: buttonExtraStyles,
46705
+ cancelAction: cancelAction,
46706
+ cancelButtonText: cancelButtonText,
46707
+ hideModal: hideModal,
46708
+ isMobile: isMobile
46709
+ }), hasContinueButton && /*#__PURE__*/React__default.createElement(ContinueButton, {
46710
+ buttonExtraStyles: buttonExtraStyles,
46711
+ continueAction: continueAction,
46712
+ continueButtonText: continueButtonText,
46713
+ continueURL: continueURL,
46714
+ isContinueActionDisabled: isContinueActionDisabled,
46715
+ isLoading: isLoading,
46716
+ isMobile: isMobile,
46717
+ useDangerButton: useDangerButton
46718
+ }), hasCloseButton && /*#__PURE__*/React__default.createElement(CloseButton, {
46719
+ buttonExtraStyles: buttonExtraStyles,
46720
+ closeButtonText: closeButtonText,
46721
+ hideModal: hideModal,
46722
+ isMobile: isMobile
46723
+ })].filter(function (button) {
46724
+ return button;
46725
+ }))))), children);
46666
46726
  };
46727
+ var ModalControlV2 = withWindowSize(Modal$2);
46667
46728
 
46668
46729
  var _excluded$A = ["version"];
46669
46730
  var Modal$3 = function Modal(_ref) {
46670
46731
  var _ref$version = _ref.version,
46671
46732
  version = _ref$version === void 0 ? "v1" : _ref$version,
46672
46733
  rest = _objectWithoutProperties(_ref, _excluded$A);
46673
- var ModalControl = version === "v1" ? Modal$1 : Modal$2;
46734
+ var ModalControl = version === "v1" ? Modal$1 : ModalControlV2;
46674
46735
  return /*#__PURE__*/React__default.createElement(ModalControl, rest);
46675
46736
  };
46676
46737