secullum-react-native-ui 4.15.1-beta.0 → 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,15 +32,17 @@ 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
- filteredItems: () => {
39
+ filterItems: () => {
38
40
  label: string;
39
41
  value: any;
40
42
  icon?: string | undefined;
41
43
  nativeID?: string | undefined;
42
44
  }[];
45
+ shouldDisplaySearchField: () => boolean | undefined;
43
46
  renderClosedDropDown: (item: any, inputStyle: any) => JSX.Element | null;
44
47
  getStyles: () => any;
45
48
  render(): JSX.Element;
@@ -105,11 +105,15 @@ class DropDown extends React.Component {
105
105
  this.setState({ modalOpen: false });
106
106
  onChange(value);
107
107
  };
108
- this.filteredItems = () => {
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
+ this.shouldDisplaySearchField = () => {
114
+ const { items, searchable, minItemsToShowSearch } = this.props;
115
+ return items.length >= minItemsToShowSearch && searchable;
116
+ };
113
117
  this.renderClosedDropDown = (item, inputStyle) => {
114
118
  const { iconComponent } = this.props;
115
119
  const theme = (0, theme_1.getTheme)();
@@ -148,7 +152,7 @@ class DropDown extends React.Component {
148
152
  };
149
153
  this.getStyles = () => {
150
154
  const theme = (0, theme_1.getTheme)();
151
- const { icon, arrowColor } = this.props;
155
+ const { icon, arrowColor, minItemsToShowSearch } = this.props;
152
156
  const styles = react_native_1.StyleSheet.create({
153
157
  container: Object.assign({ paddingHorizontal: 16, paddingVertical: 8, borderWidth: 1, borderColor: theme.borderColor1, borderRadius: 3 }, (icon
154
158
  ? {
@@ -192,7 +196,10 @@ class DropDown extends React.Component {
192
196
  right: 16
193
197
  },
194
198
  modalOverlay: {
195
- justifyContent: this.props.items.length >= 10 && this.props.searchable ? 'flex-start' : 'center'
199
+ justifyContent: this.props.items.length >= minItemsToShowSearch &&
200
+ this.props.searchable
201
+ ? 'flex-start'
202
+ : 'center'
196
203
  },
197
204
  modalContainer: {
198
205
  maxHeight: '95%',
@@ -253,7 +260,7 @@ class DropDown extends React.Component {
253
260
  searchLabel: {
254
261
  fontSize: 16,
255
262
  marginLeft: 16,
256
- fontFamily: theme.fontFamily1,
263
+ fontFamily: theme.fontFamily1
257
264
  },
258
265
  inputWrapper: {
259
266
  flexDirection: 'row',
@@ -285,7 +292,8 @@ class DropDown extends React.Component {
285
292
  const selectedItem = items.find(x => x.value === value);
286
293
  const styles = this.getStyles();
287
294
  const theme = (0, theme_1.getTheme)();
288
- const filteredItems = items.filter(item => item.label.toLowerCase().includes(searchText.toLowerCase()));
295
+ const filteredItems = this.filterItems();
296
+ const visibleItems = searchable ? filteredItems : items;
289
297
  return (React.createElement(react_native_1.TouchableWithoutFeedback, { onPress: () => __awaiter(this, void 0, void 0, function* () {
290
298
  if (onPress) {
291
299
  const result = yield onPress();
@@ -315,19 +323,12 @@ class DropDown extends React.Component {
315
323
  justifyContent: 'center'
316
324
  }
317
325
  ] },
318
- items.length >= 10 && searchable && (React.createElement(react_native_1.View, { style: styles.searchContainer }, React.createElement(react_native_1.View, { style: styles.inputWrapper }, React.createElement(react_native_1.TextInput, {
319
- style: styles.searchInput,
320
- value: searchText,
321
- placeholder: 'Buscar',
322
- onChangeText: (text) => this.setState({ searchText: text })
323
- }), React.createElement(FontAwesome_1.default, {
324
- name: "search",
325
- size: 16,
326
- color: "gray",
327
- style: styles.searchIcon
328
- })))),
329
- filteredItems.length > 0 ? (React.createElement(react_native_1.FlatList, { data: searchable ? filteredItems : items, initialNumToRender: filteredItems.length, keyExtractor: item => item.value.toString(), renderItem: ({ item, index }) => {
330
- return (React.createElement(DropDownItem, { nativeID: item.nativeID, first: index === 0, last: index === (searchable ? filteredItems : items).length - 1, label: item.label, value: item.value, onPress: this.handleItemPress, icon: item.icon, iconComponent: iconComponent }));
326
+ this.shouldDisplaySearchField() && (React.createElement(react_native_1.View, { style: styles.searchContainer },
327
+ React.createElement(react_native_1.View, { style: styles.inputWrapper },
328
+ React.createElement(react_native_1.TextInput, { style: styles.searchInput, value: searchText, placeholder: "Buscar", onChangeText: text => this.setState({ searchText: text }) }),
329
+ React.createElement(FontAwesome_1.default, { name: "search", size: 16, color: "gray", style: styles.searchIcon })))),
330
+ filteredItems.length > 0 ? (React.createElement(react_native_1.FlatList, { data: visibleItems, initialNumToRender: visibleItems.length, keyExtractor: item => item.value.toString(), renderItem: ({ item, index }) => {
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 }));
331
332
  } })) : (React.createElement(react_native_1.View, { style: styles.emptyMessageContainer },
332
333
  React.createElement(FontAwesome_1.default, { name: "warning", color: theme.warningColor, size: 24 }),
333
334
  React.createElement(react_native_1.Text, { style: styles.modalItem }, emptyMessage)))))))));
@@ -335,5 +336,6 @@ class DropDown extends React.Component {
335
336
  }
336
337
  exports.DropDown = DropDown;
337
338
  DropDown.defaultProps = {
338
- emptyMessage: 'Não há registros cadastrados'
339
+ emptyMessage: 'Não há registros cadastrados',
340
+ minItemsToShowSearch: 10
339
341
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secullum-react-native-ui",
3
- "version": "4.15.1-beta.0",
3
+ "version": "4.15.1-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "files": [