mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
6776bb8916
* docs: update demo * chore: add script * test: fix demo test * docs: convert demos * chore: move script * test: remove react-dom import * chore: update deps * docs: update riddle js * test: fix image test * docs: fix riddle demo
1.2 KiB
1.2 KiB
order | title | ||||
---|---|---|---|---|---|
1.1 |
|
zh-CN
提供选择器,自由切换不同类型的日期选择器,常用于日期筛选场合。
en-US
Switch in different types of pickers by Select.
import React, { useState } from 'react';
import { DatePicker, TimePicker, Select, Space } from 'antd';
const { Option } = Select;
function PickerWithType({ type, onChange }) {
if (type === 'time') return <TimePicker onChange={onChange} />;
if (type === 'date') return <DatePicker onChange={onChange} />;
return <DatePicker picker={type} onChange={onChange} />;
}
function SwitchablePicker() {
const [type, setType] = useState('time');
return (
<Space>
<Select value={type} onChange={setType}>
<Option value="time">Time</Option>
<Option value="date">Date</Option>
<Option value="week">Week</Option>
<Option value="month">Month</Option>
<Option value="quarter">Quarter</Option>
<Option value="year">Year</Option>
</Select>
<PickerWithType type={type} onChange={value => console.log(value)} />
</Space>
);
}
export default () => <SwitchablePicker />;