rmc-picker
Advanced tools
Comparing version 3.7.1 to 3.8.0
@@ -50,5 +50,5 @@ 'use strict'; | ||
children = props.children, | ||
selectedValue = props.selectedValue, | ||
style = props.style; | ||
var selectedValue = this.getValue(); | ||
var colElements = children.map(function (col, i) { | ||
@@ -55,0 +55,0 @@ return _react2["default"].createElement( |
@@ -45,5 +45,5 @@ 'use strict'; | ||
pure = props.pure, | ||
children = props.children, | ||
selectedValue = props.selectedValue; | ||
children = props.children; | ||
var selectedValue = this.getValue(); | ||
var colElements = children.map(function (col, i) { | ||
@@ -50,0 +50,0 @@ return _react2["default"].createElement( |
@@ -5,8 +5,8 @@ declare var _default: { | ||
pickerPrefixCls: string; | ||
cols: never[]; | ||
onValueChange(): void; | ||
disabled: boolean; | ||
}; | ||
getValue(): any; | ||
onValueChange(i: any, v: any): void; | ||
}; | ||
export default _default; |
@@ -11,3 +11,2 @@ 'use strict'; | ||
pickerPrefixCls: 'rmc-picker', | ||
cols: [], | ||
onValueChange: function onValueChange() {}, | ||
@@ -18,4 +17,13 @@ | ||
}, | ||
getValue: function getValue() { | ||
if (this.props.selectedValue) { | ||
return this.props.selectedValue; | ||
} else { | ||
return this.props.children.map(function (c) { | ||
return c.props.children[0].value; | ||
}); | ||
} | ||
}, | ||
onValueChange: function onValueChange(i, v) { | ||
var value = this.props.selectedValue.concat(); | ||
var value = this.getValue().concat(); | ||
value[i] = v; | ||
@@ -22,0 +30,0 @@ this.props.onValueChange(value, i); |
@@ -34,2 +34,5 @@ 'use strict'; | ||
}, | ||
getValue: function getValue() { | ||
return this.props.selectedValue || this.props.children && this.props.children[0] && this.props.children[0].value; | ||
}, | ||
shouldComponentUpdate: function shouldComponentUpdate(nextProps) { | ||
@@ -36,0 +39,0 @@ return this.props.selectedValue !== nextProps.selectedValue || !(0, _isChildrenEqual2["default"])(this.props.children, nextProps.children, this.props.pure); |
@@ -119,2 +119,5 @@ 'use strict'; | ||
}, | ||
getValue: function getValue() { | ||
return this.props.selectedValue || this.props.children && this.props.children[0] && this.props.children[0].value; | ||
}, | ||
toChildrenArray: function toChildrenArray(children) { | ||
@@ -121,0 +124,0 @@ return children; |
@@ -74,3 +74,3 @@ 'use strict'; | ||
), | ||
props.content | ||
this.getContent() | ||
); | ||
@@ -77,0 +77,0 @@ }, |
@@ -76,3 +76,3 @@ 'use strict'; | ||
), | ||
this.props.content | ||
this.getContent() | ||
) | ||
@@ -79,0 +79,0 @@ ); |
@@ -5,2 +5,4 @@ declare var _default: { | ||
okText: string; | ||
pickerValueProp: string; | ||
pickerValueChangeProp: string; | ||
dismissText: string; | ||
@@ -12,5 +14,8 @@ title: string; | ||
getInitialState(): { | ||
pickerValue: null; | ||
visible: any; | ||
}; | ||
componentWillReceiveProps(nextProps: any): void; | ||
onPickerChange(pickerValue: any): void; | ||
saveRef(picker: any): void; | ||
setVisibleState(visible: any): void; | ||
@@ -21,2 +26,3 @@ fireVisibleChange(visible: any): void; | ||
onOk(): void; | ||
getContent(): any; | ||
onDismiss(): void; | ||
@@ -23,0 +29,0 @@ hide(): void; |
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); | ||
var _defineProperty3 = _interopRequireDefault(_defineProperty2); | ||
var _react = require('react'); | ||
@@ -20,2 +24,4 @@ | ||
okText: 'Ok', | ||
pickerValueProp: 'selectedValue', | ||
pickerValueChangeProp: 'onValueChange', | ||
dismissText: 'Dismiss', | ||
@@ -29,2 +35,3 @@ title: '', | ||
return { | ||
pickerValue: null, | ||
visible: this.props.visible || false | ||
@@ -38,2 +45,15 @@ }; | ||
}, | ||
onPickerChange: function onPickerChange(pickerValue) { | ||
if (this.state.pickerValue !== pickerValue) { | ||
this.setState({ | ||
pickerValue: pickerValue | ||
}); | ||
if (this.picker && this.picker.props[this.props.pickerValueChangeProp]) { | ||
this.picker.props[this.props.pickerValueChangeProp](pickerValue); | ||
} | ||
} | ||
}, | ||
saveRef: function saveRef(picker) { | ||
this.picker = picker; | ||
}, | ||
setVisibleState: function setVisibleState(visible) { | ||
@@ -43,2 +63,7 @@ this.setState({ | ||
}); | ||
if (!visible) { | ||
this.setState({ | ||
pickerValue: null | ||
}); | ||
} | ||
}, | ||
@@ -84,5 +109,14 @@ fireVisibleChange: function fireVisibleChange(visible) { | ||
onOk: function onOk() { | ||
this.props.onOk(); | ||
this.props.onOk(this.picker && this.picker.getValue()); | ||
this.fireVisibleChange(false); | ||
}, | ||
getContent: function getContent() { | ||
if (this.props.picker) { | ||
var _React$cloneElement; | ||
return _react2["default"].cloneElement(this.props.picker, (_React$cloneElement = {}, (0, _defineProperty3["default"])(_React$cloneElement, this.props.pickerValueProp, this.state.pickerValue || this.props.value), (0, _defineProperty3["default"])(_React$cloneElement, this.props.pickerValueChangeProp, this.onPickerChange), (0, _defineProperty3["default"])(_React$cloneElement, 'ref', this.saveRef), _React$cloneElement)); | ||
} else { | ||
return this.props.content; | ||
} | ||
}, | ||
onDismiss: function onDismiss() { | ||
@@ -89,0 +123,0 @@ this.props.onDismiss(); |
/// <reference types="react" /> | ||
import React from 'react'; | ||
export interface PopupPickerProps { | ||
picker?: any; | ||
value?: any; | ||
triggerType?: string; | ||
@@ -27,2 +29,4 @@ WrapComponent?: any; | ||
className?: string; | ||
pickerValueProp?: string; | ||
pickerValueChangeProp?: string; | ||
/** web only */ | ||
@@ -33,4 +37,1 @@ transitionName?: string; | ||
} | ||
export interface PopupPickerState { | ||
visible: boolean; | ||
} |
{ | ||
"name": "rmc-picker", | ||
"version": "3.7.1", | ||
"version": "3.8.0", | ||
"description": "React Mobile Picker Component(web and react-native)", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
50451
1349