Skip to content

Commit

Permalink
Merge pull request #195 from ahmed-deriv/ahmed/DAPI-817/chore-add-vis…
Browse files Browse the repository at this point in the history
…ual-effect-on-copy

Ahmed/dapi 817/chore add visual effect on copy
  • Loading branch information
ahmed-deriv authored Jan 20, 2025
2 parents 170569e + 64f05db commit f981ef4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
3 changes: 3 additions & 0 deletions i18n/en/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -1118,5 +1118,8 @@
},
"The server is currently unable to handle the request due to a temporary overload or maintenance of the server. Please try again later.": {
"message": "The server is currently unable to handle the request due to a temporary overload or maintenance of the server. Please try again later."
},
"Copied": {
"message": "Copied"
}
}
3 changes: 3 additions & 0 deletions i18n/fr/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -1118,5 +1118,8 @@
},
"The server is currently unable to handle the request due to a temporary overload or maintenance of the server. Please try again later.": {
"message": "Le serveur est actuellement incapable de traiter la requête en raison d'une surcharge temporaire ou d'une maintenance du serveur. Veuillez réessayer plus tard."
},
"Copied": {
"message": "Copié"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,38 @@
.copyTextIcon {
margin-left: 8px;
margin-top: 4px;
position: relative;
}

.tooltip {
position: absolute;
background-color: rgba(0, 0, 0, 0.75);
color: white;
padding: 5px 10px;
border-radius: 4px;
top: 100%;
left: 50%;
transform: translateX(-50%);
z-index: 1000;
white-space: nowrap;
font-size: 12px;
transition: opacity 0.3s ease, visibility 0.3s ease;
opacity: 0;
visibility: hidden;

&::after {
content: '';
position: absolute;
top: -6px;
left: 50%;
transform: translateX(-50%);
border-width: 0 6px 6px;
border-style: solid;
border-color: transparent transparent rgba(0, 0, 0, 0.75);
}
}

.tooltip.visible {
opacity: 1;
visibility: visible;
}
29 changes: 18 additions & 11 deletions src/features/dashboard/components/common-table/cell-copy-text.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import React from 'react';
import { LabelPairedCopyLgRegularIcon } from '@deriv/quill-icons';
import { Text } from '@deriv-com/quill-ui';
import Translate from '@docusaurus/Translate';
import styles from './cell-copy-text.module.scss';

const CopyTextCell: React.FC<{
cell: {
value: React.ReactNode;
};
}> = ({ cell }) => {
}> = ({ cell: { value } }) => {
const [tooltipVisible, setTooltipVisible] = React.useState(false);

const handleCopy = React.useCallback(() => {
navigator.clipboard.writeText(value.toString());
setTooltipVisible(true);
setTimeout(() => setTooltipVisible(false), 1000);
}, [value]);

return (
<React.Fragment>
{cell.value ? (
<div
className={styles.copyText}
onClick={() => {
navigator.clipboard.writeText(cell.value.toString());
}}
>
<Text>{cell.value}</Text>
{value && (
<div className={styles.copyText} onClick={handleCopy}>
<Text>{value}</Text>
<span className={styles.copyTextIcon}>
<LabelPairedCopyLgRegularIcon />
{tooltipVisible && (
<div className={`${styles.tooltip} ${tooltipVisible ? styles.visible : ''}`}>
<Translate>Copied</Translate>
</div>
)}
</span>
</div>
) : (
''
)}
</React.Fragment>
);
Expand Down

0 comments on commit f981ef4

Please sign in to comment.