Skip to content

Commit

Permalink
chore(deps-dev): bump eslint-config-airbnb from 18.2.1 to 19.0.0 (#32824
Browse files Browse the repository at this point in the history
)

* chore(deps-dev): bump eslint-config-airbnb from 18.2.1 to 19.0.0

Bumps [eslint-config-airbnb](https://github.com/airbnb/javascript) from 18.2.1 to 19.0.0.
- [Release notes](https://github.com/airbnb/javascript/releases)
- [Commits](airbnb/javascript@eslint-config-airbnb-v18.2.1...eslint-config-airbnb-v19.0.0)

---
updated-dependencies:
- dependency-name: eslint-config-airbnb
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* chore: code style

* memoize-one

* add comment

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* fix lint

* improve useMemo deps

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: afc163 <afc163@gmail.com>
  • Loading branch information
dependabot[bot] and afc163 committed Nov 26, 2021
1 parent 6f837e0 commit 20d5502
Show file tree
Hide file tree
Showing 51 changed files with 367 additions and 344 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ module.exports = {
'jsx-a11y/href-no-hash': 0,
'jsx-a11y/control-has-associated-label': 0,
'import/no-extraneous-dependencies': 0,
'react/jsx-no-constructed-context-values': 0,
'react/no-unstable-nested-components': 0,
},
},
],
Expand All @@ -100,7 +102,8 @@ module.exports = {
'react/no-unused-prop-types': 0,
'react/default-props-match-prop-types': 0,
'react-hooks/rules-of-hooks': 2, // Checks rules of Hooks

'react/function-component-definition': 0,
'react/no-unused-class-component-methods': 0,
'import/extensions': 0,
'import/no-cycle': 0,
'import/no-extraneous-dependencies': [
Expand Down
2 changes: 1 addition & 1 deletion components/_util/__tests__/unreachableException.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import UnreachableException from '../unreachableException';
describe('UnreachableException', () => {
it('error thrown matches snapshot', () => {
const exception = new UnreachableException('some value');
expect(exception.message).toMatchInlineSnapshot(`"unreachable case: \\"some value\\""`);
expect(exception.error.message).toMatchInlineSnapshot(`"unreachable case: \\"some value\\""`);
});
});
5 changes: 4 additions & 1 deletion components/_util/unreachableException.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

export default class UnreachableException {
error: Error;

constructor(value: never) {
return new Error(`unreachable case: ${JSON.stringify(value)}`);
this.error = new Error(`unreachable case: ${JSON.stringify(value)}`);
}
}
21 changes: 11 additions & 10 deletions components/anchor/Anchor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import classNames from 'classnames';
import memoizeOne from 'memoize-one';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import Affix from '../affix';
import AnchorLink from './AnchorLink';
Expand Down Expand Up @@ -258,7 +259,6 @@ export default class Anchor extends React.Component<AnchorProps, AnchorState, Co

render() {
const { getPrefixCls, direction } = this.context;

const {
prefixCls: customizePrefixCls,
className = '',
Expand All @@ -267,6 +267,7 @@ export default class Anchor extends React.Component<AnchorProps, AnchorState, Co
affix,
showInkInFixed,
children,
onClick,
} = this.props;
const { activeLink } = this.state;

Expand Down Expand Up @@ -309,16 +310,16 @@ export default class Anchor extends React.Component<AnchorProps, AnchorState, Co
</div>
);

const contextValue = memoizeOne((link, onClickFn) => ({
registerLink: this.registerLink,
unregisterLink: this.unregisterLink,
scrollTo: this.handleScrollTo,
activeLink: link,
onClick: onClickFn,
}))(activeLink, onClick);

return (
<AnchorContext.Provider
value={{
registerLink: this.registerLink,
unregisterLink: this.unregisterLink,
activeLink: this.state.activeLink,
scrollTo: this.handleScrollTo,
onClick: this.props.onClick,
}}
>
<AnchorContext.Provider value={contextValue}>
{!affix ? (
anchorContent
) : (
Expand Down
4 changes: 2 additions & 2 deletions components/breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const getPath = (path: string, params: any) => {
return path;
};

const addChildPath = (paths: string[], childPath: string = '', params: any) => {
const addChildPath = (paths: string[], childPath: string, params: any) => {
const originalPaths = [...paths];
const path = getPath(childPath, params);
const path = getPath(childPath || '', params);
if (path) {
originalPaths.push(path);
}
Expand Down
1 change: 1 addition & 0 deletions components/button/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ describe('Button', () => {
it('should handle fragment as children', () => {
const wrapper = mount(
<Button>
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
<>text</>
</Button>,
);
Expand Down
2 changes: 1 addition & 1 deletion components/button/button-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ButtonGroup: React.FC<ButtonGroupProps> = props => (
break;
default:
// eslint-disable-next-line no-console
console.warn(new UnreachableException(size));
console.warn((new UnreachableException(size)).error);
}

const classes = classNames(
Expand Down
3 changes: 2 additions & 1 deletion components/carousel/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mount } from 'enzyme';
import Carousel from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { sleep } from '../../../tests/utils';

describe('Carousel', () => {
mountTest(Carousel);
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('Carousel', () => {
const spy = jest.spyOn(ref.current.innerSlider, 'autoPlay');
window.resizeTo(1000);
expect(spy).not.toHaveBeenCalled();
await new Promise(resolve => setTimeout(resolve, 500));
await sleep(500);
expect(spy).toHaveBeenCalled();
});

Expand Down
3 changes: 1 addition & 2 deletions components/checkbox/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,16 @@ const InternalCheckboxGroup: React.ForwardRefRenderFunction<HTMLDivElement, Chec
));
}

// eslint-disable-next-line react/jsx-no-constructed-context-values
const context = {
toggleOption,
value,
disabled: restProps.disabled,
name: restProps.name,

// https://github.com/ant-design/ant-design/issues/16376
registerValue,
cancelValue,
};

const classString = classNames(
groupPrefixCls,
{
Expand Down
3 changes: 2 additions & 1 deletion components/descriptions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ function Descriptions({

// Children
const rows = getRows(children, mergedColumn);
const contextValue = React.useMemo(() => ({ labelStyle, contentStyle }), [labelStyle, contentStyle]);

return (
<DescriptionsContext.Provider value={{ labelStyle, contentStyle }}>
<DescriptionsContext.Provider value={contextValue}>
<div
className={classNames(
prefixCls,
Expand Down
5 changes: 3 additions & 2 deletions components/form/FormItemInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const FormItemInput: React.FC<FormItemInputProps & FormItemInputMiscProps> = pro
) : null;

// Pass to sub FormItem should not with col info
const subFormContext = { ...formContext };
const subFormContext = React.useMemo(() => ({ ...formContext }), [formContext]);
delete subFormContext.labelCol;
delete subFormContext.wrapperCol;

Expand All @@ -87,8 +87,9 @@ const FormItemInput: React.FC<FormItemInputProps & FormItemInputMiscProps> = pro
{icon}
</div>
);
const formItemContext = React.useMemo(() => ({ prefixCls, status }), [prefixCls, status]);
const errorListDom = (
<FormItemPrefixContext.Provider value={{ prefixCls, status }}>
<FormItemPrefixContext.Provider value={formItemContext}>
<ErrorList
errors={errors}
warnings={warnings}
Expand Down
9 changes: 8 additions & 1 deletion components/form/FormList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ const FormList: React.FC<FormListProps> = ({

const { getPrefixCls } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('form', customizePrefixCls);
const contextValue = React.useMemo(
() => ({
prefixCls,
status: 'error' as const,
}),
[prefixCls],
);

return (
<List {...props}>
{(fields, operation, meta) => (
<FormItemPrefixContext.Provider value={{ prefixCls, status: 'error' }}>
<FormItemPrefixContext.Provider value={contextValue}>
{children(
fields.map(field => ({ ...field, fieldKey: field.key })),
operation,
Expand Down
98 changes: 48 additions & 50 deletions components/form/demo/form-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,56 +94,54 @@ const Demo = () => {
};

return (
<>
<Form.Provider
onFormFinish={(name, { values, forms }) => {
if (name === 'userForm') {
const { basicForm } = forms;
const users = basicForm.getFieldValue('users') || [];
basicForm.setFieldsValue({ users: [...users, values] });
setVisible(false);
}
}}
>
<Form {...layout} name="basicForm" onFinish={onFinish}>
<Form.Item name="group" label="Group Name" rules={[{ required: true }]}>
<Input />
</Form.Item>
<Form.Item
label="User List"
shouldUpdate={(prevValues, curValues) => prevValues.users !== curValues.users}
>
{({ getFieldValue }) => {
const users: UserType[] = getFieldValue('users') || [];
return users.length ? (
<ul>
{users.map((user, index) => (
<li key={index} className="user">
<Avatar icon={<UserOutlined />} />
{user.name} - {user.age}
</li>
))}
</ul>
) : (
<Typography.Text className="ant-form-text" type="secondary">
( <SmileOutlined /> No user yet. )
</Typography.Text>
);
}}
</Form.Item>
<Form.Item {...tailLayout}>
<Button htmlType="submit" type="primary">
Submit
</Button>
<Button htmlType="button" style={{ margin: '0 8px' }} onClick={showUserModal}>
Add User
</Button>
</Form.Item>
</Form>

<ModalForm visible={visible} onCancel={hideUserModal} />
</Form.Provider>
</>
<Form.Provider
onFormFinish={(name, { values, forms }) => {
if (name === 'userForm') {
const { basicForm } = forms;
const users = basicForm.getFieldValue('users') || [];
basicForm.setFieldsValue({ users: [...users, values] });
setVisible(false);
}
}}
>
<Form {...layout} name="basicForm" onFinish={onFinish}>
<Form.Item name="group" label="Group Name" rules={[{ required: true }]}>
<Input />
</Form.Item>
<Form.Item
label="User List"
shouldUpdate={(prevValues, curValues) => prevValues.users !== curValues.users}
>
{({ getFieldValue }) => {
const users: UserType[] = getFieldValue('users') || [];
return users.length ? (
<ul>
{users.map((user, index) => (
<li key={index} className="user">
<Avatar icon={<UserOutlined />} />
{user.name} - {user.age}
</li>
))}
</ul>
) : (
<Typography.Text className="ant-form-text" type="secondary">
( <SmileOutlined /> No user yet. )
</Typography.Text>
);
}}
</Form.Item>
<Form.Item {...tailLayout}>
<Button htmlType="submit" type="primary">
Submit
</Button>
<Button htmlType="button" style={{ margin: '0 8px' }} onClick={showUserModal}>
Add User
</Button>
</Form.Item>
</Form>

<ModalForm visible={visible} onCancel={hideUserModal} />
</Form.Provider>
);
};

Expand Down
50 changes: 24 additions & 26 deletions components/form/demo/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,30 @@ const FormLayoutDemo = () => {
: null;

return (
<>
<Form
{...formItemLayout}
layout={formLayout}
form={form}
initialValues={{ layout: formLayout }}
onValuesChange={onFormLayoutChange}
>
<Form.Item label="Form Layout" name="layout">
<Radio.Group value={formLayout}>
<Radio.Button value="horizontal">Horizontal</Radio.Button>
<Radio.Button value="vertical">Vertical</Radio.Button>
<Radio.Button value="inline">Inline</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item label="Field A">
<Input placeholder="input placeholder" />
</Form.Item>
<Form.Item label="Field B">
<Input placeholder="input placeholder" />
</Form.Item>
<Form.Item {...buttonItemLayout}>
<Button type="primary">Submit</Button>
</Form.Item>
</Form>
</>
<Form
{...formItemLayout}
layout={formLayout}
form={form}
initialValues={{ layout: formLayout }}
onValuesChange={onFormLayoutChange}
>
<Form.Item label="Form Layout" name="layout">
<Radio.Group value={formLayout}>
<Radio.Button value="horizontal">Horizontal</Radio.Button>
<Radio.Button value="vertical">Vertical</Radio.Button>
<Radio.Button value="inline">Inline</Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item label="Field A">
<Input placeholder="input placeholder" />
</Form.Item>
<Form.Item label="Field B">
<Input placeholder="input placeholder" />
</Form.Item>
<Form.Item {...buttonItemLayout}>
<Button type="primary">Submit</Button>
</Form.Item>
</Form>
);
};

Expand Down

0 comments on commit 20d5502

Please sign in to comment.