mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
refactor(ui): standardize copy code feedback across all tabs (#5584)
This commit is contained in:
parent
b6fda4fe6f
commit
667c86eaae
@ -2,6 +2,7 @@ import type {ButtonProps} from "@heroui/react";
|
|||||||
|
|
||||||
import {useClipboard} from "@heroui/use-clipboard";
|
import {useClipboard} from "@heroui/use-clipboard";
|
||||||
import {memo} from "react";
|
import {memo} from "react";
|
||||||
|
import {Tooltip} from "@heroui/react";
|
||||||
|
|
||||||
import {PreviewButton} from "./preview-button";
|
import {PreviewButton} from "./preview-button";
|
||||||
|
|
||||||
@ -32,7 +33,17 @@ export const CopyButton = memo<CopyButtonProps>(({value, className, ...buttonPro
|
|||||||
copy(value);
|
copy(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
return <PreviewButton className={className} icon={icon} onPress={handleCopy} {...buttonProps} />;
|
return (
|
||||||
|
<Tooltip
|
||||||
|
key={copied ? "copied" : "copy"}
|
||||||
|
className="text-xs px-2"
|
||||||
|
closeDelay={0}
|
||||||
|
content={copied ? "Copied!" : "Copy"}
|
||||||
|
radius="md"
|
||||||
|
>
|
||||||
|
<PreviewButton className={className} icon={icon} onPress={handleCopy} {...buttonProps} />
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
CopyButton.displayName = "CopyButton";
|
CopyButton.displayName = "CopyButton";
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import {useSandpack} from "@codesandbox/sandpack-react";
|
|||||||
import {Tooltip, Button} from "@heroui/react";
|
import {Tooltip, Button} from "@heroui/react";
|
||||||
import {useClipboard} from "@heroui/use-clipboard";
|
import {useClipboard} from "@heroui/use-clipboard";
|
||||||
|
|
||||||
import {CopyLinearIcon} from "@/components/icons";
|
import {CheckLinearIcon, CopyLinearIcon} from "@/components/icons";
|
||||||
|
|
||||||
export const CopyButton = ({code: codeProp}: {code?: string}) => {
|
export const CopyButton = ({code: codeProp}: {code?: string}) => {
|
||||||
const {copy, copied} = useClipboard();
|
const {copy, copied} = useClipboard();
|
||||||
@ -16,15 +16,33 @@ export const CopyButton = ({code: codeProp}: {code?: string}) => {
|
|||||||
copy(code);
|
copy(code);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const icon = copied ? (
|
||||||
|
<CheckLinearIcon
|
||||||
|
className="text-white dark:text-zinc-500 opacity-0 scale-50 data-[visible=true]:opacity-100 data-[visible=true]:scale-100 transition-transform-opacity"
|
||||||
|
data-visible={copied}
|
||||||
|
height={16}
|
||||||
|
size={16}
|
||||||
|
width={16}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<CopyLinearIcon
|
||||||
|
className="text-white dark:text-zinc-500 opacity-0 scale-50 data-[visible=true]:opacity-100 data-[visible=true]:scale-100 transition-transform-opacity"
|
||||||
|
data-visible={!copied}
|
||||||
|
height={16}
|
||||||
|
width={16}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
|
key={copied ? "copied" : "copy"}
|
||||||
className="text-xs px-2"
|
className="text-xs px-2"
|
||||||
closeDelay={0}
|
closeDelay={0}
|
||||||
content={copied ? "Copied!" : "Copy"}
|
content={copied ? "Copied!" : "Copy"}
|
||||||
radius="md"
|
radius="md"
|
||||||
>
|
>
|
||||||
<Button isIconOnly size="sm" title="Copy Code" variant="light" onPress={copyHandler}>
|
<Button isIconOnly size="sm" title="Copy Code" variant="light" onPress={copyHandler}>
|
||||||
<CopyLinearIcon className="text-white dark:text-zinc-500" height={16} width={16} />
|
{icon}
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user