1414 * limitations under the License.
1515 */
1616
17- import { ButtonHTMLAttributes , MutableRefObject , PropsWithChildren , useEffect , useRef , useState } from 'react'
18- import { Link , LinkProps } from 'react-router-dom'
17+ import { MutableRefObject , PropsWithChildren , useEffect , useRef , useState } from 'react'
18+ import { Link } from 'react-router-dom'
1919import { Progressing } from '@Common/Progressing'
2020import { Tooltip } from '@Common/Tooltip'
2121import { TooltipProps } from '@Common/Tooltip/types'
@@ -26,6 +26,7 @@ import './button.scss'
2626
2727const ButtonElement = ( {
2828 component = ButtonComponentType . button ,
29+ anchorProps,
2930 linkProps,
3031 buttonProps,
3132 onClick,
@@ -53,26 +54,44 @@ const ButtonElement = ({
5354 elementRef : MutableRefObject < HTMLButtonElement | HTMLAnchorElement >
5455 }
5556> ) => {
57+ // Added the specific class to ensure that the link override is applied
58+ const linkOrAnchorClassName = `${ props . className } button__link ${ props . disabled ? 'dc__disable-click' : '' } `
59+
5660 if ( component === ButtonComponentType . link ) {
5761 return (
5862 < Link
5963 { ...linkProps }
6064 { ...props }
61- // Added the specific class to ensure that the link override is applied
62- className = { `${ props . className } button__link ${ props . disabled ? 'dc__disable-click' : '' } ` }
63- onClick = { onClick as LinkProps [ 'onClick' ] }
65+ className = { linkOrAnchorClassName }
66+ onClick = { onClick as ButtonProps < typeof component > [ 'onClick' ] }
6467 ref = { elementRef as MutableRefObject < HTMLAnchorElement > }
6568 />
6669 )
6770 }
6871
72+ if ( component === ButtonComponentType . anchor ) {
73+ return (
74+ < a
75+ target = "_blank"
76+ rel = "noopener noreferrer"
77+ { ...anchorProps }
78+ { ...props }
79+ className = { linkOrAnchorClassName }
80+ onClick = { onClick as ButtonProps < typeof component > [ 'onClick' ] }
81+ ref = { elementRef as MutableRefObject < HTMLAnchorElement > }
82+ >
83+ { props . children }
84+ </ a >
85+ )
86+ }
87+
6988 return (
7089 < button
7190 { ...buttonProps }
7291 { ...props }
7392 // eslint-disable-next-line react/button-has-type
7493 type = { buttonProps ?. type || 'button' }
75- onClick = { onClick as ButtonHTMLAttributes < HTMLButtonElement > [ 'onClick' ] }
94+ onClick = { onClick as ButtonProps < typeof component > [ 'onClick' ] }
7695 ref = { elementRef as MutableRefObject < HTMLButtonElement > }
7796 />
7897 )
0 commit comments