Skip to content

Commit

Permalink
Add property textClassName (#3)
Browse files Browse the repository at this point in the history
* feat(copytext): add textClassname property

* test: adding test for textClassName
  • Loading branch information
matheusrocha89 authored Jan 12, 2025
1 parent 6f33552 commit 11d8cdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/CopyText/CopyText.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ describe("CopyText", () => {
expect(screen.getByText("Copied!")).toBeInTheDocument();
});

it("should apply textClassName to the text element", () => {
render(<CopyText text="Hello" textClassName="custom-text" />);
expect(screen.getByText("Hello")).toHaveClass("custom-text");
});

describe("behavior", () => {
it("should copy the text when the button is clicked", async () => {
render(<CopyText text="Let's copy text" />);
Expand Down
4 changes: 3 additions & 1 deletion src/CopyText/CopyText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type CopyTextProps = {
copied?: boolean;
onClick?: () => void;
text: string;
textClassName?: string;
};

const CopyText = ({
Expand All @@ -23,6 +24,7 @@ const CopyText = ({
showIcon = true,
copiedButtonLabel = "Copied",
copyButtonLabel = "Copy",
textClassName,
}: CopyTextProps) => {
const copyText = async () => {
await navigator.clipboard.writeText(text);
Expand All @@ -31,7 +33,7 @@ const CopyText = ({

return (
<span className={cx(styles.wrapper, className)}>
{text}
<span className={textClassName}>{text}</span>
<button className={cx(styles.button, buttonClassName)} onClick={copyText}>
{copied ? (
<>
Expand Down

0 comments on commit 11d8cdc

Please sign in to comment.