Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wanjj_1210
ant-design
提交
fd1d54cf
A
ant-design
项目概览
wanjj_1210
/
ant-design
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
ant-design
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fd1d54cf
编写于
3月 30, 2016
作者:
A
afc163
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1298 from ant-design/refactor-datepicker-hoc
refactor: remove mixin
上级
f89d2dba
2e86463a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
160 addition
and
168 deletion
+160
-168
components/date-picker/PickerMixin.jsx
components/date-picker/PickerMixin.jsx
+0
-58
components/date-picker/RangePicker.jsx
components/date-picker/RangePicker.jsx
+23
-57
components/date-picker/createPicker.jsx
components/date-picker/createPicker.jsx
+14
-50
components/date-picker/index.jsx
components/date-picker/index.jsx
+4
-3
components/date-picker/wrapPicker.jsx
components/date-picker/wrapPicker.jsx
+119
-0
未找到文件。
components/date-picker/PickerMixin.jsx
已删除
100644 → 0
浏览文件 @
f89d2dba
import
React
from
'
react
'
;
import
defaultLocale
from
'
./locale/zh_CN
'
;
import
DateTimeFormat
from
'
gregorian-calendar-format
'
;
import
GregorianCalendar
from
'
gregorian-calendar
'
;
export
default
{
contextTypes
:
{
antLocale
:
React
.
PropTypes
.
object
,
},
getLocale
()
{
let
locale
=
defaultLocale
;
if
(
this
.
context
.
antLocale
&&
this
.
context
.
antLocale
.
DatePicker
)
{
locale
=
this
.
context
.
antLocale
.
DatePicker
;
}
// 统一合并为完整的 Locale
const
result
=
{
...
locale
,
...
this
.
props
.
locale
};
result
.
lang
=
{
...
locale
.
lang
,
...
this
.
props
.
locale
.
lang
};
return
result
;
},
getFormatter
()
{
if
(
!
this
.
formats
)
{
this
.
formats
=
{};
}
const
formats
=
this
.
formats
;
const
format
=
this
.
props
.
format
;
if
(
formats
[
format
])
{
return
formats
[
format
];
}
formats
[
format
]
=
new
DateTimeFormat
(
format
,
this
.
getLocale
().
lang
.
format
);
return
formats
[
format
];
},
parseDateFromValue
(
value
)
{
if
(
value
)
{
if
(
typeof
value
===
'
string
'
)
{
return
this
.
getFormatter
().
parse
(
value
,
{
locale
:
this
.
getLocale
()
});
}
else
if
(
value
instanceof
Date
)
{
let
date
=
new
GregorianCalendar
(
this
.
getLocale
());
date
.
setTime
(
+
value
);
return
date
;
}
}
return
value
;
},
// remove input readonly warning
handleInputChange
()
{
},
toggleOpen
(
e
)
{
this
.
setState
({
open
:
e
.
open
});
},
};
components/date-picker/RangePicker.jsx
浏览文件 @
fd1d54cf
...
@@ -2,83 +2,61 @@ import React from 'react';
...
@@ -2,83 +2,61 @@ import React from 'react';
import
GregorianCalendar
from
'
gregorian-calendar
'
;
import
GregorianCalendar
from
'
gregorian-calendar
'
;
import
RangeCalendar
from
'
rc-calendar/lib/RangeCalendar
'
;
import
RangeCalendar
from
'
rc-calendar/lib/RangeCalendar
'
;
import
DatePicker
from
'
rc-calendar/lib/Picker
'
;
import
DatePicker
from
'
rc-calendar/lib/Picker
'
;
import
TimePicker
from
'
rc-time-picker
'
;
import
classNames
from
'
classnames
'
;
import
classNames
from
'
classnames
'
;
import
PickerMixin
from
'
./PickerMixin
'
;
export
default
React
.
createClass
({
export
default
React
.
createClass
({
getDefaultProps
()
{
getDefaultProps
()
{
return
{
return
{
defaultValue
:
[],
defaultValue
:
[],
format
:
'
yyyy-MM-dd
'
,
startPlaceholder
:
'
开始日期
'
,
startPlaceholder
:
'
开始日期
'
,
endPlaceholder
:
'
结束日期
'
,
endPlaceholder
:
'
结束日期
'
,
transitionName
:
'
slide-up
'
,
popupStyle
:
{},
onChange
()
{
},
onOk
()
{
},
locale
:
{},
align
:
{
offset
:
[
0
,
-
9
],
},
open
:
false
};
};
},
},
getInitialState
()
{
getInitialState
()
{
const
{
value
,
defaultValue
}
=
this
.
props
;
const
{
value
,
defaultValue
,
parseDateFromValue
}
=
this
.
props
;
const
start
=
(
value
&&
value
[
0
])
||
defaultValue
[
0
];
const
start
=
(
value
&&
value
[
0
])
||
defaultValue
[
0
];
const
end
=
(
value
&&
value
[
1
])
||
defaultValue
[
1
];
const
end
=
(
value
&&
value
[
1
])
||
defaultValue
[
1
];
return
{
return
{
value
:
[
value
:
[
this
.
parseDateFromValue
(
start
),
parseDateFromValue
(
start
),
this
.
parseDateFromValue
(
end
)
parseDateFromValue
(
end
)
]
]
};
};
},
},
mixins
:
[
PickerMixin
],
componentWillReceiveProps
(
nextProps
)
{
componentWillReceiveProps
(
nextProps
)
{
if
(
'
value
'
in
nextProps
)
{
if
(
'
value
'
in
nextProps
)
{
const
value
=
nextProps
.
value
||
[];
const
value
=
nextProps
.
value
||
[];
const
start
=
thi
s
.
parseDateFromValue
(
value
[
0
]);
const
start
=
nextProp
s
.
parseDateFromValue
(
value
[
0
]);
const
end
=
thi
s
.
parseDateFromValue
(
value
[
1
]);
const
end
=
nextProp
s
.
parseDateFromValue
(
value
[
1
]);
this
.
setState
({
this
.
setState
({
value
:
[
start
,
end
]
value
:
[
start
,
end
]
});
});
}
}
},
},
handleChange
(
value
)
{
handleChange
(
value
)
{
if
(
!
(
'
value
'
in
this
.
props
))
{
const
props
=
this
.
props
;
if
(
!
(
'
value
'
in
props
))
{
this
.
setState
({
value
});
this
.
setState
({
value
});
}
}
const
startDate
=
value
[
0
]
?
new
Date
(
value
[
0
].
getTime
())
:
null
;
const
startDate
=
value
[
0
]
?
new
Date
(
value
[
0
].
getTime
())
:
null
;
const
endDate
=
value
[
1
]
?
new
Date
(
value
[
1
].
getTime
())
:
null
;
const
endDate
=
value
[
1
]
?
new
Date
(
value
[
1
].
getTime
())
:
null
;
const
startDateString
=
value
[
0
]
?
thi
s
.
getFormatter
().
format
(
value
[
0
])
:
''
;
const
startDateString
=
value
[
0
]
?
prop
s
.
getFormatter
().
format
(
value
[
0
])
:
''
;
const
endDateString
=
value
[
1
]
?
thi
s
.
getFormatter
().
format
(
value
[
1
])
:
''
;
const
endDateString
=
value
[
1
]
?
prop
s
.
getFormatter
().
format
(
value
[
1
])
:
''
;
thi
s
.
props
.
onChange
([
startDate
,
endDate
],
[
startDateString
,
endDateString
]);
prop
s
.
props
.
onChange
([
startDate
,
endDate
],
[
startDateString
,
endDateString
]);
},
},
render
()
{
render
()
{
const
locale
=
this
.
getLocale
();
const
props
=
this
.
props
;
const
locale
=
props
.
locale
;
// 以下两行代码
// 以下两行代码
// 给没有初始值的日期选择框提供本地化信息
// 给没有初始值的日期选择框提供本地化信息
// 否则会以周日开始排
// 否则会以周日开始排
let
defaultCalendarValue
=
new
GregorianCalendar
(
locale
);
let
defaultCalendarValue
=
new
GregorianCalendar
(
locale
);
defaultCalendarValue
.
setTime
(
Date
.
now
());
defaultCalendarValue
.
setTime
(
Date
.
now
());
const
{
disabledDate
,
showTime
,
s
ize
,
s
tartPlaceholder
,
endPlaceholder
,
getCalendarContainer
,
const
{
disabledDate
,
showTime
,
startPlaceholder
,
endPlaceholder
,
getCalendarContainer
,
transitionName
,
disabled
,
popupStyle
,
align
,
style
,
onOk
}
=
this
.
props
;
transitionName
,
disabled
,
popupStyle
,
align
,
style
,
onOk
}
=
this
.
props
;
const
state
=
this
.
state
;
const
state
=
this
.
state
;
let
timePicker
=
null
;
if
(
showTime
)
{
timePicker
=
(<
TimePicker
prefixCls
=
"ant-time-picker"
placeholder
=
{
locale
.
lang
.
timePlaceholder
}
transitionName
=
"slide-up"
/>);
}
const
calendarClassName
=
classNames
({
const
calendarClassName
=
classNames
({
[
'
ant-calendar-time
'
]:
showTime
,
[
'
ant-calendar-time
'
]:
showTime
,
});
});
...
@@ -91,7 +69,7 @@ export default React.createClass({
...
@@ -91,7 +69,7 @@ export default React.createClass({
onOk
:
this
.
handleChange
,
onOk
:
this
.
handleChange
,
};
};
if
(
timePicker
)
{
if
(
props
.
timePicker
)
{
pickerChangeHandler
.
onChange
=
(
value
)
=>
{
pickerChangeHandler
.
onChange
=
(
value
)
=>
{
// Click clear button
// Click clear button
if
(
value
===
null
||
value
.
length
===
0
)
{
if
(
value
===
null
||
value
.
length
===
0
)
{
...
@@ -106,7 +84,7 @@ export default React.createClass({
...
@@ -106,7 +84,7 @@ export default React.createClass({
<
RangeCalendar
<
RangeCalendar
prefixCls
=
"ant-calendar"
prefixCls
=
"ant-calendar"
className
=
{
calendarClassName
}
className
=
{
calendarClassName
}
timePicker
=
{
timePicker
}
timePicker
=
{
props
.
timePicker
}
disabledDate
=
{
disabledDate
}
disabledDate
=
{
disabledDate
}
dateInputPlaceholder
=
{
[
startPlaceholder
,
endPlaceholder
]
}
dateInputPlaceholder
=
{
[
startPlaceholder
,
endPlaceholder
]
}
locale
=
{
locale
.
lang
}
locale
=
{
locale
.
lang
}
...
@@ -116,19 +94,7 @@ export default React.createClass({
...
@@ -116,19 +94,7 @@ export default React.createClass({
/>
/>
);
);
const
pickerClass
=
classNames
({
return
(<
span
className
=
{
props
.
pickerClass
}
style
=
{
style
}
>
'
ant-calendar-picker
'
:
true
,
'
ant-calendar-picker-open
'
:
state
.
open
});
const
pickerInputClass
=
classNames
({
'
ant-calendar-range-picker
'
:
true
,
'
ant-input
'
:
true
,
'
ant-input-lg
'
:
size
===
'
large
'
,
'
ant-input-sm
'
:
size
===
'
small
'
,
});
return
(<
span
className
=
{
pickerClass
}
style
=
{
style
}
>
<
DatePicker
<
DatePicker
transitionName
=
{
transitionName
}
transitionName
=
{
transitionName
}
disabled
=
{
disabled
}
disabled
=
{
disabled
}
...
@@ -138,8 +104,8 @@ export default React.createClass({
...
@@ -138,8 +104,8 @@ export default React.createClass({
style
=
{
popupStyle
}
style
=
{
popupStyle
}
align
=
{
align
}
align
=
{
align
}
getCalendarContainer
=
{
getCalendarContainer
}
getCalendarContainer
=
{
getCalendarContainer
}
onOpen
=
{
thi
s
.
toggleOpen
}
onOpen
=
{
prop
s
.
toggleOpen
}
onClose
=
{
thi
s
.
toggleOpen
}
onClose
=
{
prop
s
.
toggleOpen
}
{
...
pickerChangeHandler
}
{
...
pickerChangeHandler
}
>
>
{
{
...
@@ -147,18 +113,18 @@ export default React.createClass({
...
@@ -147,18 +113,18 @@ export default React.createClass({
const
start
=
value
[
0
];
const
start
=
value
[
0
];
const
end
=
value
[
1
];
const
end
=
value
[
1
];
return
(
return
(
<
span
className
=
{
pickerInputClass
}
disabled
=
{
disabled
}
>
<
span
className
=
{
p
rops
.
p
ickerInputClass
}
disabled
=
{
disabled
}
>
<
input
<
input
disabled
=
{
disabled
}
disabled
=
{
disabled
}
onChange
=
{
thi
s
.
handleInputChange
}
onChange
=
{
prop
s
.
handleInputChange
}
value
=
{
start
&&
thi
s
.
getFormatter
().
format
(
start
)
}
value
=
{
start
&&
prop
s
.
getFormatter
().
format
(
start
)
}
placeholder
=
{
startPlaceholder
}
placeholder
=
{
startPlaceholder
}
className
=
"ant-calendar-range-picker-input"
/>
className
=
"ant-calendar-range-picker-input"
/>
<
span
className
=
"ant-calendar-range-picker-separator"
>
~
</
span
>
<
span
className
=
"ant-calendar-range-picker-separator"
>
~
</
span
>
<
input
<
input
disabled
=
{
disabled
}
disabled
=
{
disabled
}
onChange
=
{
thi
s
.
handleInputChange
}
onChange
=
{
prop
s
.
handleInputChange
}
value
=
{
end
&&
thi
s
.
getFormatter
().
format
(
end
)
}
value
=
{
end
&&
prop
s
.
getFormatter
().
format
(
end
)
}
placeholder
=
{
endPlaceholder
}
placeholder
=
{
endPlaceholder
}
className
=
"ant-calendar-range-picker-input"
/>
className
=
"ant-calendar-range-picker-input"
/>
<
span
className
=
"ant-calendar-picker-icon"
/>
<
span
className
=
"ant-calendar-picker-icon"
/>
...
...
components/date-picker/createPicker.jsx
浏览文件 @
fd1d54cf
...
@@ -2,51 +2,33 @@ import React from 'react';
...
@@ -2,51 +2,33 @@ import React from 'react';
import
MonthCalendar
from
'
rc-calendar/lib/MonthCalendar
'
;
import
MonthCalendar
from
'
rc-calendar/lib/MonthCalendar
'
;
import
RcDatePicker
from
'
rc-calendar/lib/Picker
'
;
import
RcDatePicker
from
'
rc-calendar/lib/Picker
'
;
import
GregorianCalendar
from
'
gregorian-calendar
'
;
import
GregorianCalendar
from
'
gregorian-calendar
'
;
import
TimePicker
from
'
rc-time-picker
'
;
import
classNames
from
'
classnames
'
;
import
classNames
from
'
classnames
'
;
import
PickerMixin
from
'
./PickerMixin
'
;
export
default
function
createPicker
(
TheCalendar
,
defaultFormat
)
{
export
default
function
createPicker
(
TheCalendar
)
{
return
React
.
createClass
({
return
React
.
createClass
({
getDefaultProps
()
{
return
{
format
:
defaultFormat
||
'
yyyy-MM-dd
'
,
transitionName
:
'
slide-up
'
,
popupStyle
:
{},
onChange
()
{
},
onOk
()
{
},
locale
:
{},
align
:
{
offset
:
[
0
,
-
9
],
},
open
:
false
,
};
},
getInitialState
()
{
getInitialState
()
{
return
{
return
{
value
:
this
.
parseDateFromValue
(
this
.
props
.
value
||
this
.
props
.
defaultValue
)
value
:
this
.
p
rops
.
p
arseDateFromValue
(
this
.
props
.
value
||
this
.
props
.
defaultValue
)
};
};
},
},
mixins
:
[
PickerMixin
],
componentWillReceiveProps
(
nextProps
)
{
componentWillReceiveProps
(
nextProps
)
{
if
(
'
value
'
in
nextProps
)
{
if
(
'
value
'
in
nextProps
)
{
this
.
setState
({
this
.
setState
({
value
:
thi
s
.
parseDateFromValue
(
nextProps
.
value
)
value
:
nextProp
s
.
parseDateFromValue
(
nextProps
.
value
)
});
});
}
}
},
},
handleChange
(
value
)
{
handleChange
(
value
)
{
if
(
!
(
'
value
'
in
this
.
props
))
{
const
props
=
this
.
props
;
if
(
!
(
'
value
'
in
props
))
{
this
.
setState
({
value
});
this
.
setState
({
value
});
}
}
const
timeValue
=
value
?
new
Date
(
value
.
getTime
())
:
null
;
const
timeValue
=
value
?
new
Date
(
value
.
getTime
())
:
null
;
this
.
props
.
onChange
(
timeValue
,
value
?
thi
s
.
getFormatter
().
format
(
value
)
:
''
);
props
.
onChange
(
timeValue
,
value
?
prop
s
.
getFormatter
().
format
(
value
)
:
''
);
},
},
render
()
{
render
()
{
const
props
=
this
.
props
;
const
props
=
this
.
props
;
const
locale
=
this
.
getLocale
()
;
const
locale
=
props
.
locale
;
// 以下两行代码
// 以下两行代码
// 给没有初始值的日期选择框提供本地化信息
// 给没有初始值的日期选择框提供本地化信息
// 否则会以周日开始排
// 否则会以周日开始排
...
@@ -56,12 +38,6 @@ export default function createPicker(TheCalendar, defaultFormat) {
...
@@ -56,12 +38,6 @@ export default function createPicker(TheCalendar, defaultFormat) {
const
placeholder
=
(
'
placeholder
'
in
props
)
const
placeholder
=
(
'
placeholder
'
in
props
)
?
props
.
placeholder
:
locale
.
lang
.
placeholder
;
?
props
.
placeholder
:
locale
.
lang
.
placeholder
;
const
timePicker
=
props
.
showTime
?
(<
TimePicker
prefixCls
=
"ant-time-picker"
placeholder
=
{
locale
.
lang
.
timePlaceholder
}
transitionName
=
"slide-up"
/>)
:
null
;
const
disabledTime
=
props
.
showTime
?
props
.
disabledTime
:
null
;
const
disabledTime
=
props
.
showTime
?
props
.
disabledTime
:
null
;
const
calendarClassName
=
classNames
({
const
calendarClassName
=
classNames
({
...
@@ -93,7 +69,7 @@ export default function createPicker(TheCalendar, defaultFormat) {
...
@@ -93,7 +69,7 @@ export default function createPicker(TheCalendar, defaultFormat) {
disabledDate
=
{
props
.
disabledDate
}
disabledDate
=
{
props
.
disabledDate
}
disabledTime
=
{
disabledTime
}
disabledTime
=
{
disabledTime
}
locale
=
{
locale
.
lang
}
locale
=
{
locale
.
lang
}
timePicker
=
{
timePicker
}
timePicker
=
{
props
.
timePicker
}
defaultValue
=
{
defaultCalendarValue
}
defaultValue
=
{
defaultCalendarValue
}
dateInputPlaceholder
=
{
placeholder
}
dateInputPlaceholder
=
{
placeholder
}
prefixCls
=
"ant-calendar"
prefixCls
=
"ant-calendar"
...
@@ -101,18 +77,6 @@ export default function createPicker(TheCalendar, defaultFormat) {
...
@@ -101,18 +77,6 @@ export default function createPicker(TheCalendar, defaultFormat) {
{
...
calendarHandler
}
/>
{
...
calendarHandler
}
/>
);
);
const
pickerClass
=
classNames
({
'
ant-calendar-picker
'
:
true
,
'
ant-calendar-picker-open
'
:
this
.
state
.
open
,
});
const
inputClass
=
classNames
({
'
ant-calendar-picker-input
'
:
true
,
'
ant-input
'
:
true
,
'
ant-input-lg
'
:
props
.
size
===
'
large
'
,
'
ant-input-sm
'
:
props
.
size
===
'
small
'
,
});
// default width for showTime
// default width for showTime
const
pickerStyle
=
{};
const
pickerStyle
=
{};
if
(
props
.
showTime
)
{
if
(
props
.
showTime
)
{
...
@@ -120,7 +84,7 @@ export default function createPicker(TheCalendar, defaultFormat) {
...
@@ -120,7 +84,7 @@ export default function createPicker(TheCalendar, defaultFormat) {
}
}
return
(
return
(
<
span
className
=
{
pickerClass
}
style
=
{
{
...
pickerStyle
,
...
props
.
style
}
}
>
<
span
className
=
{
p
rops
.
p
ickerClass
}
style
=
{
{
...
pickerStyle
,
...
props
.
style
}
}
>
<
RcDatePicker
<
RcDatePicker
transitionName
=
{
props
.
transitionName
}
transitionName
=
{
props
.
transitionName
}
disabled
=
{
props
.
disabled
}
disabled
=
{
props
.
disabled
}
...
@@ -130,8 +94,8 @@ export default function createPicker(TheCalendar, defaultFormat) {
...
@@ -130,8 +94,8 @@ export default function createPicker(TheCalendar, defaultFormat) {
style
=
{
props
.
popupStyle
}
style
=
{
props
.
popupStyle
}
align
=
{
props
.
align
}
align
=
{
props
.
align
}
getCalendarContainer
=
{
props
.
getCalendarContainer
}
getCalendarContainer
=
{
props
.
getCalendarContainer
}
onOpen
=
{
thi
s
.
toggleOpen
}
onOpen
=
{
prop
s
.
toggleOpen
}
onClose
=
{
thi
s
.
toggleOpen
}
onClose
=
{
prop
s
.
toggleOpen
}
{
...
pickerChangeHandler
}
{
...
pickerChangeHandler
}
>
>
{
{
...
@@ -140,10 +104,10 @@ export default function createPicker(TheCalendar, defaultFormat) {
...
@@ -140,10 +104,10 @@ export default function createPicker(TheCalendar, defaultFormat) {
<
span
>
<
span
>
<
input
<
input
disabled
=
{
props
.
disabled
}
disabled
=
{
props
.
disabled
}
onChange
=
{
thi
s
.
handleInputChange
}
onChange
=
{
prop
s
.
handleInputChange
}
value
=
{
value
&&
thi
s
.
getFormatter
().
format
(
value
)
}
value
=
{
value
&&
prop
s
.
getFormatter
().
format
(
value
)
}
placeholder
=
{
placeholder
}
placeholder
=
{
placeholder
}
className
=
{
i
nputClass
}
/>
className
=
{
props
.
pickerI
nputClass
}
/>
<
span
className
=
"ant-calendar-picker-icon"
/>
<
span
className
=
"ant-calendar-picker-icon"
/>
</
span
>
</
span
>
);
);
...
...
components/date-picker/index.jsx
浏览文件 @
fd1d54cf
import
RcCalendar
from
'
rc-calendar
'
;
import
RcCalendar
from
'
rc-calendar
'
;
import
MonthCalendar
from
'
rc-calendar/lib/MonthCalendar
'
;
import
MonthCalendar
from
'
rc-calendar/lib/MonthCalendar
'
;
import
createPicker
from
'
./createPicker
'
;
import
createPicker
from
'
./createPicker
'
;
import
wrapPicker
from
'
./wrapPicker
'
;
import
RangePicker
from
'
./RangePicker
'
;
import
RangePicker
from
'
./RangePicker
'
;
import
Calendar
from
'
./Calendar
'
;
import
Calendar
from
'
./Calendar
'
;
const
DatePicker
=
createPicker
(
RcCalendar
);
const
DatePicker
=
wrapPicker
(
createPicker
(
RcCalendar
)
);
const
MonthPicker
=
createPicker
(
MonthCalendar
,
'
yyyy-MM
'
);
const
MonthPicker
=
wrapPicker
(
createPicker
(
MonthCalendar
)
,
'
yyyy-MM
'
);
DatePicker
.
Calendar
=
Calendar
;
DatePicker
.
Calendar
=
Calendar
;
DatePicker
.
RangePicker
=
RangePicker
;
DatePicker
.
RangePicker
=
wrapPicker
(
RangePicker
,
'
yyyy-MM-dd
'
)
;
DatePicker
.
MonthPicker
=
MonthPicker
;
DatePicker
.
MonthPicker
=
MonthPicker
;
export
default
DatePicker
;
export
default
DatePicker
;
components/date-picker/wrapPicker.jsx
0 → 100644
浏览文件 @
fd1d54cf
import
React
,
{
PropTypes
}
from
'
react
'
;
import
TimePicker
from
'
rc-time-picker
'
;
import
DateTimeFormat
from
'
gregorian-calendar-format
'
;
import
GregorianCalendar
from
'
gregorian-calendar
'
;
import
classNames
from
'
classnames
'
;
import
defaultLocale
from
'
./locale/zh_CN
'
;
export
default
function
wrapPicker
(
Picker
,
defaultFormat
)
{
return
class
PickerWrapper
extends
React
.
Component
{
static
defaultProps
=
{
format
:
defaultFormat
||
'
yyyy-MM-dd
'
,
transitionName
:
'
slide-up
'
,
popupStyle
:
{},
onChange
()
{},
onOk
()
{},
locale
:
{},
align
:
{
offset
:
[
0
,
-
9
],
},
open
:
false
}
static
contextTypes
=
{
antLocale
:
PropTypes
.
object
,
}
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{};
}
// remove input readonly warning
handleInputChange
()
{}
getLocale
()
{
const
props
=
this
.
props
;
let
locale
=
defaultLocale
;
const
context
=
this
.
context
;
if
(
context
.
antLocale
&&
context
.
antLocale
.
DatePicker
)
{
locale
=
context
.
antLocale
.
DatePicker
;
}
// 统一合并为完整的 Locale
const
result
=
{
...
locale
,
...
props
.
locale
};
result
.
lang
=
{
...
locale
.
lang
,
...
props
.
locale
.
lang
};
return
result
;
}
getFormatter
=
()
=>
{
if
(
!
this
.
formats
)
{
this
.
formats
=
{};
}
const
formats
=
this
.
formats
;
const
format
=
this
.
props
.
format
;
if
(
formats
[
format
])
{
return
formats
[
format
];
}
formats
[
format
]
=
new
DateTimeFormat
(
format
,
this
.
getLocale
().
lang
.
format
);
return
formats
[
format
];
}
parseDateFromValue
=
(
value
)
=>
{
if
(
value
)
{
if
(
typeof
value
===
'
string
'
)
{
return
this
.
getFormatter
().
parse
(
value
,
{
locale
:
this
.
getLocale
()
});
}
else
if
(
value
instanceof
Date
)
{
let
date
=
new
GregorianCalendar
(
this
.
getLocale
());
date
.
setTime
(
+
value
);
return
date
;
}
}
return
value
;
}
toggleOpen
=
(
e
)
=>
{
this
.
setState
({
open
:
e
.
open
});
}
render
()
{
const
props
=
this
.
props
;
const
state
=
this
.
state
;
const
pickerClass
=
classNames
({
'
ant-calendar-picker
'
:
true
,
'
ant-calendar-picker-open
'
:
state
.
open
});
const
pickerInputClass
=
classNames
({
'
ant-calendar-range-picker
'
:
true
,
'
ant-input
'
:
true
,
'
ant-input-lg
'
:
props
.
size
===
'
large
'
,
'
ant-input-sm
'
:
props
.
size
===
'
small
'
,
});
const
locale
=
this
.
getLocale
();
const
timePicker
=
props
.
showTime
?
(
<
TimePicker
prefixCls
=
"ant-time-picker"
placeholder
=
{
locale
.
lang
.
timePlaceholder
}
transitionName
=
"slide-up"
/>
)
:
null
;
return
(
<
Picker
{
...
this
.
props
}
pickerClass
=
{
pickerClass
}
pickerInputClass
=
{
pickerInputClass
}
locale
=
{
locale
}
timePicker
=
{
timePicker
}
toggleOpen
=
{
this
.
toggleOpen
}
handleInputChange
=
{
this
.
handleInputChange
}
getFormatter
=
{
this
.
getFormatter
}
parseDateFromValue
=
{
this
.
parseDateFromValue
}
/>
);
}
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录