tycho-components 0.2.15 → 0.2.16
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./styles.scss";
|
|
2
2
|
export declare const TitlePositions: readonly ["top", "right"];
|
|
3
3
|
type TitlePosition = (typeof TitlePositions)[number];
|
|
4
4
|
export type Props = {
|
|
@@ -6,7 +6,6 @@ export type Props = {
|
|
|
6
6
|
title?: string;
|
|
7
7
|
content: string;
|
|
8
8
|
titlePosition?: TitlePosition;
|
|
9
|
-
hideTitle?: boolean;
|
|
10
9
|
};
|
|
11
|
-
export default function AppCopyText({ className, title, content, titlePosition,
|
|
10
|
+
export default function AppCopyText({ className, title, content, titlePosition, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
12
11
|
export {};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from
|
|
3
|
-
import cx from
|
|
4
|
-
import
|
|
5
|
-
import { Icon, Tooltip } from
|
|
6
|
-
import { useTranslation } from
|
|
7
|
-
export const TitlePositions = [
|
|
8
|
-
export default function AppCopyText({ className, title, content, titlePosition =
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import cx from "classnames";
|
|
4
|
+
import "./styles.scss";
|
|
5
|
+
import { Icon, Tooltip } from "tycho-storybook";
|
|
6
|
+
import { useTranslation } from "react-i18next";
|
|
7
|
+
export const TitlePositions = ["top", "right"];
|
|
8
|
+
export default function AppCopyText({ className, title, content, titlePosition = "right", }) {
|
|
9
9
|
const [copied, setCopied] = useState(false);
|
|
10
10
|
const [isHovered, setIsHovered] = useState(false);
|
|
11
|
-
const { t } = useTranslation(
|
|
12
|
-
const getClassNames = cx(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const { t } = useTranslation("common");
|
|
12
|
+
const getClassNames = cx("ds-copy-text", className, {
|
|
13
|
+
"title-top": titlePosition === "top" && title,
|
|
14
|
+
"title-right": titlePosition === "right" && title,
|
|
15
|
+
"no-title": !title,
|
|
16
16
|
});
|
|
17
17
|
const handleClipboard = () => {
|
|
18
18
|
navigator.clipboard
|
|
@@ -24,12 +24,12 @@ export default function AppCopyText({ className, title, content, titlePosition =
|
|
|
24
24
|
}, 2000);
|
|
25
25
|
})
|
|
26
26
|
.catch((err) => {
|
|
27
|
-
console.error(
|
|
27
|
+
console.error("Failed to copy text:", err);
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
-
const tooltipTitle = copied ? t(
|
|
31
|
-
const iconName = copied ?
|
|
30
|
+
const tooltipTitle = copied ? t("tooltip.copied") : t("tooltip.copy");
|
|
31
|
+
const iconName = copied ? "check" : "content_copy";
|
|
32
32
|
const iconFilled = isHovered && !copied;
|
|
33
|
-
const contentElement = (_jsxs("div", { className: getClassNames, onClick: handleClipboard, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), children: [
|
|
33
|
+
const contentElement = (_jsxs("div", { className: getClassNames, onClick: handleClipboard, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), children: [title && _jsx("span", { className: "ds-copy-text__title", children: title }), title && titlePosition === "right" && (_jsx("span", { className: "ds-copy-text__separator", children: "|" })), _jsxs("div", { className: "group-content", children: [_jsx("span", { className: "ds-copy-text__content", children: content }), _jsx(Icon, { name: iconName, size: "small", className: "ds-copy-text__icon", filled: iconFilled })] })] }));
|
|
34
34
|
return (_jsx(Tooltip, { title: tooltipTitle, placement: "top", mode: "simple", triggerOpen: copied ? true : undefined, children: contentElement }));
|
|
35
35
|
}
|