diff --git a/README.md b/README.md index c906fa8..193843a 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,17 @@ class CreateNewAppointment extends Component { onRemoveItem={data => { this.setState({ data }) }} + tagStyle={{ + selectedTagArea: { + backgroundColor: 'black' + }, + selectedTagText: { + color: 'white' + }, + icon: { + color: 'red' + } + }} /> ) @@ -87,5 +98,6 @@ class CreateNewAppointment extends Component { | **selectedTitleStyle** | _Object_ | none | Set custom style for display selected title text | | **buttonTextStyle** | _Object_ | none | Set custom button text style | | **buttonStyle** | _Object_ | none | Set custom button style | +| **tagStyle** | _Object_ | none | Set custom styles for tags | **MIT Licensed** diff --git a/index.js b/index.js index 5c94a58..d53c6b0 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,13 @@ class Select2 extends Component { colorTheme: '#16a45f', buttonTextStyle: {}, buttonStyle: {}, - showSearchBox: true + showSearchBox: true, + tagStyle: {}, + showLine: true, + popupTitleStyle: {}, + inputStyle: {}, + listBlockStyle: {}, + showCheckbox: true } state = { show: false, @@ -29,7 +35,7 @@ class Select2 extends Component { data: [], keyword: '' } - animatedHeight = new Animated.Value(INIT_HEIGHT); + animatedHeight = new Animated.Value(this.props.windowHeight || INIT_HEIGHT); componentDidMount() { this.init(); @@ -81,6 +87,7 @@ class Select2 extends Component { } onItemSelected = (item, isSelectSingle) => { + let { showCheckbox, onSelect } = this.props let selectedItem = []; let { data } = this.state; item.checked = !item.checked; @@ -95,22 +102,29 @@ class Select2 extends Component { if (item.checked) selectedItem.push(item); }) this.setState({ data, selectedItem }); + + if (!showCheckbox) { + onSelect && onSelect([item.id], [item]); + this.setState({ show: false, keyword: '', preSelectedItem: this.state.selectedItem }); + } } keyExtractor = (item, idx) => idx.toString(); renderItem = ({ item, idx }) => { - let { colorTheme, isSelectSingle } = this.props; + let { colorTheme, isSelectSingle, showCheckbox } = this.props; return ( this.onItemSelected(item, isSelectSingle)} activeOpacity={0.7} - style={styles.itemWrapper}> - + style={[styles.itemWrapper, item.containerStyle]}> + {item.name} - + } ); } @@ -129,7 +143,7 @@ class Select2 extends Component { let { style, modalStyle, title, onSelect, onRemoveItem, popupTitle, colorTheme, isSelectSingle, cancelButtonText, selectButtonText, searchPlaceHolderText, - selectedTitleStyle, buttonTextStyle, buttonStyle, showSearchBox + selectedTitleStyle, buttonTextStyle, buttonStyle, showSearchBox, tagStyle, showLine, popupTitleStyle, inputStyle, listBlockStyle, showCheckbox } = this.props; let { show, selectedItem, preSelectedItem } = this.state; return ( @@ -150,44 +164,47 @@ class Select2 extends Component { isVisible={show}> - + {popupTitle || title} - + { showLine && } { showSearchBox ? this.setState({ keyword })} onFocus={() => { Animated.spring(this.animatedHeight, { toValue: INIT_HEIGHT + (Platform.OS === 'ios' ? height * 0.2 : 0), - friction: 7 + friction: 7, + useNativeDriver: false }).start(); }} onBlur={() => { Animated.spring(this.animatedHeight, { toValue: INIT_HEIGHT, - friction: 7 + friction: 7, + useNativeDriver: false }).start(); }} /> : null } - + { showCheckbox && +