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

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.d.ts CHANGED
@@ -302,15 +302,16 @@ declare const CollapsibleSection: React.FC<Expand<CollapsibleSectionProps> &
302
302
  React.HTMLAttributes<HTMLElement>>;
303
303
 
304
304
  interface CopyableProps {
305
- text: string;
305
+ content: string;
306
+ onCopy?: () => void;
306
307
  initialPopoverContent?: string;
307
- copiedPopoverContent?: string;
308
+ copySuccessPopoverContent?: string;
309
+ copyErrorPopoverContent?: string;
308
310
  copiedPopoverContentDuration?: number;
309
- withPopover?: boolean;
311
+ hasPopover?: boolean;
310
312
  popoverID?: number;
311
313
  popoverMinWidth?: string;
312
- onCopy?: () => void;
313
- extraStyles?: string;
314
+ popoverExtraStyles?: string;
314
315
  }
315
316
 
316
317
  declare const Copyable: React.FC<Expand<CopyableProps> &
@@ -368,6 +369,9 @@ interface PopoverProps {
368
369
  arrowBottom: string;
369
370
  arrowLeft: string;
370
371
  };
372
+ arrowDirection?: "left" | "right" | "top" | "bottom";
373
+ transform?: string;
374
+ disclosedExtraStyles?: string;
371
375
  }
372
376
 
373
377
  declare const Popover: React.FC<Expand<PopoverProps> &
package/dist/index.esm.js CHANGED
@@ -22748,6 +22748,22 @@ var fallbackValues$i = {
22748
22748
  popoverTriggerColor: popoverTriggerColor
22749
22749
  };
22750
22750
 
22751
+ var arrowBorder = function arrowBorder(direction) {
22752
+ var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "8px";
22753
+ var angle = "".concat(width, " solid transparent");
22754
+ var straight = "".concat(width, " solid rgba(255, 255, 255, 0.85)");
22755
+
22756
+ if (direction == "down") {
22757
+ return "border-left: ".concat(angle, "; border-right: ").concat(angle, "; border-top: ").concat(straight);
22758
+ } else if (direction == "up") {
22759
+ return "border-left: ".concat(angle, "; border-right: ").concat(angle, "; border-bottom: ").concat(straight);
22760
+ } else if (direction == "left") {
22761
+ return "border-top: ".concat(angle, "; border-bottom: ").concat(angle, "; border-right: ").concat(straight);
22762
+ } else if (direction == "right") {
22763
+ return "border-top: ".concat(angle, "; border-bottom: ").concat(angle, "; border-left: ").concat(straight);
22764
+ }
22765
+ };
22766
+
22751
22767
  var Popover = function Popover(_ref) {
22752
22768
  var themeValues = _ref.themeValues,
22753
22769
  _ref$triggerText = _ref.triggerText,
@@ -22772,7 +22788,11 @@ var Popover = function Popover(_ref) {
22772
22788
  _ref$height = _ref.height,
22773
22789
  height = _ref$height === void 0 ? "auto" : _ref$height,
22774
22790
  position = _ref.position,
22775
- arrowPosition = _ref.arrowPosition;
22791
+ arrowPosition = _ref.arrowPosition,
22792
+ _ref$arrowDirection = _ref.arrowDirection,
22793
+ arrowDirection = _ref$arrowDirection === void 0 ? "down" : _ref$arrowDirection,
22794
+ transform = _ref.transform,
22795
+ buttonExtraStyles = _ref.buttonExtraStyles;
22776
22796
  var hoverColor = themeValues.hoverColor,
22777
22797
  activeColor = themeValues.activeColor,
22778
22798
  popoverTriggerColor = themeValues.popoverTriggerColor;
@@ -22847,7 +22867,8 @@ var Popover = function Popover(_ref) {
22847
22867
  "aria-labelledby": "btnPopover".concat(popoverID, "_info Disclosure").concat(popoverID),
22848
22868
  "aria-describedby": "Disclosure".concat(popoverID),
22849
22869
  "aria-controls": "Disclosed".concat(popoverID),
22850
- ref: triggerRef
22870
+ ref: triggerRef,
22871
+ extraStyles: buttonExtraStyles
22851
22872
  }, hasIcon && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, null), /*#__PURE__*/React.createElement(Box, {
22852
22873
  padding: "0",
22853
22874
  srOnly: true
@@ -22866,10 +22887,10 @@ var Popover = function Popover(_ref) {
22866
22887
  tabIndex: popoverFocus && popoverOpen ? "0" : "-1",
22867
22888
  minWidth: minWidth,
22868
22889
  maxWidth: maxWidth,
22869
- 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 ")
22890
+ 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 ? transform : "none", ";\n ")
22870
22891
  }, /*#__PURE__*/React.createElement(Paragraph$1, null, content), /*#__PURE__*/React.createElement(Box, {
22871
22892
  padding: "0",
22872
- 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, ";")
22893
+ 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 ")
22873
22894
  })));
22874
22895
  };
22875
22896
 
@@ -37441,7 +37462,6 @@ var CollapsibleSection = function CollapsibleSection(_ref) {
37441
37462
  }
37442
37463
  };
37443
37464
 
37444
- useEffect$1(function () {}, [isOpen]);
37445
37465
  var numChildren = typeof children === "Array" ? children.length : 1;
37446
37466
  var label = name !== "" ? name : !customTitle ? title : "collapsible section";
37447
37467
  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);
@@ -37567,13 +37587,23 @@ var ClipboardIcon = function ClipboardIcon(_ref) {
37567
37587
  var ClipboardIcon$1 = themeComponent(ClipboardIcon, "Icons", fallbackValues$2, "primary");
37568
37588
 
37569
37589
  /*
37570
- This component will render `text` and a clipboard icon. When hovered, a popover with content `initialPopoverContent` will be displayed.
37571
- When clicked, `text` will be copied to the clipboard, the popover content will change to `copiedPopoverContent` for `copiedPopoverContentDuration` milliseconds,
37572
- and the `onCopy` callback will be executed.
37590
+ This component will render `content` and a clipboard icon.
37591
+ When hovered, a popover with content `initialPopoverContent` will be displayed.
37592
+ to the left of the content.
37593
+
37594
+ When clicked, `content` will be copied to the clipboard, the popover content
37595
+ will change to `copySuccessPopoverContent` for `copiedPopoverContentDuration`
37596
+ milliseconds, and the `onCopy` callback will be executed.
37597
+
37598
+ If the content was unable to be copied to the clipboard, the popover will instead
37599
+ display `copyErrorPopoverContent`
37600
+
37601
+ If you only want the copy to clipboard behaviour without a popover, pass the prop
37602
+ `hasPopover={false}`
37573
37603
  */
37574
37604
 
37575
- var CopyableText = function CopyableText(_ref) {
37576
- var text = _ref.text,
37605
+ var CopyableContent = function CopyableContent(_ref) {
37606
+ var content = _ref.content,
37577
37607
  onClick = _ref.onClick;
37578
37608
  return /*#__PURE__*/React.createElement(ButtonWithAction, {
37579
37609
  "data-testid": "copyable-trigger",
@@ -37584,79 +37614,123 @@ var CopyableText = function CopyableText(_ref) {
37584
37614
  }, /*#__PURE__*/React.createElement(Stack, {
37585
37615
  direction: "row",
37586
37616
  childGap: "0.25rem"
37587
- }, /*#__PURE__*/React.createElement(Text$1, null, text), /*#__PURE__*/React.createElement(ClipboardIcon$1, null)));
37617
+ }, /*#__PURE__*/React.createElement(Text$1, null, content), /*#__PURE__*/React.createElement(ClipboardIcon$1, null)));
37588
37618
  };
37589
37619
 
37590
37620
  var Copyable = function Copyable(_ref2) {
37591
- var text = _ref2.text,
37621
+ var content = _ref2.content,
37592
37622
  onCopy = _ref2.onCopy,
37593
37623
  _ref2$initialPopoverC = _ref2.initialPopoverContent,
37594
37624
  initialPopoverContent = _ref2$initialPopoverC === void 0 ? "Click to copy to clipboard" : _ref2$initialPopoverC,
37595
- _ref2$copiedPopoverCo = _ref2.copiedPopoverContent,
37596
- copiedPopoverContent = _ref2$copiedPopoverCo === void 0 ? "Copied!" : _ref2$copiedPopoverCo,
37597
- _ref2$withPopover = _ref2.withPopover,
37598
- withPopover = _ref2$withPopover === void 0 ? true : _ref2$withPopover,
37625
+ _ref2$copySuccessPopo = _ref2.copySuccessPopoverContent,
37626
+ copySuccessPopoverContent = _ref2$copySuccessPopo === void 0 ? "Copied!" : _ref2$copySuccessPopo,
37627
+ _ref2$copyErrorPopove = _ref2.copyErrorPopoverContent,
37628
+ copyErrorPopoverContent = _ref2$copyErrorPopove === void 0 ? "Unable to copy value" : _ref2$copyErrorPopove,
37629
+ _ref2$copiedPopoverCo = _ref2.copiedPopoverContentDuration,
37630
+ copiedPopoverContentDuration = _ref2$copiedPopoverCo === void 0 ? 1000 : _ref2$copiedPopoverCo,
37631
+ _ref2$hasPopover = _ref2.hasPopover,
37632
+ hasPopover = _ref2$hasPopover === void 0 ? true : _ref2$hasPopover,
37599
37633
  _ref2$popoverMinWidth = _ref2.popoverMinWidth,
37600
37634
  popoverMinWidth = _ref2$popoverMinWidth === void 0 ? "210px" : _ref2$popoverMinWidth,
37601
- _ref2$copiedPopoverCo2 = _ref2.copiedPopoverContentDuration,
37602
- copiedPopoverContentDuration = _ref2$copiedPopoverCo2 === void 0 ? 1000 : _ref2$copiedPopoverCo2,
37603
37635
  _ref2$popoverID = _ref2.popoverID,
37604
37636
  popoverID = _ref2$popoverID === void 0 ? 0 : _ref2$popoverID,
37605
- extraStyles = _ref2.extraStyles;
37606
- var popoverPosition = {
37607
- top: "-65px",
37608
- right: "auto",
37609
- bottom: "auto",
37610
- left: "50%"
37611
- };
37612
- var popoverArrowPosition = {
37613
- arrowTop: "auto",
37614
- arrowRight: "auto",
37615
- arrowBottom: "-8px",
37616
- arrowLeft: "calc(50% - 4px)" // Popover arrow is 8px wide. This places the middle of the arrow in the middle of the popover.
37617
-
37618
- };
37637
+ popoverExtraStyles = _ref2.popoverExtraStyles;
37619
37638
 
37620
37639
  var _useState = useState(initialPopoverContent),
37621
37640
  _useState2 = _slicedToArray(_useState, 2),
37622
37641
  popoverContent = _useState2[0],
37623
37642
  setPopoverContent = _useState2[1];
37624
37643
 
37625
- var _useState3 = useState(undefined),
37644
+ var _useState3 = useState(false),
37626
37645
  _useState4 = _slicedToArray(_useState3, 2),
37627
- timer = _useState4[0],
37628
- setTimer = _useState4[1];
37646
+ startTimer = _useState4[0],
37647
+ setStartTimer = _useState4[1];
37629
37648
 
37630
- var onClick = function onClick() {
37631
- setPopoverContent(copiedPopoverContent);
37632
- navigator.clipboard.writeText(text)["catch"](function (e) {
37633
- return console.error(e);
37634
- });
37635
- onCopy === null || onCopy === void 0 ? void 0 : onCopy();
37649
+ var _useState5 = useState(false),
37650
+ _useState6 = _slicedToArray(_useState5, 2),
37651
+ attemptCopy = _useState6[0],
37652
+ setAttemptCopy = _useState6[1];
37636
37653
 
37637
- if (timer) {
37638
- clearTimeout(timer);
37654
+ var _useState7 = useState(null),
37655
+ _useState8 = _slicedToArray(_useState7, 2),
37656
+ timeoutId = _useState8[0],
37657
+ setTimeoutId = _useState8[1];
37658
+
37659
+ var cleanup = function cleanup() {
37660
+ if (timeoutId) {
37661
+ // console.log(`Clearing timeout ${timeoutId}`);
37662
+ clearTimeout(timeoutId);
37663
+ }
37664
+ };
37665
+
37666
+ useEffect$1(function () {
37667
+ if (startTimer) {
37668
+ if (timeoutId) {
37669
+ // If there's an active timeout, clean it up.
37670
+ cleanup();
37671
+ } // Start a timeout to restore popover content to the initial value.
37672
+ // Record the ID of the timeout so it can be cleaned up later.
37673
+ // console.log("Starting timeout");
37674
+
37675
+
37676
+ setTimeoutId(setTimeout(function () {
37677
+ // console.log(`Timeout ${timeoutId} finished`);
37678
+ setPopoverContent(initialPopoverContent);
37679
+ }, copiedPopoverContentDuration)); // Set startTimer to false immediately after starting the timer,
37680
+ // so subsequent clicks will start a new timer, refreshing the duration.
37681
+
37682
+ setStartTimer(false);
37683
+ } // Return cleanup function so timeout will be cleared when component unmoumnts.
37684
+
37685
+
37686
+ return cleanup;
37687
+ }, [startTimer]);
37688
+ useEffect$1(function () {
37689
+ if (attemptCopy) {
37690
+ navigator.clipboard.writeText(content).then(function () {
37691
+ setPopoverContent(copySuccessPopoverContent);
37692
+ onCopy === null || onCopy === void 0 ? void 0 : onCopy();
37693
+ setAttemptCopy(false);
37694
+ })["catch"](function (error) {
37695
+ console.error(error);
37696
+ setPopoverContent(copyErrorPopoverContent);
37697
+ setAttemptCopy(false);
37698
+ });
37639
37699
  }
37700
+ }, [attemptCopy]);
37640
37701
 
37641
- setTimer(setTimeout(function () {
37642
- setPopoverContent(initialPopoverContent);
37643
- setTimer(undefined);
37644
- }, copiedPopoverContentDuration));
37702
+ var onClick = function onClick() {
37703
+ setStartTimer(true);
37704
+ setAttemptCopy(true);
37645
37705
  };
37646
37706
 
37647
- return withPopover ? /*#__PURE__*/React.createElement(Popover$1, {
37707
+ var popoverArrowWidth = "8px";
37708
+ return hasPopover ? /*#__PURE__*/React.createElement(Popover$1, {
37648
37709
  minWidth: popoverMinWidth,
37649
- position: popoverPosition,
37650
- arrowPosition: popoverArrowPosition,
37710
+ position: {
37711
+ top: "auto",
37712
+ right: "auto",
37713
+ bottom: "auto",
37714
+ left: "calc(-".concat(popoverArrowWidth, " - 8px)")
37715
+ },
37716
+ arrowPosition: {
37717
+ arrowTop: "auto",
37718
+ arrowRight: "-8px",
37719
+ arrowBottom: "calc(50% - ".concat(popoverArrowWidth, ")"),
37720
+ arrowLeft: "auto"
37721
+ },
37722
+ transform: "translate(-100%, -75%)",
37723
+ arrowDirection: "right",
37651
37724
  popoverID: popoverID,
37652
- extraStyles: "> button#btnPopover".concat(popoverID, " { margin: 0 }; > #Disclosed").concat(popoverID, " { transform: translateX(-50%); }; ").concat(extraStyles),
37653
- triggerText: CopyableText({
37654
- text: text,
37725
+ buttonExtraStyles: "margin: 0",
37726
+ extraStyles: popoverExtraStyles,
37727
+ triggerText: CopyableContent({
37728
+ content: content,
37655
37729
  onClick: onClick
37656
37730
  }),
37657
37731
  content: popoverContent
37658
- }) : CopyableText({
37659
- text: text,
37732
+ }) : CopyableContent({
37733
+ content: content,
37660
37734
  onClick: onClick
37661
37735
  });
37662
37736
  };