Skip to content

Commit

Permalink
Merge e921896 into 2d8c213
Browse files Browse the repository at this point in the history
  • Loading branch information
heiyu4585 authored Aug 19, 2022
2 parents 2d8c213 + e921896 commit 30c93a8
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 11 deletions.
4 changes: 4 additions & 0 deletions docs/demo/AutoComplete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## AutoComplete


<code src="../examples/AutoComplete.tsx" />
4 changes: 4 additions & 0 deletions docs/demo/Cascader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Cascader


<code src="../examples/Cascader.tsx" />
4 changes: 0 additions & 4 deletions docs/demo/basic.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/examples/basic.tsx → docs/examples/AutoComplete.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AutoComplete, ConfigProvider } from '../../src';
import { AutoComplete } from '../../src';

export default () => {
return (
Expand Down
47 changes: 47 additions & 0 deletions docs/examples/Cascader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import { Cascader } from '../../src';

export default () => {
const options = [
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [
{
value: 'xihu',
label: 'West Lake',
},
],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [
{
value: 'zhonghuamen',
label: 'Zhong Hua Men',
},
],
},
],
},
];

function onChange(value) {
console.log(value);
}

return (
<Cascader options={options} onChange={onChange} placeholder="Please select" />
);
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
},
"license": "MIT",
"dependencies": {
"classnames": "^2.2.6"
"classnames": "^2.2.6",
"dayjs": "^1.11.4"
},
"peerDependencies": {
"antd": "4.x",
Expand All @@ -56,7 +57,7 @@
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@umijs/fabric": "^2.5.2",
"antd": "^5.0.0-experimental.10",
"antd": "^5.0.0-experimental.18",
"dumi": "^1.1.0",
"eslint": "^7.18.0",
"father": "^4.0.0-rc.8",
Expand Down
2 changes: 1 addition & 1 deletion src/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CompatibleAutoComplete = React.forwardRef(
) => {
warning(
!dropdownClassName,
`[Compatible: AutoComplete] 'dropdownClassName' is deprecated. Please use 'popupClassName' instead.`,
"[antd: AutoComplete] `dropdownClassName` is removed in v5, please use `popupClassName` instead.",
);

return (
Expand Down
32 changes: 32 additions & 0 deletions src/Cascader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react';
import { Cascader } from 'antd';
import warning from 'rc-util/lib/warning';

type CascaderProps = Parameters<typeof Cascader>[0];
type CascaderRef = CascaderProps['ref'];

type CompatibleCascaderProps = CascaderProps & {
/** @deprecated Please use `popupClassName` instead. */
dropdownClassName?: string;
};

const CompatibleCascader = React.forwardRef(
(
{ dropdownClassName, popupClassName, ...restProps }: CompatibleCascaderProps,
ref: CascaderRef,
) => {
warning(
!dropdownClassName,
"[antd: Cascader] `dropdownClassName` is removed in v5, please use `popupClassName` instead.",
);
return (
<Cascader {...restProps} popupClassName={popupClassName || dropdownClassName} ref={ref} />
);
},
);

if (process.env.NODE_ENV !== 'production') {
CompatibleCascader.displayName = 'CompatibleCascader';
}

export default CompatibleCascader;
5 changes: 3 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from 'antd';

import AutoComplete from './AutoComplete';
export { AutoComplete };
import Cascader from './Cascader';

export { AutoComplete,Cascader};
2 changes: 1 addition & 1 deletion tests/AutoComplete.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('AutoComplete', () => {
);

expect(errSpy).toHaveBeenCalledWith(
"Warning: [Compatible: AutoComplete] 'dropdownClassName' is deprecated. Please use 'popupClassName' instead.",
"Warning: [antd: AutoComplete] `dropdownClassName` is removed in v5, please use `popupClassName` instead.",
);

// TODO: Remove this when antd release version
Expand Down
58 changes: 58 additions & 0 deletions tests/Cascader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import { Cascader } from '../src';
import { render } from '@testing-library/react';

describe('Cascader', () => {

const options = [
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [
{
value: 'xihu',
label: 'West Lake',
},
],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [
{
value: 'zhonghuamen',
label: 'Zhong Hua Men',
},
],
},
],
},
];

it('dropdownClassName', async () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

const { container } = render(
<Cascader options={options} dropdownClassName="test" />
);

expect(errSpy).toHaveBeenNthCalledWith(1,
"Warning: [antd: Cascader] `dropdownClassName` is removed in v5, please use `popupClassName` instead.",
);

// TODO: Remove this when antd release version
// expect(container.querySelector('.test')).toBeTruthy();

errSpy.mockRestore();
});
});

0 comments on commit 30c93a8

Please sign in to comment.