import React, { HTMLAttributes } from 'react'; import './silke-link.scss'; import { LinkProps, Link } from 'react-router-dom'; import { SilkeIcon, SilkeIcons } from '../silke-icon'; const getRelFromTarget = (target?: string): 'noopener noreferrer' | undefined => { return !target || target.toLowerCase() === '_self' || target.toLowerCase() === '_top' || target.toLowerCase() === '_parent' ? undefined : 'noopener noreferrer'; }; const getClassNames = ( className?: string, standalone?: boolean, kind?: 'primary' | 'secondary', ): string => { const cn = className ? ['silke-link', className] : ['silke-link']; if (standalone) { cn.push('silke-link--standalone'); } if (kind) { cn.push(kind); } return cn.join(' '); }; interface LinkChildProps { external?: boolean; icon?: SilkeIcons; children?: React.ReactNode; } const LinkChild = (props: LinkChildProps) => { const { children, icon, external } = props; const displayIcon = !!(icon || external); return ( <> {displayIcon ? {children} : children} {displayIcon && ( )} ); }; interface SilkeLinkProps extends Omit, 'children'>, LinkChildProps { standalone?: boolean; kind?: 'primary' | 'secondary'; } export const SilkeLink: React.FunctionComponent = ({ kind = 'primary', ...props }: SilkeLinkProps) => { const { target, standalone, className, external, children, icon, ...rest } = props; const rel = getRelFromTarget(target); return ( {children} ); }; interface SilkeRouterLinkProps extends Omit, LinkChildProps { standalone?: boolean; } export const SilkeRouterLink: React.FunctionComponent = ( props: SilkeRouterLinkProps, ) => { const { className, standalone, external, children, icon, ...rest } = props; return ( {children} ); }; export interface SilkeButtonLinkProps extends HTMLAttributes { standalone?: boolean; icon?: SilkeIcons; } export const SilkeButtonLink = (props: SilkeButtonLinkProps) => { const { className, standalone, icon, children, ...rest } = props; return ( ); };