@rn-components-dropdown/dropdown 1.0.6 → 1.0.8

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.
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  const react_1 = __importDefault(require("react"));
40
40
  const react_native_svg_1 = __importStar(require("react-native-svg"));
41
- const ArrowDown = ({ size = 24, color = "black" }) => (<react_native_svg_1.default width={size} height={size} viewBox="0 0 24 24" fill="none">
41
+ const ArrowDown = ({ size = 16, color = "black" }) => (<react_native_svg_1.default width={size} height={size} viewBox="0 0 24 24" fill="none">
42
42
  <react_native_svg_1.Mask id="mask0_2371_2505" maskUnits="userSpaceOnUse" x={0} y={0} width={24} height={24}>
43
43
  <react_native_svg_1.Rect width={24} height={24} rx={1} fill="#fff"/>
44
44
  </react_native_svg_1.Mask>
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  const react_1 = __importDefault(require("react"));
40
40
  const react_native_svg_1 = __importStar(require("react-native-svg"));
41
- const ArrowUp = ({ size = 24, color = "#1C1B1F" }) => (<react_native_svg_1.default width={size} height={size} viewBox="0 0 24 24" fill="none">
41
+ const ArrowUp = ({ size = 16, color = "#1C1B1F" }) => (<react_native_svg_1.default width={size} height={size} viewBox="0 0 24 24" fill="none">
42
42
  <react_native_svg_1.Mask id="mask0_2375_2500" maskUnits="userSpaceOnUse" x={0} y={0} width={24} height={24}>
43
43
  <react_native_svg_1.Rect x={24} y={24} width={24} height={24} rx={1} transform="rotate(-180 24 24)" fill={color}/>
44
44
  </react_native_svg_1.Mask>
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  const react_1 = __importDefault(require("react"));
40
40
  const react_native_svg_1 = __importStar(require("react-native-svg"));
41
- const SearchIcon = ({ size = 24, color = "#1C1B1F" }) => (<react_native_svg_1.default width={size} height={size} viewBox="0 0 18 18" fill={color}>
41
+ const SearchIcon = ({ size = 18, color = "#1C1B1F" }) => (<react_native_svg_1.default width={size} height={size} viewBox="0 0 18 18" fill={color}>
42
42
  <react_native_svg_1.Path d="M17.3 17.3C16.9134 17.6866 16.2866 17.6866 15.9 17.3L11.6989 13.0989C10.9025 12.3025 9.63504 12.2695 8.575 12.65C7.925 12.8833 7.23333 13 6.5 13C4.68333 13 3.14583 12.3708 1.8875 11.1125C0.629167 9.85417 0 8.31667 0 6.5C0 4.68333 0.629167 3.14583 1.8875 1.8875C3.14583 0.629167 4.68333 0 6.5 0C8.31667 0 9.85417 0.629167 11.1125 1.8875C12.3708 3.14583 13 4.68333 13 6.5C13 7.23333 12.8833 7.925 12.65 8.575C12.2695 9.63504 12.3025 10.9025 13.0989 11.6989L17.3 15.9C17.6866 16.2866 17.6866 16.9134 17.3 17.3ZM6.5 11C7.75 11 8.8125 10.5625 9.6875 9.6875C10.5625 8.8125 11 7.75 11 6.5C11 5.25 10.5625 4.1875 9.6875 3.3125C8.8125 2.4375 7.75 2 6.5 2C5.25 2 4.1875 2.4375 3.3125 3.3125C2.4375 4.1875 2 5.25 2 6.5C2 7.75 2.4375 8.8125 3.3125 9.6875C4.1875 10.5625 5.25 11 6.5 11Z"/>
43
43
  </react_native_svg_1.default>);
44
44
  exports.default = SearchIcon;
@@ -53,7 +53,7 @@ const DropdownComponent = (props) => {
53
53
  const { styles, colors } = (0, DropdownStyle_1.useDropdownStyle)({});
54
54
  const { ref, font, visible, refList, position, onSelect, listData, onSearch, onMeasure, searchText, showOrClose, scrollIndex, currentValue, onCheckPress, onClearPress, setSearchText, keyboardHeight, } = (0, useDropdown_1.default)({ ...props });
55
55
  const renderRight = () => {
56
- return renderRightIcon ? (renderRightIcon(visible)) : (<SvgButton_1.default icon={subfixIcon ? subfixIcon : visible ? <svg_1.ArrowDown color={iconColor}/> : <svg_1.ArrowUp color={iconColor}/>} onPress={showOrClose} style={react_native_1.StyleSheet.flatten([
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
57
  iconStyle,
58
58
  styles.icon,
59
59
  { tintColor: iconColor },
@@ -94,7 +94,7 @@ const DropdownComponent = (props) => {
94
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)));
95
95
  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
96
  <react_native_1.View style={react_native_1.StyleSheet.flatten([itemContainerStyle])}>
97
- {renderItem ? (renderItem(item, isSelected)) : (<react_native_1.View style={styles.item}>
97
+ {renderItem ? (renderItem(item, isSelected, labelField, valueField)) : (<react_native_1.View style={styles.item}>
98
98
  <SvgButton_1.default icon={multiSelectIcon ? multiSelectIcon : <CheckIcon_1.default color={colors.white}/>} onPress={() => onCheckPress(item)} style={[
99
99
  styles.checkContainer,
100
100
  {
@@ -132,7 +132,7 @@ const DropdownComponent = (props) => {
132
132
  lodash_1.default.assign(item, { _index: index });
133
133
  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={() => onSelect(item)}>
134
134
  <react_native_1.View style={react_native_1.StyleSheet.flatten([itemContainerStyle])}>
135
- {renderItem ? (renderItem(item, selected)) : (<react_native_1.View style={styles.item}>
135
+ {renderItem ? (renderItem(item, selected, labelField, valueField)) : (<react_native_1.View style={styles.item}>
136
136
  {renderRadio(selected)}
137
137
  <AppText_1.default style={react_native_1.StyleSheet.flatten([
138
138
  styles.textItem,
@@ -12,7 +12,7 @@ declare const useDropdown: <T, Mode extends "single" | "multi">(props: DropdownP
12
12
  position: any;
13
13
  onSelect: (item: any) => void;
14
14
  onSearch: (text: string) => void;
15
- listData: any[];
15
+ listData: T[];
16
16
  onMeasure: () => void;
17
17
  searchText: string;
18
18
  showOrClose: () => void;
@@ -61,7 +61,7 @@ export type DropdownProps<S, T extends SelectionType> = {
61
61
  flatListProps?: Omit<FlatListProps<any>, 'renderItem' | 'data'>;
62
62
  renderLeftIcon?: (visible?: boolean) => React.JSX.Element | null | undefined;
63
63
  renderRightIcon?: (visible?: boolean) => React.JSX.Element | null | undefined;
64
- renderItem?: (item: S, selected?: boolean) => React.JSX.Element | null | undefined;
64
+ renderItem?: (item: S, selected?: boolean, labelField?: keyof S, valueField?: keyof S) => React.JSX.Element | null | undefined;
65
65
  renderInputSearch?: (onSearch: (text: string) => void) => React.JSX.Element | null | undefined;
66
66
  };
67
67
  export interface IUseDetectDevice {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rn-components-dropdown/dropdown",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import Svg, { Path, Mask, Rect, G } from "react-native-svg";
3
3
 
4
- const ArrowDown = ({ size = 24, color = "black" }) => (
4
+ const ArrowDown = ({ size = 16, color = "black" }) => (
5
5
  <Svg width={size} height={size} viewBox="0 0 24 24" fill="none">
6
6
  <Mask
7
7
  id="mask0_2371_2505"
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import Svg, { Mask, Rect, G, Path } from "react-native-svg";
3
3
  import { SvgInterface } from "../../interface/svg.interface";
4
4
 
5
- const ArrowUp = ({ size = 24, color = "#1C1B1F" }: SvgInterface) => (
5
+ const ArrowUp = ({ size = 16, color = "#1C1B1F" }: SvgInterface) => (
6
6
  <Svg width={size} height={size} viewBox="0 0 24 24" fill="none">
7
7
  <Mask
8
8
  id="mask0_2375_2500"
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
- import Svg, { Path, SvgProps } from "react-native-svg";
2
+ import Svg, { Path } from "react-native-svg";
3
3
  import { SvgInterface } from "../../interface/svg.interface";
4
4
 
5
- const SearchIcon = ({ size = 24, color = "#1C1B1F" }: SvgInterface) => (
5
+ const SearchIcon = ({ size= 18, color = "#1C1B1F" }: SvgInterface) => (
6
6
  <Svg width={size} height={size} viewBox="0 0 18 18" fill={color}>
7
7
  <Path d="M17.3 17.3C16.9134 17.6866 16.2866 17.6866 15.9 17.3L11.6989 13.0989C10.9025 12.3025 9.63504 12.2695 8.575 12.65C7.925 12.8833 7.23333 13 6.5 13C4.68333 13 3.14583 12.3708 1.8875 11.1125C0.629167 9.85417 0 8.31667 0 6.5C0 4.68333 0.629167 3.14583 1.8875 1.8875C3.14583 0.629167 4.68333 0 6.5 0C8.31667 0 9.85417 0.629167 11.1125 1.8875C12.3708 3.14583 13 4.68333 13 6.5C13 7.23333 12.8833 7.925 12.65 8.575C12.2695 9.63504 12.3025 10.9025 13.0989 11.6989L17.3 15.9C17.6866 16.2866 17.6866 16.9134 17.3 17.3ZM6.5 11C7.75 11 8.8125 10.5625 9.6875 9.6875C10.5625 8.8125 11 7.75 11 6.5C11 5.25 10.5625 4.1875 9.6875 3.3125C8.8125 2.4375 7.75 2 6.5 2C5.25 2 4.1875 2.4375 3.3125 3.3125C2.4375 4.1875 2 5.25 2 6.5C2 7.75 2.4375 8.8125 3.3125 9.6875C4.1875 10.5625 5.25 11 6.5 11Z"/>
8
8
  </Svg>
@@ -92,7 +92,7 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
92
92
  renderRightIcon(visible)
93
93
  ) : (
94
94
  <SvgButton
95
- icon={subfixIcon ? subfixIcon : visible ? <ArrowDown color={iconColor} /> : <ArrowUp color={iconColor} />}
95
+ icon={subfixIcon ? subfixIcon : visible ? <ArrowUp color={iconColor} /> : <ArrowDown color={iconColor} />}
96
96
  onPress={showOrClose}
97
97
  style={StyleSheet.flatten([
98
98
  iconStyle,
@@ -104,7 +104,7 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
104
104
  };
105
105
 
106
106
  const _renderDropdown = () => {
107
- const isSelected = currentValue && _.get(currentValue, valueField);
107
+ const isSelected: boolean = currentValue && _.get(currentValue, valueField);
108
108
  return (
109
109
  <TouchableWithoutFeedback
110
110
  testID={testID}
@@ -169,7 +169,7 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
169
169
  );
170
170
 
171
171
  const renderCheckItem = useCallback(
172
- ({ item, index }: { item: any; index: number }) => {
172
+ ({ item, index }: { item: T; index: number }) => {
173
173
  const isSelected = _.some(currentValue, h =>
174
174
  _.isEqual(_.get(h, valueField), _.get(item, valueField)),
175
175
  );
@@ -187,8 +187,8 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
187
187
  >
188
188
  <View style={StyleSheet.flatten([itemContainerStyle])}>
189
189
  {renderItem ? (
190
- renderItem(item, isSelected)
191
- ) : (
190
+ renderItem(item, isSelected, labelField, valueField)
191
+ ) : (
192
192
  <View style={styles.item}>
193
193
  <SvgButton
194
194
  icon={multiSelectIcon ? multiSelectIcon : <CheckIcon color={colors.white}/> }
@@ -233,7 +233,7 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
233
233
  );
234
234
 
235
235
  const _renderItem = useCallback(
236
- ({ item, index }: { item: any; index: number }) => {
236
+ ({ item, index }: { item: T; index: number }) => {
237
237
  const isSelected = currentValue && _.get(currentValue, valueField);
238
238
  const selected = _.isEqual(_.get(item, valueField), isSelected);
239
239
  _.assign(item, { _index: index });
@@ -251,7 +251,7 @@ const DropdownComponent = <T, Mode extends 'single' | 'multi'>(
251
251
  >
252
252
  <View style={StyleSheet.flatten([itemContainerStyle])}>
253
253
  {renderItem ? (
254
- renderItem(item, selected)
254
+ renderItem(item, selected, labelField, valueField)
255
255
  ) : (
256
256
  <View style={styles.item}>
257
257
  {renderRadio(selected)}
@@ -50,7 +50,7 @@ const useDropdown = <T, Mode extends 'single' | 'multi'>(
50
50
  const orientation = useDeviceOrientation();
51
51
  const [position, setPosition] = useState<any>();
52
52
  const [searchText, setSearchText] = useState('');
53
- const [listData, setListData] = useState<any[]>(data);
53
+ const [listData, setListData] = useState<T[]>(data);
54
54
  const [visible, setVisible] = useState<boolean>(false);
55
55
  const [currentValue, setCurrentValue] = useState<any>(null);
56
56
  const statusBarHeight: number = StatusBar.currentHeight || 0;
@@ -77,6 +77,8 @@ export type DropdownProps<S, T extends SelectionType> = {
77
77
  renderItem?: (
78
78
  item: S,
79
79
  selected?: boolean,
80
+ labelField?: keyof S,
81
+ valueField?: keyof S,
80
82
  ) => React.JSX.Element | null | undefined;
81
83
  renderInputSearch?: (
82
84
  onSearch: (text: string) => void,