Skip to content

Commit

Permalink
chore: replace omit (ant-design#28846)
Browse files Browse the repository at this point in the history
* chore: Replace omit.js with rc-util omit

* chore: Replace omit.js with rc-util omit

* fix ts

* fix ts

* fix ts
  • Loading branch information
zombieJ authored Jan 13, 2021
1 parent 3006be0 commit 4315ac5
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 97 deletions.
4 changes: 2 additions & 2 deletions components/affix/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import ResizeObserver from 'rc-resize-observer';
import { ConfigContext, ConfigConsumerProps } from '../config-provider';
import { throttleByAnimationFrameDecorator } from '../_util/throttleByAnimationFrame';
Expand Down Expand Up @@ -269,7 +269,7 @@ class Affix extends React.Component<AffixProps, AffixState> {
let props = omit(this.props, ['prefixCls', 'offsetTop', 'offsetBottom', 'target', 'onChange']);
// Omit this since `onTestUpdatePosition` only works on test.
if (process.env.NODE_ENV === 'test') {
props = omit(props, ['onTestUpdatePosition']);
props = omit(props as typeof props & { onTestUpdatePosition: any }, ['onTestUpdatePosition']);
}

return (
Expand Down
14 changes: 9 additions & 5 deletions components/auto-complete/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/**
* TODO: 4.0
* - remove `dataSource`
* - `size` not work with customizeInput
* - customizeInput not feedback `ENTER` key since accessibility enhancement
*
* - Remove `dataSource`
* - `size` not work with customizeInput
* - CustomizeInput not feedback `ENTER` key since accessibility enhancement
*/

import * as React from 'react';
import toArray from 'rc-util/lib/Children/toArray';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import Select, { InternalSelectProps, OptionType, RefSelectProps } from '../select';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import devWarning from '../_util/devWarning';
Expand Down Expand Up @@ -115,7 +116,10 @@ const AutoComplete: React.ForwardRefRenderFunction<RefSelectProps, AutoCompleteP
prefixCls={prefixCls}
className={classNames(`${prefixCls}-auto-complete`, className)}
mode={Select.SECRET_COMBOBOX_MODE_DO_NOT_USE as any}
getInputElement={getInputElement}
{...{
// Internal api
getInputElement,
}}
>
{optionChildren}
</Select>
Expand Down
2 changes: 1 addition & 1 deletion components/back-top/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CSSMotion from 'rc-motion';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import VerticalAlignTopOutlined from '@ant-design/icons/VerticalAlignTopOutlined';
import { throttleByAnimationFrame } from '../_util/throttleByAnimationFrame';
import { ConfigContext } from '../config-provider';
Expand Down
4 changes: 2 additions & 2 deletions components/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/button-has-type */
import * as React from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';

import Group from './button-group';
import { ConfigContext } from '../config-provider';
Expand Down Expand Up @@ -262,7 +262,7 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
? spaceChildren(children, isNeedInserted() && autoInsertSpace)
: null;

const linkButtonRestProps = omit(rest as AnchorButtonProps, ['navigate']);
const linkButtonRestProps = omit(rest as AnchorButtonProps & { navigate: any }, ['navigate']);
if (linkButtonRestProps.href !== undefined) {
return (
<a {...linkButtonRestProps} className={classes} onClick={handleClick} ref={buttonRef}>
Expand Down
2 changes: 1 addition & 1 deletion components/card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import Grid from './Grid';
import Meta from './Meta';
import Tabs, { TabsProps } from '../tabs';
Expand Down
66 changes: 39 additions & 27 deletions components/cascader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import RcCascader from 'rc-cascader';
import arrayTreeFilter from 'array-tree-filter';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import KeyCode from 'rc-util/lib/KeyCode';
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
import DownOutlined from '@ant-design/icons/DownOutlined';
Expand Down Expand Up @@ -89,9 +89,9 @@ export interface CascaderProps {
placeholder?: string;
/** 输入框大小,可选 `large` `default` `small` */
size?: SizeType;
/** 输入框name */
/** 输入框 name */
name?: string;
/** 输入框id */
/** 输入框 id */
id?: string;
/** Whether has border style */
bordered?: boolean;
Expand Down Expand Up @@ -119,6 +119,11 @@ export interface CascaderProps {
fieldNames?: FieldNamesType;
suffixIcon?: React.ReactNode;
dropdownRender?: (menus: React.ReactNode) => React.ReactNode;

// Miss prop defines.
autoComplete?: string;
transitionName?: string;
children?: React.ReactElement;
}

export interface CascaderState {
Expand Down Expand Up @@ -547,26 +552,32 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {

// Fix bug of https://github.com/facebook/react/pull/5004
// and https://fb.me/react-unknown-prop
const inputProps = omit(otherProps, [
'onChange',
'options',
'popupPlacement',
'transitionName',
'displayRender',
'onPopupVisibleChange',
'changeOnSelect',
'expandTrigger',
'popupVisible',
'getPopupContainer',
'loadData',
'popupClassName',
'filterOption',
'renderFilteredOption',
'sortFilteredOption',
'notFoundContent',
'fieldNames',
'bordered',
]);
const inputProps = omit(
// Not know why these props left
otherProps as typeof otherProps & {
filterOption: any;
renderFilteredOption: any;
sortFilteredOption: any;
defaultValue: any;
},
[
'onChange',
'options',
'popupPlacement',
'transitionName',
'displayRender',
'onPopupVisibleChange',
'changeOnSelect',
'expandTrigger',
'popupVisible',
'getPopupContainer',
'loadData',
'filterOption',
'renderFilteredOption',
'sortFilteredOption',
'fieldNames',
],
);

let { options } = props;
const names: FilledFieldNamesType = getFilledFieldNames(this.props);
Expand Down Expand Up @@ -611,12 +622,12 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
inputIcon = <DownOutlined className={arrowCls} />;
}

const input = children || (
const input: React.ReactElement = children || (
<span style={style} className={pickerCls}>
<span className={`${prefixCls}-picker-label`}>{this.getLabel()}</span>
<Input
{...inputProps}
tabIndex="-1"
tabIndex={-1}
ref={this.saveInput}
prefixCls={inputPrefixCls}
placeholder={value && value.length > 0 ? undefined : placeholder}
Expand Down Expand Up @@ -649,7 +660,7 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
);

const getPopupContainer = props.getPopupContainer || getContextPopupContainer;
const rest = omit(props, [
const rest = omit(props as typeof props & { inputIcon: any; loadingIcon: any }, [
'inputIcon',
'expandIcon',
'loadingIcon',
Expand Down Expand Up @@ -677,7 +688,8 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
loadingIcon={loadingIcon}
popupClassName={rcCascaderPopupClassName}
popupPlacement={this.getPopupPlacement(direction)}
dropdownRender={dropdownRender}
// rc-cascader should update ts define to fix this case
dropdownRender={dropdownRender as any}
>
{input}
</RcCascader>
Expand Down
2 changes: 1 addition & 1 deletion components/checkbox/Group.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import Checkbox, { CheckboxChangeEvent } from './Checkbox';
import { ConfigContext } from '../config-provider';

Expand Down
6 changes: 3 additions & 3 deletions components/collapse/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import classNames from 'classnames';
import RightOutlined from '@ant-design/icons/RightOutlined';

import toArray from 'rc-util/lib/Children/toArray';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import CollapsePanel, { CollapsibleType } from './CollapsePanel';
import { ConfigContext } from '../config-provider';
import collapseMotion from '../_util/motion';
Expand Down Expand Up @@ -95,8 +95,8 @@ const Collapse: CollapseInterface = props => {
if (child.props?.disabled) {
const key = child.key || String(index);
const { disabled, collapsible } = child.props;
const childProps: CollapseProps = {
...omit(child.props, 'disabled'),
const childProps: CollapseProps & { key: React.Key } = {
...omit(child.props, ['disabled']),
key,
collapsible: collapsible ?? (disabled ? 'disabled' : undefined),
};
Expand Down
3 changes: 1 addition & 2 deletions components/drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RcDrawer from 'rc-drawer';
import getScrollBarSize from 'rc-util/lib/getScrollBarSize';
import CloseOutlined from '@ant-design/icons/CloseOutlined';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import { ConfigContext, DirectionType } from '../config-provider';
import { tuple } from '../_util/type';

Expand Down Expand Up @@ -304,7 +304,6 @@ class Drawer extends React.Component<InternalDrawerProps, IDrawerState> {
'footer',
'title',
'push',
'visible',
'width',
'height',
])}
Expand Down
9 changes: 2 additions & 7 deletions components/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FieldProps } from 'rc-field-form/lib/Field';
import FieldContext from 'rc-field-form/lib/FieldContext';
import { Meta, NamePath } from 'rc-field-form/lib/interface';
import { supportRef } from 'rc-util/lib/ref';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import Row from '../grid/row';
import { ConfigContext } from '../config-provider';
import { tuple } from '../_util/type';
Expand Down Expand Up @@ -204,24 +204,19 @@ function FormItem<Values = any>(props: FormItemProps<Values>): React.ReactElemen
'extra',
'getValueFromEvent',
'getValueProps',
'hasFeedback',
'help',
'htmlFor',
'id', // It is deprecated because `htmlFor` is its replacement.
'initialValue',
'isListField',
'label',
'labelAlign',
'labelCol',
'normalize',
'preserve',
'required',
'tooltip',
'validateFirst',
'validateStatus',
'valuePropName',
'wrapperCol',
'_internalItemRender',
'_internalItemRender' as any,
])}
>
{/* Label */}
Expand Down
6 changes: 4 additions & 2 deletions components/form/context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import { FormProvider as RcFormProvider } from 'rc-field-form';
import { FormProviderProps as RcFormProviderProps } from 'rc-field-form/lib/FormContext';
import { ColProps } from '../grid/col';
Expand Down Expand Up @@ -35,7 +35,9 @@ export const FormItemContext = React.createContext<FormItemContextProps>({
});

/** Form Provider */
export interface FormProviderProps extends Omit<RcFormProviderProps, 'validateMessages'> {}
export interface FormProviderProps extends Omit<RcFormProviderProps, 'validateMessages'> {
prefixCls?: string;
}

export const FormProvider: React.FC<FormProviderProps> = props => {
const providerProps = omit(props, ['prefixCls']);
Expand Down
4 changes: 2 additions & 2 deletions components/input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import Group from './Group';
import Search from './Search';
import TextArea from './TextArea';
Expand Down Expand Up @@ -266,7 +266,7 @@ class Input extends React.Component<InputProps, InputState> {
) => {
const { className, addonBefore, addonAfter, size: customizeSize, disabled } = this.props;
// Fix https://fb.me/react-unknown-prop
const otherProps = omit(this.props, [
const otherProps = omit(this.props as InputProps & { inputType: any }, [
'prefixCls',
'onPressEnter',
'addonBefore',
Expand Down
6 changes: 3 additions & 3 deletions components/input/Password.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import EyeOutlined from '@ant-design/icons/EyeOutlined';
import EyeInvisibleOutlined from '@ant-design/icons/EyeInvisibleOutlined';

Expand All @@ -20,7 +20,7 @@ const ActionMap: Record<string, string> = {
hover: 'onMouseOver',
};

const Password = React.forwardRef<unknown, PasswordProps>((props, ref) => {
const Password = React.forwardRef<any, PasswordProps>((props, ref) => {
const [visible, setVisible] = useState(false);

const onVisibleChange = () => {
Expand Down Expand Up @@ -78,7 +78,7 @@ const Password = React.forwardRef<unknown, PasswordProps>((props, ref) => {
className: inputClassName,
prefixCls: inputPrefixCls,
suffix: suffixIcon,
};
} as InputProps;

if (size) {
omittedProps.size = size;
Expand Down
6 changes: 3 additions & 3 deletions components/input/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import RcTextArea, { TextAreaProps as RcTextAreaProps } from 'rc-textarea';
import ResizableTextArea from 'rc-textarea/lib/ResizableTextArea';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import classNames from 'classnames';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import ClearableLabeledInput from './ClearableLabeledInput';
Expand Down Expand Up @@ -44,7 +44,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
const { getPrefixCls, direction } = React.useContext(ConfigContext);
const size = React.useContext(SizeContext);

const innerRef = React.useRef<RcTextArea>();
const innerRef = React.useRef<RcTextArea>(null);
const clearableInputRef = React.useRef<ClearableLabeledInput>(null);

const [value, setValue] = useMergedState(props.defaultValue, {
Expand Down Expand Up @@ -99,7 +99,7 @@ const TextArea = React.forwardRef<TextAreaRef, TextAreaProps>(
[`${prefixCls}-sm`]: size === 'small' || customizeSize === 'small',
[`${prefixCls}-lg`]: size === 'large' || customizeSize === 'large',
})}
style={showCount ? null : style}
style={showCount ? undefined : style}
prefixCls={prefixCls}
onChange={handleChange}
ref={innerRef}
Expand Down
2 changes: 1 addition & 1 deletion components/layout/Sider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { useContext, useRef, useState, useEffect } from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import BarsOutlined from '@ant-design/icons/BarsOutlined';
import RightOutlined from '@ant-design/icons/RightOutlined';
import LeftOutlined from '@ant-design/icons/LeftOutlined';
Expand Down
2 changes: 1 addition & 1 deletion components/menu/SubMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { SubMenu as RcSubMenu } from 'rc-menu';
import classNames from 'classnames';
import omit from 'omit.js';
import omit from 'rc-util/lib/omit';
import MenuContext, { MenuContextProps } from './MenuContext';
import { isValidElement } from '../_util/reactNode';

Expand Down
Loading

0 comments on commit 4315ac5

Please sign in to comment.