You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"tokenName": "text-tertiary","token": "theme.palette.text.tertiary","Alias_of": "charcoal-60","hex": "#8c999e","role": "Second level text color to indicate lower prominence and establish visual hierarchy."},
379
379
{"tokenName": "text-inverse","token": "theme.palette.text.inverse","Alias_of": "charcoal-10","hex": "#000d12","role": "This text color is the polar opposite of the default text color in any theme."},
380
380
{"tokenName": "text-disabled","token": "theme.palette.text.disabled","Alias_of": "charcoal-50","hex": "#647176","role": "This text color is the polar opposite of the default text color in any theme."},
381
-
{"tokenName": "text-constant-white","token": "theme.palette.text.constant.white","Alias_of": "charcoal-100","hex": "#fdfdfd","role": "This text color remains constant across both themes and is used on surfaces that don’t change as themes change."},
381
+
{"tokenName": "text-constant-white","token": "theme.palette.text.constant.white","Alias_of": "charcoal-100","hex": "#fdfdfd","role": "This text color remains constant across both themes and is used on surfaces that don't change as themes change."},
382
382
{"tokenName": "text-brand","token": "theme.palette.text.brand","Alias_of": "keppel-40","hex": "#00b39f","role": "Color for text relating to the brand."},
383
383
{"tokenName": "text-info","token": "theme.palette.text.info","Alias_of": "blue-40","hex": "#2196f3","role": "Color for text relating to notifications and information."},
384
384
{"tokenName": "text-success","token": "theme.palette.text.success","Alias_of": "green-40","hex": "#36bc3b","role": "Color for text relating to success."},
@@ -402,39 +402,164 @@ const componentColors = [
402
402
];
403
403
404
404
405
-
constCopyColor=({ hex , token })=>{
406
-
const[copyText,setCopyText]=useState("Copy");
405
+
constCopyColor=({ hex, token, copyValue })=>{
406
+
const[copyState,setCopyState]=useState({
407
+
text: "Copy",
408
+
isCopied: false,
409
+
isHovered: false
410
+
});
407
411
408
-
consthandleCopy=async()=>{
409
-
awaitcopyToClipboard(hex||token);
410
-
setCopyText("Copied");
411
-
setTimeout(()=>setCopyText("Copy"),1000);
412
+
consthandleCopy=useCallback(async()=>{
413
+
try{
414
+
constvalueToCopy=copyValue||hex||token;
415
+
awaitcopyToClipboard(valueToCopy);
416
+
417
+
setCopyState({
418
+
text: "Copied!",
419
+
isCopied: true,
420
+
isHovered: false
421
+
});
422
+
423
+
setTimeout(()=>{
424
+
setCopyState({
425
+
text: "Copy",
426
+
isCopied: false,
427
+
isHovered: false
428
+
});
429
+
},2000);
430
+
}catch(error){
431
+
console.error("Failed to copy to clipboard:",error);
432
+
setCopyState({
433
+
text: "Failed",
434
+
isCopied: false,
435
+
isHovered: false
436
+
});
437
+
438
+
setTimeout(()=>{
439
+
setCopyState({
440
+
text: "Copy",
441
+
isCopied: false,
442
+
isHovered: false
443
+
});
444
+
},1500);
445
+
}
446
+
},[copyValue,hex,token]);
447
+
448
+
consthandleMouseEnter=useCallback(()=>{
449
+
if(!copyState.isCopied){
450
+
setCopyState(prev=>({
451
+
...prev,
452
+
isHovered: true
453
+
}));
454
+
}
455
+
},[copyState.isCopied]);
456
+
457
+
consthandleMouseLeave=useCallback(()=>{
458
+
setCopyState(prev=>({
459
+
...prev,
460
+
isHovered: false
461
+
}));
462
+
},[]);
463
+
464
+
465
+
constgetTooltipTitle=()=>{
466
+
if(copyState.isCopied){
467
+
return"Copied";
468
+
}
469
+
if(copyState.text==="Failed"){
470
+
return"Failed to copy. Try again.";
471
+
}
472
+
return"Click to copy to clipboard";
473
+
};
474
+
475
+
constgetCopyValue=()=>{
476
+
returncopyValue||hex||token;
412
477
};
413
478
414
479
return(
415
480
<CustomTooltip
416
-
title={copyText==="Copied" ? "Copied" : "Copy"}
417
-
enterDelay={800}
418
-
leaveDelay={10}
481
+
title={getTooltipTitle()}
482
+
enterDelay={600}
483
+
leaveDelay={100}
419
484
placement="right"
420
485
>
421
486
<Box
487
+
component="button"
488
+
role="button"
489
+
tabIndex={0}
490
+
aria-label={`Copy ${getCopyValue()} to clipboard`}
0 commit comments