-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace timepicker dropdownClassName to popupClassName (#139)
* feat: replace timepicker dropdownClassName to popupClassName * feat: edit warning info * feat: add rangePicker
- Loading branch information
Showing
5 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## TimePicker | ||
|
||
|
||
<code src="../examples/TimePicker.tsx" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { TimePicker, } from '../../src'; | ||
import type { Dayjs } from 'dayjs'; | ||
import dayjs from 'dayjs'; | ||
import customParseFormat from 'dayjs/plugin/customParseFormat'; | ||
dayjs.extend(customParseFormat); | ||
|
||
export default () => { | ||
const onChange = (time: Dayjs, timeString: string) => { | ||
console.log(time, timeString); | ||
}; | ||
|
||
return ( | ||
<TimePicker onChange={onChange} defaultValue={dayjs('00:00:00', 'HH:mm:ss')} /> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
import { TimePicker } from 'antd'; | ||
import warning from 'rc-util/lib/warning'; | ||
|
||
type TimePickerProps = Parameters<typeof TimePicker>[0]; | ||
type TimePickerRef = TimePickerProps['ref']; | ||
|
||
type RangePickerProps = Parameters<typeof TimePicker>[0]; | ||
type RangePickerRef = RangePickerProps['ref']; | ||
|
||
type CompatibleTimePickerProps = TimePickerProps & { | ||
/** @deprecated Please use `popupClassName` instead. */ | ||
dropdownClassName?: string; | ||
}; | ||
|
||
type CompatibleRangePickerProps = RangePickerProps & { | ||
/** @deprecated Please use `popupClassName` instead. */ | ||
dropdownClassName?: string; | ||
}; | ||
|
||
const CompatibleTimePicker = React.forwardRef( | ||
( | ||
{ dropdownClassName, popupClassName, ...restProps }: CompatibleTimePickerProps, | ||
ref: TimePickerRef, | ||
) => { | ||
warning( | ||
!dropdownClassName, | ||
"[antd: TimePicker] `dropdownClassName` is removed in v5, please use `popupClassName` instead.", | ||
); | ||
|
||
return ( | ||
<TimePicker {...restProps} popupClassName={popupClassName || dropdownClassName} ref={ref} /> | ||
); | ||
}, | ||
); | ||
|
||
|
||
|
||
CompatibleTimePicker.RangePicker = React.forwardRef( | ||
( | ||
{ dropdownClassName, popupClassName, ...restProps }: CompatibleRangePickerProps, | ||
ref: RangePickerRef, | ||
) => { | ||
warning( | ||
!dropdownClassName, | ||
"[antd: RangePicker] `dropdownClassName` is removed in v5, please use `popupClassName` instead.", | ||
); | ||
|
||
return ( | ||
<TimePicker.RangePicker {...restProps} popupClassName={popupClassName || dropdownClassName} ref={ref} /> | ||
); | ||
}, | ||
); | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
CompatibleTimePicker.displayName = 'CompatibleTimePicker'; | ||
} | ||
export default CompatibleTimePicker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import { TimePicker } from '../src'; | ||
import { render } from '@testing-library/react'; | ||
|
||
describe('TimePicker', () => { | ||
|
||
|
||
it('TimePicker dropdownClassName', async () => { | ||
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
const { container } = render( | ||
<TimePicker | ||
dropdownClassName="test" | ||
/>, | ||
); | ||
|
||
expect(errSpy).toHaveBeenCalledWith( | ||
"Warning: [antd: TimePicker] `dropdownClassName` is removed in v5, please use `popupClassName` instead.", | ||
); | ||
|
||
// TODO: Remove this when antd release version | ||
// expect(container.querySelector('.test')).toBeTruthy(); | ||
|
||
errSpy.mockRestore(); | ||
}); | ||
|
||
it('TimePicker.RangePicker dropdownClassName', async () => { | ||
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
const { container } = render( | ||
<TimePicker.RangePicker | ||
dropdownClassName="test" | ||
/>, | ||
); | ||
|
||
expect(errSpy).toHaveBeenCalledWith( | ||
"Warning: [antd: RangePicker] `dropdownClassName` is removed in v5, please use `popupClassName` instead.", | ||
); | ||
|
||
// TODO: Remove this when antd release version | ||
// expect(container.querySelector('.test')).toBeTruthy(); | ||
|
||
errSpy.mockRestore(); | ||
}); | ||
}); |
2c26b66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
compatible – ./
compatible-pro-components.vercel.app
compatible-git-master-pro-components.vercel.app
compatible-nine.vercel.app