refactor to typescript

This commit is contained in:
yiminghe 2016-06-22 13:18:43 +08:00
parent 2be285d236
commit 9a0d751f94
162 changed files with 318 additions and 264 deletions

2
.gitignore vendored
View File

@ -27,3 +27,5 @@ dist
elasticsearch-* elasticsearch-*
config/base.yaml config/base.yaml
typings typings
components/**/*.js
components/**/*.jsx

View File

@ -0,0 +1,12 @@
export default function splitObject(obj, parts) {
let left = {};
let right = {};
Object.keys(obj).forEach((k)=> {
if (parts.indexOf(k) !== -1) {
left[k] = obj[k];
} else {
right = obj[k];
}
});
return [left, right];
}

View File

@ -1,5 +1,5 @@
import React from 'react'; import * as React from 'react';
import ReactDOM from 'react-dom'; import * as ReactDOM from 'react-dom';
import addEventListener from 'rc-util/lib/Dom/addEventListener'; import addEventListener from 'rc-util/lib/Dom/addEventListener';
import classNames from 'classnames'; import classNames from 'classnames';
import warning from 'warning'; import warning from 'warning';
@ -33,7 +33,17 @@ function getOffset(element) {
}; };
} }
export default class Affix extends React.Component { // Affix
export interface AffixProps {
/**
*
*/
offsetTop?:number,
offsetBottom?:number,
style?:React.CSSProperties
}
export default class Affix extends React.Component<AffixProps, any> {
static propTypes = { static propTypes = {
offsetTop: React.PropTypes.number, offsetTop: React.PropTypes.number,
offsetBottom: React.PropTypes.number, offsetBottom: React.PropTypes.number,

View File

@ -1,6 +1,7 @@
import React, { createElement } from 'react'; import React, {createElement} from 'react';
import { findDOMNode } from 'react-dom'; import {findDOMNode} from 'react-dom';
import isCssAnimationSupported from '../_util/isCssAnimationSupported'; import isCssAnimationSupported from '../_util/isCssAnimationSupported';
import assign from 'object-assign';
function getNumberArray(num) { function getNumberArray(num) {
return num ? return num ?
@ -15,7 +16,8 @@ export default class ScrollNumber extends React.Component {
prefixCls: 'ant-scroll-number', prefixCls: 'ant-scroll-number',
count: null, count: null,
component: 'sup', component: 'sup',
onAnimated() {}, onAnimated() {
},
height: 18, height: 18,
} }
@ -122,10 +124,9 @@ export default class ScrollNumber extends React.Component {
} }
render() { render() {
const props = { const props = assign({}, this.props, {
...this.props,
className: `${this.props.prefixCls} ${this.props.className}`, className: `${this.props.prefixCls} ${this.props.className}`,
}; });
return createElement( return createElement(
this.props.component, this.props.component,
props, props,

View File

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import splitObject from '../_util/splitObject';
export default class BreadcrumbItem extends React.Component { export default class BreadcrumbItem extends React.Component {
static defaultProps = { static defaultProps = {
@ -16,7 +17,7 @@ export default class BreadcrumbItem extends React.Component {
} }
render() { render() {
const { prefixCls, separator, children, ...restProps } = this.props; const [{prefixCls, separator, children},restProps] = splitObject(this.props, ['prefixCls', 'separator', 'children']);
let link; let link;
if ('href' in this.props) { if ('href' in this.props) {
link = <a className={`${prefixCls}-link`} {...restProps}>{children}</a>; link = <a className={`${prefixCls}-link`} {...restProps}>{children}</a>;

View File

@ -1,10 +1,11 @@
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import splitObject from '../_util/splitObject';
const prefix = 'ant-btn-group-'; const prefix = 'ant-btn-group-';
export default function ButtonGroup(props) { export default function ButtonGroup(props) {
const { size, className, ...others } = props; const [{size, className},others] = splitObject(props, ['size', 'className']);
// large => lg // large => lg
// small => sm // small => sm

View File

@ -2,7 +2,7 @@ import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { findDOMNode } from 'react-dom'; import { findDOMNode } from 'react-dom';
import Icon from '../icon'; import Icon from '../icon';
import splitObject from '../_util/splitObject';
const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/; const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/;
const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar); const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar);
function isString(str) { function isString(str) {
@ -76,7 +76,8 @@ export default class Button extends React.Component {
render() { render() {
const props = this.props; const props = this.props;
const { type, shape, size, className, htmlType, children, icon, loading, prefixCls, ...others } = props; const [{type, shape, size, className, htmlType, children, icon, loading, prefixCls}, others] = splitObject(props,
['type', 'shape','size', 'className','htmlType', 'children','icon','loading','prefixCls']);
// large => lg // large => lg
// small => sm // small => sm

View File

@ -4,6 +4,7 @@ import defaultLocale from './locale/zh_CN';
import FullCalendar from 'rc-calendar/lib/FullCalendar'; import FullCalendar from 'rc-calendar/lib/FullCalendar';
import { PREFIX_CLS } from './Constants'; import { PREFIX_CLS } from './Constants';
import Header from './Header'; import Header from './Header';
import assign from 'object-assign';
function noop() { return null; } function noop() { return null; }
@ -69,8 +70,8 @@ export default class Calendar extends React.Component {
locale = context.antLocale.Calendar; locale = context.antLocale.Calendar;
} }
// 统一合并为完整的 Locale // 统一合并为完整的 Locale
const result = { ...locale, ...props.locale }; const result = assign({}, locale, props.locale);
result.lang = { ...locale.lang, ...props.locale.lang }; result.lang = assign({}, locale.lang,props.locale.lang);
return result; return result;
} }

View File

@ -1,9 +1,13 @@
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import splitObject from '../_util/splitObject';
export default props => { export default props => {
let { prefixCls = 'ant-card', className, children, extra, bodyStyle, const [{
title, loading, bordered = true, ...other } = props; prefixCls = 'ant-card', className, extra, bodyStyle,
title, loading, bordered = true
}, others] = splitObject(props,
['prefixCls', 'className', 'children', 'extra', 'bodyStyle', 'title', 'loading', 'bordered']);
let children = props.children;
const classString = classNames({ const classString = classNames({
[prefixCls]: true, [prefixCls]: true,
[className]: !!className, [className]: !!className,
@ -30,7 +34,7 @@ export default props => {
) : null; ) : null;
return ( return (
<div {...other} className={classString}> <div {...others} className={classString}>
{head} {head}
{extra ? <div className={`${prefixCls}-extra`}>{extra}</div> : null} {extra ? <div className={`${prefixCls}-extra`}>{extra}</div> : null}
<div className={`${prefixCls}-body`} style={bodyStyle}>{children}</div> <div className={`${prefixCls}-body`} style={bodyStyle}>{children}</div>

View File

@ -1,5 +1,6 @@
// matchMedia polyfill for // matchMedia polyfill for
// https://github.com/WickyNilliams/enquire.js/issues/82 // https://github.com/WickyNilliams/enquire.js/issues/82
import assign from 'object-assign';
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
const matchMediaPolyfill = function matchMediaPolyfill() { const matchMediaPolyfill = function matchMediaPolyfill() {
return { return {
@ -23,7 +24,7 @@ export default class Carousel extends React.Component {
} }
render() { render() {
let props = { ...this.props }; let props = assign({}, this.props);
if (props.effect === 'fade') { if (props.effect === 'fade') {
props.fade = true; props.fade = true;

View File

@ -4,6 +4,7 @@ import Input from '../input';
import Icon from '../icon'; import Icon from '../icon';
import arrayTreeFilter from 'array-tree-filter'; import arrayTreeFilter from 'array-tree-filter';
import classNames from 'classnames'; import classNames from 'classnames';
import splitObject from '../_util/splitObject';
export default class Cascader extends React.Component { export default class Cascader extends React.Component {
static defaultProps = { static defaultProps = {
@ -71,8 +72,10 @@ export default class Cascader extends React.Component {
render() { render() {
const props = this.props; const props = this.props;
const { prefixCls, children, placeholder, size, disabled, const [{prefixCls, children, placeholder, size, disabled,
className, style, allowClear, ...otherProps } = props; className, style, allowClear}, others] = splitObject(props,
['prefixCls', 'children','placeholder', 'size','disabled', 'className','style','allowClear']);
const sizeCls = classNames({ const sizeCls = classNames({
'ant-input-lg': size === 'large', 'ant-input-lg': size === 'large',
'ant-input-sm': size === 'small', 'ant-input-sm': size === 'small',
@ -93,7 +96,7 @@ export default class Cascader extends React.Component {
}); });
// Fix bug of https://github.com/facebook/react/pull/5004 // Fix bug of https://github.com/facebook/react/pull/5004
delete otherProps.onChange; delete others.onChange;
return ( return (
<RcCascader {...props} <RcCascader {...props}
@ -107,7 +110,7 @@ export default class Cascader extends React.Component {
style={style} style={style}
className={pickerCls} className={pickerCls}
> >
<Input {...otherProps} <Input {...others}
placeholder={this.state.value && this.state.value.length > 0 ? null : placeholder} placeholder={this.state.value && this.state.value.length > 0 ? null : placeholder}
className={`${prefixCls}-input ant-input ${sizeCls}`} className={`${prefixCls}-input ant-input ${sizeCls}`}
value={null} value={null}

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import Checkbox from './index'; import Checkbox from './index';
import PureRenderMixin from 'react-addons-pure-render-mixin'; import PureRenderMixin from 'react-addons-pure-render-mixin';
import assign from 'object-assign';
export default class CheckboxGroup extends React.Component { export default class CheckboxGroup extends React.Component {
static defaultProps = { static defaultProps = {
options: [], options: [],

View File

@ -3,7 +3,7 @@ import React from 'react';
import CheckboxGroup from './Group'; import CheckboxGroup from './Group';
import classNames from 'classnames'; import classNames from 'classnames';
import PureRenderMixin from 'react-addons-pure-render-mixin'; import PureRenderMixin from 'react-addons-pure-render-mixin';
import splitObject from '../_util/splitObject';
export default class Checkbox extends React.Component { export default class Checkbox extends React.Component {
static Group = CheckboxGroup; static Group = CheckboxGroup;
static defaultProps = { static defaultProps = {
@ -13,7 +13,7 @@ export default class Checkbox extends React.Component {
return PureRenderMixin.shouldComponentUpdate.apply(this, args); return PureRenderMixin.shouldComponentUpdate.apply(this, args);
} }
render() { render() {
const { prefixCls, style, children, className, ...restProps } = this.props; const [{ prefixCls, style, children, className },restProps] = splitObject(this.props, ['prefixCls', 'style', 'children', 'className']);
const classString = classNames({ const classString = classNames({
[className]: !!className, [className]: !!className,
[`${prefixCls}-wrapper`]: true, [`${prefixCls}-wrapper`]: true,

View File

@ -3,16 +3,17 @@ import MonthCalendar from 'rc-calendar/lib/MonthCalendar';
import RcDatePicker from 'rc-calendar/lib/Picker'; import RcDatePicker from 'rc-calendar/lib/Picker';
import GregorianCalendar from 'gregorian-calendar'; import GregorianCalendar from 'gregorian-calendar';
import classNames from 'classnames'; import classNames from 'classnames';
import assign from 'object-assign';
export default function createPicker(TheCalendar) { export default function createPicker(TheCalendar) {
return class CalenderWrapper extends React.Component { // use class typescript error
constructor(props) { const CalenderWrapper = React.createClass({
super(props);
this.state = { getInitialState() {
return {
value: this.props.parseDateFromValue(this.props.value || this.props.defaultValue), value: this.props.parseDateFromValue(this.props.value || this.props.defaultValue),
}; };
} },
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if ('value' in nextProps) { if ('value' in nextProps) {
@ -20,16 +21,16 @@ export default function createPicker(TheCalendar) {
value: nextProps.parseDateFromValue(nextProps.value), value: nextProps.parseDateFromValue(nextProps.value),
}); });
} }
} },
handleChange = (value) => { handleChange(value) {
const props = this.props; const props = this.props;
if (!('value' in props)) { if (!('value' in props)) {
this.setState({ value }); this.setState({value});
} }
const timeValue = value ? new Date(value.getTime()) : null; const timeValue = value ? new Date(value.getTime()) : null;
props.onChange(timeValue, value ? props.getFormatter().format(value) : ''); props.onChange(timeValue, value ? props.getFormatter().format(value) : '');
} },
render() { render() {
const props = this.props; const props = this.props;
@ -71,7 +72,7 @@ export default function createPicker(TheCalendar) {
} }
return ( return (
<span className={props.pickerClass} style={{ ...pickerStyle, ...props.style }}> <span className={props.pickerClass} style={assign({}, pickerStyle, props.style)}>
<RcDatePicker <RcDatePicker
transitionName={props.transitionName} transitionName={props.transitionName}
disabled={props.disabled} disabled={props.disabled}
@ -89,7 +90,7 @@ export default function createPicker(TheCalendar) {
{ {
({ value }) => { ({ value }) => {
return ( return (
<span> <span>
<input <input
disabled={props.disabled} disabled={props.disabled}
readOnly readOnly
@ -97,14 +98,16 @@ export default function createPicker(TheCalendar) {
placeholder={placeholder} placeholder={placeholder}
className={props.pickerInputClass} className={props.pickerInputClass}
/> />
<span className="ant-calendar-picker-icon" /> <span className="ant-calendar-picker-icon"/>
</span> </span>
); );
}
} }
}
</RcDatePicker> </RcDatePicker>
</span> </span>
); );
} },
}; });
return CalenderWrapper;
} }

View File

@ -1,16 +1,15 @@
import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/en_US'; import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/en_US';
import CalendarLocale from 'rc-calendar/lib/locale/en_US'; import CalendarLocale from 'rc-calendar/lib/locale/en_US';
import TimePickerLocale from '../../time-picker/locale/en_US'; import TimePickerLocale from '../../time-picker/locale/en_US';
import assign from 'object-assign';
// 统一合并为完整的 Locale // 统一合并为完整的 Locale
const locale = { ...GregorianCalendarLocale }; const locale = assign({}, GregorianCalendarLocale);
locale.lang = { locale.lang = assign({
placeholder: 'Select date', placeholder: 'Select date',
rangePlaceholder: ['Start date', 'End date'], rangePlaceholder: ['Start date', 'End date'],
...CalendarLocale, },CalendarLocale);
};
locale.timePickerLocale = { ...TimePickerLocale }; locale.timePickerLocale = assign({}, TimePickerLocale);
// All settings at: // All settings at:
// https://github.com/ant-design/ant-design/issues/424 // https://github.com/ant-design/ant-design/issues/424

View File

@ -5,15 +5,14 @@
import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/ru_RU'; import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/ru_RU';
import CalendarLocale from 'rc-calendar/lib/locale/ru_RU'; import CalendarLocale from 'rc-calendar/lib/locale/ru_RU';
import TimePickerLocale from '../../time-picker/locale/ru_RU'; import TimePickerLocale from '../../time-picker/locale/ru_RU';
import assign from 'object-assign';
const locale = { ...GregorianCalendarLocale }; const locale = assign({}, GregorianCalendarLocale);
locale.lang = { locale.lang = assign({
placeholder: 'Выберите дату', placeholder: 'Выберите дату',
rangePlaceholder: ['Начальная дата', 'Конечная дата'], rangePlaceholder: ['Начальная дата', 'Конечная дата'],
...CalendarLocale, },CalendarLocale);
};
locale.timePickerLocale = { ...TimePickerLocale }; locale.timePickerLocale = assign({}, TimePickerLocale);
// All settings at: // All settings at:
// https://github.com/ant-design/ant-design/issues/424 // https://github.com/ant-design/ant-design/issues/424

View File

@ -1,16 +1,15 @@
import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/zh_CN'; import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/zh_CN';
import CalendarLocale from 'rc-calendar/lib/locale/zh_CN'; import CalendarLocale from 'rc-calendar/lib/locale/zh_CN';
import TimePickerLocale from '../../time-picker/locale/zh_CN'; import TimePickerLocale from '../../time-picker/locale/zh_CN';
import assign from 'object-assign';
// 统一合并为完整的 Locale // 统一合并为完整的 Locale
const locale = { ...GregorianCalendarLocale }; const locale = assign({}, GregorianCalendarLocale);
locale.lang = { locale.lang = assign({
placeholder: '请选择日期', placeholder: '请选择日期',
rangePlaceholder: ['开始日期', '结束日期'], rangePlaceholder: ['开始日期', '结束日期'],
...CalendarLocale, }, CalendarLocale);
};
locale.timePickerLocale = { ...TimePickerLocale }; locale.timePickerLocale = assign({}, TimePickerLocale);
// should add whitespace between char in Button // should add whitespace between char in Button
locale.lang.ok = '确 定'; locale.lang.ok = '确 定';

View File

@ -1,28 +1,33 @@
import React, { PropTypes } from 'react'; import React, {PropTypes} from 'react';
import TimePicker from 'rc-time-picker'; import TimePicker from 'rc-time-picker';
import DateTimeFormat from 'gregorian-calendar-format'; import DateTimeFormat from 'gregorian-calendar-format';
import GregorianCalendar from 'gregorian-calendar'; import GregorianCalendar from 'gregorian-calendar';
import classNames from 'classnames'; import classNames from 'classnames';
import defaultLocale from './locale/zh_CN'; import defaultLocale from './locale/zh_CN';
import assign from 'object-assign';
export default function wrapPicker(Picker, defaultFormat) { export default function wrapPicker(Picker, defaultFormat) {
return class PickerWrapper extends React.Component { const PickerWrapper = React.createClass({
static defaultProps = { getDefaultProps() {
format: defaultFormat || 'yyyy-MM-dd', return {
transitionName: 'slide-up', format: defaultFormat || 'yyyy-MM-dd',
popupStyle: {}, transitionName: 'slide-up',
onChange() {}, popupStyle: {},
onOk() {}, onChange() {
toggleOpen() {}, },
locale: {}, onOk() {
align: { },
offset: [0, -9], toggleOpen() {
}, },
} locale: {},
align: {
offset: [0, -9],
},
};
},
static contextTypes = { contextTypes: {
antLocale: PropTypes.object, antLocale: PropTypes.object,
} },
getLocale() { getLocale() {
const props = this.props; const props = this.props;
@ -32,21 +37,21 @@ export default function wrapPicker(Picker, defaultFormat) {
locale = context.antLocale.DatePicker; locale = context.antLocale.DatePicker;
} }
// 统一合并为完整的 Locale // 统一合并为完整的 Locale
const result = { ...locale, ...props.locale }; const result = assign({}, locale, props.locale);
result.lang = { ...locale.lang, ...props.locale.lang }; result.lang = assign({}, locale.lang, props.locale.lang);
return result; return result;
} },
getFormatter = () => { getFormatter() {
const format = this.props.format; const format = this.props.format;
const formatter = new DateTimeFormat(format, this.getLocale().lang.format); const formatter = new DateTimeFormat(format, this.getLocale().lang.format);
return formatter; return formatter;
} },
parseDateFromValue = (value) => { parseDateFromValue(value) {
if (value) { if (value) {
if (typeof value === 'string') { if (typeof value === 'string') {
return this.getFormatter().parse(value, { locale: this.getLocale() }); return this.getFormatter().parse(value, {locale: this.getLocale()});
} else if (value instanceof Date) { } else if (value instanceof Date) {
let date = new GregorianCalendar(this.getLocale()); let date = new GregorianCalendar(this.getLocale());
date.setTime(+value); date.setTime(+value);
@ -54,11 +59,11 @@ export default function wrapPicker(Picker, defaultFormat) {
} }
} }
return value; return value;
} },
toggleOpen = ({ open }) => { toggleOpen ({open}) {
this.props.toggleOpen({ open }); this.props.toggleOpen({open});
} },
render() { render() {
const props = this.props; const props = this.props;
@ -103,6 +108,7 @@ export default function wrapPicker(Picker, defaultFormat) {
parseDateFromValue={this.parseDateFromValue} parseDateFromValue={this.parseDateFromValue}
/> />
); );
} },
}; });
return PickerWrapper;
} }

View File

@ -4,7 +4,7 @@ import Icon from '../icon';
import Dropdown from './dropdown'; import Dropdown from './dropdown';
const ButtonGroup = Button.Group; const ButtonGroup = Button.Group;
import classNames from 'classnames'; import classNames from 'classnames';
import splitObject from '../_util/splitObject';
export default class DropdownButton extends React.Component { export default class DropdownButton extends React.Component {
static defaultProps = { static defaultProps = {
align: { align: {
@ -20,7 +20,8 @@ export default class DropdownButton extends React.Component {
} }
render() { render() {
const { type, overlay, trigger, align, children, className, onClick, ...restProps } = this.props; const [{ type, overlay, trigger, align, children, className, onClick },restProps] = splitObject(this.props,
['type', 'overlay', 'trigger', 'align', 'children', 'className', 'onClick']);
const cls = classNames({ const cls = classNames({
'ant-dropdown-button': true, 'ant-dropdown-button': true,
className: !!className, className: !!className,

View File

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import RcDropdown from 'rc-dropdown'; import RcDropdown from 'rc-dropdown';
import splitObject from '../_util/splitObject';
export default class Dropdown extends React.Component { export default class Dropdown extends React.Component {
static defaultProps = { static defaultProps = {
@ -10,12 +11,14 @@ export default class Dropdown extends React.Component {
} }
render() { render() {
const { overlay, ...otherProps } = this.props; const [{overlay}, others] = splitObject(this.props,
['overlay']);
const menu = React.cloneElement(overlay, { const menu = React.cloneElement(overlay, {
openTransitionName: 'zoom-big', openTransitionName: 'zoom-big',
}); });
return ( return (
<RcDropdown {...otherProps} overlay={menu} /> <RcDropdown {...others} overlay={menu} />
); );
} }
} }

View File

@ -1,3 +1,4 @@
import assign from 'object-assign';
const ValueMixin = { const ValueMixin = {
setValue(field, e) { setValue(field, e) {
let v = e; let v = e;
@ -13,10 +14,7 @@ const ValueMixin = {
const newFormData = {}; const newFormData = {};
newFormData[field] = v; newFormData[field] = v;
this.setState({ this.setState({
formData: { formData: assign({}, this.state.formData, newFormData),
...this.state.formData,
...newFormData,
},
}); });
}, },
}; };

View File

@ -2,13 +2,12 @@ import Form from './Form';
import FormItem from './FormItem'; import FormItem from './FormItem';
import ValueMixin from './ValueMixin'; import ValueMixin from './ValueMixin';
import createDOMForm from 'rc-form/lib/createDOMForm'; import createDOMForm from 'rc-form/lib/createDOMForm';
import assign from 'object-assign';
Form.create = (o = {}) => { Form.create = (o = {}) => {
const options = { const options = assign({}, o, {
...o,
fieldNameProp: 'id', fieldNameProp: 'id',
fieldMetaProp: '__meta', fieldMetaProp: '__meta',
}; });
return createDOMForm(options); return createDOMForm(options);
}; };

View File

@ -1,7 +0,0 @@
import React from 'react';
export default props => {
let { type, className = '', ...other } = props;
className += ` anticon anticon-${type}`;
return <i className={className} {...other} />;
};

10
components/icon/index.tsx Normal file
View File

@ -0,0 +1,10 @@
import React from 'react';
import splitObject from '../_util/splitObject';
export default props => {
const [{type, className = ''}, others] = splitObject(props,
['type','className']);
let className2 = `${className} anticon anticon-${type}`;
return <i className={className2} {...others} />;
};

2
components/index.tsx Normal file
View File

@ -0,0 +1,2 @@
import Affix from './affix';
export { Affix };

View File

@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import RcInputNumber from 'rc-input-number'; import RcInputNumber from 'rc-input-number';
import splitObject from '../_util/splitObject';
export default class InputNumber extends React.Component { export default class InputNumber extends React.Component {
static defaultProps = { static defaultProps = {
@ -9,13 +10,14 @@ export default class InputNumber extends React.Component {
} }
render() { render() {
const { className, size, ...other } = this.props; const [{className, size}, others] = splitObject(this.props,
['size','className']);
const inputNumberClass = classNames({ const inputNumberClass = classNames({
[`${this.props.prefixCls}-lg`]: size === 'large', [`${this.props.prefixCls}-lg`]: size === 'large',
[`${this.props.prefixCls}-sm`]: size === 'small', [`${this.props.prefixCls}-sm`]: size === 'small',
[className]: !!className, [className]: !!className,
}); });
return <RcInputNumber className={inputNumberClass} {...other} />; return <RcInputNumber className={inputNumberClass} {...others} />;
} }
} }

View File

@ -1,7 +1,7 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import calculateNodeHeight from './calculateNodeHeight'; import calculateNodeHeight from './calculateNodeHeight';
import assign from 'object-assign';
function fixControlledValue(value) { function fixControlledValue(value) {
if (typeof value === 'undefined' || value === null) { if (typeof value === 'undefined' || value === null) {
return ''; return '';
@ -131,7 +131,7 @@ export default class Input extends Component {
} }
renderInput() { renderInput() {
const props = { ...this.props }; const props = assign({}, this.props);
const prefixCls = props.prefixCls; const prefixCls = props.prefixCls;
if (!props.type) { if (!props.type) {
return props.children; return props.children;
@ -156,10 +156,7 @@ export default class Input extends Component {
return ( return (
<textarea <textarea
{...props} {...props}
style={{ style={assign({}, props.style, this.state.textareaStyles)}
...props.style,
...this.state.textareaStyles,
}}
className={inputClassName} className={inputClassName}
onKeyDown={this.handleKeyDown} onKeyDown={this.handleKeyDown}
onChange={this.handleTextareaChange} onChange={this.handleTextareaChange}

View File

@ -1,11 +1,12 @@
import React, { PropTypes } from 'react'; import React, { PropTypes } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import assign from 'object-assign';
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]); const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
const objectOrNumber = PropTypes.oneOfType([PropTypes.object, PropTypes.number]); const objectOrNumber = PropTypes.oneOfType([PropTypes.object, PropTypes.number]);
import splitObject from '../_util/splitObject';
export default function Col(props) { export default function Col(props) {
const { span, order, offset, push, pull, className, children, ...others } = props; const [{span, order, offset, push, pull, className, children}, others] = splitObject(props,
['span', 'order','offset', 'push','pull', 'className','children']);
let sizeClassObj = {}; let sizeClassObj = {};
['xs', 'sm', 'md', 'lg'].forEach(size => { ['xs', 'sm', 'md', 'lg'].forEach(size => {
let sizeProps = {}; let sizeProps = {};
@ -14,24 +15,22 @@ export default function Col(props) {
} else if (typeof props[size] === 'object') { } else if (typeof props[size] === 'object') {
sizeProps = props[size] || {}; sizeProps = props[size] || {};
} }
sizeClassObj = { sizeClassObj = assign({}, sizeClassObj, {
...sizeClassObj,
[`ant-col-${size}-${sizeProps.span}`]: sizeProps.span !== undefined, [`ant-col-${size}-${sizeProps.span}`]: sizeProps.span !== undefined,
[`ant-col-${size}-order-${sizeProps.order}`]: sizeProps.order, [`ant-col-${size}-order-${sizeProps.order}`]: sizeProps.order,
[`ant-col-${size}-offset-${sizeProps.offset}`]: sizeProps.offset, [`ant-col-${size}-offset-${sizeProps.offset}`]: sizeProps.offset,
[`ant-col-${size}-push-${sizeProps.push}`]: sizeProps.push, [`ant-col-${size}-push-${sizeProps.push}`]: sizeProps.push,
[`ant-col-${size}-pull-${sizeProps.pull}`]: sizeProps.pull, [`ant-col-${size}-pull-${sizeProps.pull}`]: sizeProps.pull,
}; });
}); });
const classes = classNames({ const classes = classNames(assign({}, {
[`ant-col-${span}`]: span !== undefined, [`ant-col-${span}`]: span !== undefined,
[`ant-col-order-${order}`]: order, [`ant-col-order-${order}`]: order,
[`ant-col-offset-${offset}`]: offset, [`ant-col-offset-${offset}`]: offset,
[`ant-col-push-${push}`]: push, [`ant-col-push-${push}`]: push,
[`ant-col-pull-${pull}`]: pull, [`ant-col-pull-${pull}`]: pull,
[className]: !!className, [className]: !!className,
...sizeClassObj, },sizeClassObj));
});
return <div {...others} className={classes}>{children}</div>; return <div {...others} className={classes}>{children}</div>;
} }

View File

@ -1,6 +1,7 @@
import React, { Children, cloneElement } from 'react'; import React, { Children, cloneElement } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import assign from 'object-assign';
import splitObject from '../_util/splitObject';
export default class Row extends React.Component { export default class Row extends React.Component {
static defaultProps = { static defaultProps = {
gutter: 0, gutter: 0,
@ -14,7 +15,8 @@ export default class Row extends React.Component {
gutter: React.PropTypes.number, gutter: React.PropTypes.number,
} }
render() { render() {
const { type, justify, align, className, gutter, style, children, ...others } = this.props; const [{type, justify, align, className, gutter, style, children}, others] = splitObject(this.props,
['type', 'justify','align', 'className','gutter', 'style','children']);
const classes = classNames({ const classes = classNames({
'ant-row': !type, 'ant-row': !type,
[`ant-row-${type}`]: type, [`ant-row-${type}`]: type,
@ -22,20 +24,18 @@ export default class Row extends React.Component {
[`ant-row-${type}-${align}`]: align, [`ant-row-${type}-${align}`]: align,
[className]: className, [className]: className,
}); });
const rowStyle = gutter > 0 ? { const rowStyle = gutter > 0 ? assign({}, {
marginLeft: gutter / -2, marginLeft: gutter / -2,
marginRight: gutter / -2, marginRight: gutter / -2,
...style, },style) : style;
} : style;
const cols = Children.map(children, col => { const cols = Children.map(children, col => {
if (!col) return null; if (!col) return null;
return cloneElement(col, { return cloneElement(col, {
style: gutter > 0 ? { style: gutter > 0 ? assign({}, {
paddingLeft: gutter / 2, paddingLeft: gutter / 2,
paddingRight: gutter / 2, paddingRight: gutter / 2,
...col.props.style, }, col.props.style) : col.props.style,
} : col.props.style,
}); });
}); });
return <div {...others} className={classes} style={rowStyle}>{cols}</div>; return <div {...others} className={classes} style={rowStyle}>{cols}</div>;

View File

@ -5,9 +5,9 @@ import Icon from '../icon';
import Button from '../button'; import Button from '../button';
import classNames from 'classnames'; import classNames from 'classnames';
import { getConfirmLocale } from './locale'; import { getConfirmLocale } from './locale';
import assign from 'object-assign';
export default function confirm(config) { export default function confirm(config) {
const props = { ...config }; const props = assign({}, config);
let div = document.createElement('div'); let div = document.createElement('div');
document.body.appendChild(div); document.body.appendChild(div);

View File

@ -1,52 +1,47 @@
import Modal from './Modal'; import Modal from './Modal';
import confirm from './confirm'; import confirm from './confirm';
import assign from 'object-assign';
Modal.info = function (props) { Modal.info = function (props) {
const config = { const config = assign({}, {
type: 'info', type: 'info',
iconType: 'info-circle', iconType: 'info-circle',
okCancel: false, okCancel: false,
...props, }, props);
};
return confirm(config); return confirm(config);
}; };
Modal.success = function (props) { Modal.success = function (props) {
const config = { const config = assign({}, {
type: 'success', type: 'success',
iconType: 'check-circle', iconType: 'check-circle',
okCancel: false, okCancel: false,
...props, }, props);
};
return confirm(config); return confirm(config);
}; };
Modal.error = function (props) { Modal.error = function (props) {
const config = { const config = assign({}, {
type: 'error', type: 'error',
iconType: 'cross-circle', iconType: 'cross-circle',
okCancel: false, okCancel: false,
...props, }, props);
};
return confirm(config); return confirm(config);
}; };
Modal.warning = Modal.warn = function (props) { Modal.warning = Modal.warn = function (props) {
const config = { const config = assign({}, {
type: 'warning', type: 'warning',
iconType: 'exclamation-circle', iconType: 'exclamation-circle',
okCancel: false, okCancel: false,
...props, }, props);
};
return confirm(config); return confirm(config);
}; };
Modal.confirm = function (props) { Modal.confirm = function (props) {
const config = { const config = assign({}, {
type: 'confirm', type: 'confirm',
okCancel: true, okCancel: true,
...props, }, props);
};
return confirm(config); return confirm(config);
}; };

View File

@ -1,16 +1,18 @@
import assign from 'object-assign';
const defaultLocale = { const defaultLocale = {
okText: '确定', okText: '确定',
cancelText: '取消', cancelText: '取消',
justOkText: '知道了', justOkText: '知道了',
}; };
let runtimeLocale = { ...defaultLocale }; let runtimeLocale = assign({}, defaultLocale);
export function changeConfirmLocale(newLocale) { export function changeConfirmLocale(newLocale) {
if (newLocale) { if (newLocale) {
runtimeLocale = { ...runtimeLocale, ...newLocale }; runtimeLocale = assign({}, runtimeLocale, newLocale);
} else { } else {
runtimeLocale = { ...defaultLocale }; runtimeLocale = assign({}, defaultLocale);
} }
} }

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import Notification from 'rc-notification'; import Notification from 'rc-notification';
import Icon from '../icon'; import Icon from '../icon';
import assign from 'object-assign';
let defaultTop = 24; let defaultTop = 24;
let notificationInstance; let notificationInstance;
let defaultDuration = 4.5; let defaultDuration = 4.5;
@ -91,7 +91,7 @@ const api = {
}; };
['success', 'info', 'warning', 'error'].forEach((type) => { ['success', 'info', 'warning', 'error'].forEach((type) => {
api[type] = (args) => api.open({ ...args, icon: type }); api[type] = (args) => api.open(assign({}, args,{ icon: type }));
}); });
api.warn = api.warning; api.warn = api.warning;

View File

@ -3,7 +3,7 @@ import Tooltip from '../tooltip';
import Icon from '../icon'; import Icon from '../icon';
import Button from '../button'; import Button from '../button';
import getPlacements from '../popover/placements'; import getPlacements from '../popover/placements';
import splitObject from '../_util/splitObject';
const placements = getPlacements(); const placements = getPlacements();
const prefixCls = 'ant-popover'; const prefixCls = 'ant-popover';
const noop = () => {}; const noop = () => {};
@ -58,7 +58,8 @@ export default class Popconfirm extends React.Component {
} }
render() { render() {
const { title, placement, overlayStyle, trigger, ...restProps } = this.props; const [{ title, placement, overlayStyle, trigger },restProps] = splitObject(this.props,
['title', 'placement', 'overlayStyle', 'trigger']);
let { okText, cancelText } = this.props; let { okText, cancelText } = this.props;
if (this.context.antLocale && this.context.antLocale.Popconfirm) { if (this.context.antLocale && this.context.antLocale.Popconfirm) {
okText = okText || this.context.antLocale.Popconfirm.okText; okText = okText || this.context.antLocale.Popconfirm.okText;

View File

@ -2,7 +2,7 @@ import React, { PropTypes } from 'react';
import Icon from '../icon'; import Icon from '../icon';
import { Circle } from 'rc-progress'; import { Circle } from 'rc-progress';
import classNames from 'classnames'; import classNames from 'classnames';
import splitObject from '../_util/splitObject';
const statusColorMap = { const statusColorMap = {
normal: '#2db7f5', normal: '#2db7f5',
exception: '#ff5500', exception: '#ff5500',
@ -30,8 +30,12 @@ export default class Line extends React.Component {
} }
render() { render() {
const { prefixCls, status, format, percent, trailColor, const [{
type, strokeWidth, width, className, showInfo, ...restProps } = this.props; prefixCls, status, format, percent, trailColor,
type, strokeWidth, width, className, showInfo
},restProps] = splitObject(this.props,
['prefixCls', 'status', 'format', 'percent', 'trailColor', 'type', 'strokeWidth', 'width',
'className', 'showInfo']);
const progressStatus = (parseInt(percent, 10) >= 100 && !('status' in this.props)) const progressStatus = (parseInt(percent, 10) >= 100 && !('status' in this.props))
? 'success' : (status || 'normal'); ? 'success' : (status || 'normal');
let progressInfo; let progressInfo;

Some files were not shown because too many files have changed in this diff Show More