Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+37
-39
@@ -8,64 +8,62 @@
|
||||
import React from "react";
|
||||
import { FeatherCopy } from "@subframe/core";
|
||||
import * as SubframeCore from "@subframe/core";
|
||||
import copy from "copy-to-clipboard";
|
||||
import * as SubframeUtils from "../../utils";
|
||||
import { Tooltip } from "../Tooltip";
|
||||
|
||||
export interface CopyToClipboardButtonRootProps
|
||||
extends Omit<
|
||||
React.ComponentProps<typeof SubframeCore.CopyToClipboard.Root>,
|
||||
"clipboardText"
|
||||
> {
|
||||
export interface CopyToClipboardButtonRootProps extends Omit<React.ComponentProps<typeof SubframeCore.CopyToClipboard.Root>, "clipboardText" | "onCopy"> {
|
||||
clipboardText?: React.ReactNode;
|
||||
tooltipText?: React.ReactNode;
|
||||
icon?: React.ReactNode;
|
||||
onCopy?: () => void;
|
||||
onCopy?: (copied: boolean) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const CopyToClipboardButtonRoot = React.forwardRef<
|
||||
HTMLDivElement,
|
||||
CopyToClipboardButtonRootProps
|
||||
>(function CopyToClipboardButtonRoot(
|
||||
{
|
||||
clipboardText,
|
||||
tooltipText,
|
||||
icon = <FeatherCopy />,
|
||||
className,
|
||||
...otherProps
|
||||
}: CopyToClipboardButtonRootProps,
|
||||
const CopyToClipboardButtonRoot = React.forwardRef<HTMLDivElement, CopyToClipboardButtonRootProps>(function CopyToClipboardButtonRoot(
|
||||
{ clipboardText, tooltipText, icon = <FeatherCopy />, onCopy, options, className, ...otherProps }: CopyToClipboardButtonRootProps,
|
||||
ref
|
||||
) {
|
||||
const copyValue = () => {
|
||||
if (typeof clipboardText !== "string") return;
|
||||
const copied = copy(clipboardText, options);
|
||||
onCopy?.(copied);
|
||||
};
|
||||
|
||||
return (
|
||||
<SubframeCore.Tooltip.Provider>
|
||||
<SubframeCore.Tooltip.Root>
|
||||
<SubframeCore.Tooltip.Trigger asChild={true}>
|
||||
<SubframeCore.CopyToClipboard.Root
|
||||
clipboardText={clipboardText as string}
|
||||
<div
|
||||
{...otherProps}
|
||||
aria-label={otherProps["aria-label"] ?? (typeof tooltipText === "string" ? tooltipText : undefined)}
|
||||
className={SubframeUtils.twClassNames(
|
||||
"group/e8c76626 flex h-6 w-6 cursor-pointer flex-col items-center justify-center gap-2 rounded-md hover:bg-[#f5f5f5]",
|
||||
className
|
||||
)}
|
||||
onClick={(event) => {
|
||||
otherProps.onClick?.(event);
|
||||
if (!event.defaultPrevented) copyValue();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
otherProps.onKeyDown?.(event);
|
||||
if (event.defaultPrevented || (event.key !== "Enter" && event.key !== " ")) return;
|
||||
event.preventDefault();
|
||||
copyValue();
|
||||
}}
|
||||
ref={ref}
|
||||
role={otherProps.role ?? "button"}
|
||||
tabIndex={otherProps.tabIndex ?? 0}
|
||||
>
|
||||
<div
|
||||
className={SubframeUtils.twClassNames(
|
||||
"group/e8c76626 flex h-6 w-6 cursor-pointer flex-col items-center justify-center gap-2 rounded-md hover:bg-[#f5f5f5]",
|
||||
className
|
||||
)}
|
||||
ref={ref}
|
||||
>
|
||||
{icon ? (
|
||||
<SubframeCore.IconWrapper className="font-['Inter'] text-[14px] font-[400] leading-[20px] text-[#737373] group-hover/e8c76626:text-[#171717]">
|
||||
{icon}
|
||||
</SubframeCore.IconWrapper>
|
||||
) : null}
|
||||
</div>
|
||||
</SubframeCore.CopyToClipboard.Root>
|
||||
{icon ? (
|
||||
<SubframeCore.IconWrapper className="font-['Inter'] text-[14px] leading-[20px] font-[400] text-[#737373] group-hover/e8c76626:text-[#171717]">
|
||||
{icon}
|
||||
</SubframeCore.IconWrapper>
|
||||
) : null}
|
||||
</div>
|
||||
</SubframeCore.Tooltip.Trigger>
|
||||
<SubframeCore.Tooltip.Portal>
|
||||
<SubframeCore.Tooltip.Content
|
||||
side="bottom"
|
||||
align="center"
|
||||
sideOffset={8}
|
||||
asChild={true}
|
||||
>
|
||||
<SubframeCore.Tooltip.Content side="bottom" align="center" sideOffset={8} asChild={true}>
|
||||
<Tooltip>{tooltipText}</Tooltip>
|
||||
</SubframeCore.Tooltip.Content>
|
||||
</SubframeCore.Tooltip.Portal>
|
||||
|
||||
+58
-1
@@ -1,4 +1,11 @@
|
||||
"use client";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { SaveToast } from "~/components/notifications/SaveToast";
|
||||
import { COPY_TOAST_DURATION_MS } from "~/hooks/use-copy-toast";
|
||||
|
||||
import { CopyToClipboardButton as CopyToClipboardButtonComponent } from "./CopyToClipboardButton";
|
||||
|
||||
/**
|
||||
@@ -7,4 +14,54 @@ import { CopyToClipboardButton as CopyToClipboardButtonComponent } from "./CopyT
|
||||
* Learn more: https://docs.subframe.com/concepts/syncing-components#wrapping-components
|
||||
*/
|
||||
|
||||
export const CopyToClipboardButton = CopyToClipboardButtonComponent;
|
||||
type GeneratedProps = React.ComponentProps<typeof CopyToClipboardButtonComponent>;
|
||||
|
||||
export type CopyToClipboardButtonProps = Omit<GeneratedProps, "onCopy"> & {
|
||||
successKey?: string;
|
||||
errorKey?: string;
|
||||
onCopy?: (copied: boolean) => void;
|
||||
};
|
||||
|
||||
export const CopyToClipboardButton = React.forwardRef<HTMLDivElement, CopyToClipboardButtonProps>(function CopyToClipboardButton(
|
||||
{ successKey, errorKey, onCopy, ...props },
|
||||
ref
|
||||
) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<CopyToClipboardButtonComponent
|
||||
{...props}
|
||||
ref={ref}
|
||||
onCopy={(copied) => {
|
||||
onCopy?.(copied);
|
||||
if (copied) {
|
||||
toast.custom(
|
||||
() => (
|
||||
<SaveToast
|
||||
variant="success"
|
||||
title={t(successKey ?? "shared.copyToast.successTitle", {
|
||||
defaultValue: t("shared.copyToast.successTitle"),
|
||||
})}
|
||||
/>
|
||||
),
|
||||
{ duration: COPY_TOAST_DURATION_MS }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
toast.custom(
|
||||
() => (
|
||||
<SaveToast
|
||||
variant="error"
|
||||
title={t("shared.copyToast.errorTitle")}
|
||||
description={t(errorKey ?? "shared.copyToast.errorDescription", {
|
||||
defaultValue: t("shared.copyToast.errorDescription"),
|
||||
})}
|
||||
/>
|
||||
),
|
||||
{ duration: COPY_TOAST_DURATION_MS }
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user