1
- import React from "react" ;
1
+ import React , { useState } from "react" ;
2
2
import { navigate } from "gatsby" ;
3
3
import { useLocation } from "@reach/router" ;
4
4
@@ -8,7 +8,8 @@ import { Col, Row } from "../../../../../reusecore/Layout";
8
8
import Button from "../../../../../reusecore/Button" ;
9
9
import { useStyledDarkMode } from "../../../../../theme/app/useStyledDarkMode" ;
10
10
11
- import { styled , Table , TableContainer , TableCell , TableRow , TableHead , TableBody , SistentThemeProvider } from "@sistent/sistent" ;
11
+ import { styled , Table , TableContainer , TableCell , TableRow , TableHead , TableBody , SistentThemeProvider , CustomTooltip , Box , } from "@sistent/sistent" ;
12
+ import { copyToClipboard } from "../../../../../components/CodeBlock/copy-to-clipboard.js" ;
12
13
13
14
const brandColors = [
14
15
{ tokenName : "keppel-70" , token : "theme.palette.brand.default" , name : "Keppel" , hex : "#DAf3EB" } ,
@@ -403,6 +404,47 @@ const componentColors = [
403
404
] ;
404
405
405
406
407
+ const CopyColor = ( { hex , token } ) => {
408
+ const [ copyText , setCopyText ] = useState ( "Copy" ) ;
409
+ const [ showCopy , setShowCopy ] = useState ( false ) ;
410
+
411
+ const handleCopy = async ( ) => {
412
+ await copyToClipboard ( hex || token ) ;
413
+ setCopyText ( "Copied" ) ;
414
+ setTimeout ( ( ) => setCopyText ( "Copy" ) , 1000 ) ;
415
+ } ;
416
+
417
+ return (
418
+ < CustomTooltip
419
+ title = { copyText === "Copied" ? "Copied" : "Copy" }
420
+ enterDelay = { 800 }
421
+ leaveDelay = { 10 }
422
+ placement = "right"
423
+ >
424
+ < Box
425
+ sx = { {
426
+ position : "relative" ,
427
+ display : "inline-flex" ,
428
+ alignItems : "center" ,
429
+ cursor : "pointer" ,
430
+ padding : "2px 4px" ,
431
+ borderRadius : "3px" ,
432
+ transition : "background-color 0.2s ease" ,
433
+ "&:hover" : {
434
+ backgroundColor : ( theme ) =>
435
+ theme . palette . action ?. hover || "rgba(0, 0, 0, 0.04)" ,
436
+ } ,
437
+ } }
438
+ onMouseEnter = { ( ) => setShowCopy ( true ) }
439
+ onMouseLeave = { ( ) => setShowCopy ( false ) }
440
+ onClick = { handleCopy }
441
+ >
442
+ < span > { hex || token } </ span >
443
+ </ Box >
444
+ </ CustomTooltip >
445
+ ) ;
446
+ } ;
447
+
406
448
const PreviewBox = styled ( "div" ) ( ( { theme, bgcolor } ) => ( {
407
449
backgroundColor : bgcolor ,
408
450
width : "1.6rem" ,
@@ -411,8 +453,10 @@ const PreviewBox = styled("div")(({ theme, bgcolor }) => ({
411
453
border : `1px solid ${ theme . palette . divider } ` ,
412
454
boxShadow : "inset 0 0 3px rgba(0,0,0,0.15)" ,
413
455
margin : "0 auto" ,
456
+
414
457
} ) ) ;
415
458
459
+
416
460
const PreviewTextBox = styled ( "p" ) ( ( { theme, tokenName } ) => {
417
461
const colorsMap = {
418
462
"text-default" : theme . palette . text . default ,
@@ -582,9 +626,9 @@ const ColorCode = () => {
582
626
>
583
627
< StyledTableCell > { col . tokenName } </ StyledTableCell >
584
628
< StyledTableCell > { col . name } </ StyledTableCell >
585
- < StyledTableCell > { col . hex } </ StyledTableCell >
629
+ < StyledTableCell > < CopyColor hex = { col . hex } /> </ StyledTableCell >
586
630
< StyledTableCell sx = { { fontFamily : "monospace" } } >
587
- { col . token }
631
+ < CopyColor hex = { col . token } />
588
632
</ StyledTableCell >
589
633
< StyledTableCell align = "center" >
590
634
< PreviewBox bgcolor = { col . hex } />
@@ -622,9 +666,9 @@ const ColorCode = () => {
622
666
>
623
667
< StyledTableCell > { col . tokenName } </ StyledTableCell >
624
668
< StyledTableCell > { col . name } </ StyledTableCell >
625
- < StyledTableCell > { col . hex } </ StyledTableCell >
669
+ < StyledTableCell > < CopyColor hex = { col . hex } /> </ StyledTableCell >
626
670
< StyledTableCell sx = { { fontFamily : "monospace" } } >
627
- { col . token }
671
+ < CopyColor hex = { col . token } />
628
672
</ StyledTableCell >
629
673
< StyledTableCell align = "center" >
630
674
< PreviewBox bgcolor = { col . hex } />
@@ -663,9 +707,9 @@ const ColorCode = () => {
663
707
>
664
708
< StyledTableCell > { col . tokenName } </ StyledTableCell >
665
709
< StyledTableCell > { col . name } </ StyledTableCell >
666
- < StyledTableCell > { col . hex } </ StyledTableCell >
710
+ < StyledTableCell > < CopyColor hex = { col . hex } /> </ StyledTableCell >
667
711
< StyledTableCell sx = { { fontFamily : "monospace" } } >
668
- { col . token }
712
+ < CopyColor hex = { col . token } />
669
713
</ StyledTableCell >
670
714
< StyledTableCell align = "center" >
671
715
< PreviewBox bgcolor = { col . hex } />
@@ -713,9 +757,9 @@ const ColorCode = () => {
713
757
>
714
758
< StyledTableCell > { col . tokenName } </ StyledTableCell >
715
759
< StyledTableCell > { col . Alias_of } </ StyledTableCell >
716
- < StyledTableCell > { col . hex } </ StyledTableCell >
760
+ < StyledTableCell > < CopyColor hex = { col . hex } /> </ StyledTableCell >
717
761
< StyledTableCell sx = { { fontFamily : "monospace" } } >
718
- { col . token }
762
+ < CopyColor hex = { col . token } />
719
763
</ StyledTableCell >
720
764
< StyledTableCell align = "center" >
721
765
< PreviewBox bgcolor = { col . hex } />
@@ -756,9 +800,9 @@ const ColorCode = () => {
756
800
>
757
801
< StyledTableCell > { col . tokenName } </ StyledTableCell >
758
802
< StyledTableCell > { col . Alias_of } </ StyledTableCell >
759
- < StyledTableCell > { col . hex } </ StyledTableCell >
803
+ < StyledTableCell > < CopyColor hex = { col . hex } /> </ StyledTableCell >
760
804
< StyledTableCell sx = { { fontFamily : "monospace" } } >
761
- { col . token }
805
+ < CopyColor hex = { col . token } />
762
806
</ StyledTableCell >
763
807
< StyledTableCell align = "center" >
764
808
< PreviewTextBox tokenName = { col . tokenName } > Aa</ PreviewTextBox >
@@ -799,9 +843,9 @@ const ColorCode = () => {
799
843
>
800
844
< StyledTableCell > { col . tokenName } </ StyledTableCell >
801
845
< StyledTableCell > { col . Alias_of } </ StyledTableCell >
802
- < StyledTableCell > { col . hex } </ StyledTableCell >
846
+ < StyledTableCell > < CopyColor hex = { col . hex } /> </ StyledTableCell >
803
847
< StyledTableCell sx = { { fontFamily : "monospace" } } >
804
- { col . token }
848
+ < CopyColor hex = { col . token } />
805
849
</ StyledTableCell >
806
850
< StyledTableCell align = "center" >
807
851
< PreviewBorderBox tokenName = { col . tokenName } />
@@ -847,9 +891,9 @@ const ColorCode = () => {
847
891
>
848
892
< StyledTableCell > { col . tokenName } </ StyledTableCell >
849
893
< StyledTableCell > { col . Alias_of } </ StyledTableCell >
850
- < StyledTableCell > { col . hex } </ StyledTableCell >
894
+ < StyledTableCell > < CopyColor hex = { col . hex } /> </ StyledTableCell >
851
895
< StyledTableCell sx = { { fontFamily : "monospace" } } >
852
- { col . token }
896
+ < CopyColor hex = { col . token } />
853
897
</ StyledTableCell >
854
898
< StyledTableCell align = "center" >
855
899
< PreviewBox bgcolor = { col . hex } />
0 commit comments