@@ -6,23 +6,12 @@ import type {
6
6
DO_NOT_USE_LinkButtonProps as LinkButtonProps ,
7
7
} from './types' ;
8
8
9
- export function useButtonFunctionality ( props : ButtonProps | LinkButtonProps ) {
10
- // Fallbacking aria-label to string children is not necessary as screen
11
- // readers natively understand that scenario. Leaving it here for a bunch of
12
- // our tests that query by aria-label.
13
- const accessibleLabel =
14
- props [ 'aria-label' ] ??
15
- ( typeof props . children === 'string' ? props . children : undefined ) ;
16
-
17
- const useButtonTrackingLogger = ( ) => {
18
- const hasAnalyticsDebug = window . localStorage ?. getItem ( 'DEBUG_ANALYTICS' ) === '1' ;
9
+ const defaultCreateButtonTracking = ( props : ButtonProps ) => {
10
+ const hasAnalyticsDebug = window . localStorage ?. getItem ( 'DEBUG_ANALYTICS' ) === '1' ;
11
+ return ( ) => {
19
12
const hasCustomAnalytics =
20
13
props . analyticsEventName || props . analyticsEventKey || props . analyticsParams ;
21
- if ( ! hasCustomAnalytics || ! hasAnalyticsDebug ) {
22
- return ( ) => { } ;
23
- }
24
-
25
- return ( ) => {
14
+ if ( hasCustomAnalytics && hasAnalyticsDebug ) {
26
15
// eslint-disable-next-line no-console
27
16
console . log ( 'buttonAnalyticsEvent' , {
28
17
eventKey : props . analyticsEventKey ,
@@ -31,13 +20,22 @@ export function useButtonFunctionality(props: ButtonProps | LinkButtonProps) {
31
20
href : 'href' in props ? props . href : undefined ,
32
21
...props . analyticsParams ,
33
22
} ) ;
34
- } ;
23
+ }
35
24
} ;
25
+ } ;
26
+
27
+ export function useButtonFunctionality ( props : ButtonProps | LinkButtonProps ) {
28
+ // Fallbacking aria-label to string children is not necessary as screen
29
+ // readers natively understand that scenario. Leaving it here for a bunch of
30
+ // our tests that query by aria-label.
31
+ const accessibleLabel =
32
+ props [ 'aria-label' ] ??
33
+ ( typeof props . children === 'string' ? props . children : undefined ) ;
36
34
37
- const useButtonTracking =
38
- HookStore . get ( 'react-hook:use-button-tracking' ) [ 0 ] ?? useButtonTrackingLogger ;
35
+ const createButtonTracking =
36
+ HookStore . get ( 'react-hook:use-button-tracking' ) [ 0 ] ?? defaultCreateButtonTracking ;
39
37
40
- const buttonTracking = useButtonTracking ( {
38
+ const buttonTracking = createButtonTracking ( {
41
39
analyticsEventName : props . analyticsEventName ,
42
40
analyticsEventKey : props . analyticsEventKey ,
43
41
analyticsParams : {
0 commit comments