11import { Link } from "react-router-dom" ;
22import React , { forwardRef } from "react" ;
3+ import { Icons } from "../constants/icons" ;
4+ import { Icon } from "../icons/icon" ;
35import "./anchor.scss" ;
46
57/*
@@ -13,6 +15,7 @@ export interface AnchorProps {
1315 children ?: any ;
1416 cssClassName ?: string ;
1517 external ?: boolean ;
18+ icon ?: keyof typeof Icons ;
1619 id ?: string ;
1720 onClick ?: ( e : React . MouseEvent < HTMLElement > , value ?: any ) => void ;
1821 onKeyDown ?: ( e : React . KeyboardEvent < HTMLAnchorElement > ) => void ;
@@ -49,7 +52,7 @@ const Anchor: React.RefForwardingComponent<Link, AnchorProps> = forwardRef(
4952 relAttribute = "noopener noreferrer" ;
5053 }
5154
52- const commonProps = {
55+ const attributes = {
5356 "aria-label" : props . ariaLabel ,
5457 className : cssClassNames . join ( " " ) ,
5558 id : props . id ,
@@ -61,17 +64,27 @@ const Anchor: React.RefForwardingComponent<Link, AnchorProps> = forwardRef(
6164 onKeyDown : props . onKeyDown ,
6265 } ;
6366
67+ const content = (
68+ < React . Fragment >
69+ { // if
70+ props . icon && (
71+ < Icon type = { props . icon } />
72+ ) }
73+ { props . children }
74+ </ React . Fragment >
75+ )
76+
6477 if ( props . external === true ) {
6578 return (
66- < a href = { props . to } { ...commonProps } >
67- { props . children }
79+ < a href = { props . to } { ...attributes } >
80+ { content }
6881 </ a >
6982 ) ;
7083 }
7184
7285 return (
73- < Link to = { props . to } { ...commonProps } >
74- { props . children }
86+ < Link to = { props . to } { ...attributes } >
87+ { content }
7588 </ Link >
7689 ) ;
7790 }
0 commit comments