@@ -5,13 +5,16 @@ import type {StyleProp, TextStyle, ViewStyle} from 'react-native';
55import { View } from 'react-native' ;
66import Button from '@components/Button' ;
77import CaretWrapper from '@components/CaretWrapper' ;
8+ import Icon from '@components/Icon' ;
89import PopoverWithMeasuredContent from '@components/PopoverWithMeasuredContent' ;
910import Text from '@components/Text' ;
1011import withViewportOffsetTop from '@components/withViewportOffsetTop' ;
12+ import { useMemoizedLazyExpensifyIcons } from '@hooks/useLazyAsset' ;
1113import useOnyx from '@hooks/useOnyx' ;
1214import usePopoverPosition from '@hooks/usePopoverPosition' ;
1315import useResponsiveLayout from '@hooks/useResponsiveLayout' ;
1416import useStyleUtils from '@hooks/useStyleUtils' ;
17+ import useTheme from '@hooks/useTheme' ;
1518import useThemeStyles from '@hooks/useThemeStyles' ;
1619import useWindowDimensions from '@hooks/useWindowDimensions' ;
1720import variables from '@styles/variables' ;
@@ -56,6 +59,7 @@ type DropdownButtonProps = WithSentryLabel & {
5659
5760 /** Wrapper style for the outer view */
5861 wrapperStyle ?: StyleProp < ViewStyle > ;
62+ onClosePress ?: ( ) => void ;
5963} ;
6064
6165const ANCHOR_ORIGIN = {
@@ -75,13 +79,16 @@ function DropdownButton({
7579 caretWrapperStyle,
7680 wrapperStyle,
7781 sentryLabel,
82+ onClosePress,
7883} : DropdownButtonProps ) {
7984 // We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to distinguish RHL and narrow layout
8085 // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
8186 const { isSmallScreenWidth} = useResponsiveLayout ( ) ;
87+ const icons = useMemoizedLazyExpensifyIcons ( [ 'Close' ] ) ;
8288
8389 const styles = useThemeStyles ( ) ;
8490 const StyleUtils = useStyleUtils ( ) ;
91+ const theme = useTheme ( ) ;
8592 const { windowHeight} = useWindowDimensions ( ) ;
8693 const triggerRef = useRef < View | null > ( null ) ;
8794 const anchorRef = useRef < View | null > ( null ) ;
@@ -144,6 +151,8 @@ function DropdownButton({
144151 return PopoverComponent ( { closeOverlay : toggleOverlay , isExpanded : isOverlayVisible , setPopoverWidth : setCustomPopoverWidth } ) ;
145152 } , [ PopoverComponent , toggleOverlay , isOverlayVisible ] ) ;
146153
154+ const shouldShowCloseButton = ! ! onClosePress ;
155+
147156 return (
148157 < View
149158 ref = { anchorRef }
@@ -156,28 +165,49 @@ function DropdownButton({
156165 onPress = { calculatePopoverPositionAndToggleOverlay }
157166 />
158167 ) : (
159- < Button
160- ref = { triggerRef }
161- innerStyles = { [ isOverlayVisible && styles . buttonHoveredBG , { maxWidth : 256 } , innerStyles ] }
162- onPress = { calculatePopoverPositionAndToggleOverlay }
163- sentryLabel = { sentryLabel }
164- // eslint-disable-next-line react/jsx-props-no-spreading
165- { ...( medium ? { medium : true } : { small : true } ) }
166- >
167- < CaretWrapper
168- style = { [ styles . flex1 , styles . mw100 , caretWrapperStyle ] }
169- caretWidth = { medium ? variables . iconSizeSmall : variables . iconSizeExtraSmall }
170- caretHeight = { medium ? variables . iconSizeSmall : variables . iconSizeExtraSmall }
171- isActive = { isOverlayVisible }
168+ < View style = { [ styles . flexRow ] } >
169+ < Button
170+ ref = { triggerRef }
171+ innerStyles = { [ isOverlayVisible && styles . buttonHoveredBG , { maxWidth : 256 } , innerStyles , shouldShowCloseButton && styles . pr2 ] }
172+ onPress = { calculatePopoverPositionAndToggleOverlay }
173+ sentryLabel = { sentryLabel }
174+ shouldRemoveRightBorderRadius = { shouldShowCloseButton }
175+ // eslint-disable-next-line react/jsx-props-no-spreading
176+ { ...( medium ? { medium : true } : { small : true } ) }
172177 >
173- < Text
174- numberOfLines = { 1 }
175- style = { [ styles . textMicroBold , styles . flexShrink1 , labelStyle ] }
178+ < CaretWrapper
179+ style = { [ styles . flex1 , styles . mw100 , caretWrapperStyle ] }
180+ caretWidth = { medium ? variables . iconSizeSmall : variables . iconSizeExtraSmall }
181+ caretHeight = { medium ? variables . iconSizeSmall : variables . iconSizeExtraSmall }
182+ isActive = { isOverlayVisible }
176183 >
177- { buttonText }
178- </ Text >
179- </ CaretWrapper >
180- </ Button >
184+ < Text
185+ numberOfLines = { 1 }
186+ style = { [ styles . textMicroBold , styles . flexShrink1 , labelStyle ] }
187+ >
188+ { buttonText }
189+ </ Text >
190+ </ CaretWrapper >
191+ </ Button >
192+ { shouldShowCloseButton && (
193+ < >
194+ < View style = { [ styles . buttonDivider ] } />
195+ < Button
196+ small
197+ shouldRemoveLeftBorderRadius
198+ innerStyles = { [ styles . pl0 , styles . pr0half , styles . filterDropDownCloseIcon ] }
199+ onPress = { onClosePress }
200+ >
201+ < Icon
202+ src = { icons . Close }
203+ fill = { theme . icon }
204+ width = { variables . iconSizeXXSmall }
205+ height = { variables . iconSizeXXSmall }
206+ />
207+ </ Button >
208+ </ >
209+ ) }
210+ </ View >
181211 ) }
182212
183213 { /* Dropdown overlay */ }
0 commit comments