@@ -2,7 +2,7 @@ import React, { useMemo } from "react"
2
2
import styled from "styled-components"
3
3
import ReactSelect , { components as defaultComponents } from "react-select"
4
4
5
- const withDataAttrs = Component => props => {
5
+ const useDataAttrs = ( props , name ) => {
6
6
const { "data-ga" : dataGA , "data-testid" : dataTestId } = props . selectProps
7
7
8
8
const ga = useMemo ( ( ) => {
@@ -11,42 +11,54 @@ const withDataAttrs = Component => props => {
11
11
const gaParts = dataGA . split ( "::" )
12
12
if ( ! gaParts [ 1 ] ) return dataGA
13
13
14
- gaParts [ 1 ] = `${ gaParts [ 1 ] } -${ Component . displayName } `
14
+ gaParts [ 1 ] = `${ gaParts [ 1 ] } -${ name } `
15
15
return gaParts . join ( "::" )
16
16
} , [ dataGA ] )
17
17
18
- const testId = `${ dataTestId || "" } ${ Component . displayName } `
18
+ const testId = `${ dataTestId || "" } ${ name } `
19
19
20
- return < Component data-ga = { ga } data-testid = { testId } { ...props } />
20
+ return { "data-ga" : ga , "data-testid" : testId }
21
+ }
22
+
23
+ const withDataAttrs = ( Component , name ) => props => {
24
+ const dataProps = useDataAttrs ( props , name )
25
+
26
+ return < Component { ...props } innerProps = { { ...( props . innerProps || { } ) , ...dataProps } } />
27
+ }
28
+
29
+ const withDOMDataAttrs = ( Component , name ) => props => {
30
+ const dataProps = useDataAttrs ( props , name )
31
+
32
+ return < Component { ...props } { ...dataProps } />
21
33
}
22
34
23
35
const customComponents = {
24
36
...defaultComponents ,
25
- ClearIndicator : withDataAttrs ( defaultComponents . ClearIndicator ) ,
26
- Control : withDataAttrs ( defaultComponents . Control ) ,
27
- DropdownIndicator : withDataAttrs ( defaultComponents . DropdownIndicator ) ,
28
- DownChevron : withDataAttrs ( defaultComponents . DownChevron ) ,
29
- CrossIcon : withDataAttrs ( defaultComponents . CrossIcon ) ,
30
- Group : withDataAttrs ( defaultComponents . Group ) ,
31
- GroupHeading : withDataAttrs ( defaultComponents . GroupHeading ) ,
32
- IndicatorsContainer : withDataAttrs ( defaultComponents . IndicatorsContainer ) ,
33
- IndicatorSeparator : withDataAttrs ( defaultComponents . IndicatorSeparator ) ,
34
- Input : withDataAttrs ( defaultComponents . Input ) ,
35
- LoadingIndicator : withDataAttrs ( defaultComponents . LoadingIndicator ) ,
36
- Menu : withDataAttrs ( defaultComponents . Menu ) ,
37
- MenuList : withDataAttrs ( defaultComponents . MenuList ) ,
38
- MenuPortal : withDataAttrs ( defaultComponents . MenuPortal ) ,
39
- LoadingMessage : withDataAttrs ( defaultComponents . LoadingMessage ) ,
40
- NoOptionsMessage : withDataAttrs ( defaultComponents . NoOptionsMessage ) ,
41
- MultiValue : withDataAttrs ( defaultComponents . MultiValue ) ,
42
- MultiValueContainer : withDataAttrs ( defaultComponents . MultiValueContainer ) ,
43
- MultiValueLabel : withDataAttrs ( defaultComponents . MultiValueLabel ) ,
44
- MultiValueRemove : withDataAttrs ( defaultComponents . MultiValueRemove ) ,
45
- Option : withDataAttrs ( defaultComponents . Option ) ,
46
- Placeholder : withDataAttrs ( defaultComponents . Placeholder ) ,
47
- SelectContainer : withDataAttrs ( defaultComponents . SelectContainer ) ,
48
- SingleValue : withDataAttrs ( defaultComponents . SingleValue ) ,
49
- ValueContainer : withDataAttrs ( defaultComponents . ValueContainer ) ,
37
+ ClearIndicator : withDataAttrs ( defaultComponents . ClearIndicator , "ClearIndicator" ) ,
38
+ Control : withDataAttrs ( defaultComponents . Control , "Control" ) ,
39
+ DropdownIndicator : withDataAttrs ( defaultComponents . DropdownIndicator , "DropdownIndicator" ) ,
40
+ DownChevron : withDataAttrs ( defaultComponents . DownChevron , "DownChevron" ) ,
41
+ CrossIcon : withDataAttrs ( defaultComponents . CrossIcon , "CrossIcon" ) ,
42
+ Group : withDataAttrs ( defaultComponents . Group , "Group" ) ,
43
+ GroupHeading : withDataAttrs ( defaultComponents . GroupHeading , "GroupHeading" ) ,
44
+ IndicatorsContainer : withDataAttrs ( defaultComponents . IndicatorsContainer , "IndicatorsContainer" ) ,
45
+ IndicatorSeparator : withDataAttrs ( defaultComponents . IndicatorSeparator , "IndicatorSeparator" ) ,
46
+ Input : withDOMDataAttrs ( defaultComponents . Input , "Input" ) ,
47
+ LoadingIndicator : withDataAttrs ( defaultComponents . LoadingIndicator , "LoadingIndicator" ) ,
48
+ Menu : withDataAttrs ( defaultComponents . Menu , "Menu" ) ,
49
+ MenuList : withDataAttrs ( defaultComponents . MenuList , "MenuList" ) ,
50
+ MenuPortal : withDataAttrs ( defaultComponents . MenuPortal , "MenuPortal" ) ,
51
+ LoadingMessage : withDataAttrs ( defaultComponents . LoadingMessage , "LoadingMessage" ) ,
52
+ MultiValue : withDataAttrs ( defaultComponents . MultiValue , "MultiValue" ) ,
53
+ MultiValueContainer : withDataAttrs ( defaultComponents . MultiValueContainer , "MultiValueContainer" ) ,
54
+ MultiValueLabel : withDataAttrs ( defaultComponents . MultiValueLabel , "MultiValueLabel" ) ,
55
+ MultiValueRemove : withDataAttrs ( defaultComponents . MultiValueRemove , "MultiValueRemove" ) ,
56
+ NoOptionsMessage : withDataAttrs ( defaultComponents . NoOptionsMessage , "NoOptionsMessage" ) ,
57
+ Option : withDataAttrs ( defaultComponents . Option , "Option" ) ,
58
+ Placeholder : withDataAttrs ( defaultComponents . Placeholder , "Placeholder" ) ,
59
+ SelectContainer : withDataAttrs ( defaultComponents . SelectContainer , "SelectContainer" ) ,
60
+ SingleValue : withDataAttrs ( defaultComponents . SingleValue , "SingleValue" ) ,
61
+ ValueContainer : withDataAttrs ( defaultComponents . ValueContainer , "ValueContainer" ) ,
50
62
}
51
63
52
64
const makeCustomTheme = theme => selectTheme => {
0 commit comments