@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.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,12 @@ 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
+ _ref$transform = _ref.transform,
22795
+ transform = _ref$transform === void 0 ? "none" : _ref$transform,
22796
+ buttonExtraStyles = _ref.buttonExtraStyles;
22776
22797
  var hoverColor = themeValues.hoverColor,
22777
22798
  activeColor = themeValues.activeColor,
22778
22799
  popoverTriggerColor = themeValues.popoverTriggerColor;
@@ -22847,7 +22868,8 @@ var Popover = function Popover(_ref) {
22847
22868
  "aria-labelledby": "btnPopover".concat(popoverID, "_info Disclosure").concat(popoverID),
22848
22869
  "aria-describedby": "Disclosure".concat(popoverID),
22849
22870
  "aria-controls": "Disclosed".concat(popoverID),
22850
- ref: triggerRef
22871
+ ref: triggerRef,
22872
+ extraStyles: buttonExtraStyles
22851
22873
  }, hasIcon && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, null), /*#__PURE__*/React.createElement(Box, {
22852
22874
  padding: "0",
22853
22875
  srOnly: true
@@ -22866,10 +22888,10 @@ var Popover = function Popover(_ref) {
22866
22888
  tabIndex: popoverFocus && popoverOpen ? "0" : "-1",
22867
22889
  minWidth: minWidth,
22868
22890
  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 ")
22891
+ 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 ")
22870
22892
  }, /*#__PURE__*/React.createElement(Paragraph$1, null, content), /*#__PURE__*/React.createElement(Box, {
22871
22893
  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, ";")
22894
+ 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
22895
  })));
22874
22896
  };
22875
22897
 
@@ -37441,7 +37463,6 @@ var CollapsibleSection = function CollapsibleSection(_ref) {
37441
37463
  }
37442
37464
  };
37443
37465
 
37444
- useEffect$1(function () {}, [isOpen]);
37445
37466
  var numChildren = typeof children === "Array" ? children.length : 1;
37446
37467
  var label = name !== "" ? name : !customTitle ? title : "collapsible section";
37447
37468
  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);
@@ -37551,8 +37572,8 @@ var ClipboardIcon = function ClipboardIcon(_ref) {
37551
37572
  width: "16",
37552
37573
  height: "18"
37553
37574
  }, /*#__PURE__*/React.createElement("path", {
37554
- "fill-rule": "evenodd",
37555
- "clip-rule": "evenodd",
37575
+ fillRule: "evenodd",
37576
+ clipRule: "evenodd",
37556
37577
  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",
37557
37578
  fill: themeValues.singleIconColor
37558
37579
  })), /*#__PURE__*/React.createElement("g", {
@@ -37567,13 +37588,23 @@ var ClipboardIcon = function ClipboardIcon(_ref) {
37567
37588
  var ClipboardIcon$1 = themeComponent(ClipboardIcon, "Icons", fallbackValues$2, "primary");
37568
37589
 
37569
37590
  /*
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.
37591
+ This component will render `content` and a clipboard icon.
37592
+ When hovered, a popover with content `initialPopoverContent` will be displayed.
37593
+ to the left of the content.
37594
+
37595
+ When clicked, `content` will be copied to the clipboard, the popover content
37596
+ will change to `copySuccessPopoverContent` for `copiedPopoverContentDuration`
37597
+ milliseconds, and the `onCopy` callback will be executed.
37598
+
37599
+ If the content was unable to be copied to the clipboard, the popover will instead
37600
+ display `copyErrorPopoverContent`
37601
+
37602
+ If you only want the copy to clipboard behaviour without a popover, pass the prop
37603
+ `hasPopover={false}`
37573
37604
  */
37574
37605
 
37575
- var CopyableText = function CopyableText(_ref) {
37576
- var text = _ref.text,
37606
+ var CopyableContent = function CopyableContent(_ref) {
37607
+ var content = _ref.content,
37577
37608
  onClick = _ref.onClick;
37578
37609
  return /*#__PURE__*/React.createElement(ButtonWithAction, {
37579
37610
  "data-testid": "copyable-trigger",
@@ -37584,79 +37615,123 @@ var CopyableText = function CopyableText(_ref) {
37584
37615
  }, /*#__PURE__*/React.createElement(Stack, {
37585
37616
  direction: "row",
37586
37617
  childGap: "0.25rem"
37587
- }, /*#__PURE__*/React.createElement(Text$1, null, text), /*#__PURE__*/React.createElement(ClipboardIcon$1, null)));
37618
+ }, /*#__PURE__*/React.createElement(Text$1, null, content), /*#__PURE__*/React.createElement(ClipboardIcon$1, null)));
37588
37619
  };
37589
37620
 
37590
37621
  var Copyable = function Copyable(_ref2) {
37591
- var text = _ref2.text,
37622
+ var content = _ref2.content,
37592
37623
  onCopy = _ref2.onCopy,
37593
37624
  _ref2$initialPopoverC = _ref2.initialPopoverContent,
37594
37625
  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,
37626
+ _ref2$copySuccessPopo = _ref2.copySuccessPopoverContent,
37627
+ copySuccessPopoverContent = _ref2$copySuccessPopo === void 0 ? "Copied!" : _ref2$copySuccessPopo,
37628
+ _ref2$copyErrorPopove = _ref2.copyErrorPopoverContent,
37629
+ copyErrorPopoverContent = _ref2$copyErrorPopove === void 0 ? "Unable to copy value" : _ref2$copyErrorPopove,
37630
+ _ref2$copiedPopoverCo = _ref2.copiedPopoverContentDuration,
37631
+ copiedPopoverContentDuration = _ref2$copiedPopoverCo === void 0 ? 1000 : _ref2$copiedPopoverCo,
37632
+ _ref2$hasPopover = _ref2.hasPopover,
37633
+ hasPopover = _ref2$hasPopover === void 0 ? true : _ref2$hasPopover,
37599
37634
  _ref2$popoverMinWidth = _ref2.popoverMinWidth,
37600
- popoverMinWidth = _ref2$popoverMinWidth === void 0 ? "210px" : _ref2$popoverMinWidth,
37601
- _ref2$copiedPopoverCo2 = _ref2.copiedPopoverContentDuration,
37602
- copiedPopoverContentDuration = _ref2$copiedPopoverCo2 === void 0 ? 1000 : _ref2$copiedPopoverCo2,
37635
+ popoverMinWidth = _ref2$popoverMinWidth === void 0 ? "max-content" : _ref2$popoverMinWidth,
37603
37636
  _ref2$popoverID = _ref2.popoverID,
37604
37637
  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
- };
37638
+ popoverExtraStyles = _ref2.popoverExtraStyles;
37619
37639
 
37620
37640
  var _useState = useState(initialPopoverContent),
37621
37641
  _useState2 = _slicedToArray(_useState, 2),
37622
37642
  popoverContent = _useState2[0],
37623
37643
  setPopoverContent = _useState2[1];
37624
37644
 
37625
- var _useState3 = useState(undefined),
37645
+ var _useState3 = useState(false),
37626
37646
  _useState4 = _slicedToArray(_useState3, 2),
37627
- timer = _useState4[0],
37628
- setTimer = _useState4[1];
37647
+ startTimer = _useState4[0],
37648
+ setStartTimer = _useState4[1];
37629
37649
 
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();
37650
+ var _useState5 = useState(false),
37651
+ _useState6 = _slicedToArray(_useState5, 2),
37652
+ attemptCopy = _useState6[0],
37653
+ setAttemptCopy = _useState6[1];
37636
37654
 
37637
- if (timer) {
37638
- clearTimeout(timer);
37655
+ var _useState7 = useState(null),
37656
+ _useState8 = _slicedToArray(_useState7, 2),
37657
+ timeoutId = _useState8[0],
37658
+ setTimeoutId = _useState8[1];
37659
+
37660
+ var cleanup = function cleanup() {
37661
+ if (timeoutId) {
37662
+ // console.log(`Clearing timeout ${timeoutId}`);
37663
+ clearTimeout(timeoutId);
37639
37664
  }
37665
+ };
37666
+
37667
+ useEffect$1(function () {
37668
+ if (startTimer) {
37669
+ if (timeoutId) {
37670
+ // If there's an active timeout, clean it up.
37671
+ cleanup();
37672
+ } // Start a timeout to restore popover content to the initial value.
37673
+ // Record the ID of the timeout so it can be cleaned up later.
37674
+ // console.log("Starting timeout");
37675
+
37676
+
37677
+ setTimeoutId(setTimeout(function () {
37678
+ // console.log(`Timeout ${timeoutId} finished`);
37679
+ setPopoverContent(initialPopoverContent);
37680
+ }, copiedPopoverContentDuration)); // Set startTimer to false immediately after starting the timer,
37681
+ // so subsequent clicks will start a new timer, refreshing the duration.
37682
+
37683
+ setStartTimer(false);
37684
+ } // Return cleanup function so timeout will be cleared when component unmoumnts.
37685
+
37640
37686
 
37641
- setTimer(setTimeout(function () {
37642
- setPopoverContent(initialPopoverContent);
37643
- setTimer(undefined);
37644
- }, copiedPopoverContentDuration));
37687
+ return cleanup;
37688
+ }, [startTimer]);
37689
+ useEffect$1(function () {
37690
+ if (attemptCopy) {
37691
+ navigator.clipboard.writeText(content).then(function () {
37692
+ setPopoverContent(copySuccessPopoverContent);
37693
+ onCopy === null || onCopy === void 0 ? void 0 : onCopy();
37694
+ setAttemptCopy(false);
37695
+ })["catch"](function (error) {
37696
+ console.error(error);
37697
+ setPopoverContent(copyErrorPopoverContent);
37698
+ setAttemptCopy(false);
37699
+ });
37700
+ }
37701
+ }, [attemptCopy]);
37702
+
37703
+ var onClick = function onClick() {
37704
+ setStartTimer(true);
37705
+ setAttemptCopy(true);
37645
37706
  };
37646
37707
 
37647
- return withPopover ? /*#__PURE__*/React.createElement(Popover$1, {
37708
+ var popoverArrowWidth = "8px";
37709
+ return hasPopover ? /*#__PURE__*/React.createElement(Popover$1, {
37648
37710
  minWidth: popoverMinWidth,
37649
- position: popoverPosition,
37650
- arrowPosition: popoverArrowPosition,
37711
+ position: {
37712
+ top: "auto",
37713
+ right: "auto",
37714
+ bottom: "auto",
37715
+ left: "calc(-".concat(popoverArrowWidth, " - 8px)")
37716
+ },
37717
+ arrowPosition: {
37718
+ arrowTop: "auto",
37719
+ arrowRight: "-8px",
37720
+ arrowBottom: "calc(50% - ".concat(popoverArrowWidth, ")"),
37721
+ arrowLeft: "auto"
37722
+ },
37723
+ transform: "translate(-100%, -75%)",
37724
+ arrowDirection: "right",
37651
37725
  popoverID: popoverID,
37652
- extraStyles: "> button#btnPopover".concat(popoverID, " { margin: 0 }; > #Disclosed").concat(popoverID, " { transform: translateX(-50%); }; ").concat(extraStyles),
37653
- triggerText: CopyableText({
37654
- text: text,
37726
+ buttonExtraStyles: "margin: 0",
37727
+ extraStyles: popoverExtraStyles,
37728
+ triggerText: CopyableContent({
37729
+ content: content,
37655
37730
  onClick: onClick
37656
37731
  }),
37657
37732
  content: popoverContent
37658
- }) : CopyableText({
37659
- text: text,
37733
+ }) : CopyableContent({
37734
+ content: content,
37660
37735
  onClick: onClick
37661
37736
  });
37662
37737
  };