|
1 | | -import React, { useState, useCallback } from "react"; |
| 1 | +import React from "react"; |
2 | 2 | import { navigate } from "gatsby"; |
3 | 3 | import { useLocation } from "@reach/router"; |
4 | 4 | import { SistentLayout } from "../../sistent-layout"; |
5 | 5 | import { Col, Row } from "../../../../../reusecore/Layout"; |
6 | 6 | import Button from "../../../../../reusecore/Button"; |
7 | 7 | import { useStyledDarkMode } from "../../../../../theme/app/useStyledDarkMode"; |
8 | 8 |
|
9 | | -import { styled, Table, TableContainer, TableCell, TableRow, TableHead, TableBody, SistentThemeProvider, CustomTooltip, Box, } from "@sistent/sistent"; |
10 | | -import { copyToClipboard } from "../../../../../components/CodeBlock/copy-to-clipboard.js"; |
| 9 | +import { styled, Table, TableContainer, TableCell, TableRow, TableHead, TableBody, SistentThemeProvider } from "@sistent/sistent"; |
| 10 | +import CopyValue from "../../../../../components/CopyValue"; |
11 | 11 |
|
12 | 12 | const brandColors = [ |
13 | 13 | { tokenName: "keppel-70", token: "theme.palette.brand.default", name: "Keppel", hex: "#DAf3EB" }, |
@@ -401,170 +401,6 @@ const componentColors = [ |
401 | 401 | { tokenName: "icon-disabled", token: "theme.palette.icon.disabled", Alias_of: "charcoal-50", hex: "#647176", role: "Color for icon components." }, |
402 | 402 | ]; |
403 | 403 |
|
404 | | - |
405 | | -const CopyColor = ({ hex, token, copyValue }) => { |
406 | | - const [copyState, setCopyState] = useState({ |
407 | | - text: "Copy", |
408 | | - isCopied: false, |
409 | | - isHovered: false |
410 | | - }); |
411 | | - |
412 | | - const handleCopy = useCallback(async () => { |
413 | | - try { |
414 | | - const valueToCopy = copyValue || hex || token; |
415 | | - await copyToClipboard(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 | | - const handleMouseEnter = useCallback(() => { |
449 | | - if (!copyState.isCopied) { |
450 | | - setCopyState(prev => ({ |
451 | | - ...prev, |
452 | | - isHovered: true |
453 | | - })); |
454 | | - } |
455 | | - }, [copyState.isCopied]); |
456 | | - |
457 | | - const handleMouseLeave = useCallback(() => { |
458 | | - setCopyState(prev => ({ |
459 | | - ...prev, |
460 | | - isHovered: false |
461 | | - })); |
462 | | - }, []); |
463 | | - |
464 | | - |
465 | | - const getTooltipTitle = () => { |
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 | | - const getCopyValue = () => { |
476 | | - return copyValue || hex || token; |
477 | | - }; |
478 | | - |
479 | | - return ( |
480 | | - <CustomTooltip |
481 | | - title={getTooltipTitle()} |
482 | | - enterDelay={600} |
483 | | - leaveDelay={100} |
484 | | - placement="right" |
485 | | - > |
486 | | - <Box |
487 | | - component="button" |
488 | | - role="button" |
489 | | - tabIndex={0} |
490 | | - aria-label={`Copy ${getCopyValue()} to clipboard`} |
491 | | - sx={{ |
492 | | - position: "relative", |
493 | | - display: "inline-flex", |
494 | | - alignItems: "center", |
495 | | - cursor: "pointer", |
496 | | - padding: "4px 8px", |
497 | | - borderRadius: "4px", |
498 | | - border: "none", |
499 | | - background: "transparent", |
500 | | - fontFamily: "monospace", |
501 | | - fontSize: "0.875rem", |
502 | | - color: (theme) => theme.palette.text.primary, |
503 | | - transition: "all 0.2s ease-in-out", |
504 | | - outline: "none", |
505 | | - width: "fit-content", |
506 | | - minWidth: "200px", |
507 | | - "&:hover": { |
508 | | - backgroundColor: (theme) => |
509 | | - !copyState.isCopied && (theme.palette.action?.hover || "rgba(0, 0, 0, 0.04)"), |
510 | | - transform: !copyState.isCopied ? "translateY(-1px)" : "none", |
511 | | - boxShadow: !copyState.isCopied ? "0 2px 4px rgba(0, 0, 0, 0.1)" : "none", |
512 | | - }, |
513 | | - "&:focus": { |
514 | | - backgroundColor: (theme) => |
515 | | - theme.palette.action?.hover || "rgba(0, 0, 0, 0.04)", |
516 | | - outline: "2px solid", |
517 | | - outlineColor: (theme) => theme.palette.primary.main, |
518 | | - outlineOffset: "2px", |
519 | | - }, |
520 | | - "&:active": { |
521 | | - transform: "translateY(0)", |
522 | | - boxShadow: "0 1px 2px rgba(0, 0, 0, 0.1)", |
523 | | - }, |
524 | | - ...(copyState.isCopied && { |
525 | | - border: "2px solid", |
526 | | - borderColor: (theme) => theme.palette.success.main, |
527 | | - backgroundColor: "transparent", |
528 | | - "&:hover": { |
529 | | - backgroundColor: "transparent", |
530 | | - transform: "none", |
531 | | - boxShadow: "none", |
532 | | - } |
533 | | - }), |
534 | | - ...(copyState.text === "Failed" && { |
535 | | - border: "2px solid", |
536 | | - borderColor: (theme) => theme.palette.error.main, |
537 | | - backgroundColor: "transparent", |
538 | | - "&:hover": { |
539 | | - backgroundColor: "transparent", |
540 | | - transform: "none", |
541 | | - boxShadow: "none", |
542 | | - } |
543 | | - }), |
544 | | - }} |
545 | | - onClick={handleCopy} |
546 | | - onMouseEnter={handleMouseEnter} |
547 | | - onMouseLeave={handleMouseLeave} |
548 | | - > |
549 | | - <span>{getCopyValue()}</span> |
550 | | - <Box |
551 | | - component="span" |
552 | | - sx={{ |
553 | | - marginLeft: "4px", |
554 | | - fontSize: "0.75rem", |
555 | | - opacity: 0, |
556 | | - visibility: "hidden", |
557 | | - width: "0px", |
558 | | - overflow: "hidden", |
559 | | - }} |
560 | | - > |
561 | | - {copyState.text} |
562 | | - </Box> |
563 | | - </Box> |
564 | | - </CustomTooltip> |
565 | | - ); |
566 | | -}; |
567 | | - |
568 | 404 | const PreviewBox = styled("div")(({ theme, bgcolor }) => ({ |
569 | 405 | backgroundColor: bgcolor, |
570 | 406 | width: "2.6rem", |
@@ -754,7 +590,7 @@ const ColorCode = () => { |
754 | 590 | <StyledTableCell>{col.name}</StyledTableCell> |
755 | 591 | <StyledTableCell>{col.hex}</StyledTableCell> |
756 | 592 | <StyledTableCell sx={{ fontFamily: "monospace" }}> |
757 | | - <CopyColor hex={col.token} /> |
| 593 | + <CopyValue copyValue={col.token} /> |
758 | 594 | </StyledTableCell> |
759 | 595 | <StyledTableCell align="center"> |
760 | 596 | <PreviewBox bgcolor={col.hex} /> |
@@ -791,7 +627,7 @@ const ColorCode = () => { |
791 | 627 | <StyledTableCell>{col.name}</StyledTableCell> |
792 | 628 | <StyledTableCell>{col.hex}</StyledTableCell> |
793 | 629 | <StyledTableCell sx={{ fontFamily: "monospace" }}> |
794 | | - <CopyColor hex={col.token} /> |
| 630 | + <CopyValue copyValue={col.token} /> |
795 | 631 | </StyledTableCell> |
796 | 632 | <StyledTableCell align="center"> |
797 | 633 | <PreviewBox bgcolor={col.hex} /> |
@@ -829,7 +665,7 @@ const ColorCode = () => { |
829 | 665 | <StyledTableCell>{col.name}</StyledTableCell> |
830 | 666 | <StyledTableCell>{col.hex}</StyledTableCell> |
831 | 667 | <StyledTableCell sx={{ fontFamily: "monospace" }}> |
832 | | - <CopyColor hex={col.token} /> |
| 668 | + <CopyValue copyValue={col.token} /> |
833 | 669 | </StyledTableCell> |
834 | 670 | <StyledTableCell align="center"> |
835 | 671 | <PreviewBox bgcolor={col.hex} /> |
@@ -876,7 +712,7 @@ const ColorCode = () => { |
876 | 712 | <StyledTableCell>{col.Alias_of}</StyledTableCell> |
877 | 713 | <StyledTableCell>{col.hex}</StyledTableCell> |
878 | 714 | <StyledTableCell sx={{ fontFamily: "monospace" }}> |
879 | | - <CopyColor hex={col.token} /> |
| 715 | + <CopyValue copyValue={col.token} /> |
880 | 716 | </StyledTableCell> |
881 | 717 | <StyledTableCell align="center"> |
882 | 718 | <PreviewBox bgcolor={col.hex} /> |
@@ -916,7 +752,7 @@ const ColorCode = () => { |
916 | 752 | <StyledTableCell>{col.Alias_of}</StyledTableCell> |
917 | 753 | <StyledTableCell>{col.hex}</StyledTableCell> |
918 | 754 | <StyledTableCell sx={{ fontFamily: "monospace" }}> |
919 | | - <CopyColor hex={col.token} /> |
| 755 | + <CopyValue copyValue={col.token} /> |
920 | 756 | </StyledTableCell> |
921 | 757 | <StyledTableCell align="center"> |
922 | 758 | <PreviewTextBox tokenName={col.tokenName} >Aa</PreviewTextBox> |
@@ -956,7 +792,7 @@ const ColorCode = () => { |
956 | 792 | <StyledTableCell>{col.Alias_of}</StyledTableCell> |
957 | 793 | <StyledTableCell>{col.hex}</StyledTableCell> |
958 | 794 | <StyledTableCell sx={{ fontFamily: "monospace" }}> |
959 | | - <CopyColor hex={col.token} /> |
| 795 | + <CopyValue copyValue={col.token} /> |
960 | 796 | </StyledTableCell> |
961 | 797 | <StyledTableCell align="center"> |
962 | 798 | <PreviewBorderBox tokenName={col.tokenName} /> |
@@ -1001,7 +837,7 @@ const ColorCode = () => { |
1001 | 837 | <StyledTableCell>{col.Alias_of}</StyledTableCell> |
1002 | 838 | <StyledTableCell>{col.hex}</StyledTableCell> |
1003 | 839 | <StyledTableCell sx={{ fontFamily: "monospace" }}> |
1004 | | - <CopyColor hex={col.token} /> |
| 840 | + <CopyValue copyValue={col.token} /> |
1005 | 841 | </StyledTableCell> |
1006 | 842 | <StyledTableCell align="center"> |
1007 | 843 | <PreviewBox bgcolor={col.hex} /> |
|
0 commit comments