diff --git a/components/_util/getLocale.tsx b/components/_util/getLocale.tsx index 04de6ef2ea..20922821c7 100644 --- a/components/_util/getLocale.tsx +++ b/components/_util/getLocale.tsx @@ -1,14 +1,20 @@ -import assign from 'object-assign'; - export function getComponentLocale(props, context, componentName, getDefaultLocale) { const locale = context && context.antLocale && context.antLocale[componentName] ? context.antLocale[componentName] : getDefaultLocale(); - let result = assign({}, locale); + let result = { + ...locale, + }; if (props.locale) { - result = assign(result, props.locale); + result = { + ...result, + ...props.locale, + }; if (props.locale.lang) { - result.lang = assign({}, locale.lang, props.locale.lang); + result.lang = { + ...locale.lang, + ...props.locale.lang, + }; } } return result; diff --git a/components/action-sheet/index.web.tsx b/components/action-sheet/index.web.tsx index 7e23d7d170..5599e23b9f 100644 --- a/components/action-sheet/index.web.tsx +++ b/components/action-sheet/index.web.tsx @@ -1,12 +1,9 @@ -/* tslint:disable:no-unused-variable */ /* tslint:disable:jsx-no-multiline-js */ import React from 'react'; -/* tslint:enable:no-unused-variable */ import ReactDOM from 'react-dom'; import Dialog from 'rc-dialog'; import classNames from 'classnames'; import Icon from '../icon/index.web'; -import assign from 'object-assign'; import getDataAttr from '../_util/getDataAttr'; import Touchable from 'rc-touchable'; @@ -16,10 +13,11 @@ function noop() { } const queue: any[] = []; function createActionSheet(flag, config, callback) { - const props = assign({}, { + const props = { prefixCls: 'am-action-sheet', cancelButtonText: '取消', - }, config); + ...config, + }; const { prefixCls, className, transitionName, maskTransitionName, maskClosable = true } = props; let div: any = document.createElement('div'); diff --git a/components/carousel/index.web.tsx b/components/carousel/index.web.tsx index 71152446f5..27a66827bb 100644 --- a/components/carousel/index.web.tsx +++ b/components/carousel/index.web.tsx @@ -2,8 +2,8 @@ import React from 'react'; import createReactClass from 'create-react-class'; import classNames from 'classnames'; import ReactCarousel from 'rmc-nuka-carousel'; -import assign from 'object-assign'; import CarouselProps from './PropsType'; +import omit from 'omit.js'; export default class Carousel extends React.Component { static defaultProps = { @@ -37,17 +37,21 @@ export default class Carousel extends React.Component { } render() { - const { className, prefixCls, dotStyle, dotActiveStyle } = this.props; - let props = assign({}, this.props); - props = assign(props, { - wrapAround: props.infinite, - slideIndex: props.selectedIndex, - beforeSlide: props.beforeChange, - }); + const { + className, prefixCls, dotStyle, dotActiveStyle, infinite, + selectedIndex, beforeChange, dots, vertical, + } = this.props; + const restProps = omit(this.props, ['infinite', 'selectedIndex', 'beforeChange', 'afterChange', 'dots']); + const newProps = { + ...restProps, + wrapAround: infinite, + slideIndex: selectedIndex, + beforeSlide: beforeChange, + }; let Decorators: any[] = []; const current = this.state.selectedIndex; - if (props.dots) { + if (dots) { Decorators = [{ component: createReactClass({ render() { @@ -79,21 +83,15 @@ export default class Carousel extends React.Component { }]; } - ['infinite', 'selectedIndex', 'beforeChange', 'afterChange', 'dots'].forEach(prop => { - if (props.hasOwnProperty(prop)) { - delete props[prop]; - } - }); - const wrapCls = classNames({ [className as string]: className, [prefixCls as string]: true, - [`${prefixCls}-vertical`]: props.vertical, + [`${prefixCls}-vertical`]: vertical, }); return ( { - static defaultProps = assign({ + static defaultProps = { triggerType: 'onClick', styles: PopupStyles, minuteStep: 1, - }, getDefaultProps()); + ...getDefaultProps(), + }; static contextTypes = { antLocale: PropTypes.object, diff --git a/components/date-picker/index.web.tsx b/components/date-picker/index.web.tsx index 11a4051af7..41e8966fa1 100644 --- a/components/date-picker/index.web.tsx +++ b/components/date-picker/index.web.tsx @@ -1,20 +1,19 @@ -/* eslint no-console:0 */ import React from 'react'; import PropTypes from 'prop-types'; import PopupDatePicker from 'rmc-date-picker/lib/Popup'; import RCDatePicker from 'rmc-date-picker/lib/DatePicker'; import { formatFn, getProps, getDefaultDate } from './utils'; -import assign from 'object-assign'; import tsPropsType from './PropsType'; import { getComponentLocale, getLocaleCode } from '../_util/getLocale'; function getDefaultProps() { - return assign({ + return { prefixCls: 'am-picker', pickerPrefixCls: 'am-picker-col', popupPrefixCls: 'am-picker-popup', minuteStep: 1, - }, getProps()); + ...getProps(), + }; } export default class DatePicker extends React.Component { diff --git a/components/input-item/index.tsx b/components/input-item/index.tsx index e139a53b01..c32d10fb1d 100644 --- a/components/input-item/index.tsx +++ b/components/input-item/index.tsx @@ -1,11 +1,11 @@ /* tslint:disable:jsx-no-multiline-js */ import React from 'react'; -import assign from 'object-assign'; import { View, Image, Text, TouchableWithoutFeedback, StyleSheet } from 'react-native'; import Input from './Input'; import variables from '../style/themes/default'; import InputItemProps from './PropsType'; import InputItemStyle from './style/index'; +import omit from 'omit.js'; const noop: any = () => {}; @@ -116,16 +116,10 @@ export default class InputItem extends React.Component { (extra as string).length * variables.font_size_heading : 0, }; - const restProps = assign({}, this.props); - [ + const restProps = omit(this.props, [ 'type', 'clear', 'children', 'error', 'extra', 'labelNumber', 'last', 'onExtraClick', 'onErrorClick', 'styles', - ].forEach(prop => { - if (restProps.hasOwnProperty(prop)) { - delete restProps[prop]; - } - }); - + ]); const keyboardTypeArray = ['default', 'email-address', 'numeric', 'phone-pad', 'ascii-capable', 'numbers-and-punctuation', 'url', 'number-pad', 'name-phone-pad', 'decimal-pad', 'twitter', 'web-search']; diff --git a/components/list-view/demo/basic-row.tsx b/components/list-view/demo/basic-row.tsx index d6bd39436f..382e75c3fe 100644 --- a/components/list-view/demo/basic-row.tsx +++ b/components/list-view/demo/basic-row.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { View, Text, TouchableHighlight, Image } from 'react-native'; import { ListView } from 'antd-mobile'; -import assign from 'object-assign'; const data = [ { @@ -54,7 +53,10 @@ export default class BasicRowDemo extends React.Component { // console.log('reach end', event); this.setState({ isLoading: true }); setTimeout(() => { - this.rData = assign({}, this.rData, this.genData(++pageIndex)); + this.rData = { + ...this.rData, + ...this.genData(++pageIndex), + }; this.setState({ dataSource: this.state.dataSource.cloneWithRows(this.rData), isLoading: false, diff --git a/components/menu/index.web.tsx b/components/menu/index.web.tsx index 294b400172..1c78f223c5 100644 --- a/components/menu/index.web.tsx +++ b/components/menu/index.web.tsx @@ -1,7 +1,6 @@ /* tslint:disable:jsx-no-multiline-js */ import React from 'react'; import classNames from 'classnames'; -import assign from 'object-assign'; import List from '../list/index.web'; import Flex from '../flex/index.web'; import SubMenu from './SubMenu.web'; @@ -103,7 +102,10 @@ export default class Menu extends React.Component { [prefixCls as string]: true, [className as string]: !!className, })} - style={assign({}, style, heightStyle)} + style={{ + ...style, + ...heightStyle, + }} > {level === 2 && diff --git a/components/modal/Modal.web.tsx b/components/modal/Modal.web.tsx index 01fae5d47e..b65a0b69d2 100644 --- a/components/modal/Modal.web.tsx +++ b/components/modal/Modal.web.tsx @@ -1,9 +1,9 @@ import React from 'react'; import Dialog from 'rc-dialog'; import classNames from 'classnames'; -import assign from 'object-assign'; import Touchable from 'rc-touchable'; import { ModalProps, ModalComponent } from './PropsType'; +import omit from 'omit.js'; function checkIfAndroid(platform) { return platform === 'android' || @@ -119,23 +119,22 @@ export default class Modal extends ModalComponent { : null; // transparent 模式下, 内容默认居中 - const rootStyle = transparent ? assign({ - width: '5.4rem', - height: 'auto', - }, style) : assign({ - width: '100%', - height: '100%', - }, style); + const rootStyle = transparent ? + { + width: '5.4rem', + height: 'auto', + ...style, + } : + { + width: '100%', + height: '100%', + ...style, + }; - const restProps = assign({}, this.props); - ['prefixCls', 'className', 'transparent', 'animated', 'transitionName', 'maskTransitionName', + const restProps = omit(this.props, [ + 'prefixCls', 'className', 'transparent', 'animated', 'transitionName', 'maskTransitionName', 'style', 'footer', 'touchFeedback', 'wrapProps', - ].forEach(prop => { - if (restProps.hasOwnProperty(prop)) { - delete restProps[prop]; - } - }); - + ]); const wrapProps = { onTouchStart: e => this.isInModal(e) }; return ( diff --git a/components/notice-bar/Marquee.tsx b/components/notice-bar/Marquee.tsx index 7e5c344dc0..6ab4af5fd3 100644 --- a/components/notice-bar/Marquee.tsx +++ b/components/notice-bar/Marquee.tsx @@ -7,7 +7,6 @@ import React from 'react'; import createReactClass from 'create-react-class'; import ReactDOM from 'react-dom'; -import assign from 'object-assign'; export interface MarqueeProp { prefixCls?: string; @@ -56,12 +55,13 @@ const Marquee = createReactClass({ render() { const { prefixCls, className, text } = this.props; - const style = assign({ + const style = { position: 'relative', right: this.state.animatedWidth, whiteSpace: 'nowrap', display: 'inline-block', - }, this.props.style); + ...this.props.style, + }; return (
{text}
diff --git a/components/notice-bar/index.web.tsx b/components/notice-bar/index.web.tsx index 61af6cc141..c66d7a2834 100644 --- a/components/notice-bar/index.web.tsx +++ b/components/notice-bar/index.web.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import assign from 'object-assign'; import classNames from 'classnames'; import Icon from '../icon'; import NoticeBarProps from './PropsType'; @@ -59,13 +58,14 @@ export default class NoticeBar extends React.Component { [className as string]: !!className, }); - let marquee = assign({}, { + let marquee = { loop: false, leading: 500, trailing: 800, fps: 40, style: {}, - }, marqueeProps); + ...marqueeProps, + }; return this.state.show ? (
diff --git a/components/pagination/index.web.tsx b/components/pagination/index.web.tsx index 8f6f492e05..c60da44e0a 100644 --- a/components/pagination/index.web.tsx +++ b/components/pagination/index.web.tsx @@ -91,7 +91,10 @@ export default class Pagination extends React.Component { } markup =
{arr}
; } - const cls = classNames(prefixCls, className); + const cls = classNames({ + [prefixCls as string]: true, + [className as string]: !!className, + }); return (
{ }) { - const props = assign({}, { + const props = { prefixCls: 'am-popup', animationType: 'slide-down', - }, config); + ...config, + }; const { prefixCls, transitionName, animationType, maskTransitionName, maskClosable = true, onMaskClose, @@ -73,7 +71,10 @@ function create(instanceId, config, content, afterClose = (_x: any) => { }) { footer="" transitionName={transitionName || transName} maskTransitionName={maskTransitionName || 'am-fade'} - maskProps={assign({}, props.maskProps, maskProps)} + maskProps={{ + ...props.maskProps, + ... maskProps, + }} > {content} , diff --git a/components/progress/index.web.tsx b/components/progress/index.web.tsx index 559cf6a522..0450b96e80 100644 --- a/components/progress/index.web.tsx +++ b/components/progress/index.web.tsx @@ -1,6 +1,5 @@ import React from 'react'; import classNames from 'classnames'; -import assign from 'object-assign'; import ProgressProps from './PropsType'; export default class Progress extends React.Component { @@ -46,7 +45,7 @@ export default class Progress extends React.Component { aria-valuemin="0" aria-valuemax="100" > -
+
); } diff --git a/components/refresh-control/index.web.tsx b/components/refresh-control/index.web.tsx index e25b9f8bb1..8eb62acdd8 100644 --- a/components/refresh-control/index.web.tsx +++ b/components/refresh-control/index.web.tsx @@ -1,14 +1,11 @@ -/* tslint:disable:no-unused-variable */ import React from 'react'; -/* tslint:enable:no-unused-variable */ import ListView from 'rmc-list-view'; import Icon from '../icon'; -// import tsPropsType from './PropsType'; -import assign from 'object-assign'; const dpr = typeof window !== 'undefined' && (window as any).devicePixelRatio || 2; -ListView.RefreshControl.defaultProps = assign({}, ListView.RefreshControl.defaultProps, { +ListView.RefreshControl.defaultProps = { + ...ListView.RefreshControl.defaultProps, prefixCls: 'am-refresh-control', icon: [
@@ -21,6 +18,6 @@ ListView.RefreshControl.defaultProps = assign({}, ListView.RefreshControl.defaul loading: , refreshing: false, distanceToRefresh: 50 / 2 * dpr, -}); +}; export default ListView.RefreshControl; diff --git a/components/search-bar/index.tsx b/components/search-bar/index.tsx index e1bdc11710..91f626ae80 100644 --- a/components/search-bar/index.tsx +++ b/components/search-bar/index.tsx @@ -1,12 +1,19 @@ /* tslint:disable:jsx-no-multiline-js */ import React from 'react'; -import assign from 'object-assign'; import { View, TextInput, Text, Image } from 'react-native'; import { SearchBarProps, SearchBarState, defaultProps } from './PropsType'; -import styles from './style/index'; +import styles, { SearchBarStyle } from './style'; +import omit from 'omit.js'; -export default class SearchBar extends React.Component { - static defaultProps = assign(defaultProps, { styles }); +export interface SearchBarNativeProps extends SearchBarProps { + styles: SearchBarStyle; +} + +export default class SearchBar extends React.Component { + static defaultProps = { + ...defaultProps, + styles, + }; constructor(props) { super(props); @@ -73,14 +80,9 @@ export default class SearchBar extends React.Component { - if (restProps.hasOwnProperty(prop)) { - delete restProps[prop]; - } - }); + ]); const { value, focus } = this.state; const _showCancelButton = showCancelButton || focus; return ( diff --git a/components/search-bar/style/index.tsx b/components/search-bar/style/index.tsx index 99687dbb80..649abc4de6 100644 --- a/components/search-bar/style/index.tsx +++ b/components/search-bar/style/index.tsx @@ -1,7 +1,16 @@ import variables from '../../style/themes/default'; -import { StyleSheet, ViewStyle } from 'react-native'; +import { StyleSheet, ViewStyle, TextStyle, ImageStyle } from 'react-native'; -export default StyleSheet.create({ +export interface SearchBarStyle { + input: TextStyle; + inputWrapper: ViewStyle; + wrapper: ViewStyle; + cancelTextContainer: ViewStyle; + cancelText: TextStyle; + search: ImageStyle; +} + +export default StyleSheet.create({ inputWrapper: { flex: 1, flexDirection: 'row', @@ -19,7 +28,7 @@ export default StyleSheet.create({ flex: 1, paddingTop: 0, paddingBottom: 0, - } as ViewStyle, + }, wrapper: { backgroundColor: variables.search_bar_fill, height: variables.search_bar_height, @@ -27,17 +36,17 @@ export default StyleSheet.create({ paddingRight: variables.h_spacing_md, flexDirection: 'row', alignItems: 'center', - } as ViewStyle, + }, cancelTextContainer: { height: variables.search_bar_input_height, justifyContent: 'center', alignItems: 'center', - } as ViewStyle, + }, cancelText: { fontSize: variables.link_button_font_size, color: variables.color_link, paddingLeft: variables.h_spacing_lg, - } as ViewStyle, + }, search: { tintColor: variables.input_color_icon, position: 'absolute', @@ -45,5 +54,5 @@ export default StyleSheet.create({ top: (variables.search_bar_height - variables.icon_size_xxs) / 2, width: variables.icon_size_xxs, height: variables.icon_size_xxs, - } as ViewStyle, + }, }); diff --git a/components/segmented-control/segmented.android.tsx b/components/segmented-control/segmented.android.tsx index 852c25ed6f..81d7313111 100644 --- a/components/segmented-control/segmented.android.tsx +++ b/components/segmented-control/segmented.android.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { View, Text, TouchableWithoutFeedback } from 'react-native'; -import assign from 'object-assign'; import SegmentedControlProps from './PropsType'; import AndroidStyle from './style/'; @@ -76,10 +75,11 @@ export default class SegmentedControl extends React.Component diff --git a/components/segmented-control/segmented.ios.tsx b/components/segmented-control/segmented.ios.tsx index 5335aa86e3..c0b5e4528f 100644 --- a/components/segmented-control/segmented.ios.tsx +++ b/components/segmented-control/segmented.ios.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { SegmentedControlIOS } from 'react-native'; import SegmentedControlProps from './PropsType'; -import assign from 'object-assign'; +import omit from 'omit.js'; export default class SegmentedControl extends React.Component { static defaultProps = { @@ -11,11 +11,7 @@ export default class SegmentedControl extends React.Component { static defaultProps = { @@ -11,18 +11,20 @@ export default class Stepper extends React.Component { readOnly: false, disabled: false, styles, + inputStyle: {}, }; render() { - const restProps = objectAssign({}, this.props); const inputAndroidStyle = Platform.OS === 'android' ? { top: 6, paddingTop: 0, height: 26, } : {}; - const inputStyle = objectAssign({}, inputAndroidStyle, this.props.inputStyle); - delete restProps.inputStyle; - + const inputStyle = { + ...inputAndroidStyle, + ...this.props.inputStyle, + }; + const restProps = omit(this.props, ['inputStyle']); return ( ); diff --git a/components/tab-bar/tabbar.ios.tsx b/components/tab-bar/tabbar.ios.tsx index 1819099af4..0ee25b828b 100644 --- a/components/tab-bar/tabbar.ios.tsx +++ b/components/tab-bar/tabbar.ios.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { TabBarIOS } from 'react-native'; -import assign from 'object-assign'; import { TabBarProps } from './PropsType'; +import omit from 'omit.js'; class TabBar extends React.Component { static defaultProps = { @@ -14,16 +14,13 @@ class TabBar extends React.Component { render() { const { barTintColor, tintColor, unselectedTintColor } = this.props; - const resetProps = assign({}, this.props); - ['barTintColor', 'tintColor', 'unselectedTintColor'].forEach(item => { - delete resetProps[item]; - }); + const restProps = omit(this.props, ['barTintColor', 'tintColor', 'unselectedTintColor']); return ( ); } diff --git a/components/table/index.web.tsx b/components/table/index.web.tsx index 8824a6fd05..6baf655e56 100644 --- a/components/table/index.web.tsx +++ b/components/table/index.web.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import assign from 'object-assign'; import RcTable from 'rc-table'; import warning from 'warning'; @@ -13,7 +12,10 @@ export default class Table extends React.Component { warning(false, 'Table is going to be deprecated at antd-mobile@2.0. see https://goo.gl/xb0YEX'); const { prefixCls, columns, dataSource, direction, scrollX, titleFixed } = this.props; - const newProps = assign({}, this.props, { data: dataSource }); + const newProps = { + ...this.props, + data: dataSource, + }; let table; // 默认纵向 diff --git a/components/textarea-item/index.tsx b/components/textarea-item/index.tsx index 5c95c2e21b..80ea1002dc 100644 --- a/components/textarea-item/index.tsx +++ b/components/textarea-item/index.tsx @@ -1,10 +1,10 @@ /* tslint:disable:jsx-no-multiline-js */ import React from 'react'; -import assign from 'object-assign'; import { View, Image, Text, TextInput, TouchableWithoutFeedback } from 'react-native'; import variables from '../style/themes/default'; import TextAreaItemProps from './PropsType'; import TextAreaItemStyle from './style/index'; +import omit from 'omit.js'; function fixControlledValue(value) { if (typeof value === 'undefined' || value === null) { @@ -94,15 +94,9 @@ export default class TextAreaItem extends React.Component 0 ? count : undefined; - const restProps = assign({}, this.props); - [ + const restProps = omit(this.props, [ 'rows', 'error', 'clear', 'count', 'autoHeight', 'last', 'onErrorClick', 'styles', 'style', - ].forEach(prop => { - if (restProps.hasOwnProperty(prop)) { - delete restProps[prop]; - } - }); - + ]); return ( { static defaultProps = { Component: 'div', }; render() { - const props = assign({}, this.props); + const props = { + ...this.props, + }; if (Array.isArray(props.style)) { - const style = {}; + let style = {}; props.style.forEach(s => { - assign(style, s); + style = { + ...style, + ...s, + }; }); props.style = style; } diff --git a/package.json b/package.json index fb13e67329..b106f97178 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "create-react-class": "^15.5.2", "moment": "~2.18.1", "normalize.css": "^7.0.0", - "object-assign": "~4.1.0", "omit.js": "~0.1.0", "prop-types": "^15.5.8", "rc-checkbox": "~2.0.0", @@ -72,7 +71,7 @@ "antd": "2.x", "antd-demo-jest": "^1.2.0", "antd-mobile-demo-data": "^0.1.1", - "antd-tools": "^1.4.2", + "antd-tools": "^1.6.0", "babel-eslint": "^7.1.0", "babel-jest": "^20.0.3", "babel-plugin-import": "^1.2.1",