Merge pull request #534 from RickCole21/master

扩充下datepicker的可选快捷键、样式fix
This commit is contained in:
liaoxuezhi 2020-04-08 11:58:06 +08:00 committed by GitHub
commit dde2d7deca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -87,6 +87,7 @@
background: $Calendar-shortcuts-bg;
padding: ($Calendar-shortcuts-height - $Calendar-fontSize * $lineHeightBase) / 2 $gap-sm;
list-style: none;
width: px2rem(250px);
&+.rdt .rdtPicker {
padding-top: 0;
@ -95,7 +96,7 @@
.#{$ns}DatePicker-shortcut {
display: inline-block;
margin-right: $gap-md;
margin-right: $gap-sm;
a {
font-size: $Calendar-fontSize;

View File

@ -17,6 +17,12 @@ import Calendar from './calendar/Calendar';
import 'react-datetime/css/react-datetime.css';
const availableShortcuts: {[propName: string]: any} = {
now: {
label: '现在',
date: (now: moment.Moment) => {
return now;
}
},
today: {
label: '今天',
date: (now: moment.Moment) => {
@ -89,6 +95,28 @@ const availableShortcuts: {[propName: string]: any} = {
};
const advancedShortcuts = [
{
regexp: /^(\d+)hoursago$/,
resolve: (_: string, hours: string) => {
return {
label: `${hours}小时前`,
date: (now: moment.Moment) => {
return now.subtract(hours, 'hours');
}
};
}
},
{
regexp: /^(\d+)hourslater$/,
resolve: (_: string, hours: string) => {
return {
label: `${hours}小时后`,
date: (now: moment.Moment) => {
return now.add(hours, 'hours');
}
};
}
},
{
regexp: /^(\d+)daysago$/,
resolve: (_: string, days: string) => {