From 87108475785e86c71b87b7b3d103c694ab9d1584 Mon Sep 17 00:00:00 2001 From: Alban Bailly Date: Mon, 26 Jun 2023 13:41:54 -0400 Subject: [PATCH] Refactor: [M3-6522-link] argsTypes --- packages/manager/src/components/Link.tsx | 30 ++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/components/Link.tsx b/packages/manager/src/components/Link.tsx index 0eee87a3e93..4c1f157b927 100644 --- a/packages/manager/src/components/Link.tsx +++ b/packages/manager/src/components/Link.tsx @@ -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) => void; +} + +export const Link = (props: Props) => { const isLinkExternal = isExternal(props.to as string); return isLinkExternal ? (