···11+---
22+title: CopyToClipboardButton
33+description: A button component that copies text to the clipboard when clicked, with visual feedback via a tooltip.
44+---
55+66+import { PropDocs } from '../../../lib/PropDocs'
77+import { Example } from '../../../lib/Example'
88+import { Basic } from '../../../examples/copy-to-clipboard-button/basic'
99+import { CustomIcon } from '../../../examples/copy-to-clipboard-button/custom-icon'
1010+1111+<Example src={Basic} />
1212+1313+## Installation
1414+1515+Run the following command to add the copy to clipboard button component to your project.
1616+1717+```bash
1818+pnpm hip install copy-to-clipboard-button
1919+```
2020+2121+## Props
2222+2323+<PropDocs components={["CopyToClipboardButton"]} />
2424+2525+## Features
2626+2727+### Custom Icon
2828+2929+You can customize the icon displayed on the button.
3030+3131+<Example src={CustomIcon} />
3232+3333+## Related Components
3434+3535+- [IconButton](/docs/components/buttons/icon-button) - The base icon button component used by CopyToClipboardButton
3636+- [Button](/docs/components/buttons/button) - For buttons with text and icons
3737+- [Tooltip](/docs/components/overlays/tooltip) - For providing context on buttons
3838+
···11+"use client";
22+13import * as stylex from "@stylexjs/stylex";
24import { Copy } from "lucide-react";
35import { useRef, useState } from "react";
4655-import { IconButton } from "@/components/icon-button";
77+import { IconButton } from "../icon-button";
88+import { StyleXComponentProps } from "../theme/types";
69710const defaultIcon = <Copy />;
81199-export function CopyToClipboardButton({
1212+/**
1313+ * Props for the CopyToClipboardButton component.
1414+ */
1515+export interface CopyToClipboardButtonProps extends StyleXComponentProps<{}> {
1616+ /**
1717+ * The text to copy to the clipboard when the button is clicked.
1818+ */
1919+ text: string;
2020+ /**
2121+ * Optional icon to display. Defaults to a Copy icon.
2222+ */
2323+ icon?: React.ReactNode;
2424+}
2525+2626+/**
2727+ * A button component that copies text to the clipboard when clicked.
2828+ * Displays a tooltip that changes to "Copied ✓" after copying.
2929+ */
3030+export const CopyToClipboardButton = ({
1031 style,
1132 text,
1233 icon = defaultIcon,
1313-}: {
1414- style?: stylex.StyleXStyles;
1515- text: string;
1616- icon?: React.ReactNode;
1717-}) {
3434+}: CopyToClipboardButtonProps) => {
1835 const [tooltipText, setTooltipText] = useState("Copy to clipboard");
1936 const [tooltipOpen, setTooltipOpen] = useState(false);
2037 const timeoutRef = useRef<NodeJS.Timeout | null>(null);
···5168 !timeoutRef.current && setTooltipOpen(isOpen)
5269 }
5370 variant="tertiary"
5454- style={[style]}
7171+ style={style}
5572 size="sm"
5673 onClick={handleCopy}
5774 >
5875 {icon}
5976 </IconButton>
6077 );
6161-}
7878+};
7979+
+1-1
apps/docs/src/lib/Example.tsx
···88import { radius } from "../components/theme/radius.stylex";
99import { uiColor } from "../components/theme/color.stylex";
1010import { spacing } from "../components/theme/spacing.stylex";
1111-import { CopyToClipboardButton } from "./CopyToClipboardButton";
1111+import { CopyToClipboardButton } from "@/components/copy-to-clipboard-button";
12121313const styles = stylex.create({
1414 card: {
+1-1
apps/docs/src/routes/docs.$.tsx
···4747} from "@/components/typography";
4848import { Text } from "@/components/typography/text";
4949import { TableOfContents } from "@/components/table-of-contents";
5050-import { CopyToClipboardButton } from "@/lib/CopyToClipboardButton";
5050+import { CopyToClipboardButton } from "@/components/copy-to-clipboard-button";
51515252import { animationDuration } from "../components/theme/animations.stylex";
5353import { radius } from "../components/theme/radius.stylex";
+2
packages/hip-ui/src/cli/install.tsx
···2929import { comboboxConfig } from "../components/combobox/combobox-config.js";
3030import { commandMenuConfig } from "../components/command-menu/command-menu-config.js";
3131import { contentConfig } from "../components/content/content-config.js";
3232+import { copyToClipboardButtonConfig } from "../components/copy-to-clipboard-button/copy-to-clipboard-button-config.js";
3233import { contextMenuConfig } from "../components/context-menu/context-menu-config.js";
3334import { dateFieldConfig } from "../components/date-field/date-field-config.js";
3435import { datePickerConfig } from "../components/date-picker/date-picker-config.js";
···9798 flexConfig,
9899 typographyConfig,
99100 contentConfig,
101101+ copyToClipboardButtonConfig,
100102 tooltipConfig,
101103 iconButtonConfig,
102104 popoverConfig,