@rn-components-dropdown/dropdown 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,15 +45,16 @@ const react_1 = __importStar(require("react"));
45
45
  const useDropdown_1 = __importDefault(require("./hooks/useDropdown"));
46
46
  const SvgButton_1 = __importDefault(require("../svgButton/SvgButton"));
47
47
  const DropdownStyle_1 = require("./DropdownStyle");
48
+ const CheckIcon_1 = __importDefault(require("../../assets/svg/CheckIcon"));
48
49
  const svg_1 = require("../../assets/svg");
49
50
  const TextInput_1 = __importDefault(require("./components/input/TextInput"));
50
- const CheckIcon_1 = __importDefault(require("../../assets/svg/CheckIcon"));
51
51
  const DropdownComponent = (props) => {
52
- const { label, testID, iconStyle, renderItem, style = {}, subfixIcon, labelField, valueField, onChangeText, itemTextStyle, flatListProps, minHeight = 0, containerStyle, search = false, renderLeftIcon, multiSelectIcon, itemTestIDField, maxHeight = 300, inverted = true, renderRightIcon, backgroundColor, placeholderStyle, inputSearchStyle, searchPlaceholder, selectedTextStyle, renderInputSearch, iconColor = 'gray', accessibilityLabel, itemContainerStyle, labelContainer = {}, labelTextStyle = {}, selectedTextProps = {}, selectionType = 'single', activeColor = 'lightGray', keyboardAvoiding = true, dropdownPosition = 'auto', placeholder = 'Select item', itemAccessibilityLabelField, showsVerticalScrollIndicator = true, } = props;
52
+ const { label, testID, iconStyle, renderItem, style = {}, subfixIcon, labelField, valueField, onChangeText, itemTextStyle, flatListProps, minHeight = 0, containerStyle, search = false, renderLeftIcon, multiSelectIcon, itemTestIDField, maxHeight = 300, inverted = true, renderRightIcon, backgroundColor, placeholderStyle, inputSearchStyle, searchPlaceholder, selectedTextStyle, renderInputSearch, chipContainerProps, iconColor = 'gray', accessibilityLabel, itemContainerStyle, labelContainer = {}, labelTextStyle = {}, selectedTextProps = {}, selectionType = 'single', activeColor = 'lightGray', keyboardAvoiding = true, dropdownPosition = 'auto', placeholder = 'Select item', itemAccessibilityLabelField, showsVerticalScrollIndicator = true, } = props;
53
+ const { chipColor, clearIcon, textColor, onClearPress: onClear, } = chipContainerProps;
53
54
  const { styles, colors } = (0, DropdownStyle_1.useDropdownStyle)({});
54
55
  const { ref, font, visible, refList, position, onSelect, listData, onSearch, onMeasure, searchText, showOrClose, scrollIndex, currentValue, onCheckPress, onClearPress, setSearchText, keyboardHeight, } = (0, useDropdown_1.default)({ ...props });
55
56
  const renderRight = () => {
56
- return renderRightIcon ? (renderRightIcon(visible)) : (<SvgButton_1.default icon={subfixIcon ? subfixIcon : visible ? <svg_1.ArrowUp color={iconColor}/> : <svg_1.ArrowDown color={iconColor}/>} onPress={showOrClose} style={react_native_1.StyleSheet.flatten([
57
+ return renderRightIcon ? (renderRightIcon(visible)) : (<SvgButton_1.default icon={subfixIcon ? (subfixIcon) : visible ? (<svg_1.ArrowUp color={iconColor}/>) : (<svg_1.ArrowDown color={iconColor}/>)} onPress={showOrClose} style={react_native_1.StyleSheet.flatten([
57
58
  iconStyle,
58
59
  styles.icon,
59
60
  { tintColor: iconColor },
@@ -77,7 +78,10 @@ const DropdownComponent = (props) => {
77
78
  </AppText_1.default>) : (<react_native_1.View style={styles.showMultiSelectContainer}>
78
79
  <react_native_1.ScrollView showsVerticalScrollIndicator={false}>
79
80
  <react_native_1.View style={styles.wraps}>
80
- {currentValue?.map?.((i) => (<Chip_1.default chipColor={'red'} textColor={'white'} key={i?.[valueField]} label={i?.[labelField]} onClearPress={() => onClearPress(i)}/>))}
81
+ {currentValue?.map?.((i) => (<Chip_1.default chipColor={chipColor || 'red'} textColor={textColor || 'white'} clearIcon={clearIcon} key={i?.[valueField]} label={i?.[labelField]} onClearPress={() => {
82
+ onClear?.();
83
+ onClearPress?.(i);
84
+ }}/>))}
81
85
  </react_native_1.View>
82
86
  </react_native_1.ScrollView>
83
87
  </react_native_1.View>)}
@@ -91,11 +95,11 @@ const DropdownComponent = (props) => {
91
95
  </react_native_1.View>);
92
96
  }, [styles]);
93
97
  const renderCheckItem = (0, react_1.useCallback)(({ item, index }) => {
94
- const isSelected = lodash_1.default.some(currentValue, h => lodash_1.default.isEqual(lodash_1.default.get(h, valueField), lodash_1.default.get(item, valueField)));
98
+ const isSelected = lodash_1.default.some(currentValue, (h) => lodash_1.default.isEqual(lodash_1.default.get(h, valueField), lodash_1.default.get(item, valueField)));
95
99
  return (<react_native_1.TouchableHighlight key={index.toString()} testID={lodash_1.default.get(item, itemTestIDField || labelField)} accessible={!!accessibilityLabel} accessibilityLabel={lodash_1.default.get(item, itemAccessibilityLabelField || labelField)} underlayColor={colors[activeColor]} onPress={() => onCheckPress(item)}>
96
100
  <react_native_1.View style={react_native_1.StyleSheet.flatten([itemContainerStyle])}>
97
101
  {renderItem ? (renderItem(item, isSelected, labelField, valueField)) : (<react_native_1.View style={styles.item}>
98
- <SvgButton_1.default icon={multiSelectIcon ? multiSelectIcon : <CheckIcon_1.default color={colors.white}/>} onPress={() => onCheckPress(item)} style={[
102
+ <SvgButton_1.default icon={multiSelectIcon ? (multiSelectIcon) : (<CheckIcon_1.default color={colors.white}/>)} onPress={() => onCheckPress(item)} style={[
99
103
  styles.checkContainer,
100
104
  {
101
105
  backgroundColor: isSelected ? colors.gray : colors.white,
@@ -209,9 +213,9 @@ const DropdownComponent = (props) => {
209
213
  </react_native_1.View>
210
214
  </react_native_1.TouchableWithoutFeedback>);
211
215
  }, [
212
- inverted,
213
216
  styles,
214
217
  testID,
218
+ inverted,
215
219
  listData,
216
220
  scrollIndex,
217
221
  renderSearch,
@@ -15,9 +15,9 @@ const Chip = (props) => {
15
15
  <AppText_1.default size={12} fontFamily={'semiBold'} style={styles.chipText} color={textColor ? textColor : 'gray'}>
16
16
  {label}
17
17
  </AppText_1.default>
18
- <react_native_1.View style={styles.clearContainer}>
19
- <SvgButton_1.default icon={clearIcon ? clearIcon : <svg_1.ClearIcon color={textColor || colors.white}/>} onPress={onClearPress} style={styles.clearIcon}/>
20
- </react_native_1.View>
18
+ {clearIcon ? (clearIcon) : (<react_native_1.View style={styles.clearContainer}>
19
+ <SvgButton_1.default icon={<svg_1.ClearIcon size={8} color={textColor ? colors[textColor] : colors.white}/>} onPress={onClearPress} style={styles.clearIcon}/>
20
+ </react_native_1.View>)}
21
21
  </react_native_1.View>);
22
22
  };
23
23
  exports.default = Chip;
@@ -59,8 +59,8 @@ declare const useChipStyle: (props: ChipInterface) => {
59
59
  backgroundColor: string;
60
60
  };
61
61
  clearIcon: {
62
- height: number;
63
62
  width: number;
63
+ height: number;
64
64
  borderRadius: number;
65
65
  alignItems: "center";
66
66
  justifyContent: "center";
@@ -4,7 +4,7 @@ const react_1 = require("react");
4
4
  const style_1 = require("../../../../style");
5
5
  const react_native_1 = require("react-native");
6
6
  const useChipStyle = (props) => {
7
- const { chipColor } = props;
7
+ const { chipColor, textColor } = props;
8
8
  const { ...colors } = style_1.LIGHT_COLORS;
9
9
  const styles = (0, react_1.useMemo)(() => {
10
10
  return react_native_1.StyleSheet.create({
@@ -17,7 +17,7 @@ const useChipStyle = (props) => {
17
17
  },
18
18
  ios: {
19
19
  shadowRadius: 1.84,
20
- shadowOpacity: 0.25,
20
+ shadowOpacity: 0.35,
21
21
  shadowColor: colors.black,
22
22
  shadowOffset: { width: 0, height: 2 },
23
23
  },
@@ -37,23 +37,23 @@ const useChipStyle = (props) => {
37
37
  clearContainer: {
38
38
  width: 18,
39
39
  height: 18,
40
- borderWidth: 1,
40
+ borderWidth: 2,
41
41
  borderRadius: 100,
42
42
  marginHorizontal: 4,
43
43
  alignItems: 'center',
44
44
  justifyContent: 'center',
45
- borderColor: colors.white,
45
+ borderColor: textColor ? colors[textColor] : colors.white,
46
46
  backgroundColor: chipColor ? colors[chipColor] : colors.lightGray,
47
47
  },
48
48
  clearIcon: {
49
- height: 12,
50
49
  width: 12,
50
+ height: 12,
51
51
  borderRadius: 100,
52
52
  alignItems: 'center',
53
53
  justifyContent: 'center',
54
54
  },
55
55
  });
56
- }, [chipColor, colors]);
56
+ }, [chipColor, colors, textColor]);
57
57
  return {
58
58
  styles,
59
59
  colors,
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { StyleProp, TextStyle, ViewStyle, TextProps, ImageStyle, FlatListProps } from 'react-native';
3
+ import { ChipInterface } from './ChipInterface';
3
4
  import { ThemeColors } from '../../../interface/colors.interface';
4
5
  export type IDropdownRef = {
5
6
  open: () => void;
@@ -33,15 +34,15 @@ export type DropdownProps<S, T extends SelectionType> = {
33
34
  confirmSelectItem?: boolean;
34
35
  accessibilityLabel?: string;
35
36
  style?: StyleProp<ViewStyle>;
37
+ selectedTextProps?: TextProps;
36
38
  subfixIcon?: React.JSX.Element;
37
39
  onClear?: (id?: number) => void;
38
- multiSelectIcon?: React.JSX.Element;
39
- checkIconColor?: keyof ThemeColors;
40
- radioIconColor?: keyof ThemeColors;
41
- onChange?: (selecteValue?: keyof S, selectedList?: SelectionType extends 'single' | 'multi' ? S[] : S) => void;
42
- selectedTextProps?: TextProps;
43
40
  activeColor?: keyof ThemeColors;
44
41
  iconStyle?: StyleProp<ImageStyle>;
42
+ chipContainerProps: ChipInterface;
43
+ checkIconColor?: keyof ThemeColors;
44
+ radioIconColor?: keyof ThemeColors;
45
+ multiSelectIcon?: React.JSX.Element;
45
46
  mode?: 'default' | 'modal' | 'auto';
46
47
  itemTextStyle?: StyleProp<TextStyle>;
47
48
  itemAccessibilityLabelField?: string;
@@ -63,6 +64,7 @@ export type DropdownProps<S, T extends SelectionType> = {
63
64
  renderRightIcon?: (visible?: boolean) => React.JSX.Element | null | undefined;
64
65
  renderItem?: (item: S, selected?: boolean, labelField?: keyof S, valueField?: keyof S) => React.JSX.Element | null | undefined;
65
66
  renderInputSearch?: (onSearch: (text: string) => void) => React.JSX.Element | null | undefined;
67
+ onChange?: (selecteValue?: keyof S, selectedList?: SelectionType extends 'single' | 'multi' ? S[] : S) => void;
66
68
  };
67
69
  export interface IUseDetectDevice {
68
70
  isAndroid: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rn-components-dropdown/dropdown",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -16,10 +16,10 @@ import React, { useCallback } from 'react';
16
16
  import useDropdown from './hooks/useDropdown';
17
17
  import SvgButton from '../svgButton/SvgButton';
18
18
  import { useDropdownStyle } from './DropdownStyle';
19
+ import CheckIcon from '../../assets/svg/CheckIcon';
19
20
  import { ArrowDown, ArrowUp } from '../../assets/svg';
20
21
  import SearchInput from './components/input/TextInput';
21
22
  import { DropdownProps } from './interface/DropdownInterface';
22
- import CheckIcon from '../../assets/svg/CheckIcon';
23
23
 
24
24
  const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
25
25
  props: DropdownProps<T, Mode>,
@@ -51,6 +51,7 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
51
51
  searchPlaceholder,
52
52
  selectedTextStyle,
53
53
  renderInputSearch,
54
+ chipContainerProps,
54
55
  iconColor = 'gray',
55
56
  accessibilityLabel,
56
57
  itemContainerStyle,
@@ -66,6 +67,13 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
66
67
  showsVerticalScrollIndicator = true,
67
68
  } = props;
68
69
 
70
+ const {
71
+ chipColor,
72
+ clearIcon,
73
+ textColor,
74
+ onClearPress: onClear,
75
+ } = chipContainerProps;
76
+
69
77
  const { styles, colors } = useDropdownStyle({});
70
78
  const {
71
79
  ref,
@@ -92,7 +100,15 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
92
100
  renderRightIcon(visible)
93
101
  ) : (
94
102
  <SvgButton
95
- icon={subfixIcon ? subfixIcon : visible ? <ArrowUp color={iconColor} /> : <ArrowDown color={iconColor} />}
103
+ icon={
104
+ subfixIcon ? (
105
+ subfixIcon
106
+ ) : visible ? (
107
+ <ArrowUp color={iconColor} />
108
+ ) : (
109
+ <ArrowDown color={iconColor} />
110
+ )
111
+ }
96
112
  onPress={showOrClose}
97
113
  style={StyleSheet.flatten([
98
114
  iconStyle,
@@ -140,11 +156,15 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
140
156
  <View style={styles.wraps}>
141
157
  {currentValue?.map?.((i: any) => (
142
158
  <Chip
143
- chipColor={'red'}
144
- textColor={'white'}
159
+ chipColor={chipColor || 'red'}
160
+ textColor={textColor || 'white'}
161
+ clearIcon={clearIcon}
145
162
  key={i?.[valueField]}
146
163
  label={i?.[labelField]}
147
- onClearPress={() => onClearPress(i)}
164
+ onClearPress={() => {
165
+ onClear?.();
166
+ onClearPress?.(i);
167
+ }}
148
168
  />
149
169
  ))}
150
170
  </View>
@@ -170,7 +190,7 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
170
190
 
171
191
  const renderCheckItem = useCallback(
172
192
  ({ item, index }: { item: T; index: number }) => {
173
- const isSelected = _.some(currentValue, h =>
193
+ const isSelected = _.some(currentValue, (h: any) =>
174
194
  _.isEqual(_.get(h, valueField), _.get(item, valueField)),
175
195
  );
176
196
  return (
@@ -188,10 +208,16 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
188
208
  <View style={StyleSheet.flatten([itemContainerStyle])}>
189
209
  {renderItem ? (
190
210
  renderItem(item, isSelected, labelField, valueField)
191
- ) : (
211
+ ) : (
192
212
  <View style={styles.item}>
193
213
  <SvgButton
194
- icon={multiSelectIcon ? multiSelectIcon : <CheckIcon color={colors.white}/> }
214
+ icon={
215
+ multiSelectIcon ? (
216
+ multiSelectIcon
217
+ ) : (
218
+ <CheckIcon color={colors.white} />
219
+ )
220
+ }
195
221
  onPress={() => onCheckPress(item)}
196
222
  style={[
197
223
  styles.checkContainer,
@@ -370,9 +396,9 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
370
396
  );
371
397
  },
372
398
  [
373
- inverted,
374
399
  styles,
375
400
  testID,
401
+ inverted,
376
402
  listData,
377
403
  scrollIndex,
378
404
  renderSearch,
@@ -18,13 +18,22 @@ const Chip = (props: ChipInterface) => {
18
18
  >
19
19
  {label}
20
20
  </AppText>
21
- <View style={styles.clearContainer}>
22
- <SvgButton
23
- icon={clearIcon ? clearIcon : <ClearIcon color={textColor || colors.white}/> }
24
- onPress={onClearPress}
25
- style={styles.clearIcon}
26
- />
27
- </View>
21
+ {clearIcon ? (
22
+ clearIcon
23
+ ) : (
24
+ <View style={styles.clearContainer}>
25
+ <SvgButton
26
+ icon={
27
+ <ClearIcon
28
+ size={8}
29
+ color={textColor ? colors[textColor] : colors.white}
30
+ />
31
+ }
32
+ onPress={onClearPress}
33
+ style={styles.clearIcon}
34
+ />
35
+ </View>
36
+ )}
28
37
  </View>
29
38
  );
30
39
  };
@@ -4,7 +4,7 @@ import { Platform, StyleSheet } from 'react-native';
4
4
  import { ChipInterface } from '../../interface/ChipInterface';
5
5
 
6
6
  const useChipStyle = (props: ChipInterface) => {
7
- const { chipColor } = props;
7
+ const { chipColor, textColor } = props;
8
8
  const { ...colors } = LIGHT_COLORS;
9
9
  const styles = useMemo(() => {
10
10
  return StyleSheet.create({
@@ -17,7 +17,7 @@ const useChipStyle = (props: ChipInterface) => {
17
17
  },
18
18
  ios: {
19
19
  shadowRadius: 1.84,
20
- shadowOpacity: 0.25,
20
+ shadowOpacity: 0.35,
21
21
  shadowColor: colors.black,
22
22
  shadowOffset: { width: 0, height: 2 },
23
23
  },
@@ -37,23 +37,23 @@ const useChipStyle = (props: ChipInterface) => {
37
37
  clearContainer: {
38
38
  width: 18,
39
39
  height: 18,
40
- borderWidth: 1,
40
+ borderWidth: 2,
41
41
  borderRadius: 100,
42
42
  marginHorizontal: 4,
43
43
  alignItems: 'center',
44
44
  justifyContent: 'center',
45
- borderColor: colors.white,
45
+ borderColor: textColor ? colors[textColor] : colors.white,
46
46
  backgroundColor: chipColor ? colors[chipColor] : colors.lightGray,
47
47
  },
48
48
  clearIcon: {
49
- height: 12,
50
49
  width: 12,
50
+ height: 12,
51
51
  borderRadius: 100,
52
52
  alignItems: 'center',
53
53
  justifyContent: 'center',
54
54
  },
55
55
  });
56
- }, [chipColor, colors]);
56
+ }, [chipColor, colors, textColor]);
57
57
  return {
58
58
  styles,
59
59
  colors,
@@ -7,6 +7,7 @@ import type {
7
7
  ImageStyle,
8
8
  FlatListProps,
9
9
  } from 'react-native';
10
+ import { ChipInterface } from './ChipInterface';
10
11
  import { ThemeColors } from '../../../interface/colors.interface';
11
12
 
12
13
  export type IDropdownRef = {
@@ -43,18 +44,15 @@ export type DropdownProps<S, T extends SelectionType> = {
43
44
  confirmSelectItem?: boolean;
44
45
  accessibilityLabel?: string;
45
46
  style?: StyleProp<ViewStyle>;
47
+ selectedTextProps?: TextProps;
46
48
  subfixIcon?: React.JSX.Element;
47
49
  onClear?: (id?: number) => void;
48
- multiSelectIcon?:React.JSX.Element;
49
- checkIconColor?: keyof ThemeColors;
50
- radioIconColor?: keyof ThemeColors;
51
- onChange?: (
52
- selecteValue?: keyof S,
53
- selectedList?: SelectionType extends 'single' | 'multi' ? S[] : S,
54
- ) => void;
55
- selectedTextProps?: TextProps;
56
50
  activeColor?: keyof ThemeColors;
57
51
  iconStyle?: StyleProp<ImageStyle>;
52
+ chipContainerProps: ChipInterface;
53
+ checkIconColor?: keyof ThemeColors;
54
+ radioIconColor?: keyof ThemeColors;
55
+ multiSelectIcon?: React.JSX.Element;
58
56
  mode?: 'default' | 'modal' | 'auto';
59
57
  itemTextStyle?: StyleProp<TextStyle>;
60
58
  itemAccessibilityLabelField?: string;
@@ -83,6 +81,10 @@ export type DropdownProps<S, T extends SelectionType> = {
83
81
  renderInputSearch?: (
84
82
  onSearch: (text: string) => void,
85
83
  ) => React.JSX.Element | null | undefined;
84
+ onChange?: (
85
+ selecteValue?: keyof S,
86
+ selectedList?: SelectionType extends 'single' | 'multi' ? S[] : S,
87
+ ) => void;
86
88
  };
87
89
 
88
90
  export interface IUseDetectDevice {