diff options
| author | soryu <soryu@soryu.co> | 2025-12-22 04:50:25 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2025-12-23 14:47:18 +0000 |
| commit | 0741a8b8e9a2099c82bff6d6b9ebbce9c07cad53 (patch) | |
| tree | 88cbd5fecb9ca72a04aa07f1a6db4e1a751b1fd7 /makima/frontend/src/components/RewriteLink.tsx | |
| parent | aee2e4e784afd6d115fb5f7b40284c4efd2da966 (diff) | |
| download | soryu-0741a8b8e9a2099c82bff6d6b9ebbce9c07cad53.tar.gz soryu-0741a8b8e9a2099c82bff6d6b9ebbce9c07cad53.zip | |
Update makima FE to add initial listening system
Diffstat (limited to 'makima/frontend/src/components/RewriteLink.tsx')
| -rw-r--r-- | makima/frontend/src/components/RewriteLink.tsx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/makima/frontend/src/components/RewriteLink.tsx b/makima/frontend/src/components/RewriteLink.tsx new file mode 100644 index 0000000..6e591a1 --- /dev/null +++ b/makima/frontend/src/components/RewriteLink.tsx @@ -0,0 +1,63 @@ +import { Link } from "react-router"; +import { useTextScramble } from "../hooks/useTextScramble"; + +interface RewriteLinkProps { + to?: string; + href?: string; + children: string; + disabled?: boolean; + external?: boolean; + className?: string; +} + +export function RewriteLink({ + to, + href, + children, + disabled = false, + external = false, + className = "", +}: RewriteLinkProps) { + const { displayText, scramble, reset } = useTextScramble(children); + + const baseClass = `rewrite-link ${className}`; + + if (disabled) { + return ( + <span + className={baseClass} + aria-disabled="true" + onMouseEnter={scramble} + onMouseLeave={reset} + > + {displayText} + </span> + ); + } + + if (external || href) { + return ( + <a + href={href || to} + target="_blank" + rel="noopener noreferrer" + className={baseClass} + onMouseEnter={scramble} + onMouseLeave={reset} + > + {displayText} + </a> + ); + } + + return ( + <Link + to={to || "/"} + className={baseClass} + onMouseEnter={scramble} + onMouseLeave={reset} + > + {displayText} + </Link> + ); +} |
