1
1
import React , { useContext , forwardRef , useMemo } from 'react' ;
2
2
import { 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' ;
5
5
6
6
type RequiredURLSearchParamsContextValue = {
7
7
utmSource ?: string ;
@@ -75,20 +75,20 @@ export const Link = (({ href, children, ...rest }: LeafygreenLinkProps) => {
75
75
// eslint-disable-next-line react/display-name
76
76
export const Button = forwardRef (
77
77
(
78
- { href , children, ...rest } : React . ComponentProps < typeof LGButton > ,
78
+ { children, ...props } : ButtonProps ,
79
79
ref : React . ForwardedRef < HTMLButtonElement >
80
80
) => {
81
81
const { utmSource, utmMedium } = useRequiredURLSearchParams ( ) ;
82
82
83
83
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 } ) ;
86
86
}
87
87
return undefined ;
88
- } , [ href , utmSource , utmMedium ] ) ;
88
+ } , [ props , utmSource , utmMedium ] ) ;
89
89
90
90
return (
91
- < LGButton href = { hrefWithParams } { ...rest } ref = { ref } >
91
+ < LGButton { ...props } href = { hrefWithParams } ref = { ref } >
92
92
{ children }
93
93
</ LGButton >
94
94
) ;
@@ -98,20 +98,20 @@ export const Button = forwardRef(
98
98
// eslint-disable-next-line react/display-name
99
99
export const IconButton = forwardRef (
100
100
(
101
- { href , children, ...rest } : React . ComponentProps < typeof LGIconButton > ,
101
+ { children, ...props } : IconButtonProps ,
102
102
ref : React . ForwardedRef < HTMLAnchorElement >
103
103
) => {
104
104
const { utmSource, utmMedium } = useRequiredURLSearchParams ( ) ;
105
105
106
106
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 } ) ;
109
109
}
110
110
return undefined ;
111
- } , [ href , utmSource , utmMedium ] ) ;
111
+ } , [ props , utmSource , utmMedium ] ) ;
112
112
113
113
return (
114
- < LGIconButton href = { hrefWithParams } { ...rest } ref = { ref } >
114
+ < LGIconButton href = { hrefWithParams } { ...props } ref = { ref } >
115
115
{ children }
116
116
</ LGIconButton >
117
117
) ;
0 commit comments