Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear option button #16

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/components/select-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type FromSelectComponentProps = Pick<
| 'selectControlOpenDropdownA11yLabel'
| 'selectControlCloseDropdownA11yLabel'
| 'selectControlTextStyle'
| 'selectControlClearOptionButtonStyle'
| 'selectControlClearOptionButtonHitSlop'
| 'selectControlClearOptionImageStyle'
>;

type SelectControlProps = OptionalToRequired<
Expand All @@ -57,6 +60,9 @@ export const SelectControl = forwardRef<View, SelectControlProps>(
disabled,
placeholderText,
selectControlDisabledStyle,
selectControlClearOptionButtonHitSlop,
selectControlClearOptionButtonStyle,
selectControlClearOptionImageStyle,
selectControlClearOptionA11yLabel,
selectControlOpenDropdownA11yLabel,
selectControlCloseDropdownA11yLabel,
Expand Down Expand Up @@ -117,10 +123,16 @@ export const SelectControl = forwardRef<View, SelectControlProps>(
selectControlClearOptionA11yLabel || 'Clear a chosen option'
}
disabled={disabled}
onPress={onPressRemove}>
hitSlop={
selectControlClearOptionButtonHitSlop
? selectControlClearOptionButtonHitSlop
: { right: 3, left: 3 }
}
onPress={onPressRemove}
style={[styles.xIconWrapper, selectControlClearOptionButtonStyle]}>
<Image
source={require('./../../assets/icons/x.png')}
style={styles.xIcon}
style={[styles.xIcon, selectControlClearOptionImageStyle]}
/>
</TouchableOpacity>
)}
Expand Down Expand Up @@ -151,6 +163,7 @@ type Styles = {
arrowIconOpened: ImageStyle;
arrowIconClosed: ImageStyle;
xIcon: ImageStyle;
xIconWrapper: ViewStyle;
};

const styles = StyleSheet.create<Styles>({
Expand Down Expand Up @@ -195,6 +208,10 @@ const styles = StyleSheet.create<Styles>({
height: 25,
zIndex: -1,
},
xIconWrapper: {
height: '100%',
justifyContent: 'center',
},
xIcon: {
width: 20,
height: 20,
Expand Down
6 changes: 6 additions & 0 deletions src/components/select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const Select = forwardRef((props: SelectProps, ref: ForwardedRef<SelectRe
placeholderText = 'Select...',
selectContainerStyle,
selectControlButtonsContainerStyle,
selectControlClearOptionButtonStyle,
selectControlClearOptionImageStyle,
selectControlClearOptionButtonHitSlop,
selectControlClearOptionA11yLabel,
selectControlOpenDropdownA11yLabel,
selectControlCloseDropdownA11yLabel,
Expand Down Expand Up @@ -170,6 +173,9 @@ export const Select = forwardRef((props: SelectProps, ref: ForwardedRef<SelectRe
ref={containerRef}
selectControlButtonsContainerStyle={selectControlButtonsContainerStyle}
selectControlClearOptionA11yLabel={selectControlClearOptionA11yLabel}
selectControlClearOptionButtonHitSlop={selectControlClearOptionButtonHitSlop}
selectControlClearOptionButtonStyle={selectControlClearOptionButtonStyle}
selectControlClearOptionImageStyle={selectControlClearOptionImageStyle}
selectControlCloseDropdownA11yLabel={selectControlCloseDropdownA11yLabel}
selectControlDisabledStyle={selectControlDisabledStyle}
selectControlOpenDropdownA11yLabel={selectControlOpenDropdownA11yLabel}
Expand Down
30 changes: 29 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import type { FlatListProps, StyleProp, TextStyle, ViewStyle } from 'react-native';
import type {
FlatListProps,
ImageStyle,
Insets,
StyleProp,
TextStyle,
ViewStyle,
} from 'react-native';

export type OptionType = {
label: string;
Expand Down Expand Up @@ -74,6 +81,27 @@ export interface SelectProps {
*/
selectControlButtonsContainerStyle?: StyleProp<ViewStyle>;

/**
* Style of clear option button
*
* @category Styles
*/
selectControlClearOptionButtonStyle?: StyleProp<ViewStyle>;

/**
* Hit Slop for clear option button
*
* @category Styles
*/
selectControlClearOptionButtonHitSlop?: Insets;

/**
* Style of clear option image
*
* @category Styles
*/
selectControlClearOptionImageStyle?: ImageStyle;

/**
* Style of container select control
*
Expand Down