@ecoding/components.antd 0.2.32 → 0.2.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/date.picker/index.d.ts +14 -0
- package/lib/core/date.picker/index.js +40 -0
- package/lib/core/phone-input/index.d.ts +5 -0
- package/lib/core/range-picker/index.d.ts +4 -3
- package/lib/core/range-picker/index.js +43 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { RangePickerProps } from "antd/es/date-picker";
|
|
3
|
+
declare type IProps = RangePickerProps & {
|
|
4
|
+
value?: string | number;
|
|
5
|
+
disabledDate?: (current: any) => RangePickerProps['disabledDate'];
|
|
6
|
+
onChange?: any;
|
|
7
|
+
showTime?: boolean;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
format?: string;
|
|
12
|
+
};
|
|
13
|
+
declare const Picker: React.FC<IProps>;
|
|
14
|
+
export default Picker;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import { DatePicker } from "antd";
|
|
4
|
+
const Picker = (props) => {
|
|
5
|
+
const [date, setDates] = useState();
|
|
6
|
+
// const disabledDate: RangePickerProps['disabledDate'] = (current) => {
|
|
7
|
+
// // Can not select days before today and today
|
|
8
|
+
// return current && current < dayjs().endOf('day');
|
|
9
|
+
// };
|
|
10
|
+
const change = (v) => {
|
|
11
|
+
let value;
|
|
12
|
+
setDates(v);
|
|
13
|
+
if (props.format) {
|
|
14
|
+
value = dayjs(v).format(props.format || "YYYY-MM-DD HH:mm:ss");
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
value = dayjs(v).valueOf();
|
|
18
|
+
}
|
|
19
|
+
props.onChange && props.onChange(value);
|
|
20
|
+
};
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!props.value) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let v;
|
|
26
|
+
if (typeof props.value === "string") {
|
|
27
|
+
v = /^[0-9]*$/.test(props.value) ? dayjs(Number(props.value)) : dayjs(props.value);
|
|
28
|
+
}
|
|
29
|
+
if (typeof props.value === "number") {
|
|
30
|
+
v = dayjs(props.value);
|
|
31
|
+
}
|
|
32
|
+
if (typeof props.value === "object") {
|
|
33
|
+
v = props.value;
|
|
34
|
+
}
|
|
35
|
+
setDates(v);
|
|
36
|
+
}, [props.value]);
|
|
37
|
+
return (React.createElement(DatePicker, { value: date, className: props.className || undefined, style: Object.assign({}, { width: "100%" }, props.style) || undefined, showTime: props.showTime ? { defaultValue: dayjs("00:00:00", "HH:mm:ss") } : undefined, disabledDate: props.disabledDate || undefined, disabled: props.disabled || undefined, onChange: change }));
|
|
38
|
+
};
|
|
39
|
+
Picker.defaultProps = {};
|
|
40
|
+
export default Picker;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { RangePickerProps } from "antd/es/date-picker";
|
|
3
2
|
import type { Dayjs } from "dayjs";
|
|
4
3
|
declare type RangeValue = [Dayjs | null, Dayjs | null] | null;
|
|
5
|
-
|
|
4
|
+
interface IProps {
|
|
6
5
|
value?: RangeValue;
|
|
6
|
+
showTime?: boolean;
|
|
7
7
|
rangeDay?: number;
|
|
8
8
|
onChange?: any;
|
|
9
9
|
className?: string;
|
|
10
10
|
style?: React.CSSProperties;
|
|
11
11
|
disabled?: boolean;
|
|
12
|
-
|
|
12
|
+
format?: string;
|
|
13
|
+
}
|
|
13
14
|
declare const Picker: React.FC<IProps>;
|
|
14
15
|
export default Picker;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
3
|
import { DatePicker } from "antd";
|
|
4
|
+
;
|
|
4
5
|
const { RangePicker } = DatePicker;
|
|
5
6
|
const Picker = (props) => {
|
|
6
|
-
const [dates, setDates] = useState(
|
|
7
|
+
const [dates, setDates] = useState();
|
|
7
8
|
const disabledDate = (current) => {
|
|
8
9
|
if (!dates) {
|
|
9
10
|
return false;
|
|
@@ -12,11 +13,48 @@ const Picker = (props) => {
|
|
|
12
13
|
const tooEarly = dates[1] && dates[1].diff(current, "days") > props.rangeDay;
|
|
13
14
|
return !!tooEarly || !!tooLate;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
const change = (v) => {
|
|
17
|
+
if (!v) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let value;
|
|
21
|
+
setDates(v);
|
|
22
|
+
if (props.format) { // "YYYY-MM-DD HH:mm:ss"
|
|
23
|
+
value = [dayjs(v[0]).format(props.format), dayjs(v[1]).format(props.format)];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
value = [dayjs(v[0]).valueOf(), dayjs(v[1]).valueOf()];
|
|
27
|
+
}
|
|
28
|
+
props.onChange && props.onChange(value);
|
|
29
|
+
};
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!props.value || !Array.isArray(props.value) || props.value.length < 2) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const v = [];
|
|
35
|
+
props.value.forEach((item) => {
|
|
36
|
+
if (typeof item === "string") {
|
|
37
|
+
if (/^[0-9]*$/.test(item)) {
|
|
38
|
+
v.push(dayjs(Number(item)));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
v.push(dayjs(item));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (typeof item === "number") {
|
|
45
|
+
v.push(dayjs(item));
|
|
46
|
+
}
|
|
47
|
+
if (typeof item === "object") {
|
|
48
|
+
v.push(item);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
setDates(v);
|
|
52
|
+
}, [props.value]);
|
|
53
|
+
return (React.createElement(RangePicker, { value: dates, className: props.className || undefined, style: Object.assign({}, { width: "100%" }, props.style) || undefined, showTime: props.showTime ? {
|
|
16
54
|
defaultValue: [dayjs("00:00:00", "HH:mm:ss"), dayjs("23:59:59", "HH:mm:ss")]
|
|
17
|
-
}, onCalendarChange: (val) => setDates(val), disabledDate: disabledDate
|
|
55
|
+
} : undefined, onCalendarChange: (val) => setDates(val), disabledDate: props.rangeDay ? disabledDate : undefined, disabled: props.disabled || undefined, onChange: change }));
|
|
18
56
|
};
|
|
19
57
|
Picker.defaultProps = {
|
|
20
|
-
rangeDay:
|
|
58
|
+
rangeDay: undefined
|
|
21
59
|
};
|
|
22
60
|
export default Picker;
|
package/lib/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { default as AsyncCascader } from "./core/async-cascader";
|
|
|
8
8
|
export { default as LengthInput } from "./core/length-input";
|
|
9
9
|
export { default as PhoneInput } from "./core/phone-input";
|
|
10
10
|
export { default as RangePicker } from "./core/range-picker";
|
|
11
|
+
export { default as DatePicker } from "./core/date.picker";
|
|
11
12
|
export { default as SingleImgUpload } from "./core/single-img-upload";
|
|
12
13
|
export { default as SingleFileUpload } from "./core/single-file-upload";
|
|
13
14
|
export { default as MultipleUpload } from "./core/multiple-upload";
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { default as AsyncCascader } from "./core/async-cascader";
|
|
|
8
8
|
export { default as LengthInput } from "./core/length-input";
|
|
9
9
|
export { default as PhoneInput } from "./core/phone-input";
|
|
10
10
|
export { default as RangePicker } from "./core/range-picker";
|
|
11
|
+
export { default as DatePicker } from "./core/date.picker";
|
|
11
12
|
export { default as SingleImgUpload } from "./core/single-img-upload";
|
|
12
13
|
export { default as SingleFileUpload } from "./core/single-file-upload";
|
|
13
14
|
export { default as MultipleUpload } from "./core/multiple-upload";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.34",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"react-quill": "^2.0.0"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "59602e71b1f234bb4d2dd7225e337dea4bfbc82b"
|
|
48
48
|
}
|