1
- import React , { ChangeEvent , ReactNode , forwardRef , RefObject } from 'react' ;
1
+ import React , { ChangeEvent , ReactNode , forwardRef , RefObject , KeyboardEvent } from 'react' ;
2
2
import styled , { css } from 'styled-components' ;
3
3
import { ifProp , switchProp } from 'styled-tools' ;
4
4
import { MdSearch } from 'react-icons/md' ;
5
5
import colors from '../../theme/colors' ;
6
- import { AnalyticsProps } from '../../analytics' ;
6
+ import {
7
+ AnalyticsComponent ,
8
+ AnalyticsProps ,
9
+ AnalyticsEvents ,
10
+ AnalyticsComponentType ,
11
+ } from '../../analytics' ;
7
12
8
13
type Size = 'xs' | 'sm' | 'md' | 'lg' ;
9
14
@@ -95,7 +100,7 @@ type RefType =
95
100
96
101
const Input = forwardRef (
97
102
(
98
- { type, placeholder, onChange, sizeProp, className = '' , icon, ...rest } : Props ,
103
+ { type, placeholder, onChange, sizeProp, className = '' , icon, tag = '' , ...rest } : Props ,
99
104
ref : RefType
100
105
) => {
101
106
const onInputChange = ( e : ChangeEvent < HTMLInputElement > ) : any => {
@@ -107,35 +112,95 @@ const Input = forwardRef(
107
112
108
113
if ( type === 'search' ) {
109
114
return (
110
- < InputWrapper >
111
- < IconContainer >
112
- < MdSearch />
113
- </ IconContainer >
114
- < StyledInput
115
- sizeProp = { sizeProp }
116
- ref = { ref }
117
- type = { type }
118
- placeholder = { placeholder }
119
- { ...rest }
120
- onChange = { onInputChange }
121
- />
122
- </ InputWrapper >
115
+ < AnalyticsComponent >
116
+ { ( { pages, tracker, merchantId, ip } ) => (
117
+ < InputWrapper >
118
+ < IconContainer >
119
+ < MdSearch />
120
+ </ IconContainer >
121
+ < StyledInput
122
+ sizeProp = { sizeProp }
123
+ ref = { ref }
124
+ type = { type }
125
+ placeholder = { placeholder }
126
+ onChange = { onInputChange }
127
+ onKeyDown = { ( e : KeyboardEvent < HTMLInputElement > ) => {
128
+ if ( e . key === 'Enter' ) {
129
+ if ( tag ) {
130
+ tracker . track ( {
131
+ event : AnalyticsEvents . KEYBOARD_EVENT ,
132
+ type : AnalyticsComponentType . INPUT ,
133
+ tag : `${ tag } _enter` ,
134
+ pages,
135
+ merchantId,
136
+ ip,
137
+ } ) ;
138
+ }
139
+ }
140
+ } }
141
+ onClick = { ( ) => {
142
+ if ( tag ) {
143
+ tracker . track ( {
144
+ event : AnalyticsEvents . CLICK ,
145
+ type : AnalyticsComponentType . INPUT ,
146
+ tag,
147
+ pages,
148
+ merchantId,
149
+ ip,
150
+ } ) ;
151
+ }
152
+ } }
153
+ { ...rest }
154
+ />
155
+ </ InputWrapper >
156
+ ) }
157
+ </ AnalyticsComponent >
123
158
) ;
124
159
}
125
160
126
161
return (
127
- < InputWrapper className = { className } >
128
- < IconContainer > { icon } </ IconContainer >
129
- < StyledInput
130
- sizeProp = { sizeProp }
131
- ref = { ref }
132
- type = { type || 'text' }
133
- placeholder = { placeholder }
134
- onChange = { onInputChange }
135
- icon = { icon }
136
- { ...rest }
137
- />
138
- </ InputWrapper >
162
+ < AnalyticsComponent >
163
+ { ( { pages, tracker, merchantId, ip } ) => (
164
+ < InputWrapper className = { className } >
165
+ < IconContainer > { icon } </ IconContainer >
166
+ < StyledInput
167
+ sizeProp = { sizeProp }
168
+ ref = { ref }
169
+ type = { type || 'text' }
170
+ placeholder = { placeholder }
171
+ onChange = { onInputChange }
172
+ icon = { icon }
173
+ onKeyDown = { ( e : KeyboardEvent < HTMLInputElement > ) => {
174
+ if ( tag ) {
175
+ if ( e . key === 'Enter' ) {
176
+ tracker . track ( {
177
+ event : AnalyticsEvents . KEYBOARD_EVENT ,
178
+ type : AnalyticsComponentType . INPUT ,
179
+ tag : `${ tag } _enter` ,
180
+ pages,
181
+ merchantId,
182
+ ip,
183
+ } ) ;
184
+ }
185
+ }
186
+ } }
187
+ onClick = { ( ) => {
188
+ if ( tag ) {
189
+ tracker . track ( {
190
+ event : AnalyticsEvents . CLICK ,
191
+ type : AnalyticsComponentType . INPUT ,
192
+ tag,
193
+ pages,
194
+ merchantId,
195
+ ip,
196
+ } ) ;
197
+ }
198
+ } }
199
+ { ...rest }
200
+ />
201
+ </ InputWrapper >
202
+ ) }
203
+ </ AnalyticsComponent >
139
204
) ;
140
205
}
141
206
) ;
0 commit comments