Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support controlled panels for DatePicker and RangePicker, close: …
- Loading branch information
Showing
7 changed files
with
154 additions
and
12 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
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
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,82 @@ | ||
--- | ||
order: 11 | ||
title: | ||
zh-CN: 受控面板 | ||
en-US: Controlled Panels | ||
--- | ||
|
||
## zh-CN | ||
|
||
通过组合 `mode` 与 `onPanelChange` 控制要展示的面板。 | ||
|
||
## en-US | ||
|
||
Determing which panel to show with `mode` and `onPanelChange`. | ||
|
||
````jsx | ||
import { DatePicker } from 'antd'; | ||
const { RangePicker } = DatePicker; | ||
|
||
class ControlledDatePicker extends React.Component { | ||
state = { mode: 'time' }; | ||
|
||
handleOpenChange = (open) => { | ||
if (open) { | ||
this.setState({ mode: 'time' }); | ||
} | ||
} | ||
|
||
handlePanelChange = (value, mode) => { | ||
this.setState({ mode }); | ||
} | ||
|
||
render() { | ||
return ( | ||
<DatePicker | ||
mode={this.state.mode} | ||
showTime | ||
onOpenChange={this.handleOpenChange} | ||
onPanelChange={this.handlePanelChange} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
class ControlledRangePicker extends React.Component { | ||
state = { | ||
mode: ['month', 'month'], | ||
value: [], | ||
}; | ||
|
||
handlePanelChange = (value, mode) => { | ||
this.setState({ | ||
value, | ||
mode: [ | ||
mode[0] === 'date' ? 'month' : mode[0], | ||
mode[1] === 'date' ? 'month' : mode[1], | ||
], | ||
}); | ||
} | ||
|
||
render() { | ||
const { value, mode } = this.state; | ||
return ( | ||
<RangePicker | ||
placeholder={['Start month', 'End month']} | ||
format="YYYY-MM" | ||
value={value} | ||
mode={mode} | ||
onPanelChange={this.handlePanelChange} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
ReactDOM.render( | ||
<div> | ||
<ControlledDatePicker /> | ||
<br /> | ||
<ControlledRangePicker /> | ||
</div> | ||
, mountNode); | ||
```` |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
.@{calendar-prefix-cls}-month { | ||
height: 248px; | ||
.@{calendar-prefix-cls}-month-panel, | ||
.@{calendar-prefix-cls}-year-panel { | ||
top: 0; | ||
height: 248px; | ||
height: 100%; | ||
} | ||
} |
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