From 9fd535706bc13e147772ff927ef3f410481e4fa2 Mon Sep 17 00:00:00 2001 From: Brad Habenicht Date: Wed, 6 Feb 2019 17:25:52 -0500 Subject: [PATCH] feat(fscomponents): increase customizability of search bar --- .../fscomponents/src/components/SearchBar.tsx | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/packages/fscomponents/src/components/SearchBar.tsx b/packages/fscomponents/src/components/SearchBar.tsx index 0e3abd0261..b876cc2dad 100644 --- a/packages/fscomponents/src/components/SearchBar.tsx +++ b/packages/fscomponents/src/components/SearchBar.tsx @@ -32,6 +32,7 @@ export interface SearchBarProps { onFocus?: (input: any, container: any) => void; onBlur?: (input: any, container: any) => void; onCancel?: () => void; + renderCancelButton?: () => React.ReactNode; // visibility showSearchIcon?: boolean; @@ -44,6 +45,7 @@ export interface SearchBarProps { cancelTitle?: string; searchIcon?: ImageURISource; locateIcon?: ImageURISource; + cancelImage?: ImageURISource; onLocateButtonPress?: () => void; // input @@ -58,6 +60,9 @@ export interface SearchBarProps { searchIconStyle?: StyleProp; locateIconStyle?: StyleProp; inputTextStyle?: StyleProp; + cancelImageStyle?: StyleProp; + cancelImageBoxStyle?: StyleProp; + cancelContainerStyle?: StyleProp; cancelButtonWidth?: number; cancelButtonAlwaysVisible?: boolean; @@ -303,24 +308,45 @@ export class SearchBar extends PureComponent { } renderCancelButton = () => { - const { cancelTitleStyle } = this.props; + const { + cancelContainerStyle, + cancelImage, + cancelImageBoxStyle, + cancelImageStyle, + cancelTitle, + cancelTitleStyle, + renderCancelButton + } = this.props; + const { cancelButtonWidth } = this.state; + if (renderCancelButton) { + return renderCancelButton(); + } + + const viewStyle = cancelButtonWidth ? { width: cancelButtonWidth } : null; + // if cancelButtonWidth is defined, parent width is defined, so just fill all the space + const cancelStyle = cancelButtonWidth ? { flex: 1 } : { width: kCancelButtonWidthDefault }; + const cancelImageBoxStyleInput = cancelImageBoxStyle ? cancelImageBoxStyle : null; + const touchableStyle = [S.rightButton, cancelStyle, cancelImageBoxStyleInput]; + return ( - + - - {this.props.cancelTitle || 'Cancel'} - + {cancelImage ? ( + + ) : ( + + {cancelTitle || 'Cancel'} + + )} );