Skip to content

Commit 11d8cdc

Browse files
Add property textClassName (#3)
* feat(copytext): add textClassname property * test: adding test for textClassName
1 parent 6f33552 commit 11d8cdc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/CopyText/CopyText.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ describe("CopyText", () => {
5757
expect(screen.getByText("Copied!")).toBeInTheDocument();
5858
});
5959

60+
it("should apply textClassName to the text element", () => {
61+
render(<CopyText text="Hello" textClassName="custom-text" />);
62+
expect(screen.getByText("Hello")).toHaveClass("custom-text");
63+
});
64+
6065
describe("behavior", () => {
6166
it("should copy the text when the button is clicked", async () => {
6267
render(<CopyText text="Let's copy text" />);

src/CopyText/CopyText.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type CopyTextProps = {
1212
copied?: boolean;
1313
onClick?: () => void;
1414
text: string;
15+
textClassName?: string;
1516
};
1617

1718
const CopyText = ({
@@ -23,6 +24,7 @@ const CopyText = ({
2324
showIcon = true,
2425
copiedButtonLabel = "Copied",
2526
copyButtonLabel = "Copy",
27+
textClassName,
2628
}: CopyTextProps) => {
2729
const copyText = async () => {
2830
await navigator.clipboard.writeText(text);
@@ -31,7 +33,7 @@ const CopyText = ({
3133

3234
return (
3335
<span className={cx(styles.wrapper, className)}>
34-
{text}
36+
<span className={textClassName}>{text}</span>
3537
<button className={cx(styles.button, buttonClassName)} onClick={copyText}>
3638
{copied ? (
3739
<>

0 commit comments

Comments
 (0)