@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.cjs.js +129 -55
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.esm.js +129 -55
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/copyable/Copyable.js +99 -42
- package/src/components/molecules/copyable/index.d.ts +6 -5
- package/src/components/molecules/popover/Popover.js +32 -2
- package/src/components/molecules/popover/index.d.ts +3 -0
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,11 @@ 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
|
+
transform = _ref.transform,
|
|
22803
|
+
buttonExtraStyles = _ref.buttonExtraStyles;
|
|
22784
22804
|
var hoverColor = themeValues.hoverColor,
|
|
22785
22805
|
activeColor = themeValues.activeColor,
|
|
22786
22806
|
popoverTriggerColor = themeValues.popoverTriggerColor;
|
|
@@ -22855,7 +22875,8 @@ var Popover = function Popover(_ref) {
|
|
|
22855
22875
|
"aria-labelledby": "btnPopover".concat(popoverID, "_info Disclosure").concat(popoverID),
|
|
22856
22876
|
"aria-describedby": "Disclosure".concat(popoverID),
|
|
22857
22877
|
"aria-controls": "Disclosed".concat(popoverID),
|
|
22858
|
-
ref: triggerRef
|
|
22878
|
+
ref: triggerRef,
|
|
22879
|
+
extraStyles: buttonExtraStyles
|
|
22859
22880
|
}, hasIcon && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, null), /*#__PURE__*/React__default.createElement(Box, {
|
|
22860
22881
|
padding: "0",
|
|
22861
22882
|
srOnly: true
|
|
@@ -22874,10 +22895,10 @@ var Popover = function Popover(_ref) {
|
|
|
22874
22895
|
tabIndex: popoverFocus && popoverOpen ? "0" : "-1",
|
|
22875
22896
|
minWidth: minWidth,
|
|
22876
22897
|
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 ")
|
|
22898
|
+
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 ")
|
|
22878
22899
|
}, /*#__PURE__*/React__default.createElement(Paragraph$1, null, content), /*#__PURE__*/React__default.createElement(Box, {
|
|
22879
22900
|
padding: "0",
|
|
22880
|
-
extraStyles: "position: absolute
|
|
22901
|
+
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
22902
|
})));
|
|
22882
22903
|
};
|
|
22883
22904
|
|
|
@@ -37449,7 +37470,6 @@ var CollapsibleSection = function CollapsibleSection(_ref) {
|
|
|
37449
37470
|
}
|
|
37450
37471
|
};
|
|
37451
37472
|
|
|
37452
|
-
React.useEffect(function () {}, [isOpen]);
|
|
37453
37473
|
var numChildren = typeof children === "Array" ? children.length : 1;
|
|
37454
37474
|
var label = name !== "" ? name : !customTitle ? title : "collapsible section";
|
|
37455
37475
|
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);
|
|
@@ -37575,13 +37595,23 @@ var ClipboardIcon = function ClipboardIcon(_ref) {
|
|
|
37575
37595
|
var ClipboardIcon$1 = themeComponent(ClipboardIcon, "Icons", fallbackValues$2, "primary");
|
|
37576
37596
|
|
|
37577
37597
|
/*
|
|
37578
|
-
This component will render `
|
|
37579
|
-
When
|
|
37580
|
-
|
|
37598
|
+
This component will render `content` and a clipboard icon.
|
|
37599
|
+
When hovered, a popover with content `initialPopoverContent` will be displayed.
|
|
37600
|
+
to the left of the content.
|
|
37601
|
+
|
|
37602
|
+
When clicked, `content` will be copied to the clipboard, the popover content
|
|
37603
|
+
will change to `copySuccessPopoverContent` for `copiedPopoverContentDuration`
|
|
37604
|
+
milliseconds, and the `onCopy` callback will be executed.
|
|
37605
|
+
|
|
37606
|
+
If the content was unable to be copied to the clipboard, the popover will instead
|
|
37607
|
+
display `copyErrorPopoverContent`
|
|
37608
|
+
|
|
37609
|
+
If you only want the copy to clipboard behaviour without a popover, pass the prop
|
|
37610
|
+
`hasPopover={false}`
|
|
37581
37611
|
*/
|
|
37582
37612
|
|
|
37583
|
-
var
|
|
37584
|
-
var
|
|
37613
|
+
var CopyableContent = function CopyableContent(_ref) {
|
|
37614
|
+
var content = _ref.content,
|
|
37585
37615
|
onClick = _ref.onClick;
|
|
37586
37616
|
return /*#__PURE__*/React__default.createElement(ButtonWithAction, {
|
|
37587
37617
|
"data-testid": "copyable-trigger",
|
|
@@ -37592,79 +37622,123 @@ var CopyableText = function CopyableText(_ref) {
|
|
|
37592
37622
|
}, /*#__PURE__*/React__default.createElement(Stack, {
|
|
37593
37623
|
direction: "row",
|
|
37594
37624
|
childGap: "0.25rem"
|
|
37595
|
-
}, /*#__PURE__*/React__default.createElement(Text$1, null,
|
|
37625
|
+
}, /*#__PURE__*/React__default.createElement(Text$1, null, content), /*#__PURE__*/React__default.createElement(ClipboardIcon$1, null)));
|
|
37596
37626
|
};
|
|
37597
37627
|
|
|
37598
37628
|
var Copyable = function Copyable(_ref2) {
|
|
37599
|
-
var
|
|
37629
|
+
var content = _ref2.content,
|
|
37600
37630
|
onCopy = _ref2.onCopy,
|
|
37601
37631
|
_ref2$initialPopoverC = _ref2.initialPopoverContent,
|
|
37602
37632
|
initialPopoverContent = _ref2$initialPopoverC === void 0 ? "Click to copy to clipboard" : _ref2$initialPopoverC,
|
|
37603
|
-
_ref2$
|
|
37604
|
-
|
|
37605
|
-
_ref2$
|
|
37606
|
-
|
|
37633
|
+
_ref2$copySuccessPopo = _ref2.copySuccessPopoverContent,
|
|
37634
|
+
copySuccessPopoverContent = _ref2$copySuccessPopo === void 0 ? "Copied!" : _ref2$copySuccessPopo,
|
|
37635
|
+
_ref2$copyErrorPopove = _ref2.copyErrorPopoverContent,
|
|
37636
|
+
copyErrorPopoverContent = _ref2$copyErrorPopove === void 0 ? "Unable to copy value" : _ref2$copyErrorPopove,
|
|
37637
|
+
_ref2$copiedPopoverCo = _ref2.copiedPopoverContentDuration,
|
|
37638
|
+
copiedPopoverContentDuration = _ref2$copiedPopoverCo === void 0 ? 1000 : _ref2$copiedPopoverCo,
|
|
37639
|
+
_ref2$hasPopover = _ref2.hasPopover,
|
|
37640
|
+
hasPopover = _ref2$hasPopover === void 0 ? true : _ref2$hasPopover,
|
|
37607
37641
|
_ref2$popoverMinWidth = _ref2.popoverMinWidth,
|
|
37608
37642
|
popoverMinWidth = _ref2$popoverMinWidth === void 0 ? "210px" : _ref2$popoverMinWidth,
|
|
37609
|
-
_ref2$copiedPopoverCo2 = _ref2.copiedPopoverContentDuration,
|
|
37610
|
-
copiedPopoverContentDuration = _ref2$copiedPopoverCo2 === void 0 ? 1000 : _ref2$copiedPopoverCo2,
|
|
37611
37643
|
_ref2$popoverID = _ref2.popoverID,
|
|
37612
37644
|
popoverID = _ref2$popoverID === void 0 ? 0 : _ref2$popoverID,
|
|
37613
|
-
|
|
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
|
-
};
|
|
37645
|
+
popoverExtraStyles = _ref2.popoverExtraStyles;
|
|
37627
37646
|
|
|
37628
37647
|
var _useState = React.useState(initialPopoverContent),
|
|
37629
37648
|
_useState2 = _slicedToArray(_useState, 2),
|
|
37630
37649
|
popoverContent = _useState2[0],
|
|
37631
37650
|
setPopoverContent = _useState2[1];
|
|
37632
37651
|
|
|
37633
|
-
var _useState3 = React.useState(
|
|
37652
|
+
var _useState3 = React.useState(false),
|
|
37634
37653
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
37635
|
-
|
|
37636
|
-
|
|
37654
|
+
startTimer = _useState4[0],
|
|
37655
|
+
setStartTimer = _useState4[1];
|
|
37637
37656
|
|
|
37638
|
-
var
|
|
37639
|
-
|
|
37640
|
-
|
|
37641
|
-
|
|
37642
|
-
});
|
|
37643
|
-
onCopy === null || onCopy === void 0 ? void 0 : onCopy();
|
|
37657
|
+
var _useState5 = React.useState(false),
|
|
37658
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
37659
|
+
attemptCopy = _useState6[0],
|
|
37660
|
+
setAttemptCopy = _useState6[1];
|
|
37644
37661
|
|
|
37645
|
-
|
|
37646
|
-
|
|
37662
|
+
var _useState7 = React.useState(null),
|
|
37663
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
37664
|
+
timeoutId = _useState8[0],
|
|
37665
|
+
setTimeoutId = _useState8[1];
|
|
37666
|
+
|
|
37667
|
+
var cleanup = function cleanup() {
|
|
37668
|
+
if (timeoutId) {
|
|
37669
|
+
// console.log(`Clearing timeout ${timeoutId}`);
|
|
37670
|
+
clearTimeout(timeoutId);
|
|
37671
|
+
}
|
|
37672
|
+
};
|
|
37673
|
+
|
|
37674
|
+
React.useEffect(function () {
|
|
37675
|
+
if (startTimer) {
|
|
37676
|
+
if (timeoutId) {
|
|
37677
|
+
// If there's an active timeout, clean it up.
|
|
37678
|
+
cleanup();
|
|
37679
|
+
} // Start a timeout to restore popover content to the initial value.
|
|
37680
|
+
// Record the ID of the timeout so it can be cleaned up later.
|
|
37681
|
+
// console.log("Starting timeout");
|
|
37682
|
+
|
|
37683
|
+
|
|
37684
|
+
setTimeoutId(setTimeout(function () {
|
|
37685
|
+
// console.log(`Timeout ${timeoutId} finished`);
|
|
37686
|
+
setPopoverContent(initialPopoverContent);
|
|
37687
|
+
}, copiedPopoverContentDuration)); // Set startTimer to false immediately after starting the timer,
|
|
37688
|
+
// so subsequent clicks will start a new timer, refreshing the duration.
|
|
37689
|
+
|
|
37690
|
+
setStartTimer(false);
|
|
37691
|
+
} // Return cleanup function so timeout will be cleared when component unmoumnts.
|
|
37692
|
+
|
|
37693
|
+
|
|
37694
|
+
return cleanup;
|
|
37695
|
+
}, [startTimer]);
|
|
37696
|
+
React.useEffect(function () {
|
|
37697
|
+
if (attemptCopy) {
|
|
37698
|
+
navigator.clipboard.writeText(content).then(function () {
|
|
37699
|
+
setPopoverContent(copySuccessPopoverContent);
|
|
37700
|
+
onCopy === null || onCopy === void 0 ? void 0 : onCopy();
|
|
37701
|
+
setAttemptCopy(false);
|
|
37702
|
+
})["catch"](function (error) {
|
|
37703
|
+
console.error(error);
|
|
37704
|
+
setPopoverContent(copyErrorPopoverContent);
|
|
37705
|
+
setAttemptCopy(false);
|
|
37706
|
+
});
|
|
37647
37707
|
}
|
|
37708
|
+
}, [attemptCopy]);
|
|
37648
37709
|
|
|
37649
|
-
|
|
37650
|
-
|
|
37651
|
-
|
|
37652
|
-
}, copiedPopoverContentDuration));
|
|
37710
|
+
var onClick = function onClick() {
|
|
37711
|
+
setStartTimer(true);
|
|
37712
|
+
setAttemptCopy(true);
|
|
37653
37713
|
};
|
|
37654
37714
|
|
|
37655
|
-
|
|
37715
|
+
var popoverArrowWidth = "8px";
|
|
37716
|
+
return hasPopover ? /*#__PURE__*/React__default.createElement(Popover$1, {
|
|
37656
37717
|
minWidth: popoverMinWidth,
|
|
37657
|
-
position:
|
|
37658
|
-
|
|
37718
|
+
position: {
|
|
37719
|
+
top: "auto",
|
|
37720
|
+
right: "auto",
|
|
37721
|
+
bottom: "auto",
|
|
37722
|
+
left: "calc(-".concat(popoverArrowWidth, " - 8px)")
|
|
37723
|
+
},
|
|
37724
|
+
arrowPosition: {
|
|
37725
|
+
arrowTop: "auto",
|
|
37726
|
+
arrowRight: "-8px",
|
|
37727
|
+
arrowBottom: "calc(50% - ".concat(popoverArrowWidth, ")"),
|
|
37728
|
+
arrowLeft: "auto"
|
|
37729
|
+
},
|
|
37730
|
+
transform: "translate(-100%, -75%)",
|
|
37731
|
+
arrowDirection: "right",
|
|
37659
37732
|
popoverID: popoverID,
|
|
37660
|
-
|
|
37661
|
-
|
|
37662
|
-
|
|
37733
|
+
buttonExtraStyles: "margin: 0",
|
|
37734
|
+
extraStyles: popoverExtraStyles,
|
|
37735
|
+
triggerText: CopyableContent({
|
|
37736
|
+
content: content,
|
|
37663
37737
|
onClick: onClick
|
|
37664
37738
|
}),
|
|
37665
37739
|
content: popoverContent
|
|
37666
|
-
}) :
|
|
37667
|
-
|
|
37740
|
+
}) : CopyableContent({
|
|
37741
|
+
content: content,
|
|
37668
37742
|
onClick: onClick
|
|
37669
37743
|
});
|
|
37670
37744
|
};
|