forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: optimize disabledDate logic (ant-design#191)
co-author <ayn1914420862@gmail.com>
- Loading branch information
Showing
9 changed files
with
259 additions
and
21 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,64 @@ | ||
import React from 'react'; | ||
import type { Moment } from 'moment'; | ||
import moment from 'moment'; | ||
import Picker from '../src/Picker'; | ||
import momentGenerateConfig from '../src/generate/moment'; | ||
import enUS from '../src/locale/en_US'; | ||
import '../assets/index.less'; | ||
|
||
export default () => { | ||
const [value, setValue] = React.useState<Moment | null>(undefined); | ||
|
||
const onSelect = (newValue: Moment) => { | ||
console.log('Select:', newValue); | ||
}; | ||
|
||
const onChange = (newValue: Moment | null, formatString?: string) => { | ||
console.log('Change:', newValue, formatString); | ||
setValue(newValue); | ||
}; | ||
|
||
function disabledDateBeforeToday(current: Moment) { | ||
return current <= moment().endOf('day'); | ||
} | ||
|
||
function disabledDateAfterToday(current: Moment) { | ||
return current >= moment().endOf('day'); | ||
} | ||
|
||
function disabledDateAfterTodayAndBeforeLastYear(current) { | ||
return current >= moment().startOf('day') || current < moment().subtract(1, 'years'); | ||
} | ||
|
||
const sharedProps = { | ||
generateConfig: momentGenerateConfig, | ||
value, | ||
onSelect, | ||
onChange, | ||
}; | ||
|
||
return ( | ||
<div style={{ paddingBottom: '20px' }}> | ||
<h1>Value: {value ? value.format('YYYY-MM-DD HH:mm:ss') : 'null'}</h1> | ||
<h2>Date Mode</h2> | ||
<div style={{ display: 'flex', flexWrap: 'wrap' }}> | ||
<div style={{ margin: '0 8px' }}> | ||
<h3>Before Today</h3> | ||
<Picker<Moment> {...sharedProps} disabledDate={disabledDateBeforeToday} locale={enUS} /> | ||
</div> | ||
<div style={{ margin: '0 8px' }}> | ||
<h3>After Today</h3> | ||
<Picker<Moment> {...sharedProps} disabledDate={disabledDateAfterToday} locale={enUS} /> | ||
</div> | ||
<div style={{ margin: '0 8px' }}> | ||
<h3>After Today or Before last year</h3> | ||
<Picker<Moment> | ||
{...sharedProps} | ||
disabledDate={disabledDateAfterTodayAndBeforeLastYear} | ||
locale={enUS} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
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
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
Oops, something went wrong.