diff --git a/.gitignore b/.gitignore index 85d90d8d7a..86665f9ab8 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ dist elasticsearch-* config/base.yaml typings +components/**/*.js +components/**/*.jsx diff --git a/components/_util/isCssAnimationSupported.js b/components/_util/isCssAnimationSupported.tsx similarity index 100% rename from components/_util/isCssAnimationSupported.js rename to components/_util/isCssAnimationSupported.tsx diff --git a/components/_util/openAnimation.js b/components/_util/openAnimation.tsx similarity index 100% rename from components/_util/openAnimation.js rename to components/_util/openAnimation.tsx diff --git a/components/_util/splitObject.tsx b/components/_util/splitObject.tsx new file mode 100644 index 0000000000..846d4784d0 --- /dev/null +++ b/components/_util/splitObject.tsx @@ -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]; +} \ No newline at end of file diff --git a/components/affix/index.jsx b/components/affix/index.tsx similarity index 91% rename from components/affix/index.jsx rename to components/affix/index.tsx index cbf0743aaf..77fc509b39 100644 --- a/components/affix/index.jsx +++ b/components/affix/index.tsx @@ -1,5 +1,5 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; import addEventListener from 'rc-util/lib/Dom/addEventListener'; import classNames from 'classnames'; 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 { static propTypes = { offsetTop: React.PropTypes.number, offsetBottom: React.PropTypes.number, diff --git a/components/affix/style/index.js b/components/affix/style/index.tsx similarity index 100% rename from components/affix/style/index.js rename to components/affix/style/index.tsx diff --git a/components/alert/index.jsx b/components/alert/index.tsx similarity index 100% rename from components/alert/index.jsx rename to components/alert/index.tsx diff --git a/components/alert/style/index.js b/components/alert/style/index.tsx similarity index 100% rename from components/alert/style/index.js rename to components/alert/style/index.tsx diff --git a/components/badge/ScrollNumber.jsx b/components/badge/ScrollNumber.tsx similarity index 94% rename from components/badge/ScrollNumber.jsx rename to components/badge/ScrollNumber.tsx index 0b4d2ea29f..ee7821d715 100644 --- a/components/badge/ScrollNumber.jsx +++ b/components/badge/ScrollNumber.tsx @@ -1,6 +1,7 @@ -import React, { createElement } from 'react'; -import { findDOMNode } from 'react-dom'; +import React, {createElement} from 'react'; +import {findDOMNode} from 'react-dom'; import isCssAnimationSupported from '../_util/isCssAnimationSupported'; +import assign from 'object-assign'; function getNumberArray(num) { return num ? @@ -15,7 +16,8 @@ export default class ScrollNumber extends React.Component { prefixCls: 'ant-scroll-number', count: null, component: 'sup', - onAnimated() {}, + onAnimated() { + }, height: 18, } @@ -122,10 +124,9 @@ export default class ScrollNumber extends React.Component { } render() { - const props = { - ...this.props, + const props = assign({}, this.props, { className: `${this.props.prefixCls} ${this.props.className}`, - }; + }); return createElement( this.props.component, props, diff --git a/components/badge/index.jsx b/components/badge/index.tsx similarity index 100% rename from components/badge/index.jsx rename to components/badge/index.tsx diff --git a/components/badge/style/index.js b/components/badge/style/index.tsx similarity index 100% rename from components/badge/style/index.js rename to components/badge/style/index.tsx diff --git a/components/breadcrumb/Breadcrumb.jsx b/components/breadcrumb/Breadcrumb.tsx similarity index 100% rename from components/breadcrumb/Breadcrumb.jsx rename to components/breadcrumb/Breadcrumb.tsx diff --git a/components/breadcrumb/BreadcrumbItem.jsx b/components/breadcrumb/BreadcrumbItem.tsx similarity index 81% rename from components/breadcrumb/BreadcrumbItem.jsx rename to components/breadcrumb/BreadcrumbItem.tsx index 23ea1565df..50ff9a5d00 100644 --- a/components/breadcrumb/BreadcrumbItem.jsx +++ b/components/breadcrumb/BreadcrumbItem.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import splitObject from '../_util/splitObject'; export default class BreadcrumbItem extends React.Component { static defaultProps = { @@ -16,7 +17,7 @@ export default class BreadcrumbItem extends React.Component { } render() { - const { prefixCls, separator, children, ...restProps } = this.props; + const [{prefixCls, separator, children},restProps] = splitObject(this.props, ['prefixCls', 'separator', 'children']); let link; if ('href' in this.props) { link = {children}; diff --git a/components/breadcrumb/index.jsx b/components/breadcrumb/index.tsx similarity index 100% rename from components/breadcrumb/index.jsx rename to components/breadcrumb/index.tsx diff --git a/components/breadcrumb/style/index.js b/components/breadcrumb/style/index.tsx similarity index 100% rename from components/breadcrumb/style/index.js rename to components/breadcrumb/style/index.tsx diff --git a/components/button/button-group.jsx b/components/button/button-group.tsx similarity index 80% rename from components/button/button-group.jsx rename to components/button/button-group.tsx index d494a345e3..92ba3e96a2 100644 --- a/components/button/button-group.jsx +++ b/components/button/button-group.tsx @@ -1,10 +1,11 @@ import React from 'react'; import classNames from 'classnames'; +import splitObject from '../_util/splitObject'; const prefix = 'ant-btn-group-'; export default function ButtonGroup(props) { - const { size, className, ...others } = props; + const [{size, className},others] = splitObject(props, ['size', 'className']); // large => lg // small => sm diff --git a/components/button/button.jsx b/components/button/button.tsx similarity index 91% rename from components/button/button.jsx rename to components/button/button.tsx index b75b54c40f..bea8b996fe 100644 --- a/components/button/button.jsx +++ b/components/button/button.tsx @@ -2,7 +2,7 @@ import React from 'react'; import classNames from 'classnames'; import { findDOMNode } from 'react-dom'; import Icon from '../icon'; - +import splitObject from '../_util/splitObject'; const rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/; const isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar); function isString(str) { @@ -76,7 +76,8 @@ export default class Button extends React.Component { render() { 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 // small => sm diff --git a/components/button/index.jsx b/components/button/index.tsx similarity index 100% rename from components/button/index.jsx rename to components/button/index.tsx diff --git a/components/button/style/index.js b/components/button/style/index.tsx similarity index 100% rename from components/button/style/index.js rename to components/button/style/index.tsx diff --git a/components/calendar/Constants.js b/components/calendar/Constants.tsx similarity index 100% rename from components/calendar/Constants.js rename to components/calendar/Constants.tsx diff --git a/components/calendar/Header.jsx b/components/calendar/Header.tsx similarity index 100% rename from components/calendar/Header.jsx rename to components/calendar/Header.tsx diff --git a/components/calendar/index.jsx b/components/calendar/index.tsx similarity index 96% rename from components/calendar/index.jsx rename to components/calendar/index.tsx index b7f68eb3f5..6d485ac1d3 100644 --- a/components/calendar/index.jsx +++ b/components/calendar/index.tsx @@ -4,6 +4,7 @@ import defaultLocale from './locale/zh_CN'; import FullCalendar from 'rc-calendar/lib/FullCalendar'; import { PREFIX_CLS } from './Constants'; import Header from './Header'; +import assign from 'object-assign'; function noop() { return null; } @@ -69,8 +70,8 @@ export default class Calendar extends React.Component { locale = context.antLocale.Calendar; } // 统一合并为完整的 Locale - const result = { ...locale, ...props.locale }; - result.lang = { ...locale.lang, ...props.locale.lang }; + const result = assign({}, locale, props.locale); + result.lang = assign({}, locale.lang,props.locale.lang); return result; } diff --git a/components/calendar/locale/en_US.js b/components/calendar/locale/en_US.tsx similarity index 100% rename from components/calendar/locale/en_US.js rename to components/calendar/locale/en_US.tsx diff --git a/components/calendar/locale/ru_RU.js b/components/calendar/locale/ru_RU.tsx similarity index 100% rename from components/calendar/locale/ru_RU.js rename to components/calendar/locale/ru_RU.tsx diff --git a/components/calendar/locale/zh_CN.js b/components/calendar/locale/zh_CN.tsx similarity index 100% rename from components/calendar/locale/zh_CN.js rename to components/calendar/locale/zh_CN.tsx diff --git a/components/calendar/style/index.js b/components/calendar/style/index.tsx similarity index 100% rename from components/calendar/style/index.js rename to components/calendar/style/index.tsx diff --git a/components/card/index.jsx b/components/card/index.tsx similarity index 75% rename from components/card/index.jsx rename to components/card/index.tsx index 0d3213ff47..f869694dcb 100644 --- a/components/card/index.jsx +++ b/components/card/index.tsx @@ -1,9 +1,13 @@ import React from 'react'; import classNames from 'classnames'; - +import splitObject from '../_util/splitObject'; export default props => { - let { prefixCls = 'ant-card', className, children, extra, bodyStyle, - title, loading, bordered = true, ...other } = props; + const [{ + 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({ [prefixCls]: true, [className]: !!className, @@ -30,7 +34,7 @@ export default props => { ) : null; return ( -
+
{head} {extra ?
{extra}
: null}
{children}
diff --git a/components/card/style/index.js b/components/card/style/index.tsx similarity index 100% rename from components/card/style/index.js rename to components/card/style/index.tsx diff --git a/components/carousel/index.jsx b/components/carousel/index.tsx similarity index 92% rename from components/carousel/index.jsx rename to components/carousel/index.tsx index da90e64976..d1319e4f26 100644 --- a/components/carousel/index.jsx +++ b/components/carousel/index.tsx @@ -1,5 +1,6 @@ // matchMedia polyfill for // https://github.com/WickyNilliams/enquire.js/issues/82 +import assign from 'object-assign'; if (typeof window !== 'undefined') { const matchMediaPolyfill = function matchMediaPolyfill() { return { @@ -23,7 +24,7 @@ export default class Carousel extends React.Component { } render() { - let props = { ...this.props }; + let props = assign({}, this.props); if (props.effect === 'fade') { props.fade = true; diff --git a/components/carousel/style/index.js b/components/carousel/style/index.tsx similarity index 100% rename from components/carousel/style/index.js rename to components/carousel/style/index.tsx diff --git a/components/cascader/index.jsx b/components/cascader/index.tsx similarity index 90% rename from components/cascader/index.jsx rename to components/cascader/index.tsx index fca5778849..a8c6efb1dd 100644 --- a/components/cascader/index.jsx +++ b/components/cascader/index.tsx @@ -4,6 +4,7 @@ import Input from '../input'; import Icon from '../icon'; import arrayTreeFilter from 'array-tree-filter'; import classNames from 'classnames'; +import splitObject from '../_util/splitObject'; export default class Cascader extends React.Component { static defaultProps = { @@ -71,8 +72,10 @@ export default class Cascader extends React.Component { render() { const props = this.props; - const { prefixCls, children, placeholder, size, disabled, - className, style, allowClear, ...otherProps } = props; + const [{prefixCls, children, placeholder, size, disabled, + className, style, allowClear}, others] = splitObject(props, + ['prefixCls', 'children','placeholder', 'size','disabled', 'className','style','allowClear']); + const sizeCls = classNames({ 'ant-input-lg': size === 'large', '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 - delete otherProps.onChange; + delete others.onChange; return ( - 0 ? null : placeholder} className={`${prefixCls}-input ant-input ${sizeCls}`} value={null} diff --git a/components/cascader/style/index.js b/components/cascader/style/index.tsx similarity index 100% rename from components/cascader/style/index.js rename to components/cascader/style/index.tsx diff --git a/components/checkbox/Group.jsx b/components/checkbox/Group.tsx similarity index 98% rename from components/checkbox/Group.jsx rename to components/checkbox/Group.tsx index 5ec570d40d..d37c3cc24e 100644 --- a/components/checkbox/Group.jsx +++ b/components/checkbox/Group.tsx @@ -1,7 +1,7 @@ import React from 'react'; import Checkbox from './index'; import PureRenderMixin from 'react-addons-pure-render-mixin'; - +import assign from 'object-assign'; export default class CheckboxGroup extends React.Component { static defaultProps = { options: [], diff --git a/components/checkbox/index.jsx b/components/checkbox/index.tsx similarity index 81% rename from components/checkbox/index.jsx rename to components/checkbox/index.tsx index 9bca526e12..76c388ddf1 100644 --- a/components/checkbox/index.jsx +++ b/components/checkbox/index.tsx @@ -3,7 +3,7 @@ import React from 'react'; import CheckboxGroup from './Group'; import classNames from 'classnames'; import PureRenderMixin from 'react-addons-pure-render-mixin'; - +import splitObject from '../_util/splitObject'; export default class Checkbox extends React.Component { static Group = CheckboxGroup; static defaultProps = { @@ -13,7 +13,7 @@ export default class Checkbox extends React.Component { return PureRenderMixin.shouldComponentUpdate.apply(this, args); } 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({ [className]: !!className, [`${prefixCls}-wrapper`]: true, diff --git a/components/checkbox/style/index.js b/components/checkbox/style/index.tsx similarity index 100% rename from components/checkbox/style/index.js rename to components/checkbox/style/index.tsx diff --git a/components/col/index.js b/components/col/index.tsx similarity index 100% rename from components/col/index.js rename to components/col/index.tsx diff --git a/components/col/style/index.js b/components/col/style/index.tsx similarity index 100% rename from components/col/style/index.js rename to components/col/style/index.tsx diff --git a/components/collapse/index.jsx b/components/collapse/index.tsx similarity index 100% rename from components/collapse/index.jsx rename to components/collapse/index.tsx diff --git a/components/collapse/style/index.js b/components/collapse/style/index.tsx similarity index 100% rename from components/collapse/style/index.js rename to components/collapse/style/index.tsx diff --git a/components/date-picker/Calendar.jsx b/components/date-picker/Calendar.tsx similarity index 100% rename from components/date-picker/Calendar.jsx rename to components/date-picker/Calendar.tsx diff --git a/components/date-picker/RangePicker.jsx b/components/date-picker/RangePicker.tsx similarity index 100% rename from components/date-picker/RangePicker.jsx rename to components/date-picker/RangePicker.tsx diff --git a/components/date-picker/createPicker.jsx b/components/date-picker/createPicker.tsx similarity index 86% rename from components/date-picker/createPicker.jsx rename to components/date-picker/createPicker.tsx index 60580b0ffb..af61e01fb1 100644 --- a/components/date-picker/createPicker.jsx +++ b/components/date-picker/createPicker.tsx @@ -3,16 +3,17 @@ import MonthCalendar from 'rc-calendar/lib/MonthCalendar'; import RcDatePicker from 'rc-calendar/lib/Picker'; import GregorianCalendar from 'gregorian-calendar'; import classNames from 'classnames'; +import assign from 'object-assign'; export default function createPicker(TheCalendar) { - return class CalenderWrapper extends React.Component { - constructor(props) { - super(props); + // use class typescript error + const CalenderWrapper = React.createClass({ - this.state = { + getInitialState() { + return { value: this.props.parseDateFromValue(this.props.value || this.props.defaultValue), }; - } + }, componentWillReceiveProps(nextProps) { if ('value' in nextProps) { @@ -20,16 +21,16 @@ export default function createPicker(TheCalendar) { value: nextProps.parseDateFromValue(nextProps.value), }); } - } + }, - handleChange = (value) => { + handleChange(value) { const props = this.props; if (!('value' in props)) { - this.setState({ value }); + this.setState({value}); } const timeValue = value ? new Date(value.getTime()) : null; props.onChange(timeValue, value ? props.getFormatter().format(value) : ''); - } + }, render() { const props = this.props; @@ -71,7 +72,7 @@ export default function createPicker(TheCalendar) { } return ( - + { return ( - + - + - ); + ); + } } - } ); - } - }; + }, + }); + + return CalenderWrapper; } diff --git a/components/date-picker/index.jsx b/components/date-picker/index.tsx similarity index 100% rename from components/date-picker/index.jsx rename to components/date-picker/index.tsx diff --git a/components/date-picker/locale/en_US.js b/components/date-picker/locale/en_US.tsx similarity index 68% rename from components/date-picker/locale/en_US.js rename to components/date-picker/locale/en_US.tsx index 8f19d78198..fb94a32939 100644 --- a/components/date-picker/locale/en_US.js +++ b/components/date-picker/locale/en_US.tsx @@ -1,16 +1,15 @@ import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/en_US'; import CalendarLocale from 'rc-calendar/lib/locale/en_US'; import TimePickerLocale from '../../time-picker/locale/en_US'; - +import assign from 'object-assign'; // 统一合并为完整的 Locale -const locale = { ...GregorianCalendarLocale }; -locale.lang = { +const locale = assign({}, GregorianCalendarLocale); +locale.lang = assign({ placeholder: 'Select date', rangePlaceholder: ['Start date', 'End date'], - ...CalendarLocale, -}; +},CalendarLocale); -locale.timePickerLocale = { ...TimePickerLocale }; +locale.timePickerLocale = assign({}, TimePickerLocale); // All settings at: // https://github.com/ant-design/ant-design/issues/424 diff --git a/components/date-picker/locale/ru_RU.js b/components/date-picker/locale/ru_RU.tsx similarity index 72% rename from components/date-picker/locale/ru_RU.js rename to components/date-picker/locale/ru_RU.tsx index 87b68359d2..c6b233288c 100644 --- a/components/date-picker/locale/ru_RU.js +++ b/components/date-picker/locale/ru_RU.tsx @@ -5,15 +5,14 @@ import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/ru_RU'; import CalendarLocale from 'rc-calendar/lib/locale/ru_RU'; import TimePickerLocale from '../../time-picker/locale/ru_RU'; - -const locale = { ...GregorianCalendarLocale }; -locale.lang = { +import assign from 'object-assign'; +const locale = assign({}, GregorianCalendarLocale); +locale.lang = assign({ placeholder: 'Выберите дату', rangePlaceholder: ['Начальная дата', 'Конечная дата'], - ...CalendarLocale, -}; +},CalendarLocale); -locale.timePickerLocale = { ...TimePickerLocale }; +locale.timePickerLocale = assign({}, TimePickerLocale); // All settings at: // https://github.com/ant-design/ant-design/issues/424 diff --git a/components/date-picker/locale/zh_CN.js b/components/date-picker/locale/zh_CN.tsx similarity index 72% rename from components/date-picker/locale/zh_CN.js rename to components/date-picker/locale/zh_CN.tsx index 7884c3cc23..350de8ce06 100644 --- a/components/date-picker/locale/zh_CN.js +++ b/components/date-picker/locale/zh_CN.tsx @@ -1,16 +1,15 @@ import GregorianCalendarLocale from 'gregorian-calendar/lib/locale/zh_CN'; import CalendarLocale from 'rc-calendar/lib/locale/zh_CN'; import TimePickerLocale from '../../time-picker/locale/zh_CN'; - +import assign from 'object-assign'; // 统一合并为完整的 Locale -const locale = { ...GregorianCalendarLocale }; -locale.lang = { +const locale = assign({}, GregorianCalendarLocale); +locale.lang = assign({ placeholder: '请选择日期', rangePlaceholder: ['开始日期', '结束日期'], - ...CalendarLocale, -}; +}, CalendarLocale); -locale.timePickerLocale = { ...TimePickerLocale }; +locale.timePickerLocale = assign({}, TimePickerLocale); // should add whitespace between char in Button locale.lang.ok = '确 定'; diff --git a/components/date-picker/style/index.js b/components/date-picker/style/index.tsx similarity index 100% rename from components/date-picker/style/index.js rename to components/date-picker/style/index.tsx diff --git a/components/date-picker/wrapPicker.jsx b/components/date-picker/wrapPicker.tsx similarity index 74% rename from components/date-picker/wrapPicker.jsx rename to components/date-picker/wrapPicker.tsx index 90d029d19b..b96dc0d22e 100644 --- a/components/date-picker/wrapPicker.jsx +++ b/components/date-picker/wrapPicker.tsx @@ -1,28 +1,33 @@ -import React, { PropTypes } from 'react'; +import React, {PropTypes} from 'react'; import TimePicker from 'rc-time-picker'; import DateTimeFormat from 'gregorian-calendar-format'; import GregorianCalendar from 'gregorian-calendar'; import classNames from 'classnames'; import defaultLocale from './locale/zh_CN'; - +import assign from 'object-assign'; export default function wrapPicker(Picker, defaultFormat) { - return class PickerWrapper extends React.Component { - static defaultProps = { - format: defaultFormat || 'yyyy-MM-dd', - transitionName: 'slide-up', - popupStyle: {}, - onChange() {}, - onOk() {}, - toggleOpen() {}, - locale: {}, - align: { - offset: [0, -9], - }, - } + const PickerWrapper = React.createClass({ + getDefaultProps() { + return { + format: defaultFormat || 'yyyy-MM-dd', + transitionName: 'slide-up', + popupStyle: {}, + onChange() { + }, + onOk() { + }, + toggleOpen() { + }, + locale: {}, + align: { + offset: [0, -9], + }, + }; + }, - static contextTypes = { + contextTypes: { antLocale: PropTypes.object, - } + }, getLocale() { const props = this.props; @@ -32,21 +37,21 @@ export default function wrapPicker(Picker, defaultFormat) { locale = context.antLocale.DatePicker; } // 统一合并为完整的 Locale - const result = { ...locale, ...props.locale }; - result.lang = { ...locale.lang, ...props.locale.lang }; + const result = assign({}, locale, props.locale); + result.lang = assign({}, locale.lang, props.locale.lang); return result; - } + }, - getFormatter = () => { + getFormatter() { const format = this.props.format; const formatter = new DateTimeFormat(format, this.getLocale().lang.format); return formatter; - } + }, - parseDateFromValue = (value) => { + parseDateFromValue(value) { if (value) { 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) { let date = new GregorianCalendar(this.getLocale()); date.setTime(+value); @@ -54,11 +59,11 @@ export default function wrapPicker(Picker, defaultFormat) { } } return value; - } + }, - toggleOpen = ({ open }) => { - this.props.toggleOpen({ open }); - } + toggleOpen ({open}) { + this.props.toggleOpen({open}); + }, render() { const props = this.props; @@ -103,6 +108,7 @@ export default function wrapPicker(Picker, defaultFormat) { parseDateFromValue={this.parseDateFromValue} /> ); - } - }; + }, + }); + return PickerWrapper; } diff --git a/components/dropdown/dropdown-button.jsx b/components/dropdown/dropdown-button.tsx similarity index 79% rename from components/dropdown/dropdown-button.jsx rename to components/dropdown/dropdown-button.tsx index e5b330d956..1aeeb067eb 100644 --- a/components/dropdown/dropdown-button.jsx +++ b/components/dropdown/dropdown-button.tsx @@ -4,7 +4,7 @@ import Icon from '../icon'; import Dropdown from './dropdown'; const ButtonGroup = Button.Group; import classNames from 'classnames'; - +import splitObject from '../_util/splitObject'; export default class DropdownButton extends React.Component { static defaultProps = { align: { @@ -20,7 +20,8 @@ export default class DropdownButton extends React.Component { } 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({ 'ant-dropdown-button': true, className: !!className, diff --git a/components/dropdown/dropdown.jsx b/components/dropdown/dropdown.tsx similarity index 69% rename from components/dropdown/dropdown.jsx rename to components/dropdown/dropdown.tsx index 16a0c97251..95d6c97171 100644 --- a/components/dropdown/dropdown.jsx +++ b/components/dropdown/dropdown.tsx @@ -1,5 +1,6 @@ import React from 'react'; import RcDropdown from 'rc-dropdown'; +import splitObject from '../_util/splitObject'; export default class Dropdown extends React.Component { static defaultProps = { @@ -10,12 +11,14 @@ export default class Dropdown extends React.Component { } render() { - const { overlay, ...otherProps } = this.props; + const [{overlay}, others] = splitObject(this.props, + ['overlay']); + const menu = React.cloneElement(overlay, { openTransitionName: 'zoom-big', }); return ( - + ); } } diff --git a/components/dropdown/index.jsx b/components/dropdown/index.tsx similarity index 100% rename from components/dropdown/index.jsx rename to components/dropdown/index.tsx diff --git a/components/dropdown/style/index.js b/components/dropdown/style/index.tsx similarity index 100% rename from components/dropdown/style/index.js rename to components/dropdown/style/index.tsx diff --git a/components/form/Form.jsx b/components/form/Form.tsx similarity index 100% rename from components/form/Form.jsx rename to components/form/Form.tsx diff --git a/components/form/FormItem.jsx b/components/form/FormItem.tsx similarity index 100% rename from components/form/FormItem.jsx rename to components/form/FormItem.tsx diff --git a/components/form/ValueMixin.jsx b/components/form/ValueMixin.tsx similarity index 80% rename from components/form/ValueMixin.jsx rename to components/form/ValueMixin.tsx index 7450ddd687..53083b2f62 100644 --- a/components/form/ValueMixin.jsx +++ b/components/form/ValueMixin.tsx @@ -1,3 +1,4 @@ +import assign from 'object-assign'; const ValueMixin = { setValue(field, e) { let v = e; @@ -13,10 +14,7 @@ const ValueMixin = { const newFormData = {}; newFormData[field] = v; this.setState({ - formData: { - ...this.state.formData, - ...newFormData, - }, + formData: assign({}, this.state.formData, newFormData), }); }, }; diff --git a/components/form/index.jsx b/components/form/index.tsx similarity index 82% rename from components/form/index.jsx rename to components/form/index.tsx index ff86226759..531af85185 100644 --- a/components/form/index.jsx +++ b/components/form/index.tsx @@ -2,13 +2,12 @@ import Form from './Form'; import FormItem from './FormItem'; import ValueMixin from './ValueMixin'; import createDOMForm from 'rc-form/lib/createDOMForm'; - +import assign from 'object-assign'; Form.create = (o = {}) => { - const options = { - ...o, + const options = assign({}, o, { fieldNameProp: 'id', fieldMetaProp: '__meta', - }; + }); return createDOMForm(options); }; diff --git a/components/form/style/index.js b/components/form/style/index.tsx similarity index 100% rename from components/form/style/index.js rename to components/form/style/index.tsx diff --git a/components/icon/index.jsx b/components/icon/index.jsx deleted file mode 100644 index 6779d1b09c..0000000000 --- a/components/icon/index.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; - -export default props => { - let { type, className = '', ...other } = props; - className += ` anticon anticon-${type}`; - return ; -}; diff --git a/components/icon/index.tsx b/components/icon/index.tsx new file mode 100644 index 0000000000..4178a095b4 --- /dev/null +++ b/components/icon/index.tsx @@ -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 ; +}; diff --git a/components/icon/style/index.js b/components/icon/style/index.tsx similarity index 100% rename from components/icon/style/index.js rename to components/icon/style/index.tsx diff --git a/components/index.tsx b/components/index.tsx new file mode 100644 index 0000000000..48fc53d391 --- /dev/null +++ b/components/index.tsx @@ -0,0 +1,2 @@ +import Affix from './affix'; +export { Affix }; \ No newline at end of file diff --git a/components/input-number/index.jsx b/components/input-number/index.tsx similarity index 78% rename from components/input-number/index.jsx rename to components/input-number/index.tsx index 8eb6010951..23357d18d9 100644 --- a/components/input-number/index.jsx +++ b/components/input-number/index.tsx @@ -1,6 +1,7 @@ import React from 'react'; import classNames from 'classnames'; import RcInputNumber from 'rc-input-number'; +import splitObject from '../_util/splitObject'; export default class InputNumber extends React.Component { static defaultProps = { @@ -9,13 +10,14 @@ export default class InputNumber extends React.Component { } render() { - const { className, size, ...other } = this.props; + const [{className, size}, others] = splitObject(this.props, + ['size','className']); const inputNumberClass = classNames({ [`${this.props.prefixCls}-lg`]: size === 'large', [`${this.props.prefixCls}-sm`]: size === 'small', [className]: !!className, }); - return ; + return ; } } diff --git a/components/input-number/style/index.js b/components/input-number/style/index.tsx similarity index 100% rename from components/input-number/style/index.js rename to components/input-number/style/index.tsx diff --git a/components/input/Group.jsx b/components/input/Group.tsx similarity index 100% rename from components/input/Group.jsx rename to components/input/Group.tsx diff --git a/components/input/Input.jsx b/components/input/Input.tsx similarity index 96% rename from components/input/Input.jsx rename to components/input/Input.tsx index df99e87efb..4483659572 100644 --- a/components/input/Input.jsx +++ b/components/input/Input.tsx @@ -1,7 +1,7 @@ import React, { Component, PropTypes } from 'react'; import classNames from 'classnames'; import calculateNodeHeight from './calculateNodeHeight'; - +import assign from 'object-assign'; function fixControlledValue(value) { if (typeof value === 'undefined' || value === null) { return ''; @@ -131,7 +131,7 @@ export default class Input extends Component { } renderInput() { - const props = { ...this.props }; + const props = assign({}, this.props); const prefixCls = props.prefixCls; if (!props.type) { return props.children; @@ -156,10 +156,7 @@ export default class Input extends Component { return (