diff --git a/LabelSelect/LabelSelectStyle.js b/LabelSelect/LabelSelectStyle.js index ee8f533..a6970be 100644 --- a/LabelSelect/LabelSelectStyle.js +++ b/LabelSelect/LabelSelectStyle.js @@ -43,7 +43,8 @@ export default StyleSheet.create({ labelText: { padding: 6, fontSize: 14, - lineHeight: 14 + lineHeight: 14, + maxWidth: 300 }, closeContainer: { padding: 8, @@ -86,19 +87,19 @@ export default StyleSheet.create({ height: height * 0.6 - 80 }, buttonView: { - height: 40, - backgroundColor: Color.main, borderBottomLeftRadius: 10, borderBottomRightRadius: 10, flexDirection: 'row', justifyContent: 'space-around' }, modalButton: { + height: 40, width: width * 0.3, paddingLeft: 20, paddingRight: 20, justifyContent: 'center', - alignItems: 'center' + alignItems: 'center', + backgroundColor: Color.main }, modalItem: { height: 50, @@ -110,7 +111,8 @@ export default StyleSheet.create({ borderBottomColor: '#bbb' }, modalText: { - fontSize: 16 + fontSize: 16, + width: width * 0.6 - 70 }, buttonText: { color: '#fff', diff --git a/LabelSelect/index.js b/LabelSelect/index.js index de58863..d9bbced 100644 --- a/LabelSelect/index.js +++ b/LabelSelect/index.js @@ -22,15 +22,20 @@ class LabelSelect extends Component { readOnly: PropTypes.bool, enable: PropTypes.bool, onConfirm: PropTypes.func, - enableAddBtn: PropTypes.bool + enableAddBtn: PropTypes.bool, + confirmText: PropTypes.string, + cancelText: PropTypes.string } static defaultProps = { style: {}, + customStyle: {}, title: ' ', enable: true, readOnly: false, onConfirm: () => {}, - enableAddBtn: true + enableAddBtn: true, + confirmText: 'Confirm', + cancelText: 'Cancel' } constructor(props) { super(props); @@ -69,7 +74,16 @@ class LabelSelect extends Component { else {this.selectedList.push(time);} } render() { - const {readOnly, enable, title, style, enableAddBtn} = this.props; + const { + readOnly, + enable, + title, + style, + enableAddBtn, + customStyle, + confirmText, + cancelText + } = this.props; let selectedLabels = React.Children.toArray(this.props.children) .filter(item => item.type === Label) .map((child, index) => { @@ -94,7 +108,7 @@ class LabelSelect extends Component { {this.openModal();}}> + onPress={this.openModal}> - + {title} {modalItems} - + - Cancel + + {cancelText} + - Confirm + activeOpacity={0.8} + onPress={this.confirmSelect}> + + {confirmText} + @@ -156,16 +174,18 @@ class Label extends Component { static defaultProps = { onCancel: () => {}, enable: true, - readOnly: false + readOnly: false, + customStyle: {} } constructor(props) { super(props); } render() { - const {enable, readOnly, onCancel} = this.props; + const {enable, readOnly, onCancel, customStyle} = this.props; return ( - {this.props.children} + {this.props.children} {enable && !readOnly && - {this.props.children} - - {this.isSelected && } - + + {this.props.children} + + + {this.isSelected && } + ); diff --git a/README.md b/README.md index 96362ec..81894b3 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ import LabelSelect from 'react-native-label-select'; style={yourStyle} onConfirm={(list) => {...}}> - selected ItemA @@ -49,7 +49,9 @@ import LabelSelect from 'react-native-label-select'; | enable | true | bool | is the component interactive | | enableAddBtn | true | bool | whether to show the add button | | onConfirm | - | function | Triggered when the confirm button of modal is pressed with the newly selected items list passed as the only argument | - +| confirmText | - | string | Text of confirm button. | +| cancelText | - | string | Text of cancelText button. | +| customStyle | - | object | You can customize styles of `modal` / `buttonView` / `confirmButton` / `confirmText` / `cancelButton` / `cancelText` by `customStyle. | **LabelSelect.Label** @@ -57,7 +59,8 @@ import LabelSelect from 'react-native-label-select'; | Prop | Default | Type | Description | | --- | --- | --- | --- | | onCancel | - | function | Triggered when the close button of Label is pressed. | -|data| -| any | Data that bind to the Label | +| data | - | any | Data that bind to the Label | +| customStyle | - | object | You can customize styles of `text` by `customStyle. | **LabelSelect.ModalItem** @@ -76,11 +79,12 @@ import LabelSelect from 'react-native-label-select'; | --- | --- | --- | | openModal | - | Open select modal | | cancelSelect | - | Close select modal. Also triggered when the cancel button of modal being pressed. | +| customStyle | - | object | You can customize styles of `modalText` / `outerCircle` / `innerCircle` by `customStyle. | Use `ref` property as a hook to invoke internal methods. ```html -... +... ``` ```js diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index 13d2bf8..f722947 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -36,11 +36,17 @@ exports[`test renders a modal item 1`] = ` C @@ -58,6 +64,7 @@ exports[`test renders a modal item 1`] = ` "width": 20, }, Object {}, + Object {}, ] } /> @@ -99,17 +106,21 @@ exports[`test renders disabled LabelSelect 1`] = ` A @@ -137,17 +148,21 @@ exports[`test renders disabled LabelSelect 1`] = ` B @@ -194,13 +209,16 @@ exports[`test renders disabled LabelSelect 1`] = ` style={Object {}}> - - Cancel - + + Cancel + + + - - Confirm - + + Confirm + + @@ -373,15 +416,19 @@ exports[`test renders enabled LabelSelect 1`] = ` A @@ -449,15 +496,19 @@ exports[`test renders enabled LabelSelect 1`] = ` B @@ -597,13 +648,16 @@ exports[`test renders enabled LabelSelect 1`] = ` style={Object {}}> - - Cancel - + + Cancel + + + - - Confirm - + + Confirm + + @@ -776,15 +855,19 @@ exports[`test renders readOnly LabelSelect 1`] = ` A @@ -810,15 +893,19 @@ exports[`test renders readOnly LabelSelect 1`] = ` B @@ -865,13 +952,16 @@ exports[`test renders readOnly LabelSelect 1`] = ` style={Object {}}> - - Cancel - + + Cancel + + + - - Confirm - + + Confirm + + diff --git a/__tests__/test.js b/__tests__/test.js index b0731f9..dc46a00 100644 --- a/__tests__/test.js +++ b/__tests__/test.js @@ -100,8 +100,10 @@ it('interact with modal', () => { expect(arr[0]).toEqual(item); expect(tree.state('isModalVisible')).toEqual(false); select.openModal(); + expect(tree.state('isModalVisible')).toEqual(true); select.cancelSelect(); expect(tree.state('isModalVisible')).toEqual(false); + select.confirmSelect(); }); it('selecte a item', () => { diff --git a/package.json b/package.json index 1d45753..ad7fb1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-label-select", - "version": "1.0.7", + "version": "1.1.0", "description": "A label select component for React Native apps", "keywords": [ "label",