secullum-react-native-ui 4.15.1-beta.1 → 4.15.1-beta.2
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.
|
@@ -23,6 +23,7 @@ export interface DropDownProperties {
|
|
|
23
23
|
icon?: string | undefined;
|
|
24
24
|
arrowColor?: string | undefined;
|
|
25
25
|
searchable?: boolean;
|
|
26
|
+
minItemsToShowSearch: number;
|
|
26
27
|
}
|
|
27
28
|
export interface DropDownState {
|
|
28
29
|
modalOpen: boolean;
|
|
@@ -31,10 +32,11 @@ export interface DropDownState {
|
|
|
31
32
|
export declare class DropDown extends React.Component<DropDownProperties, DropDownState> {
|
|
32
33
|
static defaultProps: {
|
|
33
34
|
emptyMessage: string;
|
|
35
|
+
minItemsToShowSearch: number;
|
|
34
36
|
};
|
|
35
37
|
state: DropDownState;
|
|
36
38
|
handleItemPress: (value: any) => void;
|
|
37
|
-
|
|
39
|
+
filterItems: () => {
|
|
38
40
|
label: string;
|
|
39
41
|
value: any;
|
|
40
42
|
icon?: string | undefined;
|
|
@@ -105,14 +105,14 @@ 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
|
-
const { items, searchable } = this.props;
|
|
115
|
-
return items.length >=
|
|
114
|
+
const { items, searchable, minItemsToShowSearch } = this.props;
|
|
115
|
+
return items.length >= minItemsToShowSearch && searchable;
|
|
116
116
|
};
|
|
117
117
|
this.renderClosedDropDown = (item, inputStyle) => {
|
|
118
118
|
const { iconComponent } = this.props;
|
|
@@ -152,7 +152,7 @@ class DropDown extends React.Component {
|
|
|
152
152
|
};
|
|
153
153
|
this.getStyles = () => {
|
|
154
154
|
const theme = (0, theme_1.getTheme)();
|
|
155
|
-
const { icon, arrowColor } = this.props;
|
|
155
|
+
const { icon, arrowColor, minItemsToShowSearch } = this.props;
|
|
156
156
|
const styles = react_native_1.StyleSheet.create({
|
|
157
157
|
container: Object.assign({ paddingHorizontal: 16, paddingVertical: 8, borderWidth: 1, borderColor: theme.borderColor1, borderRadius: 3 }, (icon
|
|
158
158
|
? {
|
|
@@ -196,7 +196,10 @@ class DropDown extends React.Component {
|
|
|
196
196
|
right: 16
|
|
197
197
|
},
|
|
198
198
|
modalOverlay: {
|
|
199
|
-
justifyContent: this.
|
|
199
|
+
justifyContent: this.props.items.length >= minItemsToShowSearch &&
|
|
200
|
+
this.props.searchable
|
|
201
|
+
? 'flex-start'
|
|
202
|
+
: 'center'
|
|
200
203
|
},
|
|
201
204
|
modalContainer: {
|
|
202
205
|
maxHeight: '95%',
|
|
@@ -257,7 +260,7 @@ class DropDown extends React.Component {
|
|
|
257
260
|
searchLabel: {
|
|
258
261
|
fontSize: 16,
|
|
259
262
|
marginLeft: 16,
|
|
260
|
-
fontFamily: theme.fontFamily1
|
|
263
|
+
fontFamily: theme.fontFamily1
|
|
261
264
|
},
|
|
262
265
|
inputWrapper: {
|
|
263
266
|
flexDirection: 'row',
|
|
@@ -289,7 +292,7 @@ class DropDown extends React.Component {
|
|
|
289
292
|
const selectedItem = items.find(x => x.value === value);
|
|
290
293
|
const styles = this.getStyles();
|
|
291
294
|
const theme = (0, theme_1.getTheme)();
|
|
292
|
-
const filteredItems = this.
|
|
295
|
+
const filteredItems = this.filterItems();
|
|
293
296
|
const visibleItems = searchable ? filteredItems : items;
|
|
294
297
|
return (React.createElement(react_native_1.TouchableWithoutFeedback, { onPress: () => __awaiter(this, void 0, void 0, function* () {
|
|
295
298
|
if (onPress) {
|
|
@@ -322,9 +325,9 @@ class DropDown extends React.Component {
|
|
|
322
325
|
] },
|
|
323
326
|
this.shouldDisplaySearchField() && (React.createElement(react_native_1.View, { style: styles.searchContainer },
|
|
324
327
|
React.createElement(react_native_1.View, { style: styles.inputWrapper },
|
|
325
|
-
React.createElement(react_native_1.TextInput, { style: styles.searchInput, value: searchText, placeholder: "Buscar", onChangeText:
|
|
328
|
+
React.createElement(react_native_1.TextInput, { style: styles.searchInput, value: searchText, placeholder: "Buscar", onChangeText: text => this.setState({ searchText: text }) }),
|
|
326
329
|
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: visibleItems, initialNumToRender:
|
|
330
|
+
filteredItems.length > 0 ? (React.createElement(react_native_1.FlatList, { data: visibleItems, initialNumToRender: visibleItems.length, keyExtractor: item => item.value.toString(), renderItem: ({ item, index }) => {
|
|
328
331
|
return (React.createElement(DropDownItem, { nativeID: item.nativeID, first: index === 0, last: index === visibleItems.length - 1, label: item.label, value: item.value, onPress: this.handleItemPress, icon: item.icon, iconComponent: iconComponent }));
|
|
329
332
|
} })) : (React.createElement(react_native_1.View, { style: styles.emptyMessageContainer },
|
|
330
333
|
React.createElement(FontAwesome_1.default, { name: "warning", color: theme.warningColor, size: 24 }),
|
|
@@ -333,5 +336,6 @@ class DropDown extends React.Component {
|
|
|
333
336
|
}
|
|
334
337
|
exports.DropDown = DropDown;
|
|
335
338
|
DropDown.defaultProps = {
|
|
336
|
-
emptyMessage: 'Não há registros cadastrados'
|
|
339
|
+
emptyMessage: 'Não há registros cadastrados',
|
|
340
|
+
minItemsToShowSearch: 10
|
|
337
341
|
};
|