11import React , { useContext , forwardRef , useMemo } from 'react' ;
22import { Link as LGLink } from '@leafygreen-ui/typography' ;
3- import LGButton from '@leafygreen-ui/button' ;
4- import LGIconButton from '@leafygreen-ui/icon-button' ;
3+ import LGButton , { type ButtonProps } from '@leafygreen-ui/button' ;
4+ import LGIconButton , { type IconButtonProps } from '@leafygreen-ui/icon-button' ;
55
66type RequiredURLSearchParamsContextValue = {
77 utmSource ?: string ;
@@ -75,20 +75,20 @@ export const Link = (({ href, children, ...rest }: LeafygreenLinkProps) => {
7575// eslint-disable-next-line react/display-name
7676export const Button = forwardRef (
7777 (
78- { href , children, ...rest } : React . ComponentProps < typeof LGButton > ,
78+ { children, ...props } : ButtonProps ,
7979 ref : React . ForwardedRef < HTMLButtonElement >
8080 ) => {
8181 const { utmSource, utmMedium } = useRequiredURLSearchParams ( ) ;
8282
8383 const hrefWithParams = useMemo ( ( ) => {
84- if ( href ) {
85- return urlWithUtmParams ( href , { utmSource, utmMedium } ) ;
84+ if ( 'href' in props && props . href ) {
85+ return urlWithUtmParams ( props . href , { utmSource, utmMedium } ) ;
8686 }
8787 return undefined ;
88- } , [ href , utmSource , utmMedium ] ) ;
88+ } , [ props , utmSource , utmMedium ] ) ;
8989
9090 return (
91- < LGButton href = { hrefWithParams } { ...rest } ref = { ref } >
91+ < LGButton { ...props } href = { hrefWithParams } ref = { ref } >
9292 { children }
9393 </ LGButton >
9494 ) ;
@@ -98,20 +98,20 @@ export const Button = forwardRef(
9898// eslint-disable-next-line react/display-name
9999export const IconButton = forwardRef (
100100 (
101- { href , children, ...rest } : React . ComponentProps < typeof LGIconButton > ,
101+ { children, ...props } : IconButtonProps ,
102102 ref : React . ForwardedRef < HTMLAnchorElement >
103103 ) => {
104104 const { utmSource, utmMedium } = useRequiredURLSearchParams ( ) ;
105105
106106 const hrefWithParams = useMemo ( ( ) => {
107- if ( href ) {
108- return urlWithUtmParams ( href , { utmSource, utmMedium } ) ;
107+ if ( 'href' in props && props . href ) {
108+ return urlWithUtmParams ( props . href , { utmSource, utmMedium } ) ;
109109 }
110110 return undefined ;
111- } , [ href , utmSource , utmMedium ] ) ;
111+ } , [ props , utmSource , utmMedium ] ) ;
112112
113113 return (
114- < LGIconButton href = { hrefWithParams } { ...rest } ref = { ref } >
114+ < LGIconButton href = { hrefWithParams } { ...props } ref = { ref } >
115115 { children }
116116 </ LGIconButton >
117117 ) ;
0 commit comments