copy-button
shuip/copy-buttonFreeComponent
shuip publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by shuip on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shuip.plvo.dev/r/copy-button.jsonSource
1'use client';23import type { VariantProps } from 'class-variance-authority';4import { CheckIcon, Copy } from 'lucide-react';5import * as React from 'react';6import { Button, type buttonVariants } from '@/components/ui/button';78const DEFAULT_TIMEOUT = 2000;910type ButtonProps = React.ComponentProps<'button'> &11 VariantProps<typeof buttonVariants> & {12 asChild?: boolean;13 };1415export interface CopyButtonProps extends ButtonProps {16 value: string;17 copiedIcon?: React.ReactNode;18 notCopiedIcon?: React.ReactNode;19}2021export function CopyButton({ value, copiedIcon = <CheckIcon />, notCopiedIcon = <Copy />, ...props }: CopyButtonProps) {22 const [hasCopied, setHasCopied] = React.useState(false);2324 const handleCopy = () => {25 navigator.clipboard.writeText(value);26 setHasCopied(true);27 setTimeout(() => {28 setHasCopied(false);29 }, DEFAULT_TIMEOUT);30 };3132 return (33 <Button size='icon' variant={'ghost'} className={'z-10 size-4'} onClick={handleCopy} {...props}>34 <span className='sr-only'>Copy</span>35 {hasCopied ? copiedIcon : notCopiedIcon}36 </Button>37 );38}
What it pulls in
npm packages
Other registry items
Files it writes
More from shuip
All 52 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| confirmation-dialogconfirmation-dialog | shuip | Components | Free | 1 dep | |
| hover-revealhover-reveal | shuip | Components | Free | 1 dep | |
| rhf-address-fieldrhf-address-field | shuip | Components | Free | 5 deps · 2 files | |
| rhf-autocomplete-fieldrhf-autocomplete-field | shuip | Components | Free | 4 deps | |
| rhf-checkbox-fieldrhf-checkbox-field | shuip | Components | Free | 3 deps | |
| rhf-combobox-fieldrhf-combobox-field | shuip | Components | Free | 5 deps | |
| rhf-date-fieldrhf-date-field | shuip | Components | Free | 6 deps | |
| rhf-date-range-fieldrhf-date-range-field | shuip | Components | Free | 6 deps |
