Skip to content

Commit 1d0fbdb

Browse files
committed
bump dev dependencies; code refactoring; optimize validateSetValueParam() utility function by replacing filter + map with reduce and then use [...new Set(arr)] to make unique
1 parent d551cea commit 1d0fbdb

File tree

8 files changed

+140
-549
lines changed

8 files changed

+140
-549
lines changed

package-lock.json

Lines changed: 101 additions & 514 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@
8282
"prepend-file": "^1.3.1",
8383
"react": "^16.12.0",
8484
"react-dom": "^16.12.0",
85-
"react-scripts": "^3.3.1",
85+
"react-scripts": "^3.4.0",
8686
"react-syntax-highlighter": "^12.2.1",
8787
"react-toastify": "^5.5.0",
8888
"react-window": "^1.8.5",
8989
"rimraf": "^3.0.2",
90-
"rollup": "^1.31.0",
90+
"rollup": "^1.31.1",
9191
"rollup-plugin-babel": "^4.3.3",
9292
"rollup-plugin-commonjs": "^10.1.0",
9393
"rollup-plugin-node-resolve": "^5.2.0",

src/Select.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const ControlWrapper = styled.div<ControlWrapperProps>`
132132
align-items: center;
133133
box-sizing: border-box;
134134
justify-content: space-between;
135-
${({ isDisabled, isFocused, isInvalid, theme: { control, color }}) => (`
135+
${({ isDisabled, isFocused, isInvalid, theme: { control, color }}) => `
136136
min-height: ${control.minHeight};
137137
transition: ${control.transition};
138138
border-style: ${control.borderStyle};
@@ -144,22 +144,22 @@ const ControlWrapper = styled.div<ControlWrapperProps>`
144144
${(control.backgroundColor || isDisabled) ? `background-color: ${isDisabled ? color.disabled : control.backgroundColor};` : ''}
145145
${isFocused ? `box-shadow: ${control.boxShadow} ${isInvalid ? color.dangerLight : control.boxShadowColor};` : ''}
146146
${control.css || ''}
147-
`)}
147+
`}
148148
`;
149149

150150
const MenuWrapper = styled.div<MenuWrapperProps>`
151151
z-index: 999;
152152
cursor: default;
153153
position: absolute;
154-
${({ hideMenu, theme: { menu }}) => (`
154+
${({ hideMenu, theme: { menu }}) => `
155155
width: ${menu.width};
156156
margin: ${menu.margin};
157157
padding: ${menu.padding};
158158
box-shadow: ${menu.boxShadow};
159159
border-radius: ${menu.borderRadius};
160160
background-color: ${menu.backgroundColor};
161161
${hideMenu ? 'display: none;' : ''}
162-
`)}
162+
`}
163163
164164
animation: ${({ theme }) => css`${theme.menu.animation}`};
165165
${({ theme }) => theme.menu.css}
@@ -171,7 +171,7 @@ const MenuWrapper = styled.div<MenuWrapperProps>`
171171
white-space: nowrap;
172172
text-overflow: ellipsis;
173173
-webkit-tap-highlight-color: transparent;
174-
${({ theme: { menu: { option } } }) => (`
174+
${({ theme: { menu: { option } } }) => `
175175
padding: ${option.padding};
176176
text-align: ${option.textAlign};
177177
@@ -188,7 +188,7 @@ const MenuWrapper = styled.div<MenuWrapperProps>`
188188
&.${OPTION_DISABLED_CLS} {
189189
opacity: 0.35;
190190
}
191-
`)}
191+
`}
192192
}
193193
`;
194194

src/components/IndicatorIcons.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,41 @@ const IndicatorIconsWrapper = styled.div`
1515
const IndicatorIcon = styled.div`
1616
display: flex;
1717
box-sizing: border-box;
18-
${({ theme: { icon }}) => (`
18+
${({ theme: { icon }}) => `
1919
color: ${icon.color};
2020
padding: ${icon.padding};
2121
:hover {
2222
color: ${icon.hoverColor};
2323
}
24-
`)}
24+
`}
2525
${({ theme }) => theme.icon.css}
2626
`;
2727

2828
const Clear = styled.div`
2929
overflow: hidden;
3030
animation: ${({ theme }) => css`${theme.icon.clear.animation}`};
31-
${({ theme: { icon: { clear }}}) => (`
31+
${({ theme: { icon: { clear }}}) => `
3232
font-size: ${clear.fontSize};
3333
transition: ${clear.transition};
3434
font-weight: ${clear.fontWeight};
3535
font-family: ${clear.fontFamily};
36-
`)}
36+
`}
3737
`;
3838

3939
const Caret = styled.div<CaretProps>`
40-
${({ theme: { icon: { caret }}}) => (`
40+
${({ theme: { icon: { caret }}}) => `
4141
transition: ${caret.transition};
4242
border-top: ${caret.size} dashed;
4343
border-left: ${caret.size} solid transparent;
4444
border-right: ${caret.size} solid transparent;
45-
`)}
45+
`}
4646
4747
${({ menuOpen, isInvalid, theme: { color }}) =>
4848
menuOpen
49-
&& (`
49+
&& `
5050
transform: rotate(180deg);
5151
color: ${(isInvalid ? color.danger : (color.caretActive || color.primary))};
52-
`)}
52+
`}
5353
`;
5454

5555
const Separator = styled.div`

src/components/LoadingDots.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const StyledLoadingDots = styled.div`
1414
border-radius: 100%;
1515
display: inline-block;
1616
animation: ${({ theme }) => css`${theme.loader.animation}`};
17-
${({ theme: { loader }}) => (`
17+
${({ theme: { loader }}) => `
1818
width: ${loader.size};
1919
height: ${loader.size};
2020
background-color: ${loader.color};
21-
`)}
21+
`}
2222
2323
:nth-of-type(1) {
2424
animation-delay: -0.272s;

src/components/Menu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { MenuProps, ItemData } from '../types';
77

88
const NoOptionsMsg = styled.div`
99
text-align: center;
10-
${({ theme: { noOptions }}) => (`
10+
${({ theme: { noOptions }}) => `
1111
color: ${noOptions.color};
1212
margin: ${noOptions.margin};
1313
padding: ${noOptions.padding};
1414
font-size: ${noOptions.fontSize};
1515
${noOptions.css || ''}
16-
`)}
16+
`}
1717
`;
1818

1919
const Menu = React.forwardRef<FixedSizeList, MenuProps>((

src/components/MultiValue.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ const MultiValueWrapper = styled.div`
77
min-width: 0;
88
display: flex;
99
animation: ${({ theme }) => css`${theme.multiValue.animation}`};
10-
${({ theme: { multiValue }}) => (`
10+
${({ theme: { multiValue }}) => `
1111
margin: ${multiValue.margin};
1212
border-radius: ${multiValue.borderRadius};
1313
background-color: ${multiValue.backgroundColor};
1414
${multiValue.css || ''}
15-
`)}
15+
`}
1616
`;
1717

1818
const Label = styled.div`
1919
overflow: hidden;
2020
white-space: nowrap;
2121
text-overflow: ellipsis;
22-
${({ theme: { multiValue: { label }}}) => (`
22+
${({ theme: { multiValue: { label }}}) => `
2323
padding: ${label.padding};
2424
font-size: ${label.fontSize};
2525
border-radius: ${label.borderRadius};
26-
`)}
26+
`}
2727
`;
2828

2929
const Clear = styled.div<{ isFocused: boolean }>`
3030
display: flex;
31-
${({ isFocused, theme: { color, multiValue: { clear }}}) => (`
31+
${({ isFocused, theme: { color, multiValue: { clear }}}) => `
3232
padding: ${clear.padding};
3333
font-size: ${clear.fontSize};
3434
transition: ${clear.transition};
@@ -40,7 +40,7 @@ const Clear = styled.div<{ isFocused: boolean }>`
4040
color: ${color.danger};
4141
background-color: ${color.dangerLight};
4242
}
43-
`)}
43+
`}
4444
`;
4545

4646
const MultiValue: React.FC<MultiValueProps> = ({

src/utils.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,25 @@ export function validateSetValueParam(
209209
return SELECTED_OPTION_DEFAULT;
210210
}
211211

212-
// Get unique array of MenuOption values (ReactText[]) and use to check against menuOptions
213-
const validValuesArr = normalizeValue(values)
214-
.filter((x) => isPlainObject(x))
215-
.map((x) => getOptionValueCB(x))
216-
.filter((item, index, self) => self.indexOf(item) === index);
217-
218-
if (!isArrayWithLength(validValuesArr)) {
212+
// Get array of valid MenuOption values (ReactText[]) and use to check against menuOptions
213+
const validValues = normalizeValue(values)
214+
.reduce((acc: ReactText[], x: SelectedOption) => {
215+
isPlainObject(x) && acc.push(getOptionValueCB(x));
216+
return acc;
217+
}, []);
218+
219+
if (!isArrayWithLength(validValues)) {
219220
return SELECTED_OPTION_DEFAULT;
220221
}
221222

223+
// Get uniq validValues and verify against menuOptions provided
222224
const results = [];
225+
const validValuesUniq = [...new Set(validValues)];
226+
223227
for (const option of menuOptions) {
224-
if (validValuesArr.includes(getOptionValueCB(option))) {
228+
if (validValuesUniq.includes(getOptionValueCB(option))) {
225229
results.push(option);
226-
if (validValuesArr.length === results.length) {
230+
if (validValuesUniq.length === results.length) {
227231
break;
228232
}
229233
}

0 commit comments

Comments
 (0)