@thecb/components 7.0.2-beta.5 → 7.0.2-beta.7

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
@@ -22756,6 +22756,22 @@ var fallbackValues$i = {
22756
22756
  popoverTriggerColor: popoverTriggerColor
22757
22757
  };
22758
22758
 
22759
+ var arrowBorder = function arrowBorder(direction) {
22760
+ var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "8px";
22761
+ var angle = "".concat(width, " solid transparent");
22762
+ var straight = "".concat(width, " solid rgba(255, 255, 255, 0.85)");
22763
+
22764
+ if (direction == "down") {
22765
+ return "border-left: ".concat(angle, "; border-right: ").concat(angle, "; border-top: ").concat(straight);
22766
+ } else if (direction == "up") {
22767
+ return "border-left: ".concat(angle, "; border-right: ").concat(angle, "; border-bottom: ").concat(straight);
22768
+ } else if (direction == "left") {
22769
+ return "border-top: ".concat(angle, "; border-bottom: ").concat(angle, "; border-right: ").concat(straight);
22770
+ } else if (direction == "right") {
22771
+ return "border-top: ".concat(angle, "; border-bottom: ").concat(angle, "; border-left: ").concat(straight);
22772
+ }
22773
+ };
22774
+
22759
22775
  var Popover = function Popover(_ref) {
22760
22776
  var themeValues = _ref.themeValues,
22761
22777
  _ref$triggerText = _ref.triggerText,
@@ -22780,7 +22796,12 @@ var Popover = function Popover(_ref) {
22780
22796
  _ref$height = _ref.height,
22781
22797
  height = _ref$height === void 0 ? "auto" : _ref$height,
22782
22798
  position = _ref.position,
22783
- arrowPosition = _ref.arrowPosition;
22799
+ arrowPosition = _ref.arrowPosition,
22800
+ _ref$arrowDirection = _ref.arrowDirection,
22801
+ arrowDirection = _ref$arrowDirection === void 0 ? "down" : _ref$arrowDirection,
22802
+ _ref$transform = _ref.transform,
22803
+ transform = _ref$transform === void 0 ? "none" : _ref$transform,
22804
+ buttonExtraStyles = _ref.buttonExtraStyles;
22784
22805
  var hoverColor = themeValues.hoverColor,
22785
22806
  activeColor = themeValues.activeColor,
22786
22807
  popoverTriggerColor = themeValues.popoverTriggerColor;
@@ -22855,7 +22876,8 @@ var Popover = function Popover(_ref) {
22855
22876
  "aria-labelledby": "btnPopover".concat(popoverID, "_info Disclosure").concat(popoverID),
22856
22877
  "aria-describedby": "Disclosure".concat(popoverID),
22857
22878
  "aria-controls": "Disclosed".concat(popoverID),
22858
- ref: triggerRef
22879
+ ref: triggerRef,
22880
+ extraStyles: buttonExtraStyles
22859
22881
  }, hasIcon && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, null), /*#__PURE__*/React__default.createElement(Box, {
22860
22882
  padding: "0",
22861
22883
  srOnly: true
@@ -22874,10 +22896,10 @@ var Popover = function Popover(_ref) {
22874
22896
  tabIndex: popoverFocus && popoverOpen ? "0" : "-1",
22875
22897
  minWidth: minWidth,
22876
22898
  maxWidth: maxWidth,
22877
- extraStyles: "\n display: ".concat(popoverOpen ? "block" : "none", "; \n position: absolute; \n top: ").concat(top, "; \n right: ").concat(right, "; \n bottom: ").concat(bottom, "; \n left: ").concat(left, ";\n height: ").concat(height, ";\n ")
22899
+ extraStyles: "\n display: ".concat(popoverOpen ? "block" : "none", "; \n position: absolute; \n top: ").concat(top, "; \n right: ").concat(right, "; \n bottom: ").concat(bottom, "; \n left: ").concat(left, ";\n height: ").concat(height, ";\n transform: ").concat(transform, ";\n ")
22878
22900
  }, /*#__PURE__*/React__default.createElement(Paragraph$1, null, content), /*#__PURE__*/React__default.createElement(Box, {
22879
22901
  padding: "0",
22880
- extraStyles: "position: absolute; content: \"\"; width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 8px solid rgba(255, 255, 255, 0.85); filter: drop-shadow(2px 8px 14px black); bottom: ".concat(arrowBottom, "; right: ").concat(arrowRight, "; top: ").concat(arrowTop, "; left: ").concat(arrowLeft, ";")
22902
+ extraStyles: "\n position: absolute;\n content: \"\";\n width: 0;\n height: 0;\n ".concat(arrowBorder(arrowDirection, "8px"), ";\n filter: drop-shadow(2px 8px 14px black);\n bottom: ").concat(arrowBottom, ";\n right: ").concat(arrowRight, ";\n top: ").concat(arrowTop, ";\n left: ").concat(arrowLeft, ";\n ")
22881
22903
  })));
22882
22904
  };
22883
22905
 
@@ -37449,7 +37471,6 @@ var CollapsibleSection = function CollapsibleSection(_ref) {
37449
37471
  }
37450
37472
  };
37451
37473
 
37452
- React.useEffect(function () {}, [isOpen]);
37453
37474
  var numChildren = typeof children === "Array" ? children.length : 1;
37454
37475
  var label = name !== "" ? name : !customTitle ? title : "collapsible section";
37455
37476
  var id = "".concat(label === null || label === void 0 ? void 0 : (_label$replaceAll = label.replaceAll(" ", "-")) === null || _label$replaceAll === void 0 ? void 0 : _label$replaceAll.toLowerCase(), "-").concat(index);
@@ -37559,8 +37580,8 @@ var ClipboardIcon = function ClipboardIcon(_ref) {
37559
37580
  width: "16",
37560
37581
  height: "18"
37561
37582
  }, /*#__PURE__*/React__default.createElement("path", {
37562
- "fill-rule": "evenodd",
37563
- "clip-rule": "evenodd",
37583
+ fillRule: "evenodd",
37584
+ clipRule: "evenodd",
37564
37585
  d: "M9.83929 3.43753H14.1607V5.59825H9.83929L9.83929 3.43753ZM8.75893 3.43753C8.75893 2.84087 9.24262 2.35718 9.83929 2.35718H14.1607C14.7574 2.35718 15.2411 2.84087 15.2411 3.43753V5.59825C15.2411 6.19491 14.7574 6.67861 14.1607 6.67861H9.83929C9.24262 6.67861 8.75893 6.19491 8.75893 5.59825V3.43753ZM6.59821 3.70762H7.94866V5.32816H6.59821C6.29988 5.32816 6.05804 5.57001 6.05804 5.86834V17.4822C6.05804 17.7805 6.29988 18.0224 6.59821 18.0224H17.4018C17.7001 18.0224 17.942 17.7805 17.942 17.4822V5.86834C17.942 5.57001 17.7001 5.32816 17.4018 5.32816H16.0513V3.70762H17.4018C18.5951 3.70762 19.5625 4.67501 19.5625 5.86834V17.4822C19.5625 18.6755 18.5951 19.6429 17.4018 19.6429H6.59821C5.40488 19.6429 4.4375 18.6755 4.4375 17.4822V5.86834C4.4375 4.67501 5.40488 3.70762 6.59821 3.70762Z",
37565
37586
  fill: themeValues.singleIconColor
37566
37587
  })), /*#__PURE__*/React__default.createElement("g", {
@@ -37575,13 +37596,23 @@ var ClipboardIcon = function ClipboardIcon(_ref) {
37575
37596
  var ClipboardIcon$1 = themeComponent(ClipboardIcon, "Icons", fallbackValues$2, "primary");
37576
37597
 
37577
37598
  /*
37578
- This component will render `text` and a clipboard icon. When hovered, a popover with content `initialPopoverContent` will be displayed.
37579
- When clicked, `text` will be copied to the clipboard, the popover content will change to `copiedPopoverContent` for `copiedPopoverContentDuration` milliseconds,
37580
- and the `onCopy` callback will be executed.
37599
+ This component will render `content` and a clipboard icon.
37600
+ When hovered, a popover with content `initialPopoverContent` will be displayed.
37601
+ to the left of the content.
37602
+
37603
+ When clicked, `content` will be copied to the clipboard, the popover content
37604
+ will change to `copySuccessPopoverContent` for `copiedPopoverContentDuration`
37605
+ milliseconds, and the `onCopy` callback will be executed.
37606
+
37607
+ If the content was unable to be copied to the clipboard, the popover will instead
37608
+ display `copyErrorPopoverContent`
37609
+
37610
+ If you only want the copy to clipboard behaviour without a popover, pass the prop
37611
+ `hasPopover={false}`
37581
37612
  */
37582
37613
 
37583
- var CopyableText = function CopyableText(_ref) {
37584
- var text = _ref.text,
37614
+ var CopyableContent = function CopyableContent(_ref) {
37615
+ var content = _ref.content,
37585
37616
  onClick = _ref.onClick;
37586
37617
  return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
37587
37618
  "data-testid": "copyable-trigger",
@@ -37592,79 +37623,123 @@ var CopyableText = function CopyableText(_ref) {
37592
37623
  }, /*#__PURE__*/React__default.createElement(Stack, {
37593
37624
  direction: "row",
37594
37625
  childGap: "0.25rem"
37595
- }, /*#__PURE__*/React__default.createElement(Text$1, null, text), /*#__PURE__*/React__default.createElement(ClipboardIcon$1, null)));
37626
+ }, /*#__PURE__*/React__default.createElement(Text$1, null, content), /*#__PURE__*/React__default.createElement(ClipboardIcon$1, null)));
37596
37627
  };
37597
37628
 
37598
37629
  var Copyable = function Copyable(_ref2) {
37599
- var text = _ref2.text,
37630
+ var content = _ref2.content,
37600
37631
  onCopy = _ref2.onCopy,
37601
37632
  _ref2$initialPopoverC = _ref2.initialPopoverContent,
37602
37633
  initialPopoverContent = _ref2$initialPopoverC === void 0 ? "Click to copy to clipboard" : _ref2$initialPopoverC,
37603
- _ref2$copiedPopoverCo = _ref2.copiedPopoverContent,
37604
- copiedPopoverContent = _ref2$copiedPopoverCo === void 0 ? "Copied!" : _ref2$copiedPopoverCo,
37605
- _ref2$withPopover = _ref2.withPopover,
37606
- withPopover = _ref2$withPopover === void 0 ? true : _ref2$withPopover,
37634
+ _ref2$copySuccessPopo = _ref2.copySuccessPopoverContent,
37635
+ copySuccessPopoverContent = _ref2$copySuccessPopo === void 0 ? "Copied!" : _ref2$copySuccessPopo,
37636
+ _ref2$copyErrorPopove = _ref2.copyErrorPopoverContent,
37637
+ copyErrorPopoverContent = _ref2$copyErrorPopove === void 0 ? "Unable to copy value" : _ref2$copyErrorPopove,
37638
+ _ref2$copiedPopoverCo = _ref2.copiedPopoverContentDuration,
37639
+ copiedPopoverContentDuration = _ref2$copiedPopoverCo === void 0 ? 1000 : _ref2$copiedPopoverCo,
37640
+ _ref2$hasPopover = _ref2.hasPopover,
37641
+ hasPopover = _ref2$hasPopover === void 0 ? true : _ref2$hasPopover,
37607
37642
  _ref2$popoverMinWidth = _ref2.popoverMinWidth,
37608
- popoverMinWidth = _ref2$popoverMinWidth === void 0 ? "210px" : _ref2$popoverMinWidth,
37609
- _ref2$copiedPopoverCo2 = _ref2.copiedPopoverContentDuration,
37610
- copiedPopoverContentDuration = _ref2$copiedPopoverCo2 === void 0 ? 1000 : _ref2$copiedPopoverCo2,
37643
+ popoverMinWidth = _ref2$popoverMinWidth === void 0 ? "max-content" : _ref2$popoverMinWidth,
37611
37644
  _ref2$popoverID = _ref2.popoverID,
37612
37645
  popoverID = _ref2$popoverID === void 0 ? 0 : _ref2$popoverID,
37613
- extraStyles = _ref2.extraStyles;
37614
- var popoverPosition = {
37615
- top: "-65px",
37616
- right: "auto",
37617
- bottom: "auto",
37618
- left: "50%"
37619
- };
37620
- var popoverArrowPosition = {
37621
- arrowTop: "auto",
37622
- arrowRight: "auto",
37623
- arrowBottom: "-8px",
37624
- arrowLeft: "calc(50% - 4px)" // Popover arrow is 8px wide. This places the middle of the arrow in the middle of the popover.
37625
-
37626
- };
37646
+ popoverExtraStyles = _ref2.popoverExtraStyles;
37627
37647
 
37628
37648
  var _useState = React.useState(initialPopoverContent),
37629
37649
  _useState2 = _slicedToArray(_useState, 2),
37630
37650
  popoverContent = _useState2[0],
37631
37651
  setPopoverContent = _useState2[1];
37632
37652
 
37633
- var _useState3 = React.useState(undefined),
37653
+ var _useState3 = React.useState(false),
37634
37654
  _useState4 = _slicedToArray(_useState3, 2),
37635
- timer = _useState4[0],
37636
- setTimer = _useState4[1];
37655
+ startTimer = _useState4[0],
37656
+ setStartTimer = _useState4[1];
37637
37657
 
37638
- var onClick = function onClick() {
37639
- setPopoverContent(copiedPopoverContent);
37640
- navigator.clipboard.writeText(text)["catch"](function (e) {
37641
- return console.error(e);
37642
- });
37643
- onCopy === null || onCopy === void 0 ? void 0 : onCopy();
37658
+ var _useState5 = React.useState(false),
37659
+ _useState6 = _slicedToArray(_useState5, 2),
37660
+ attemptCopy = _useState6[0],
37661
+ setAttemptCopy = _useState6[1];
37644
37662
 
37645
- if (timer) {
37646
- clearTimeout(timer);
37663
+ var _useState7 = React.useState(null),
37664
+ _useState8 = _slicedToArray(_useState7, 2),
37665
+ timeoutId = _useState8[0],
37666
+ setTimeoutId = _useState8[1];
37667
+
37668
+ var cleanup = function cleanup() {
37669
+ if (timeoutId) {
37670
+ // console.log(`Clearing timeout ${timeoutId}`);
37671
+ clearTimeout(timeoutId);
37647
37672
  }
37673
+ };
37674
+
37675
+ React.useEffect(function () {
37676
+ if (startTimer) {
37677
+ if (timeoutId) {
37678
+ // If there's an active timeout, clean it up.
37679
+ cleanup();
37680
+ } // Start a timeout to restore popover content to the initial value.
37681
+ // Record the ID of the timeout so it can be cleaned up later.
37682
+ // console.log("Starting timeout");
37683
+
37684
+
37685
+ setTimeoutId(setTimeout(function () {
37686
+ // console.log(`Timeout ${timeoutId} finished`);
37687
+ setPopoverContent(initialPopoverContent);
37688
+ }, copiedPopoverContentDuration)); // Set startTimer to false immediately after starting the timer,
37689
+ // so subsequent clicks will start a new timer, refreshing the duration.
37690
+
37691
+ setStartTimer(false);
37692
+ } // Return cleanup function so timeout will be cleared when component unmoumnts.
37693
+
37648
37694
 
37649
- setTimer(setTimeout(function () {
37650
- setPopoverContent(initialPopoverContent);
37651
- setTimer(undefined);
37652
- }, copiedPopoverContentDuration));
37695
+ return cleanup;
37696
+ }, [startTimer]);
37697
+ React.useEffect(function () {
37698
+ if (attemptCopy) {
37699
+ navigator.clipboard.writeText(content).then(function () {
37700
+ setPopoverContent(copySuccessPopoverContent);
37701
+ onCopy === null || onCopy === void 0 ? void 0 : onCopy();
37702
+ setAttemptCopy(false);
37703
+ })["catch"](function (error) {
37704
+ console.error(error);
37705
+ setPopoverContent(copyErrorPopoverContent);
37706
+ setAttemptCopy(false);
37707
+ });
37708
+ }
37709
+ }, [attemptCopy]);
37710
+
37711
+ var onClick = function onClick() {
37712
+ setStartTimer(true);
37713
+ setAttemptCopy(true);
37653
37714
  };
37654
37715
 
37655
- return withPopover ? /*#__PURE__*/React__default.createElement(Popover$1, {
37716
+ var popoverArrowWidth = "8px";
37717
+ return hasPopover ? /*#__PURE__*/React__default.createElement(Popover$1, {
37656
37718
  minWidth: popoverMinWidth,
37657
- position: popoverPosition,
37658
- arrowPosition: popoverArrowPosition,
37719
+ position: {
37720
+ top: "auto",
37721
+ right: "auto",
37722
+ bottom: "auto",
37723
+ left: "calc(-".concat(popoverArrowWidth, " - 8px)")
37724
+ },
37725
+ arrowPosition: {
37726
+ arrowTop: "auto",
37727
+ arrowRight: "-8px",
37728
+ arrowBottom: "calc(50% - ".concat(popoverArrowWidth, ")"),
37729
+ arrowLeft: "auto"
37730
+ },
37731
+ transform: "translate(-100%, -75%)",
37732
+ arrowDirection: "right",
37659
37733
  popoverID: popoverID,
37660
- extraStyles: "> button#btnPopover".concat(popoverID, " { margin: 0 }; > #Disclosed").concat(popoverID, " { transform: translateX(-50%); }; ").concat(extraStyles),
37661
- triggerText: CopyableText({
37662
- text: text,
37734
+ buttonExtraStyles: "margin: 0",
37735
+ extraStyles: popoverExtraStyles,
37736
+ triggerText: CopyableContent({
37737
+ content: content,
37663
37738
  onClick: onClick
37664
37739
  }),
37665
37740
  content: popoverContent
37666
- }) : CopyableText({
37667
- text: text,
37741
+ }) : CopyableContent({
37742
+ content: content,
37668
37743
  onClick: onClick
37669
37744
  });
37670
37745
  };