rmc-cascader
Advanced tools
Comparing version 2.2.6 to 3.0.0
# History | ||
---- | ||
## 3.0.0 / 2016-09-07 | ||
- extract cascader from popup | ||
## 2.0.0 / 2016-06-16 | ||
- support react-native and typescript` | ||
- support react-native and typescript | ||
@@ -8,0 +13,0 @@ ## 0.2.5 / 2015-01-18 |
@@ -10,3 +10,3 @@ declare var _default: { | ||
onValueChange(index: any, selectNameValue: any): void; | ||
getNewValue(d: any, val: any): any; | ||
getValue(d: any, val: any): any; | ||
getColArray(): any[]; | ||
@@ -13,0 +13,0 @@ getChildrenTree(): any; |
@@ -11,4 +11,2 @@ 'use strict'; | ||
var _utils = require('./utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -19,3 +17,3 @@ | ||
return { | ||
cols: _utils.COLS | ||
cols: 3 | ||
}; | ||
@@ -25,3 +23,3 @@ }, | ||
return { | ||
value: this.getNewValue(this.props.data, this.props.defaultValue || this.props.value) | ||
value: this.getValue(this.props.data, this.props.defaultValue || this.props.value) | ||
}; | ||
@@ -32,3 +30,3 @@ }, | ||
this.setState({ | ||
value: this.getNewValue(nextProps.data, nextProps.value) | ||
value: this.getValue(nextProps.data, nextProps.value) | ||
}); | ||
@@ -57,4 +55,17 @@ } | ||
}, | ||
getNewValue: function getNewValue(d, val) { | ||
return (0, _utils.getDefaultValue)(d, val, this.props.cols); | ||
getValue: function getValue(d, val) { | ||
var data = d || this.props.data; | ||
var value = val || this.props.value || this.props.defaultValue; | ||
if (!value || !value.length) { | ||
value = []; | ||
for (var i = 0; i < this.props.cols; i++) { | ||
if (data && data.length) { | ||
value[i] = data[0].value; | ||
data = data[0].children; | ||
} else { | ||
value[i] = undefined; | ||
} | ||
} | ||
} | ||
return value; | ||
}, | ||
@@ -61,0 +72,0 @@ getColArray: function getColArray() { |
import * as React from 'react'; | ||
import { PopupPickerProps } from 'rmc-picker/lib/PopupPickerTypes'; | ||
import { CascaderProps, CascaderValue } from './CascaderTypes'; | ||
export interface PopupCascaderProps extends PopupPickerProps, CascaderProps { | ||
popupPrefixCls?: string; | ||
pickerRootNativeProps?: {}; | ||
rootNativeProps?: {}; | ||
pickerPrefixCls?: string; | ||
export interface PopupCascaderProps extends PopupPickerProps { | ||
cascader: React.ReactElement<CascaderProps>; | ||
visible?: boolean; | ||
mode?: string; | ||
onPickerChange?: (date: CascaderValue) => void; | ||
value?: CascaderValue; | ||
onChange?: (date: CascaderValue) => void; | ||
onVisibleChange?: (visible: boolean) => void; | ||
} | ||
export interface PopupCascaderState { | ||
pickerValue?: CascaderValue; | ||
visible?: boolean; | ||
} | ||
export default class PopupCascader extends React.Component<PopupCascaderProps, PopupCascaderState> { | ||
export default class PopupCascader extends React.Component<PopupCascaderProps, any> { | ||
cascader: any; | ||
static defaultProps: { | ||
popupPrefixCls: string; | ||
prefixCls: string; | ||
onVisibleChange: () => void; | ||
cols: number; | ||
onChange: () => void; | ||
onPickerChange: () => void; | ||
}; | ||
constructor(props: PopupCascaderProps); | ||
componentWillReceiveProps(nextProps: any): void; | ||
onPickerChange: (value: any) => void; | ||
onPickerChange: (pickerValue: any) => void; | ||
onOk: () => void; | ||
saveRef: (cascader: any) => void; | ||
setVisibleState(visible: any): void; | ||
getModal(): JSX.Element; | ||
fireVisibleChange: (visible: any) => void; | ||
render(): JSX.Element; | ||
} |
@@ -27,8 +27,2 @@ 'use strict'; | ||
var _Cascader = require('./Cascader'); | ||
var _Cascader2 = _interopRequireDefault(_Cascader); | ||
var _utils = require('./utils'); | ||
var _Popup = require('rmc-picker/lib/Popup'); | ||
@@ -42,12 +36,3 @@ | ||
var EXCLUDE_PROPS = { | ||
popupPrefixCls: 1, | ||
pickerRootNativeProps: 1, | ||
pickerPrefixCls: 1, | ||
visible: 1, | ||
mode: 1, | ||
onPickerChange: 1, | ||
onChange: 1, | ||
onVisibleChange: 1 | ||
}; | ||
function noop() {} | ||
@@ -62,20 +47,18 @@ var PopupCascader = function (_React$Component) { | ||
_this.onPickerChange = function (value) { | ||
// console.log('inner onPickerChange', value); | ||
_this.onPickerChange = function (pickerValue) { | ||
_this.setState({ | ||
pickerValue: value | ||
pickerValue: pickerValue | ||
}); | ||
_this.props.onPickerChange(value); | ||
if (_this.props.cascader.props.onChange) { | ||
_this.props.cascader.props.onChange(pickerValue); | ||
} | ||
}; | ||
_this.onOk = function () { | ||
var _this$props = _this.props; | ||
var value = _this$props.value; | ||
var cols = _this$props.cols; | ||
var data = _this$props.data; | ||
// console.log('inner onOk', this.state.pickerValue); | ||
_this.props.onChange((0, _utils.getDefaultValue)(data, _this.state.pickerValue || value, cols).filter(function (c) { | ||
_this.props.onChange(_this.cascader.getValue().filter(function (c) { | ||
return !!c; | ||
})); | ||
}; | ||
_this.saveRef = function (cascader) { | ||
_this.cascader = cascader; | ||
}; | ||
_this.fireVisibleChange = function (visible) { | ||
@@ -113,30 +96,10 @@ if (_this.state.visible !== visible) { | ||
PopupCascader.prototype.getModal = function getModal() { | ||
var _props = this.props; | ||
var data = _props.data; | ||
var cols = _props.cols; | ||
var prefixCls = _props.prefixCls; | ||
var pickerPrefixCls = _props.pickerPrefixCls; | ||
var value = _props.value; | ||
var pickerRootNativeProps = _props.pickerRootNativeProps; | ||
var extraProps = { | ||
data: data | ||
}; | ||
if (pickerPrefixCls) { | ||
extraProps.pickerPrefixCls = pickerPrefixCls; | ||
} | ||
if (prefixCls) { | ||
extraProps.prefixCls = prefixCls; | ||
} | ||
if (pickerRootNativeProps) { | ||
extraProps.rootNativeProps = pickerRootNativeProps; | ||
} | ||
return React.createElement(_Cascader2["default"], (0, _extends3["default"])({ value: this.state.pickerValue || value, cols: cols, onChange: this.onPickerChange }, extraProps)); | ||
}; | ||
PopupCascader.prototype.render = function render() { | ||
var props = (0, _utils.exclude)(this.props, EXCLUDE_PROPS); | ||
props.prefixCls = this.props.popupPrefixCls; | ||
return React.createElement(_Popup2["default"], (0, _extends3["default"])({}, props, { onVisibleChange: this.fireVisibleChange, onOk: this.onOk, content: this.getModal(), visible: this.state.visible })); | ||
var cascader = React.cloneElement(this.props.cascader, { | ||
value: this.state.pickerValue || this.props.value, | ||
onChange: this.onPickerChange, | ||
ref: this.saveRef, | ||
data: this.props.cascader.props.data | ||
}); | ||
return React.createElement(_Popup2["default"], (0, _extends3["default"])({}, this.props, { onVisibleChange: this.fireVisibleChange, onOk: this.onOk, content: cascader, visible: this.state.visible })); | ||
}; | ||
@@ -150,8 +113,6 @@ | ||
PopupCascader.defaultProps = { | ||
popupPrefixCls: 'rmc-picker-popup', | ||
onVisibleChange: _utils.noop, | ||
cols: _utils.COLS, | ||
onChange: _utils.noop, | ||
onPickerChange: _utils.noop | ||
prefixCls: 'rmc-picker-popup', | ||
onVisibleChange: noop, | ||
onChange: noop | ||
}; | ||
module.exports = exports['default']; |
{ | ||
"name": "rmc-cascader", | ||
"version": "2.2.6", | ||
"version": "3.0.0", | ||
"description": "m-cascader ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -76,3 +76,3 @@ # rmc-cascader | ||
### MCascader props | ||
### Cascader props | ||
@@ -95,9 +95,6 @@ | name | description | type | default | | ||
|className(web) | additional css class of modal node | String | '' | | ||
|prefixCls(web) | prefix class | String | 'rmc-cascader' | | ||
|pickerPrefixCls(web) | picker prefix class | String | 'rmc-picker' | | ||
|prefixCls(web) | prefix class | String | 'rmc-picker-popup' | | ||
|style(web) | additional style | object | {} | | ||
|data | The data of cascade | array | | | ||
|value | selected value | array | | | ||
|defaultValue | initial selected value | array | | | ||
|onPickerChange | | Function(value) | - | | ||
|cascader | React Cascader element | | | | ||
|onChange | exec on ok | Function(value) | | | ||
@@ -104,0 +101,0 @@ |onDismiss | exec on dismiss | function | | |
20230
18
392
124