@schemavaults/ui 0.19.1 → 0.20.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/copy-button/copy-button-variants.d.ts +4 -0
- package/dist/components/ui/copy-button/copy-button-variants.js +16 -0
- package/dist/components/ui/copy-button/copy-button-variants.js.map +1 -0
- package/dist/components/ui/copy-button/copy-button.d.ts +61 -0
- package/dist/components/ui/copy-button/copy-button.js +69 -0
- package/dist/components/ui/copy-button/copy-button.js.map +1 -0
- package/dist/components/ui/copy-button/index.d.ts +4 -0
- package/dist/components/ui/copy-button/index.js +3 -0
- package/dist/components/ui/copy-button/index.js.map +1 -0
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/components/ui/index.js.map +1 -1
- package/dist/lib/copyToClipboard.d.ts +10 -0
- package/dist/lib/copyToClipboard.js +50 -0
- package/dist/lib/copyToClipboard.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const copyButtonVariantIds: readonly ["default", "outline", "ghost", "subtle", "brand"];
|
|
2
|
+
export type CopyButtonVariant = (typeof copyButtonVariantIds)[number];
|
|
3
|
+
export declare const copyButtonSizeIds: readonly ["sm", "md", "lg", "icon-sm", "icon-md", "icon-lg"];
|
|
4
|
+
export type CopyButtonSize = (typeof copyButtonSizeIds)[number];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const copyButtonVariantIds = [
|
|
2
|
+
"default",
|
|
3
|
+
"outline",
|
|
4
|
+
"ghost",
|
|
5
|
+
"subtle",
|
|
6
|
+
"brand",
|
|
7
|
+
];
|
|
8
|
+
export const copyButtonSizeIds = [
|
|
9
|
+
"sm",
|
|
10
|
+
"md",
|
|
11
|
+
"lg",
|
|
12
|
+
"icon-sm",
|
|
13
|
+
"icon-md",
|
|
14
|
+
"icon-lg",
|
|
15
|
+
];
|
|
16
|
+
//# sourceMappingURL=copy-button-variants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-button-variants.js","sourceRoot":"","sources":["../../../../src/components/ui/copy-button/copy-button-variants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS;IACT,SAAS;IACT,OAAO;IACP,QAAQ;IACR,OAAO;CAC6B,CAAC;AAGvC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,SAAS;IACT,SAAS;IACT,SAAS;CAC2B,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { type ButtonHTMLAttributes, type ReactElement, type ReactNode, type Ref } from "react";
|
|
3
|
+
import { type CopyButtonSize, type CopyButtonVariant, copyButtonSizeIds, copyButtonVariantIds } from "./copy-button-variants";
|
|
4
|
+
declare const copyButtonVariants: (props?: ({
|
|
5
|
+
variant?: "default" | "ghost" | "outline" | "brand" | "subtle" | null | undefined;
|
|
6
|
+
size?: "sm" | "lg" | "md" | "icon-sm" | "icon-md" | "icon-lg" | null | undefined;
|
|
7
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
8
|
+
export interface CopyButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "onCopy">, VariantProps<typeof copyButtonVariants> {
|
|
9
|
+
/**
|
|
10
|
+
* The text value to copy to the clipboard.
|
|
11
|
+
*/
|
|
12
|
+
value: string;
|
|
13
|
+
/**
|
|
14
|
+
* Duration, in milliseconds, that the "copied" state is shown after a
|
|
15
|
+
* successful copy before reverting to the idle state. Defaults to 2000.
|
|
16
|
+
*/
|
|
17
|
+
resetDelay?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Optional label rendered next to the icon in the idle state. When provided,
|
|
20
|
+
* the button automatically switches to a labelled layout. Use an "icon-*"
|
|
21
|
+
* size to render an icon-only button.
|
|
22
|
+
*/
|
|
23
|
+
label?: ReactNode;
|
|
24
|
+
/**
|
|
25
|
+
* Optional label rendered next to the icon in the "copied" state. Defaults
|
|
26
|
+
* to "Copied!" when `label` is provided.
|
|
27
|
+
*/
|
|
28
|
+
copiedLabel?: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Accessible label announced to screen readers in the idle state. Defaults
|
|
31
|
+
* to "Copy to clipboard".
|
|
32
|
+
*/
|
|
33
|
+
ariaLabel?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Accessible label announced to screen readers in the copied state. Defaults
|
|
36
|
+
* to "Copied to clipboard".
|
|
37
|
+
*/
|
|
38
|
+
copiedAriaLabel?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Callback fired after a copy attempt. Receives the success flag and the
|
|
41
|
+
* original value that was attempted to be copied.
|
|
42
|
+
*/
|
|
43
|
+
onCopy?: (success: boolean, value: string) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Optional override for the idle icon. Defaults to `<Copy />` from lucide.
|
|
46
|
+
*/
|
|
47
|
+
icon?: ReactNode;
|
|
48
|
+
/**
|
|
49
|
+
* Optional override for the success icon. Defaults to `<Check />` from
|
|
50
|
+
* lucide.
|
|
51
|
+
*/
|
|
52
|
+
copiedIcon?: ReactNode;
|
|
53
|
+
ref?: Ref<HTMLButtonElement>;
|
|
54
|
+
}
|
|
55
|
+
declare function CopyButton({ value, variant, size, resetDelay, label, copiedLabel, ariaLabel, copiedAriaLabel, onCopy, icon, copiedIcon, className, onClick, disabled, type, ref, ...props }: CopyButtonProps): ReactElement;
|
|
56
|
+
declare namespace CopyButton {
|
|
57
|
+
var displayName: string;
|
|
58
|
+
}
|
|
59
|
+
export { CopyButton, copyButtonVariants, copyButtonSizeIds, copyButtonVariantIds, };
|
|
60
|
+
export type { CopyButtonSize, CopyButtonVariant };
|
|
61
|
+
export default CopyButton;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
import { Check, Copy } from "lucide-react";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState, } from "react";
|
|
6
|
+
import { cn } from "../../../lib/utils";
|
|
7
|
+
import { copyToClipboard } from "../../../lib/copyToClipboard";
|
|
8
|
+
import { copyButtonSizeIds, copyButtonVariantIds, } from "./copy-button-variants";
|
|
9
|
+
const copyButtonVariants = cva("inline-flex items-center justify-center gap-1.5 whitespace-nowrap rounded-md font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", {
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90 data-[copied=true]:bg-primary/90",
|
|
13
|
+
outline: "border border-input bg-background text-foreground hover:bg-accent hover:text-accent-foreground data-[copied=true]:border-schemavaults-brand-blue data-[copied=true]:text-schemavaults-brand-blue",
|
|
14
|
+
ghost: "text-muted-foreground hover:bg-accent hover:text-accent-foreground data-[copied=true]:text-schemavaults-brand-blue",
|
|
15
|
+
subtle: "bg-muted text-muted-foreground hover:bg-muted/80 hover:text-foreground data-[copied=true]:text-schemavaults-brand-blue",
|
|
16
|
+
brand: "bg-schemavaults-brand-blue text-primary-foreground hover:bg-schemavaults-brand-blue/90",
|
|
17
|
+
},
|
|
18
|
+
size: {
|
|
19
|
+
sm: "h-8 rounded-md px-2.5 text-xs [&_svg]:size-3.5",
|
|
20
|
+
md: "h-9 px-3 text-sm [&_svg]:size-4",
|
|
21
|
+
lg: "h-10 rounded-md px-4 text-sm [&_svg]:size-4",
|
|
22
|
+
"icon-sm": "h-7 w-7 rounded-md [&_svg]:size-3.5",
|
|
23
|
+
"icon-md": "h-9 w-9 [&_svg]:size-4",
|
|
24
|
+
"icon-lg": "h-10 w-10 rounded-md [&_svg]:size-[18px]",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: {
|
|
28
|
+
variant: "ghost",
|
|
29
|
+
size: "icon-md",
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
function CopyButton({ value, variant, size, resetDelay = 2000, label, copiedLabel, ariaLabel = "Copy to clipboard", copiedAriaLabel = "Copied to clipboard", onCopy, icon, copiedIcon, className, onClick, disabled, type = "button", ref, ...props }) {
|
|
33
|
+
const [copied, setCopied] = useState(false);
|
|
34
|
+
const timeoutRef = useRef(null);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
return () => {
|
|
37
|
+
if (timeoutRef.current !== null) {
|
|
38
|
+
clearTimeout(timeoutRef.current);
|
|
39
|
+
timeoutRef.current = null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
const handleClick = useCallback(async (event) => {
|
|
44
|
+
onClick?.(event);
|
|
45
|
+
if (event.defaultPrevented)
|
|
46
|
+
return;
|
|
47
|
+
const success = await copyToClipboard(value);
|
|
48
|
+
onCopy?.(success, value);
|
|
49
|
+
if (!success)
|
|
50
|
+
return;
|
|
51
|
+
setCopied(true);
|
|
52
|
+
if (timeoutRef.current !== null)
|
|
53
|
+
clearTimeout(timeoutRef.current);
|
|
54
|
+
timeoutRef.current = setTimeout(() => {
|
|
55
|
+
setCopied(false);
|
|
56
|
+
timeoutRef.current = null;
|
|
57
|
+
}, resetDelay);
|
|
58
|
+
}, [onClick, onCopy, resetDelay, value]);
|
|
59
|
+
const resolvedIdleIcon = icon ?? _jsx(Copy, { "aria-hidden": "true" });
|
|
60
|
+
const resolvedCopiedIcon = copiedIcon ?? (_jsx(Check, { "aria-hidden": "true" }));
|
|
61
|
+
const hasLabel = label !== undefined && label !== null;
|
|
62
|
+
const effectiveCopiedLabel = copiedLabel !== undefined ? copiedLabel : hasLabel ? "Copied!" : null;
|
|
63
|
+
const currentAriaLabel = copied ? copiedAriaLabel : ariaLabel;
|
|
64
|
+
return (_jsxs("button", { ref: ref, type: type, "data-slot": "copy-button", "data-copied": copied ? "true" : "false", "aria-label": currentAriaLabel, "aria-live": "polite", disabled: disabled, onClick: handleClick, className: cn(copyButtonVariants({ variant, size }), className), ...props, children: [_jsx("span", { "aria-hidden": "true", className: "inline-flex items-center justify-center", children: copied ? resolvedCopiedIcon : resolvedIdleIcon }), hasLabel ? (_jsx("span", { children: copied ? effectiveCopiedLabel : label })) : null] }));
|
|
65
|
+
}
|
|
66
|
+
CopyButton.displayName = "CopyButton";
|
|
67
|
+
export { CopyButton, copyButtonVariants, copyButtonSizeIds, copyButtonVariantIds, };
|
|
68
|
+
export default CopyButton;
|
|
69
|
+
//# sourceMappingURL=copy-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-button.js","sourceRoot":"","sources":["../../../../src/components/ui/copy-button/copy-button.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,GAAG,EAAqB,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GAMT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAGL,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,kBAAkB,GAAG,GAAG,CAC5B,wRAAwR,EACxR;IACE,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,OAAO,EACL,yFAAyF;YAC3F,OAAO,EACL,kMAAkM;YACpM,KAAK,EACH,oHAAoH;YACtH,MAAM,EACJ,wHAAwH;YAC1H,KAAK,EACH,wFAAwF;SAC/C;QAC7C,IAAI,EAAE;YACJ,EAAE,EAAE,gDAAgD;YACpD,EAAE,EAAE,iCAAiC;YACrC,EAAE,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,CAAC,gBAAgB,GAC1C,EACN,QAAQ,CAAC,CAAC,CAAC,CACV,yBAAO,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,KAAK,GAAQ,CACrD,CAAC,CAAC,CAAC,IAAI,IACD,CACV,CAAC;AACJ,CAAC;AACD,UAAU,CAAC,WAAW,GAAG,YAAY,CAAC;AAEtC,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,GACrB,CAAC;AAGF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CopyButton, CopyButton as default, copyButtonVariants, } from "./copy-button";
|
|
2
|
+
export type { CopyButtonProps } from "./copy-button";
|
|
3
|
+
export { copyButtonVariantIds, copyButtonSizeIds, } from "./copy-button-variants";
|
|
4
|
+
export type { CopyButtonVariant, CopyButtonSize, } from "./copy-button-variants";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ui/copy-button/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,UAAU,IAAI,OAAO,EACrB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC"}
|
|
@@ -100,6 +100,8 @@ export * from "./breadcrumb";
|
|
|
100
100
|
export type * from "./breadcrumb";
|
|
101
101
|
export * from "./kbd";
|
|
102
102
|
export type * from "./kbd";
|
|
103
|
+
export * from "./copy-button";
|
|
104
|
+
export type * from "./copy-button";
|
|
103
105
|
export * from "./spinner";
|
|
104
106
|
export type * from "./spinner";
|
|
105
107
|
export * from "./banner";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AAGzB,cAAc,aAAa,CAAC;AAG5B,cAAc,SAA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AS,CAAC;AAGxB,cAAc,UAAU,CAAC;AAGzB,cAAc,eAAe,CAAC;AAG9B,cAAc,qBAAqB,CAAC;AAGpC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,QAAQ,CAAC;AAGvB,cAAc,QAAQ,CAAC;AAGvB,cAAc,UAAU,CAAC;AAGzB,cAAc,UAAU,CAAC;AAGzB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,cAAc,CAAC;AAG7B,cAAc,OAAO,CAAC;AAGtB,cAAc,eAAe,CAAC;AAG9B,cAAc,WAAW,CAAC;AAG1B,cAAc,UAAU,CAAC;AAGzB,cAAc,eAAe,CAAC;AAG9B,cAAc,aAAa,CAAC;AAG5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write `value` to the user's clipboard. Returns true if the write succeeded.
|
|
3
|
+
*
|
|
4
|
+
* Prefers the async `navigator.clipboard.writeText` API when available in a
|
|
5
|
+
* secure context, and falls back to a transient `<textarea>` + `execCommand`
|
|
6
|
+
* path for older browsers or insecure contexts (e.g. http://). Returns false
|
|
7
|
+
* if both paths fail or if called outside of a browser environment.
|
|
8
|
+
*/
|
|
9
|
+
export declare function copyToClipboard(value: string): Promise<boolean>;
|
|
10
|
+
export default copyToClipboard;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function insecureContextCopyToClipboard(value) {
|
|
2
|
+
if (typeof document === "undefined")
|
|
3
|
+
return false;
|
|
4
|
+
const textarea = document.createElement("textarea");
|
|
5
|
+
textarea.value = value;
|
|
6
|
+
textarea.setAttribute("readonly", "");
|
|
7
|
+
textarea.style.position = "fixed";
|
|
8
|
+
textarea.style.top = "0";
|
|
9
|
+
textarea.style.left = "0";
|
|
10
|
+
textarea.style.opacity = "0";
|
|
11
|
+
textarea.style.pointerEvents = "none";
|
|
12
|
+
document.body.appendChild(textarea);
|
|
13
|
+
textarea.select();
|
|
14
|
+
textarea.setSelectionRange(0, value.length);
|
|
15
|
+
const succeeded = document.execCommand("copy");
|
|
16
|
+
document.body.removeChild(textarea);
|
|
17
|
+
return succeeded;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Write `value` to the user's clipboard. Returns true if the write succeeded.
|
|
21
|
+
*
|
|
22
|
+
* Prefers the async `navigator.clipboard.writeText` API when available in a
|
|
23
|
+
* secure context, and falls back to a transient `<textarea>` + `execCommand`
|
|
24
|
+
* path for older browsers or insecure contexts (e.g. http://). Returns false
|
|
25
|
+
* if both paths fail or if called outside of a browser environment.
|
|
26
|
+
*/
|
|
27
|
+
export async function copyToClipboard(value) {
|
|
28
|
+
if (typeof navigator !== "undefined" &&
|
|
29
|
+
navigator.clipboard &&
|
|
30
|
+
typeof navigator.clipboard.writeText === "function" &&
|
|
31
|
+
typeof window !== "undefined" &&
|
|
32
|
+
window.isSecureContext !== false) {
|
|
33
|
+
try {
|
|
34
|
+
await navigator.clipboard.writeText(value);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
console.error("Failed to use navigator.clipboard.writeText to copy content to clipboard!");
|
|
39
|
+
// Fall through to the textarea-based fallback below.
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
return insecureContextCopyToClipboard(value);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default copyToClipboard;
|
|
50
|
+
//# sourceMappingURL=copyToClipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyToClipboard.js","sourceRoot":"","sources":["../../src/lib/copyToClipboard.ts"],"names":[],"mappings":"AAAA,SAAS,8BAA8B,CAAC,KAAa;IACnD,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,QAAQ,GAAwB,QAAQ,CAAC,aAAa,CAAC,UAAU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