Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: New Picker interactive #46685

Merged
merged 92 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
3b6f4c1
chore: init
zombieJ Dec 25, 2023
df6f95a
chore: link picker
zombieJ Dec 27, 2023
c16a6bc
chore: move files
zombieJ Dec 27, 2023
3f91749
chore: update style
zombieJ Dec 28, 2023
5e85082
chore: update types
zombieJ Dec 28, 2023
fe59b45
test: update snapshot
zombieJ Dec 28, 2023
bd765ea
test: update snapshot
zombieJ Dec 28, 2023
31257f4
test: update snapshot
zombieJ Dec 28, 2023
d8d2efc
test: update snapshot
zombieJ Dec 28, 2023
3cd46cb
test: update snapshot
zombieJ Dec 28, 2023
bfa2adf
test: fix test case
zombieJ Dec 28, 2023
bdd5df4
test: update snapshot
zombieJ Dec 28, 2023
56a297c
test: update snapshot
zombieJ Dec 28, 2023
81ab39f
test: update snapshot
zombieJ Dec 28, 2023
eaa0359
test: update snapshot
zombieJ Dec 28, 2023
5c48371
chore: merge feature
zombieJ Dec 28, 2023
4ea2405
chore: clesn up useless types
zombieJ Jan 2, 2024
72b51bb
chore: update types
zombieJ Jan 2, 2024
6faec7d
chore: fix types
zombieJ Jan 2, 2024
2576570
chore: fix types
zombieJ Jan 2, 2024
8e7007c
chore: fix types
zombieJ Jan 2, 2024
d3dc3ae
chore: fix types
zombieJ Jan 2, 2024
7cc1d6f
chore: fix types
zombieJ Jan 3, 2024
1d62fe3
chore: fix types
zombieJ Jan 3, 2024
38683ff
chore: fix types
zombieJ Jan 3, 2024
69d0e99
chore: fix types
zombieJ Jan 3, 2024
4510c7f
chore: fix types
zombieJ Jan 3, 2024
4b48472
chore: update style
zombieJ Jan 3, 2024
31310ad
chore: clean up
zombieJ Jan 3, 2024
a1a6969
chore: update types
zombieJ Jan 3, 2024
e5b5b4b
test: update snapshot
zombieJ Jan 3, 2024
1d37130
test: update snapshot
zombieJ Jan 3, 2024
6c26694
test: update snapshot
zombieJ Jan 3, 2024
267eaa5
test: update snapshot
zombieJ Jan 3, 2024
a0c5f76
fix: format
zombieJ Jan 4, 2024
02b73b8
chore: update deps
zombieJ Jan 4, 2024
f18ecb0
chore: feature merge master (#46794)
zombieJ Jan 4, 2024
1f09730
Merge remote-tracking branch 'origin/feature' into picker
zombieJ Jan 4, 2024
71b8917
Merge branch 'feature' into picker
zombieJ Jan 4, 2024
2398b8e
chore: update locale size
zombieJ Jan 4, 2024
5521b1f
chore: lock dumi
zombieJ Jan 4, 2024
45f194e
test: update snapshot
zombieJ Jan 4, 2024
2f28581
test: update snapshot
zombieJ Jan 4, 2024
ba5a747
test: update snapshot
zombieJ Jan 4, 2024
5473f84
test: update snapshot
zombieJ Jan 4, 2024
9e3a0eb
test: update snapshot
zombieJ Jan 4, 2024
be4f1cc
test: update snapshot
zombieJ Jan 4, 2024
9949e80
Merge branch 'feature' into picker
li-jia-nan Jan 4, 2024
888f05f
chore: bump version
zombieJ Jan 5, 2024
56856ea
Merge branch 'picker' of https://github.com/ant-design/ant-design int…
zombieJ Jan 5, 2024
c452079
Merge remote-tracking branch 'origin/feature' into picker
zombieJ Jan 5, 2024
209e703
test: update snapshot
zombieJ Jan 5, 2024
6725616
test: update snapshot
zombieJ Jan 5, 2024
59e4459
chore: bump version
zombieJ Jan 8, 2024
6697efb
Merge remote-tracking branch 'origin/feature' into picker
zombieJ Jan 8, 2024
fbbb51c
chore: update limit
zombieJ Jan 8, 2024
f340b37
test: update snapshot
zombieJ Jan 8, 2024
c65751d
docs: update 7 days sample
zombieJ Jan 8, 2024
3429bd4
chore: rm useless style
zombieJ Jan 8, 2024
ff75e23
chore: clean up style
zombieJ Jan 8, 2024
cfb9793
docs: add buddihist era demo
zombieJ Jan 8, 2024
9522a51
refactor: interface
zombieJ Jan 9, 2024
e0c4dcc
chore: add multiple types
zombieJ Jan 9, 2024
e8174e4
docs: add demo
zombieJ Jan 9, 2024
0517ca9
chore: init style
zombieJ Jan 9, 2024
c81c8d5
chore: init style
zombieJ Jan 9, 2024
5268e35
chore: fill style
zombieJ Jan 9, 2024
1652443
chore: fill style
zombieJ Jan 9, 2024
8a3bfef
chore: style
zombieJ Jan 9, 2024
76a49bf
chore: size of it
zombieJ Jan 9, 2024
33e0d9e
chore: size style
zombieJ Jan 9, 2024
836712c
docs: add align demo
zombieJ Jan 10, 2024
12445d9
docs: needConfirm
zombieJ Jan 10, 2024
55e8b0a
chore: fix showWeek style
zombieJ Jan 11, 2024
5e5be18
test: update snapshot
zombieJ Jan 11, 2024
8254010
test: update snapshot
zombieJ Jan 11, 2024
c7bd593
Merge branch 'feature' into picker
li-jia-nan Jan 11, 2024
9d7e12b
chore: fix ts
zombieJ Jan 11, 2024
4e0a251
chore: fix ts
zombieJ Jan 11, 2024
0b405b5
chore: fix ts
zombieJ Jan 11, 2024
e9b3b53
chore: merge feature
zombieJ Jan 11, 2024
45aa76a
chore: fix ts
zombieJ Jan 11, 2024
0c0fdf8
fix: week style
zombieJ Jan 12, 2024
16d6651
docs: update dayjs note
zombieJ Jan 12, 2024
f1501ac
Merge remote-tracking branch 'origin/feature' into picker
zombieJ Jan 12, 2024
1d6294d
fix: style missing
zombieJ Jan 12, 2024
3964ec9
chore: fix footer extra style missing
zombieJ Jan 12, 2024
2f02ab6
test: update snapshot
zombieJ Jan 12, 2024
5f59ebe
Merge remote-tracking branch 'origin/feature' into picker
zombieJ Jan 15, 2024
8dbfe2e
test: update snapshot
zombieJ Jan 15, 2024
b878930
test: update snapshot
zombieJ Jan 15, 2024
4a467f9
test: update snapshot
zombieJ Jan 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions components/calendar/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Dayjs from 'dayjs';

import 'dayjs/locale/zh-cn';

import React from 'react';
import MockDate from 'mockdate';
import { type PickerPanelProps } from 'rc-picker';
import dayjsGenerateConfig from 'rc-picker/lib/generate/dayjs';
import type { Locale } from 'rc-picker/lib/interface';
import { resetWarned } from 'rc-util/lib/warning';
import React from 'react';

import Calendar from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
Expand All @@ -16,7 +19,7 @@ import Select from '../../select';
import Header, { type CalendarHeaderProps } from '../Header';

const ref: {
calendarProps?: PickerPanelProps<unknown>;
calendarProps?: PickerPanelProps<any>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rc-picker 里的 PickerPanelProps 是不是 PickerPanelProps<T = any> 这个泛型是必填的吗

calendarHeaderProps?: CalendarHeaderProps<unknown>;
} = {};

Expand All @@ -34,7 +37,7 @@ jest.mock('rc-picker', () => {
const PickerPanelComponent = RcPicker.PickerPanel;
return {
...RcPicker,
PickerPanel: (props: PickerPanelProps<unknown>) => {
PickerPanel: (props: PickerPanelProps<any>) => {
ref.calendarProps = props;
return <PickerPanelComponent {...props} />;
},
Expand Down Expand Up @@ -149,8 +152,8 @@ describe('Calendar', () => {
it('getDateRange should returns a disabledDate function', () => {
const validRange: [Dayjs.Dayjs, Dayjs.Dayjs] = [Dayjs('2018-02-02'), Dayjs('2018-05-18')];
render(<Calendar validRange={validRange} defaultValue={Dayjs('2018-02-02')} />);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-06-02'))).toBe(true);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-04-02'))).toBe(false);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-06-02'), {} as any)).toBe(true);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-04-02'), {} as any)).toBe(false);
});

it('validRange should work with disabledDate function', () => {
Expand All @@ -162,11 +165,11 @@ describe('Calendar', () => {
/>,
);

expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-02-01'))).toBe(true);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-02-02'))).toBe(false);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-02-03'))).toBe(true);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-02-04'))).toBe(false);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-06-01'))).toBe(true);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-02-01'), {} as any)).toBe(true);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-02-02'), {} as any)).toBe(false);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-02-03'), {} as any)).toBe(true);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-02-04'), {} as any)).toBe(false);
expect(ref.calendarProps?.disabledDate?.(Dayjs('2018-06-01'), {} as any)).toBe(true);
});

it('Calendar MonthSelect should display correct label', () => {
Expand Down
25 changes: 1 addition & 24 deletions components/calendar/generateCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import classNames from 'classnames';
import { PickerPanel as RCPickerPanel } from 'rc-picker';
import type { GenerateConfig } from 'rc-picker/lib/generate';
import type { CellRenderInfo } from 'rc-picker/lib/interface';
import type {
PickerPanelBaseProps as RCPickerPanelBaseProps,
PickerPanelDateProps as RCPickerPanelDateProps,
PickerPanelTimeProps as RCPickerPanelTimeProps,
} from 'rc-picker/lib/PickerPanel';
import useMergedState from 'rc-util/lib/hooks/useMergedState';

import { devUseWarning } from '../_util/warning';
Expand All @@ -17,24 +12,6 @@ import CalendarHeader from './Header';
import enUS from './locale/en_US';
import useStyle from './style';

type InjectDefaultProps<Props> = Omit<
Props,
'locale' | 'generateConfig' | 'prevIcon' | 'nextIcon' | 'superPrevIcon' | 'superNextIcon'
> & {
locale?: typeof enUS;
size?: 'large' | 'default' | 'small';
};

// Picker Props
export type PickerPanelBaseProps<DateType> = InjectDefaultProps<RCPickerPanelBaseProps<DateType>>;
export type PickerPanelDateProps<DateType> = InjectDefaultProps<RCPickerPanelDateProps<DateType>>;
export type PickerPanelTimeProps<DateType> = InjectDefaultProps<RCPickerPanelTimeProps<DateType>>;

export type PickerProps<DateType> =
| PickerPanelBaseProps<DateType>
| PickerPanelDateProps<DateType>
| PickerPanelTimeProps<DateType>;

export type CalendarMode = 'year' | 'month';
export type HeaderRender<DateType> = (config: {
value: DateType;
Expand Down Expand Up @@ -75,7 +52,7 @@ export interface CalendarProps<DateType> {
onSelect?: (date: DateType, selectInfo: SelectInfo) => void;
}

function generateCalendar<DateType>(generateConfig: GenerateConfig<DateType>) {
function generateCalendar<DateType extends object>(generateConfig: GenerateConfig<DateType>) {
zombieJ marked this conversation as resolved.
Show resolved Hide resolved
function isSameYear(date1: DateType, date2: DateType) {
return date1 && date2 && generateConfig.getYear(date1) === generateConfig.getYear(date2);
}
Expand Down
32 changes: 15 additions & 17 deletions components/date-picker/__tests__/DatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ jest.mock('@rc-component/trigger', () => {
};
});

function getCell(text: string) {
const cells = Array.from(document.querySelectorAll('.ant-picker-cell'));

return cells.find((cell) => cell.textContent === text);
}

describe('DatePicker', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

Expand Down Expand Up @@ -96,8 +102,10 @@ describe('DatePicker', () => {

it('disabled date', () => {
const disabledDate = (current: any) => current && current < dayjs().endOf('day');
const wrapper = render(<DatePicker disabledDate={disabledDate} open />);
expect(Array.from(wrapper.container.children)).toMatchSnapshot();
render(<DatePicker disabledDate={disabledDate} open />);

expect(getCell('21')).toHaveClass('ant-picker-cell-disabled');
expect(getCell('23')).not.toHaveClass('ant-picker-cell-disabled');
});

it('placeholder', () => {
Expand Down Expand Up @@ -234,12 +242,7 @@ describe('DatePicker', () => {

it('showTime={{ showHour: true }}', () => {
const { container } = render(
<DatePicker
defaultValue={dayjs()}
showTime={{ showHour: true }}
format="YYYY-MM-DD"
open
/>,
<DatePicker defaultValue={dayjs()} showTime={{ showHour: true }} format="YYYY-MM-DD" open />,
);
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(1);
expect(
Expand All @@ -249,16 +252,11 @@ describe('DatePicker', () => {
).toBe(24);
});

it('showTime={{ }} (no true args)', () => {
it('showTime={{ }} (no true args)', () => {
const { container } = render(
<DatePicker
defaultValue={dayjs()}
showTime={{ }}
format="YYYY-MM-DD"
open
/>,
<DatePicker defaultValue={dayjs()} showTime={{}} format="YYYY-MM-DD" open />,
);
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(0);
expect(container.querySelectorAll('.ant-picker-time-panel-column')).toHaveLength(3);
});

it('showTime should work correctly when format is custom function', () => {
Expand Down Expand Up @@ -411,7 +409,7 @@ describe('DatePicker', () => {
const { container } = render(
<DatePicker defaultValue={dayjs()} format="kk:mm" showTime open />,
);
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(2);
expect(container.querySelectorAll('.ant-picker-time-panel-column')).toHaveLength(2);
expect(
container
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
Expand Down
55 changes: 15 additions & 40 deletions components/date-picker/__tests__/RangePicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import type { RangeValue } from 'rc-picker/lib/interface';
import React, { useState } from 'react';
import userEvent from '@testing-library/user-event';
import { CloseCircleFilled } from '@ant-design/icons';
import userEvent from '@testing-library/user-event';
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';

import DatePicker from '..';
import focusTest from '../../../tests/shared/focusTest';
import { render, resetMockDate, setMockDate, screen, waitFor } from '../../../tests/utils';
import { resetWarned } from '../../_util/warning';
import focusTest from '../../../tests/shared/focusTest';
import { render, resetMockDate, screen, setMockDate, waitFor } from '../../../tests/utils';
import enUS from '../locale/en_US';
import { closeCircleByRole, expectCloseCircle, closePicker, openPicker, selectCell } from './utils';
import { closeCircleByRole, closePicker, expectCloseCircle, openPicker, selectCell } from './utils';

dayjs.extend(customParseFormat);

type RangeValue<DateType extends object> = [
DateType | undefined | null,
zombieJ marked this conversation as resolved.
Show resolved Hide resolved
DateType | undefined | null,
];

const { RangePicker } = DatePicker;

describe('RangePicker', () => {
Expand All @@ -30,7 +35,7 @@ describe('RangePicker', () => {
it('should not throw error when value is reset to `[]`', () => {
const birthday = dayjs('2000-01-01', 'YYYY-MM-DD');
const wrapper1 = render(<RangePicker value={[birthday, birthday]} open />);
const wrapper2 = render(<RangePicker value={[] as unknown as null} open />);
const wrapper2 = render(<RangePicker value={[] as unknown as RangeValue<any>} open />);

zombieJ marked this conversation as resolved.
Show resolved Hide resolved
expect(() => {
openPicker(wrapper1);
Expand Down Expand Up @@ -59,7 +64,7 @@ describe('RangePicker', () => {
it('the left selection is before the right selection', () => {
let rangePickerValue: dayjs.Dayjs[] = [];
const Test: React.FC = () => {
const [value, setValue] = useState<RangeValue<dayjs.Dayjs>>(null);
const [value, setValue] = useState<RangeValue<dayjs.Dayjs>>(null!);
return (
<RangePicker
value={value}
Expand All @@ -85,42 +90,12 @@ describe('RangePicker', () => {
expect(start.isBefore(end, 'date')).toBeTruthy();
});

it('the left selection is after the right selection, no selection made', () => {
let rangePickerValue: dayjs.Dayjs[] = [];
const Test: React.FC = () => {
const [value, setValue] = useState<RangeValue<dayjs.Dayjs>>(null);
return (
<RangePicker
value={value}
mode={['month', 'month']}
onPanelChange={(v) => {
setValue(v);
rangePickerValue = v as dayjs.Dayjs[];
}}
/>
);
};

const wrapper = render(<Test />);

openPicker(wrapper);
selectCell(wrapper, 'May');
openPicker(wrapper, 1);
selectCell(wrapper, 'Feb');
closePicker(wrapper, 1);

const [start, end] = rangePickerValue;

expect(start).not.toBeNull();
expect(end).toBeNull();
});

// https://github.com/ant-design/ant-design/issues/13302
describe('in "month" mode, when the left and right panels select the same month', () => {
it('the cell status is correct', () => {
let rangePickerValue: dayjs.Dayjs[] = [];
const Test: React.FC = () => {
const [value, setValue] = useState<RangeValue<dayjs.Dayjs>>(null);
const [value, setValue] = useState<RangeValue<dayjs.Dayjs>>(null!);
return (
zombieJ marked this conversation as resolved.
Show resolved Hide resolved
<RangePicker
value={value}
Expand Down