Skip to content

Commit b429655

Browse files
refactor(ui): fix review comments
1 parent 72d4a9a commit b429655

17 files changed

Lines changed: 72 additions & 119 deletions

packages/ui-components/src/components/ComboBox/components/ComboBoxContent.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,29 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React, { ReactNode, useEffect, useCallback } from "react"
6+
import React, { ReactNode, useEffect } from "react"
77
import { Combobox } from "@headlessui/react"
88
import { useComboBoxContext } from "../context"
99

1010
interface ComboBoxContentProps {
1111
children: ReactNode
1212
}
13-
const ComboBoxContent: React.FC<ComboBoxContentProps> = ({ children }) => {
13+
export const ComboBoxContent: React.FC<ComboBoxContentProps> = ({ children }) => {
1414
const {
1515
state: { selectedValue, isOpen, setIsOpen, setSelectedValue },
1616
derivedProps: { defaultValue, disabled, loading: isLoading, error: hasError, name, onChange },
1717
restProps,
1818
} = useComboBoxContext()
1919

20-
const handleChange = useCallback(
21-
(value: string) => {
22-
setSelectedValue(value)
20+
const handleChange = (value: string) => {
21+
setSelectedValue(value)
2322

24-
if (value) {
25-
setIsOpen(false)
26-
}
23+
if (value) {
24+
setIsOpen(false)
25+
}
2726

28-
onChange?.(value)
29-
},
30-
[onChange]
31-
)
27+
onChange?.(value)
28+
}
3229

3330
return (
3431
<Combobox
@@ -54,5 +51,3 @@ const ComboBoxContent: React.FC<ComboBoxContentProps> = ({ children }) => {
5451
</Combobox>
5552
)
5653
}
57-
58-
export default ComboBoxContent

packages/ui-components/src/components/ComboBox/components/ComboBoxFloatingMenu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
import React from "react"
77
import { ComboboxOptions } from "@headlessui/react"
8-
import { usePortalRef } from "../../PortalProvider/index"
98
import { createPortal } from "react-dom"
9+
import { usePortalRef } from "../../PortalProvider/index"
1010
import { useComboBoxContext } from "../context"
1111
import useComboBoxStyles from "../styles"
1212

13-
const ComboBoxFloatingMenu: React.FC = () => {
13+
export const ComboBoxFloatingMenu: React.FC = () => {
1414
const {
1515
state: { isOpen },
1616
floating: { refs, strategy, x, y, getFloatingProps },

packages/ui-components/src/components/ComboBox/components/ComboBoxInput.tsx

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React, { useCallback, ReactNode } from "react"
6+
import React, { ReactNode } from "react"
77
import { ComboboxInput } from "@headlessui/react"
88
import { OptionValuesAndLabelsKey } from "../hooks"
99
import { useComboBoxContext } from "../context"
1010
import { safeToString } from "../../../utils"
1111
import useComboBoxStyles from "../styles"
1212

13-
const ComboBoxInput: React.FC = () => {
13+
export const ComboBoxInput: React.FC = () => {
1414
const {
1515
inputElementId,
1616
helpTextId,
@@ -32,50 +32,35 @@ const ComboBoxInput: React.FC = () => {
3232

3333
const { inputStyles } = useComboBoxStyles()
3434

35-
const handleInputChange = useCallback(
36-
(event: React.ChangeEvent<HTMLInputElement>) => {
37-
const newQuery = event?.target?.value || ""
38-
setQuery(newQuery)
35+
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
36+
const newQuery = event?.target?.value || ""
37+
setQuery(newQuery)
3938

40-
// Only trigger onInputChange if it exists
41-
onInputChange?.(event)
42-
},
43-
[onInputChange]
44-
)
39+
// Only trigger onInputChange if it exists
40+
onInputChange?.(event)
41+
}
4542

46-
const handleFocus = useCallback(
47-
(event: React.FocusEvent<HTMLInputElement>) => {
48-
setFocus(true)
43+
const handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {
44+
setFocus(true)
4945

50-
if (!isOpen) {
51-
setIsOpen(true)
52-
}
46+
if (!isOpen) {
47+
setIsOpen(true)
48+
}
5349

54-
onFocus?.(event)
55-
},
56-
[isOpen, onFocus]
57-
)
50+
onFocus?.(event)
51+
}
5852

59-
const handleBlur = useCallback(
60-
(event: React.FocusEvent<HTMLInputElement>) => {
61-
setFocus(false)
62-
setIsOpen(false)
53+
const handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {
54+
setFocus(false)
55+
setIsOpen(false)
6356

64-
onBlur?.(event)
65-
},
66-
[onBlur]
67-
)
57+
onBlur?.(event)
58+
}
6859

69-
// Memoized display value calculation
70-
const displayValue = useCallback(
71-
(val: ReactNode) => {
72-
const option = mappedOptions.get(val)
73-
return (
74-
(option?.children && safeToString(option.children)) || option?.label || valueLabel || safeToString(val) || ""
75-
)
76-
},
77-
[mappedOptions, valueLabel]
78-
)
60+
const displayValue = (val: ReactNode) => {
61+
const option = mappedOptions.get(val)
62+
return (option?.children && safeToString(option.children)) || option?.label || valueLabel || safeToString(val) || ""
63+
}
7964

8065
return (
8166
<ComboboxInput<OptionValuesAndLabelsKey>
@@ -92,5 +77,3 @@ const ComboBoxInput: React.FC = () => {
9277
/>
9378
)
9479
}
95-
96-
export default ComboBoxInput

packages/ui-components/src/components/ComboBox/components/ComboBoxInputWrapper.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import useComboBoxStyles from "../styles"
1010
interface ComboBoxInputWrapperProps {
1111
children: ReactNode
1212
}
13-
const ComboBoxInputWrapper: React.FC<ComboBoxInputWrapperProps> = ({ children }) => {
13+
export const ComboBoxInputWrapper: React.FC<ComboBoxInputWrapperProps> = ({ children }) => {
1414
const { inputWrapperStyles } = useComboBoxStyles()
1515

1616
const {
@@ -23,5 +23,3 @@ const ComboBoxInputWrapper: React.FC<ComboBoxInputWrapperProps> = ({ children })
2323
</div>
2424
)
2525
}
26-
27-
export default ComboBoxInputWrapper

packages/ui-components/src/components/ComboBox/components/ComboBoxLabel.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useComboBoxContext } from "../context"
99
import { isNotEmptyString } from "../../../utils"
1010
import useComboBoxStyles from "../styles"
1111

12-
const ComboBoxLabel: React.FC = () => {
12+
export const ComboBoxLabel: React.FC = () => {
1313
const {
1414
inputElementId,
1515
derivedProps: { label, placeholder, loading: isLoading, error: hasError, required, disabled },
@@ -45,5 +45,3 @@ const ComboBoxLabel: React.FC = () => {
4545
</>
4646
)
4747
}
48-
49-
export default ComboBoxLabel

packages/ui-components/src/components/ComboBox/components/ComboBoxOuterWrapper.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import useComboBoxStyles from "../styles"
99
interface ComboBoxOuterWrapperProps {
1010
children: ReactNode
1111
}
12-
const ComboBoxOuterWrapper: React.FC<ComboBoxOuterWrapperProps> = ({ children }) => {
12+
export const ComboBoxOuterWrapper: React.FC<ComboBoxOuterWrapperProps> = ({ children }) => {
1313
const { outerWrapperStyles } = useComboBoxStyles()
1414

1515
return <div className={outerWrapperStyles}>{children}</div>
1616
}
17-
18-
export default ComboBoxOuterWrapper

packages/ui-components/src/components/ComboBox/components/ComboBoxStatusIcon.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Icon } from "../../Icon/index"
99
import { useComboBoxContext } from "../context"
1010
import useComboBoxStyles from "../styles"
1111

12-
const ComboBoxStatusIcon: React.FC = () => {
12+
export const ComboBoxStatusIcon: React.FC = () => {
1313
const {
1414
derivedProps: { loading: isLoading, error: hasError },
1515
validation: { isInvalid, isValid },
@@ -46,5 +46,3 @@ const ComboBoxStatusIcon: React.FC = () => {
4646

4747
return <>{renderStatusIcon()}</>
4848
}
49-
50-
export default ComboBoxStatusIcon

packages/ui-components/src/components/ComboBox/components/ComboBoxStatusMessage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FormHint } from "../../FormHint/index"
88
import { isNotEmptyString } from "../../../utils"
99
import { useComboBoxContext } from "../context"
1010

11-
const ComboBoxStatusMessage: React.FC = () => {
11+
export const ComboBoxStatusMessage: React.FC = () => {
1212
const {
1313
helpTextId,
1414
derivedProps: { helptext, successtext, errortext },
@@ -22,5 +22,3 @@ const ComboBoxStatusMessage: React.FC = () => {
2222
</>
2323
)
2424
}
25-
26-
export default ComboBoxStatusMessage

packages/ui-components/src/components/ComboBox/components/ComboBoxToggleButton.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Icon } from "../../Icon/index"
99
import { useComboBoxContext } from "../context"
1010
import useComboBoxStyles from "../styles"
1111

12-
const ComboBoxToggleButton: React.FC = () => {
12+
export const ComboBoxToggleButton: React.FC = () => {
1313
const {
1414
derivedProps: { error: hasError, loading: isLoading },
1515
state: { isOpen },
@@ -27,5 +27,3 @@ const ComboBoxToggleButton: React.FC = () => {
2727
</>
2828
)
2929
}
30-
31-
export default ComboBoxToggleButton

packages/ui-components/src/components/ComboBox/components/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
export { default as ComboBoxInput } from "./ComboBoxInput"
7-
export { default as ComboBoxLabel } from "./ComboBoxLabel"
8-
export { default as ComboBoxStatusIcon } from "./ComboBoxStatusIcon"
9-
export { default as ComboBoxStatusMessage } from "./ComboBoxStatusMessage"
10-
export { default as ComboBoxToggleButton } from "./ComboBoxToggleButton"
11-
export { default as ComboBoxFloatingMenu } from "./ComboBoxFloatingMenu"
12-
export { default as ComboBoxContent } from "./ComboBoxContent"
13-
export { default as ComboBoxOuterWrapper } from "./ComboBoxOuterWrapper"
14-
export { default as ComboBoxInputWrapper } from "./ComboBoxInputWrapper"
6+
export { ComboBoxInput } from "./ComboBoxInput"
7+
export { ComboBoxLabel } from "./ComboBoxLabel"
8+
export { ComboBoxStatusIcon } from "./ComboBoxStatusIcon"
9+
export { ComboBoxStatusMessage } from "./ComboBoxStatusMessage"
10+
export { ComboBoxToggleButton } from "./ComboBoxToggleButton"
11+
export { ComboBoxFloatingMenu } from "./ComboBoxFloatingMenu"
12+
export { ComboBoxContent } from "./ComboBoxContent"
13+
export { ComboBoxOuterWrapper } from "./ComboBoxOuterWrapper"
14+
export { ComboBoxInputWrapper } from "./ComboBoxInputWrapper"

0 commit comments

Comments
 (0)