UNPKG

890 BJavaScriptView Raw
1import {creatorFactory} from '@form-create/core/src/index';
2
3const DEFAULT_FORMATS = {
4 date: 'yyyy-MM-dd',
5 month: 'yyyy-MM',
6 datetime: 'yyyy-MM-dd HH:mm:ss',
7 week: 'yyyywWW',
8 timerange: 'HH:mm:ss',
9 daterange: 'yyyy-MM-dd',
10 monthrange: 'yyyy-MM',
11 datetimerange: 'yyyy-MM-dd HH:mm:ss',
12 year: 'yyyy'
13};
14
15const name = 'datePicker';
16
17export default {
18 name,
19 maker: (function () {
20 return ['year', 'month', 'date', 'dates', 'week', 'datetime', 'datetimeRange', 'dateRange', 'monthRange'].reduce((initial, type) => {
21 initial[type] = creatorFactory(name, {type: type.toLowerCase()});
22 return initial
23 }, {});
24 }()),
25 mergeProp(ctx) {
26 const props = ctx.prop.props;
27 if (!props.valueFormat) {
28 props.valueFormat = DEFAULT_FORMATS[props.type] || DEFAULT_FORMATS['date'];
29 }
30 }
31}