Skip to content

Commit

Permalink
Refactor: [M3-6522-link] argsTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Jun 26, 2023
1 parent 6859117 commit 754cae5
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/manager/src/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
import * as React from 'react';
import { Link as RouterLink, LinkProps } from 'react-router-dom';
import { Link as RouterLink } from 'react-router-dom';
import type { LinkProps } from 'react-router-dom';

const isExternal = (href: string) => {
return href.match(/http/) || href.match(/mailto/);
};

export const Link = (props: LinkProps) => {
interface Props extends LinkProps {
/**
* The link's destination. If the value contains `http` or `mailto`, it will be considered an external link and open in a new window.
*/
to: string;
/**
* The clickable text or content.
*/
children?: React.ReactNode;
/**
* When `true`, clicking the link will replace the current entry in the history stack instead of adding a new one.
* @default false
* @see https://reactrouter.com/web/api/Link/replace-bool
*/
replace?: boolean;
/**
* Optional CSS class names that are applied to the component.
*/
className?: string;
/**
* A function that will be called onClick.
*/
onClick?: (e: React.SyntheticEvent<HTMLElement>) => void;
}

export const Link = (props: Props) => {
const isLinkExternal = isExternal(props.to as string);

return isLinkExternal ? (
Expand Down

0 comments on commit 754cae5

Please sign in to comment.