ConceptPortal-public/rsconcept/frontend/src/components/control/text-url.tsx

41 lines
872 B
TypeScript
Raw Normal View History

2024-11-25 19:53:20 +03:00
import { Link } from 'react-router';
2023-07-15 17:46:19 +03:00
interface TextURLProps {
/** Text to display. */
2023-12-28 14:04:44 +03:00
text: string;
/** Tooltip for the link. */
2023-12-28 14:04:44 +03:00
title?: string;
/** URL to link to. */
2023-12-28 14:04:44 +03:00
href?: string;
/** Color of the link. */
2023-12-28 14:04:44 +03:00
color?: string;
/** Callback to be called when the link is clicked. */
2023-12-28 14:04:44 +03:00
onClick?: () => void;
2023-07-15 17:46:19 +03:00
}
/**
* Displays a text with a clickable link.
*/
export function TextURL({ text, href, title, color = 'text-primary', onClick }: TextURLProps) {
2023-12-08 19:24:08 +03:00
const design = `cursor-pointer hover:underline ${color}`;
if (href) {
return (
2023-12-28 14:04:44 +03:00
<Link tabIndex={-1} className={design} title={title} to={href}>
{text}
</Link>
);
} else if (onClick) {
return (
<button type='button' tabIndex={-1} className={design} title={title} onClick={onClick}>
2023-12-28 14:04:44 +03:00
{text}
2024-06-21 19:27:36 +03:00
</button>
2023-12-28 14:04:44 +03:00
);
} else {
return null;
}
2023-07-15 17:46:19 +03:00
}