|
1 | 1 | import React from "react" |
2 | 2 | import styled from "styled-components" |
3 | | -import ReactSelect, { components } from "react-select" |
| 3 | +import ReactSelect, { components as defaultComponents } from "react-select" |
4 | 4 | import { capitalizeFirstLetter } from "src/utils" |
5 | 5 |
|
6 | 6 | const withDataAttrs = |
@@ -33,68 +33,73 @@ const makeDataAttrs = (ga, testId) => type => { |
33 | 33 | return dataAttrs |
34 | 34 | } |
35 | 35 |
|
36 | | -const makeCustomComponents = makeComponentDataAttrs => ({ |
| 36 | +const makeCustomComponents = (components, makeComponentDataAttrs) => ({ |
| 37 | + ...defaultComponents, |
37 | 38 | ClearIndicator: withDataAttrs( |
38 | | - components.ClearIndicator, |
| 39 | + defaultComponents.ClearIndicator, |
39 | 40 | makeComponentDataAttrs("clearIndicator") |
40 | 41 | ), |
41 | | - Control: withDataAttrs(components.Control, makeComponentDataAttrs("clearIndicator")), |
| 42 | + Control: withDataAttrs(defaultComponents.Control, makeComponentDataAttrs("clearIndicator")), |
42 | 43 | DropdownIndicator: withDataAttrs( |
43 | | - components.DropdownIndicator, |
| 44 | + defaultComponents.DropdownIndicator, |
44 | 45 | makeComponentDataAttrs("dropdownIndicator") |
45 | 46 | ), |
46 | | - DownChevron: withDataAttrs(components.DownChevron, makeComponentDataAttrs("downChevron")), |
47 | | - CrossIcon: withDataAttrs(components.CrossIcon, makeComponentDataAttrs("crossIcon")), |
48 | | - Group: withDataAttrs(components.Group, makeComponentDataAttrs("group")), |
49 | | - GroupHeading: withDataAttrs(components.GroupHeading, makeComponentDataAttrs("groupHeading")), |
| 47 | + DownChevron: withDataAttrs(defaultComponents.DownChevron, makeComponentDataAttrs("downChevron")), |
| 48 | + CrossIcon: withDataAttrs(defaultComponents.CrossIcon, makeComponentDataAttrs("crossIcon")), |
| 49 | + Group: withDataAttrs(defaultComponents.Group, makeComponentDataAttrs("group")), |
| 50 | + GroupHeading: withDataAttrs( |
| 51 | + defaultComponents.GroupHeading, |
| 52 | + makeComponentDataAttrs("groupHeading") |
| 53 | + ), |
50 | 54 | IndicatorsContainer: withDataAttrs( |
51 | | - components.IndicatorsContainer, |
| 55 | + defaultComponents.IndicatorsContainer, |
52 | 56 | makeComponentDataAttrs("indicatorsContainer") |
53 | 57 | ), |
54 | 58 | IndicatorSeparator: withDataAttrs( |
55 | | - components.IndicatorSeparator, |
| 59 | + defaultComponents.IndicatorSeparator, |
56 | 60 | makeComponentDataAttrs("indicatorSeparator") |
57 | 61 | ), |
58 | | - Input: withDataAttrs(components.Input, makeComponentDataAttrs("input"), false), |
| 62 | + Input: withDataAttrs(defaultComponents.Input, makeComponentDataAttrs("input"), false), |
59 | 63 | LoadingIndicator: withDataAttrs( |
60 | | - components.LoadingIndicator, |
| 64 | + defaultComponents.LoadingIndicator, |
61 | 65 | makeComponentDataAttrs("loadingIndicator") |
62 | 66 | ), |
63 | | - Menu: withDataAttrs(components.Menu, makeComponentDataAttrs("menu")), |
64 | | - MenuList: withDataAttrs(components.MenuList, makeComponentDataAttrs("menuList")), |
65 | | - MenuPortal: withDataAttrs(components.MenuPortal, makeComponentDataAttrs("menuPortal")), |
| 67 | + Menu: withDataAttrs(defaultComponents.Menu, makeComponentDataAttrs("menu")), |
| 68 | + MenuList: withDataAttrs(defaultComponents.MenuList, makeComponentDataAttrs("menuList")), |
| 69 | + MenuPortal: withDataAttrs(defaultComponents.MenuPortal, makeComponentDataAttrs("menuPortal")), |
66 | 70 | LoadingMessage: withDataAttrs( |
67 | | - components.LoadingMessage, |
| 71 | + defaultComponents.LoadingMessage, |
68 | 72 | makeComponentDataAttrs("loadingMessage") |
69 | 73 | ), |
70 | 74 | NoOptionsMessage: withDataAttrs( |
71 | | - components.NoOptionsMessage, |
| 75 | + defaultComponents.NoOptionsMessage, |
72 | 76 | makeComponentDataAttrs("noOptionsMessage") |
73 | 77 | ), |
74 | | - MultiValue: withDataAttrs(components.MultiValue, makeComponentDataAttrs("multiValue")), |
| 78 | + MultiValue: withDataAttrs(defaultComponents.MultiValue, makeComponentDataAttrs("multiValue")), |
75 | 79 | MultiValueContainer: withDataAttrs( |
76 | | - components.MultiValueContainer, |
| 80 | + defaultComponents.MultiValueContainer, |
77 | 81 | makeComponentDataAttrs("multiValueContainer") |
78 | 82 | ), |
79 | 83 | MultiValueLabel: withDataAttrs( |
80 | | - components.MultiValueLabel, |
| 84 | + defaultComponents.MultiValueLabel, |
81 | 85 | makeComponentDataAttrs("multiValueLabel") |
82 | 86 | ), |
83 | 87 | MultiValueRemove: withDataAttrs( |
84 | | - components.MultiValueRemove, |
| 88 | + defaultComponents.MultiValueRemove, |
85 | 89 | makeComponentDataAttrs("multiValueRemove") |
86 | 90 | ), |
87 | | - Option: withDataAttrs(components.Option, makeComponentDataAttrs("option")), |
88 | | - Placeholder: withDataAttrs(components.Placeholder, makeComponentDataAttrs("placeholder")), |
| 91 | + Option: withDataAttrs(defaultComponents.Option, makeComponentDataAttrs("option")), |
| 92 | + Placeholder: withDataAttrs(defaultComponents.Placeholder, makeComponentDataAttrs("placeholder")), |
89 | 93 | SelectContainer: withDataAttrs( |
90 | | - components.SelectContainer, |
| 94 | + defaultComponents.SelectContainer, |
91 | 95 | makeComponentDataAttrs("selectContainer") |
92 | 96 | ), |
93 | | - SingleValue: withDataAttrs(components.SingleValue, makeComponentDataAttrs("singleValue")), |
| 97 | + SingleValue: withDataAttrs(defaultComponents.SingleValue, makeComponentDataAttrs("singleValue")), |
94 | 98 | ValueContainer: withDataAttrs( |
95 | | - components.ValueContainer, |
| 99 | + defaultComponents.ValueContainer, |
96 | 100 | makeComponentDataAttrs("valueContainer") |
97 | 101 | ), |
| 102 | + ...components, |
98 | 103 | }) |
99 | 104 |
|
100 | 105 | const makeCustomTheme = theme => selectTheme => { |
@@ -207,11 +212,13 @@ const makeCustomStyles = (theme, { size, ...providedStyles } = {}) => ({ |
207 | 212 | ...providedStyles, |
208 | 213 | }) |
209 | 214 |
|
210 | | -const Select = styled(ReactSelect).attrs(({ "data-ga": ga, "data-testid": testId, ...props }) => ({ |
211 | | - ...props, |
212 | | - components: makeCustomComponents(makeDataAttrs(ga, testId)), |
213 | | - theme: makeCustomTheme(props.theme), |
214 | | - styles: makeCustomStyles(props.theme, props.styles), |
215 | | -}))`` |
| 215 | +const Select = styled(ReactSelect).attrs( |
| 216 | + ({ "data-ga": ga, "data-testid": testId, components, ...props }) => ({ |
| 217 | + ...props, |
| 218 | + components: makeCustomComponents(components, makeDataAttrs(ga, testId)), |
| 219 | + theme: makeCustomTheme(props.theme), |
| 220 | + styles: makeCustomStyles(props.theme, props.styles), |
| 221 | + }) |
| 222 | +)`` |
216 | 223 |
|
217 | 224 | export default Select |
0 commit comments