1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-21 05:41:17 -04:00

fix props with forwarded ref

This commit is contained in:
2022-07-13 19:48:49 -04:00
parent 39ef018537
commit d35e40a18d
13 changed files with 68 additions and 57 deletions

View File

@@ -3,7 +3,7 @@ import innerText from "react-innertext";
import copy from "copy-to-clipboard";
import { ClipboardOcticon, CheckOcticon } from "../Icons";
import { styled, theme } from "../../lib/styles/stitches.config";
import type { ReactNode, Ref, MouseEventHandler } from "react";
import type { ReactNode, Ref, ComponentPropsWithoutRef, MouseEventHandler } from "react";
const Button = styled("button", {
lineHeight: 1,
@@ -32,13 +32,12 @@ const Icon = styled("svg", {
fill: "currentColor",
});
export type CopyButtonProps = {
source: ReactNode;
export type CopyButtonProps = ComponentPropsWithoutRef<typeof Button> & {
source: string | ReactNode;
timeout?: number;
className?: string;
};
const CopyButton = ({ source, timeout = 2000, className }: CopyButtonProps, ref: Ref<HTMLButtonElement>) => {
const CopyButton = ({ source, timeout = 2000, ...rest }: CopyButtonProps, ref: Ref<HTMLButtonElement>) => {
const [copied, setCopied] = useState(false);
const handleCopy: MouseEventHandler<HTMLButtonElement> = (e) => {
@@ -70,13 +69,13 @@ const CopyButton = ({ source, timeout = 2000, className }: CopyButtonProps, ref:
return (
<Button
className={className}
ref={ref}
title="Copy to clipboard"
aria-label="Copy to clipboard"
onClick={handleCopy}
disabled={!!copied}
disabled={copied}
copied={copied}
ref={ref}
{...rest}
>
<Icon as={copied ? CheckOcticon : ClipboardOcticon} />
</Button>