Portal/rsconcept/frontend/src/components/ui/TextURL.tsx

43 lines
880 B
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
import { Link } from 'react-router-dom';
interface TextURLProps {
/** Text to display. */
2024-06-07 20:17:03 +03:00
text: string;
/** Tooltip for the link. */
2024-06-07 20:17:03 +03:00
title?: string;
/** URL to link to. */
2024-06-07 20:17:03 +03:00
href?: string;
/** Color of the link. */
2024-06-07 20:17:03 +03:00
color?: string;
/** Callback to be called when the link is clicked. */
2024-06-07 20:17:03 +03:00
onClick?: () => void;
}
/**
* Displays a text with a clickable link.
*/
2024-06-07 20:17:03 +03:00
function TextURL({ text, href, title, color = 'clr-text-url', onClick }: TextURLProps) {
const design = `cursor-pointer hover:underline ${color}`;
if (href) {
return (
<Link tabIndex={-1} className={design} title={title} to={href}>
{text}
</Link>
);
} else if (onClick) {
return (
2024-06-21 19:16:41 +03:00
<button type='button' tabIndex={-1} className={design} onClick={onClick}>
2024-06-07 20:17:03 +03:00
{text}
2024-06-21 19:16:41 +03:00
</button>
2024-06-07 20:17:03 +03:00
);
} else {
return null;
}
}
export default TextURL;