@thecb/components 7.0.2-beta.4 → 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
 
@@ -37566,13 +37587,23 @@ var ClipboardIcon = function ClipboardIcon(_ref) {
37566
37587
  var ClipboardIcon$1 = themeComponent(ClipboardIcon, "Icons", fallbackValues$2, "primary");
37567
37588
 
37568
37589
  /*
37569
- This component will render `text` and a clipboard icon. When hovered, a popover with content `initialPopoverContent` will be displayed.
37570
- When clicked, `text` will be copied to the clipboard, the popover content will change to `copiedPopoverContent` for `copiedPopoverContentDuration` milliseconds,
37571
- 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}`
37572
37603
  */
37573
37604
 
37574
- var CopyableText = function CopyableText(_ref) {
37575
- var text = _ref.text,
37605
+ var CopyableContent = function CopyableContent(_ref) {
37606
+ var content = _ref.content,
37576
37607
  onClick = _ref.onClick;
37577
37608
  return /*#__PURE__*/React.createElement(ButtonWithAction, {
37578
37609
  "data-testid": "copyable-trigger",
@@ -37583,79 +37614,123 @@ var CopyableText = function CopyableText(_ref) {
37583
37614
  }, /*#__PURE__*/React.createElement(Stack, {
37584
37615
  direction: "row",
37585
37616
  childGap: "0.25rem"
37586
- }, /*#__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)));
37587
37618
  };
37588
37619
 
37589
37620
  var Copyable = function Copyable(_ref2) {
37590
- var text = _ref2.text,
37621
+ var content = _ref2.content,
37591
37622
  onCopy = _ref2.onCopy,
37592
37623
  _ref2$initialPopoverC = _ref2.initialPopoverContent,
37593
37624
  initialPopoverContent = _ref2$initialPopoverC === void 0 ? "Click to copy to clipboard" : _ref2$initialPopoverC,
37594
- _ref2$copiedPopoverCo = _ref2.copiedPopoverContent,
37595
- copiedPopoverContent = _ref2$copiedPopoverCo === void 0 ? "Copied!" : _ref2$copiedPopoverCo,
37596
- _ref2$withPopover = _ref2.withPopover,
37597
- 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,
37598
37633
  _ref2$popoverMinWidth = _ref2.popoverMinWidth,
37599
37634
  popoverMinWidth = _ref2$popoverMinWidth === void 0 ? "210px" : _ref2$popoverMinWidth,
37600
- _ref2$copiedPopoverCo2 = _ref2.copiedPopoverContentDuration,
37601
- copiedPopoverContentDuration = _ref2$copiedPopoverCo2 === void 0 ? 1000 : _ref2$copiedPopoverCo2,
37602
37635
  _ref2$popoverID = _ref2.popoverID,
37603
37636
  popoverID = _ref2$popoverID === void 0 ? 0 : _ref2$popoverID,
37604
- extraStyles = _ref2.extraStyles;
37605
- var popoverPosition = {
37606
- top: "-65px",
37607
- right: "auto",
37608
- bottom: "auto",
37609
- left: "-50%"
37610
- };
37611
- var popoverArrowPosition = {
37612
- arrowTop: "auto",
37613
- arrowRight: "auto",
37614
- arrowBottom: "-8px",
37615
- arrowLeft: "calc(50% - 4px)" // Popover arrow is 8px wide. This places the middle of the arrow in the middle of the popover.
37616
-
37617
- };
37637
+ popoverExtraStyles = _ref2.popoverExtraStyles;
37618
37638
 
37619
37639
  var _useState = useState(initialPopoverContent),
37620
37640
  _useState2 = _slicedToArray(_useState, 2),
37621
37641
  popoverContent = _useState2[0],
37622
37642
  setPopoverContent = _useState2[1];
37623
37643
 
37624
- var _useState3 = useState(undefined),
37644
+ var _useState3 = useState(false),
37625
37645
  _useState4 = _slicedToArray(_useState3, 2),
37626
- timer = _useState4[0],
37627
- setTimer = _useState4[1];
37646
+ startTimer = _useState4[0],
37647
+ setStartTimer = _useState4[1];
37628
37648
 
37629
- var onClick = function onClick() {
37630
- setPopoverContent(copiedPopoverContent);
37631
- navigator.clipboard.writeText(text)["catch"](function (e) {
37632
- return console.error(e);
37633
- });
37634
- 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];
37635
37653
 
37636
- if (timer) {
37637
- 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
+ });
37638
37699
  }
37700
+ }, [attemptCopy]);
37639
37701
 
37640
- setTimer(setTimeout(function () {
37641
- setPopoverContent(initialPopoverContent);
37642
- setTimer(undefined);
37643
- }, copiedPopoverContentDuration));
37702
+ var onClick = function onClick() {
37703
+ setStartTimer(true);
37704
+ setAttemptCopy(true);
37644
37705
  };
37645
37706
 
37646
- return withPopover ? /*#__PURE__*/React.createElement(Popover$1, {
37707
+ var popoverArrowWidth = "8px";
37708
+ return hasPopover ? /*#__PURE__*/React.createElement(Popover$1, {
37647
37709
  minWidth: popoverMinWidth,
37648
- position: popoverPosition,
37649
- 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",
37650
37724
  popoverID: popoverID,
37651
- extraStyles: "> button#btnPopover".concat(popoverID, " { margin: 0 }; ").concat(extraStyles),
37652
- triggerText: CopyableText({
37653
- text: text,
37725
+ buttonExtraStyles: "margin: 0",
37726
+ extraStyles: popoverExtraStyles,
37727
+ triggerText: CopyableContent({
37728
+ content: content,
37654
37729
  onClick: onClick
37655
37730
  }),
37656
37731
  content: popoverContent
37657
- }) : CopyableText({
37658
- text: text,
37732
+ }) : CopyableContent({
37733
+ content: content,
37659
37734
  onClick: onClick
37660
37735
  });
37661
37736
  };