secullum-react-native-ui 4.15.1-beta.1 → 4.15.1-beta.3
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.
|
@@ -22,7 +22,11 @@ export interface DropDownProperties {
|
|
|
22
22
|
nativeID?: string;
|
|
23
23
|
icon?: string | undefined;
|
|
24
24
|
arrowColor?: string | undefined;
|
|
25
|
-
searchable?:
|
|
25
|
+
searchable?: SearchableProps;
|
|
26
|
+
}
|
|
27
|
+
export interface SearchableProps {
|
|
28
|
+
placeHolder: string;
|
|
29
|
+
minItemsToSearch?: number;
|
|
26
30
|
}
|
|
27
31
|
export interface DropDownState {
|
|
28
32
|
modalOpen: boolean;
|
|
@@ -34,7 +38,7 @@ export declare class DropDown extends React.Component<DropDownProperties, DropDo
|
|
|
34
38
|
};
|
|
35
39
|
state: DropDownState;
|
|
36
40
|
handleItemPress: (value: any) => void;
|
|
37
|
-
|
|
41
|
+
filterItems: () => {
|
|
38
42
|
label: string;
|
|
39
43
|
value: any;
|
|
40
44
|
icon?: string | undefined;
|
|
@@ -105,14 +105,17 @@ class DropDown extends React.Component {
|
|
|
105
105
|
this.setState({ modalOpen: false });
|
|
106
106
|
onChange(value);
|
|
107
107
|
};
|
|
108
|
-
this.
|
|
108
|
+
this.filterItems = () => {
|
|
109
109
|
const { items } = this.props;
|
|
110
110
|
const { searchText } = this.state;
|
|
111
111
|
return items.filter(item => item.label.toLowerCase().includes(searchText.toLowerCase()));
|
|
112
112
|
};
|
|
113
113
|
this.shouldDisplaySearchField = () => {
|
|
114
|
+
var _a;
|
|
114
115
|
const { items, searchable } = this.props;
|
|
115
|
-
|
|
116
|
+
const defaultQuantityToSearch = 10;
|
|
117
|
+
return (searchable &&
|
|
118
|
+
items.length >= ((_a = searchable.minItemsToSearch) !== null && _a !== void 0 ? _a : defaultQuantityToSearch));
|
|
116
119
|
};
|
|
117
120
|
this.renderClosedDropDown = (item, inputStyle) => {
|
|
118
121
|
const { iconComponent } = this.props;
|
|
@@ -196,7 +199,9 @@ class DropDown extends React.Component {
|
|
|
196
199
|
right: 16
|
|
197
200
|
},
|
|
198
201
|
modalOverlay: {
|
|
199
|
-
justifyContent: this.shouldDisplaySearchField()
|
|
202
|
+
justifyContent: this.shouldDisplaySearchField()
|
|
203
|
+
? 'flex-start'
|
|
204
|
+
: 'center'
|
|
200
205
|
},
|
|
201
206
|
modalContainer: {
|
|
202
207
|
maxHeight: '95%',
|
|
@@ -257,7 +262,7 @@ class DropDown extends React.Component {
|
|
|
257
262
|
searchLabel: {
|
|
258
263
|
fontSize: 16,
|
|
259
264
|
marginLeft: 16,
|
|
260
|
-
fontFamily: theme.fontFamily1
|
|
265
|
+
fontFamily: theme.fontFamily1
|
|
261
266
|
},
|
|
262
267
|
inputWrapper: {
|
|
263
268
|
flexDirection: 'row',
|
|
@@ -289,8 +294,7 @@ class DropDown extends React.Component {
|
|
|
289
294
|
const selectedItem = items.find(x => x.value === value);
|
|
290
295
|
const styles = this.getStyles();
|
|
291
296
|
const theme = (0, theme_1.getTheme)();
|
|
292
|
-
const filteredItems = this.
|
|
293
|
-
const visibleItems = searchable ? filteredItems : items;
|
|
297
|
+
const filteredItems = searchable ? this.filterItems() : items;
|
|
294
298
|
return (React.createElement(react_native_1.TouchableWithoutFeedback, { onPress: () => __awaiter(this, void 0, void 0, function* () {
|
|
295
299
|
if (onPress) {
|
|
296
300
|
const result = yield onPress();
|
|
@@ -322,10 +326,10 @@ class DropDown extends React.Component {
|
|
|
322
326
|
] },
|
|
323
327
|
this.shouldDisplaySearchField() && (React.createElement(react_native_1.View, { style: styles.searchContainer },
|
|
324
328
|
React.createElement(react_native_1.View, { style: styles.inputWrapper },
|
|
325
|
-
React.createElement(react_native_1.TextInput, { style: styles.searchInput, value: searchText, placeholder:
|
|
329
|
+
React.createElement(react_native_1.TextInput, { style: styles.searchInput, value: searchText, placeholder: searchable === null || searchable === void 0 ? void 0 : searchable.placeHolder, onChangeText: text => this.setState({ searchText: text }) }),
|
|
326
330
|
React.createElement(FontAwesome_1.default, { name: "search", size: 16, color: "gray", style: styles.searchIcon })))),
|
|
327
|
-
filteredItems.length > 0 ? (React.createElement(react_native_1.FlatList, { data:
|
|
328
|
-
return (React.createElement(DropDownItem, { nativeID: item.nativeID, first: index === 0, last: index ===
|
|
331
|
+
filteredItems.length > 0 ? (React.createElement(react_native_1.FlatList, { data: filteredItems, initialNumToRender: filteredItems.length, keyExtractor: item => item.value.toString(), renderItem: ({ item, index }) => {
|
|
332
|
+
return (React.createElement(DropDownItem, { nativeID: item.nativeID, first: index === 0, last: index === filteredItems.length - 1, label: item.label, value: item.value, onPress: this.handleItemPress, icon: item.icon, iconComponent: iconComponent }));
|
|
329
333
|
} })) : (React.createElement(react_native_1.View, { style: styles.emptyMessageContainer },
|
|
330
334
|
React.createElement(FontAwesome_1.default, { name: "warning", color: theme.warningColor, size: 24 }),
|
|
331
335
|
React.createElement(react_native_1.Text, { style: styles.modalItem }, emptyMessage)))))))));
|