mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-15 08:59:15 +08:00
18e85a7b81
* chore: init * chore: link picker * chore: move files * chore: update style * chore: update types * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * test: fix test case * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * chore: clesn up useless types * chore: update types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: fix types * chore: update style * chore: clean up * chore: update types * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * fix: format * chore: update deps * chore: feature merge master (#46794) * fix: Fix typo s/Notificaiton/Notification/ (#46775) * docs: supplement form preserve field description (#46788) close https://github.com/ant-design/ant-design/issues/46773 * docs: tweak changelog drawer width in small screen (#46791) * docs: Update compatible-style.zh-CN.md (#46790) Signed-off-by: afc163 <afc163@gmail.com> --------- Signed-off-by: afc163 <afc163@gmail.com> Co-authored-by: hugo-syn <61210734+hugo-syn@users.noreply.github.com> Co-authored-by: Shunze Chen <qianlonwork@outlook.com> Co-authored-by: afc163 <afc163@gmail.com> * chore: update locale size * chore: lock dumi * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * chore: bump version * test: update snapshot * test: update snapshot * chore: bump version * chore: update limit * test: update snapshot * docs: update 7 days sample * chore: rm useless style * chore: clean up style * docs: add buddihist era demo * refactor: interface * chore: add multiple types * docs: add demo * chore: init style * chore: init style * chore: fill style * chore: fill style * chore: style * chore: size of it * chore: size style * docs: add align demo * docs: needConfirm * chore: fix showWeek style * test: update snapshot * chore: fix ts * chore: fix ts * chore: fix ts * chore: fix ts * fix: week style * docs: update dayjs note * fix: style missing * chore: fix footer extra style missing * test: update snapshot * test: update snapshot * test: update snapshot * test: update snapshot * chore: demo update * docs: update demo * docs: min & max date * test: update snapshot * docs: add order * chore: update deps * test: update snapshot * test: update snapshot * chore: adjust style * chore: clean up style * test: update snapshot * chore: fix comment * chore: update align * chore: bump rc-picker * test: update snapshot * test: update snapshot * test: update snapshot --------- Signed-off-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: hugo-syn <61210734+hugo-syn@users.noreply.github.com> Co-authored-by: Shunze Chen <qianlonwork@outlook.com> Co-authored-by: afc163 <afc163@gmail.com> Co-authored-by: lijianan <574980606@qq.com>
67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { DatePicker, Space } from 'antd';
|
|
import type { DatePickerProps, GetProps } from 'antd';
|
|
import type { Dayjs } from 'dayjs';
|
|
|
|
type RangePickerProps = GetProps<typeof DatePicker.RangePicker>;
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
type RangeValue = [Dayjs | null | undefined, Dayjs | null | undefined] | null;
|
|
|
|
const ControlledDatePicker = () => {
|
|
const [mode, setMode] = useState<DatePickerProps['mode']>('time');
|
|
|
|
const handleOpenChange = (open: boolean) => {
|
|
if (open) {
|
|
setMode('time');
|
|
}
|
|
};
|
|
|
|
const handlePanelChange: DatePickerProps['onPanelChange'] = (_, newMode) => {
|
|
setMode(newMode);
|
|
};
|
|
|
|
return (
|
|
<DatePicker
|
|
mode={mode}
|
|
showTime
|
|
onOpenChange={handleOpenChange}
|
|
onPanelChange={handlePanelChange}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const ControlledRangePicker = () => {
|
|
const [mode, setMode] = useState<RangePickerProps['mode']>(['month', 'month']);
|
|
const [value, setValue] = useState<RangeValue>([null, null]);
|
|
|
|
const handlePanelChange: RangePickerProps['onPanelChange'] = (newValue, newModes) => {
|
|
setValue(newValue);
|
|
setMode([
|
|
newModes[0] === 'date' ? 'month' : newModes[0],
|
|
newModes[1] === 'date' ? 'month' : newModes[1],
|
|
]);
|
|
};
|
|
|
|
return (
|
|
<RangePicker
|
|
placeholder={['Start month', 'End month']}
|
|
format="YYYY-MM"
|
|
value={value}
|
|
mode={mode}
|
|
onChange={setValue}
|
|
onPanelChange={handlePanelChange}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const App: React.FC = () => (
|
|
<Space direction="vertical" size={12}>
|
|
<ControlledDatePicker />
|
|
<ControlledRangePicker />
|
|
</Space>
|
|
);
|
|
|
|
export default App;
|