Skip to content

🎥 Make videos programmatically with React

copy to clipboard polished

Patric Salvisberg2981699ca0ef
diff --git a/packages/cli/src/editor/components/RenderModal/CliCopyButton.tsx b/packages/cli/src/editor/components/RenderModal/CliCopyButton.tsx
index d54b96c875..0a9f48063c 100644
--- a/packages/cli/src/editor/components/RenderModal/CliCopyButton.tsx
+++ b/packages/cli/src/editor/components/RenderModal/CliCopyButton.tsx
@@ -1,13 +1,29 @@
+import {useCallback, useEffect, useMemo, useState} from 'react';
+import {LIGHT_TEXT} from '../../helpers/colors';
+const iconStyle: React.CSSProperties = {
+ width: 16,
+ height: 16,
+ verticalAlign: 'sub',
+};
+
+const copiedStyle: React.CSSProperties = {
+ fontSize: '14px',
+ minHeight: '30px',
+ display: 'flex',
+ alignItems: 'center',
+};
+
export const CliCopyButton: React.FC<{valueToCopy: string}> = ({
valueToCopy,
}) => {
- const iconStyle: React.CSSProperties = {
- width: 16,
- height: 16,
- color: '#a6a8aa',
- verticalAlign: 'sub',
- };
- const clipBoardIcon = (
+ const [copied, setCopied] = useState<boolean>(false);
+ const [hovered, setHovered] = useState<boolean>(false);
+
+ const fillColor = useMemo(() => {
+ return hovered ? 'white' : LIGHT_TEXT;
+ }, [hovered]);
+
+ const clipboardIcon = (
<svg
aria-hidden="true"
focusable="false"
@@ -20,14 +36,40 @@ export const CliCopyButton: React.FC<{valueToCopy: string}> = ({
style={iconStyle}
>
<path
- fill="#a6a8aa"
+ fill={fillColor}
d="M336 64h-80c0-35.3-28.7-64-64-64s-64 28.7-64 64H48C21.5 64 0 85.5 0 112v352c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V112c0-26.5-21.5-48-48-48zM192 40c13.3 0 24 10.7 24 24s-10.7 24-24 24-24-10.7-24-24 10.7-24 24-24zm144 418c0 3.3-2.7 6-6 6H54c-3.3 0-6-2.7-6-6V118c0-3.3 2.7-6 6-6h42v36c0 6.6 5.4 12 12 12h168c6.6 0 12-5.4 12-12v-36h42c3.3 0 6 2.7 6 6z"
/>
</svg>
);
- return (
+
+ const onPointerEnter = useCallback(() => {
+ setHovered(true);
+ }, []);
+
+ const onPointerLeave = useCallback(() => {
+ setHovered(false);
+ }, []);
+
+ useEffect(() => {
+ if (!copied) {
+ return;
+ }
+
+ const handleClear = () => {
+ setCopied(false);
+ setHovered(false);
+ };
+
+ const to = setTimeout(() => handleClear(), 2000);
+ return () => clearTimeout(to);
+ }, [copied]);
+
+ // eslint-disable-next-line no-negated-condition
+ return !copied ? (
<button
type="button"
+ onPointerEnter={onPointerEnter}
+ onPointerLeave={onPointerLeave}
style={{
width: '30px',
height: '30px',
@@ -36,9 +78,12 @@ export const CliCopyButton: React.FC<{valueToCopy: string}> = ({
}}
onClick={() => {
navigator.clipboard.writeText(valueToCopy);
+ setCopied(true);
}}
>
- {clipBoardIcon}
+ {clipboardIcon}
</button>
+ ) : (
+ <span style={copiedStyle}>copied</span>
);
};