@pisell/date-picker 1.0.75 → 1.0.77
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/es/ActionBar/index.js +19 -28
- package/es/ActionBar/index.less +2 -1
- package/es/CustomCalendarHeader/index.d.ts +2 -0
- package/es/CustomCalendarHeader/index.js +53 -0
- package/es/Dialog/index.d.ts +2 -0
- package/es/Dialog/index.js +22 -0
- package/es/Drawer/index.d.ts +11 -0
- package/es/Drawer/index.js +35 -0
- package/es/Drawer/index.less +40 -0
- package/es/PisellDateRangePicker/LocaleContext.d.ts +2 -0
- package/es/PisellDateRangePicker/index.d.ts +81 -0
- package/es/PisellDateRangePicker/index.js +112 -41
- package/es/PisellDateRangePicker/index.less +56 -0
- package/es/Shortcuts/index.d.ts +4 -3
- package/es/Toolbar/index.d.ts +3 -0
- package/es/Toolbar/index.js +122 -0
- package/es/Toolbar/index.less +32 -0
- package/es/browserSelect/chevron-down.png +0 -0
- package/es/browserSelect/index.d.ts +15 -0
- package/es/browserSelect/index.js +36 -0
- package/es/browserSelect/index.less +18 -0
- package/es/constants.d.ts +58 -0
- package/es/constants.js +128 -0
- package/es/hooks/useDocumentVisibility.d.ts +2 -0
- package/es/hooks/useDocumentVisibility.js +27 -0
- package/es/hooks/useNextDay.d.ts +2 -0
- package/es/hooks/useNextDay.js +15 -0
- package/es/hooks/useUpdateEffect.d.ts +2 -0
- package/es/hooks/useUpdateEffect.js +11 -0
- package/es/icon/ChevronLeft.d.ts +5 -0
- package/es/icon/ChevronLeft.js +23 -0
- package/es/icon/ChevronLeftDouble.d.ts +5 -0
- package/es/icon/ChevronLeftDouble.js +23 -0
- package/es/icon/ChevronRight.d.ts +5 -0
- package/es/icon/ChevronRight.js +23 -0
- package/es/icon/ChevronRightDouble.d.ts +5 -0
- package/es/icon/ChevronRightDouble.js +23 -0
- package/es/index.d.ts +23 -0
- package/es/index.js +1 -0
- package/es/locales/en-US.d.ts +17 -0
- package/es/locales/en-US.js +18 -1
- package/es/locales/index.d.ts +2 -0
- package/es/locales/zh-CN.d.ts +21 -4
- package/es/locales/zh-CN.js +21 -4
- package/es/locales/zh-TW.d.ts +17 -0
- package/es/locales/zh-TW.js +18 -1
- package/es/utils/index.d.ts +32 -0
- package/es/utils/index.js +86 -3
- package/lib/ActionBar/index.js +30 -25
- package/lib/ActionBar/index.less +2 -1
- package/lib/CustomCalendarHeader/index.d.ts +2 -0
- package/lib/CustomCalendarHeader/index.js +58 -0
- package/lib/Dialog/index.d.ts +2 -0
- package/lib/Dialog/index.js +52 -0
- package/lib/Drawer/index.d.ts +11 -0
- package/lib/Drawer/index.js +62 -0
- package/lib/Drawer/index.less +40 -0
- package/lib/PisellDateRangePicker/LocaleContext.d.ts +2 -0
- package/lib/PisellDateRangePicker/index.d.ts +81 -0
- package/lib/PisellDateRangePicker/index.js +89 -33
- package/lib/PisellDateRangePicker/index.less +56 -0
- package/lib/Shortcuts/index.d.ts +4 -3
- package/lib/Toolbar/index.d.ts +3 -0
- package/lib/Toolbar/index.js +139 -0
- package/lib/Toolbar/index.less +32 -0
- package/lib/browserSelect/chevron-down.png +0 -0
- package/lib/browserSelect/index.d.ts +15 -0
- package/lib/browserSelect/index.js +59 -0
- package/lib/browserSelect/index.less +18 -0
- package/lib/constants.d.ts +58 -0
- package/lib/constants.js +178 -0
- package/lib/hooks/useDocumentVisibility.d.ts +2 -0
- package/lib/hooks/useDocumentVisibility.js +40 -0
- package/lib/hooks/useNextDay.d.ts +2 -0
- package/lib/hooks/useNextDay.js +49 -0
- package/lib/hooks/useUpdateEffect.d.ts +2 -0
- package/lib/hooks/useUpdateEffect.js +35 -0
- package/lib/icon/ChevronLeft.d.ts +5 -0
- package/lib/icon/ChevronLeft.js +60 -0
- package/lib/icon/ChevronLeftDouble.d.ts +5 -0
- package/lib/icon/ChevronLeftDouble.js +60 -0
- package/lib/icon/ChevronRight.d.ts +5 -0
- package/lib/icon/ChevronRight.js +60 -0
- package/lib/icon/ChevronRightDouble.d.ts +5 -0
- package/lib/icon/ChevronRightDouble.js +60 -0
- package/lib/{PisellDateRangePicker → icon}/CloseCircle.js +1 -1
- package/lib/index.d.ts +23 -0
- package/lib/index.js +10 -1
- package/lib/locales/en-US.d.ts +17 -0
- package/lib/locales/en-US.js +18 -1
- package/lib/locales/index.d.ts +2 -0
- package/lib/locales/zh-CN.d.ts +21 -4
- package/lib/locales/zh-CN.js +18 -1
- package/lib/locales/zh-TW.d.ts +17 -0
- package/lib/locales/zh-TW.js +18 -1
- package/lib/utils/index.d.ts +32 -0
- package/lib/utils/index.js +58 -0
- package/package.json +1 -1
- /package/es/{PisellDateRangePicker → icon}/CloseCircle.d.ts +0 -0
- /package/es/{PisellDateRangePicker → icon}/CloseCircle.js +0 -0
- /package/lib/{PisellDateRangePicker → icon}/CloseCircle.d.ts +0 -0
package/es/ActionBar/index.js
CHANGED
|
@@ -13,7 +13,7 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
13
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
14
|
import React, { useMemo, useContext } from "react";
|
|
15
15
|
import classNames from "classnames";
|
|
16
|
-
import { Button
|
|
16
|
+
import { Button } from "antd";
|
|
17
17
|
import { MuiPickersAdapterContext } from "@mui/x-date-pickers";
|
|
18
18
|
import { isArr, isMobile } from "@pisell/utils";
|
|
19
19
|
import dayjs from "dayjs";
|
|
@@ -52,6 +52,15 @@ var ActionBar = function ActionBar(props) {
|
|
|
52
52
|
onChange(newValue, "time");
|
|
53
53
|
};
|
|
54
54
|
var spaceStyle = useMemo(function () {
|
|
55
|
+
return isMobile() ? {
|
|
56
|
+
display: "flex",
|
|
57
|
+
justifyContent: "end",
|
|
58
|
+
gap: 16
|
|
59
|
+
} : {
|
|
60
|
+
display: "flex"
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
var buttonStyle = useMemo(function () {
|
|
55
64
|
return isMobile() ? {
|
|
56
65
|
display: "flex",
|
|
57
66
|
justifyContent: "end",
|
|
@@ -74,40 +83,22 @@ var ActionBar = function ActionBar(props) {
|
|
|
74
83
|
}, [showTime]);
|
|
75
84
|
return /*#__PURE__*/React.createElement("div", {
|
|
76
85
|
className: classNames(props.className, "date-picker-action-bar")
|
|
77
|
-
},
|
|
78
|
-
className: "date-picker-action-bar-left"
|
|
79
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
86
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
80
87
|
className: "date-picker-action-bar-right",
|
|
81
|
-
style: isMobile() ? {
|
|
82
|
-
display: "block"
|
|
83
|
-
} : {}
|
|
84
|
-
}, /*#__PURE__*/React.createElement(Space, {
|
|
85
|
-
split: "-",
|
|
86
|
-
style: _objectSpread({}, spaceStyle)
|
|
87
|
-
}, showTime ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TimePicker, _extends({
|
|
88
|
-
placeholder: getText("action-bar-start.time", pLocaleMap[locale])
|
|
89
|
-
}, startTimeProps, {
|
|
90
|
-
value: value[0],
|
|
91
|
-
popupClassName: "date-picker-action-bar-time-picker-popup",
|
|
92
|
-
onChange: handleStartChange,
|
|
93
|
-
inputReadOnly: true
|
|
94
|
-
})), /*#__PURE__*/React.createElement(TimePicker, _extends({
|
|
95
|
-
placeholder: getText("action-bar-end.time", pLocaleMap[locale])
|
|
96
|
-
}, endTimeProps, {
|
|
97
|
-
value: value[1],
|
|
98
|
-
popupClassName: "date-picker-action-bar-time-picker-popup",
|
|
99
|
-
onChange: handleEndChange,
|
|
100
|
-
inputReadOnly: true
|
|
101
|
-
}))) : /*#__PURE__*/React.createElement("div", null)), /*#__PURE__*/React.createElement(Space, {
|
|
102
88
|
style: _objectSpread(_objectSpread({}, spaceStyle), {}, {
|
|
103
89
|
margin: 0
|
|
104
90
|
})
|
|
105
|
-
}, /*#__PURE__*/React.createElement(Button, _extends({
|
|
91
|
+
}, /*#__PURE__*/React.createElement(Button, _extends({
|
|
92
|
+
block: isMobile(),
|
|
93
|
+
size: "large"
|
|
94
|
+
}, cancelButtonProps || {}, {
|
|
106
95
|
onClick: onCancel
|
|
107
96
|
}), getText("action-bar-cancel", pLocaleMap[locale])), /*#__PURE__*/React.createElement(Button, _extends({
|
|
108
|
-
type: "primary"
|
|
97
|
+
type: "primary",
|
|
98
|
+
size: "large",
|
|
99
|
+
block: isMobile()
|
|
109
100
|
}, okButtonProps || {}, {
|
|
110
101
|
onClick: onOk
|
|
111
|
-
}), getText("action-bar-apply", pLocaleMap[locale]))))
|
|
102
|
+
}), getText("action-bar-apply", pLocaleMap[locale]))));
|
|
112
103
|
};
|
|
113
104
|
export default ActionBar;
|
package/es/ActionBar/index.less
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Stack from '@mui/material/Stack';
|
|
3
|
+
import IconButton from '@mui/material/IconButton';
|
|
4
|
+
import Typography from '@mui/material/Typography';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import ChevronLeft from "../icon/ChevronLeft";
|
|
7
|
+
import ChevronLeftDouble from "../icon/ChevronLeftDouble";
|
|
8
|
+
import ChevronRight from "../icon/ChevronRight";
|
|
9
|
+
import ChevronRightDouble from "../icon/ChevronRightDouble";
|
|
10
|
+
var CustomCalendarHeaderRoot = styled('div')({
|
|
11
|
+
display: 'flex',
|
|
12
|
+
justifyContent: 'space-between',
|
|
13
|
+
padding: '8px 16px',
|
|
14
|
+
alignItems: 'center'
|
|
15
|
+
});
|
|
16
|
+
var CustomCalendarHeader = function CustomCalendarHeader(props) {
|
|
17
|
+
var currentMonth = props.currentMonth,
|
|
18
|
+
onMonthChange = props.onMonthChange;
|
|
19
|
+
var selectNextMonth = function selectNextMonth() {
|
|
20
|
+
return onMonthChange(currentMonth.add(1, 'month'), 'left');
|
|
21
|
+
};
|
|
22
|
+
var selectNextYear = function selectNextYear() {
|
|
23
|
+
return onMonthChange(currentMonth.add(1, 'year'), 'left');
|
|
24
|
+
};
|
|
25
|
+
var selectPreviousMonth = function selectPreviousMonth() {
|
|
26
|
+
return onMonthChange(currentMonth.subtract(1, 'month'), 'right');
|
|
27
|
+
};
|
|
28
|
+
var selectPreviousYear = function selectPreviousYear() {
|
|
29
|
+
return onMonthChange(currentMonth.subtract(1, 'year'), 'right');
|
|
30
|
+
};
|
|
31
|
+
return /*#__PURE__*/React.createElement(CustomCalendarHeaderRoot, null, /*#__PURE__*/React.createElement(Stack, {
|
|
32
|
+
spacing: 1,
|
|
33
|
+
direction: "row"
|
|
34
|
+
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
35
|
+
onClick: selectPreviousYear,
|
|
36
|
+
title: "Previous year"
|
|
37
|
+
}, /*#__PURE__*/React.createElement(ChevronLeftDouble, null)), /*#__PURE__*/React.createElement(IconButton, {
|
|
38
|
+
onClick: selectPreviousMonth,
|
|
39
|
+
title: "Previous month"
|
|
40
|
+
}, /*#__PURE__*/React.createElement(ChevronLeft, null))), /*#__PURE__*/React.createElement(Typography, {
|
|
41
|
+
variant: "body2"
|
|
42
|
+
}, currentMonth.format('MMMM YYYY')), /*#__PURE__*/React.createElement(Stack, {
|
|
43
|
+
spacing: 1,
|
|
44
|
+
direction: "row"
|
|
45
|
+
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
46
|
+
onClick: selectNextMonth,
|
|
47
|
+
title: "Next month"
|
|
48
|
+
}, /*#__PURE__*/React.createElement(ChevronRight, null)), /*#__PURE__*/React.createElement(IconButton, {
|
|
49
|
+
onClick: selectNextYear,
|
|
50
|
+
title: "Next year"
|
|
51
|
+
}, /*#__PURE__*/React.createElement(ChevronRightDouble, null))));
|
|
52
|
+
};
|
|
53
|
+
export default CustomCalendarHeader;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
// import Drawer from "../Drawer";
|
|
3
|
+
|
|
4
|
+
import Drawer from "@mui/material/Drawer";
|
|
5
|
+
var Dialog = function Dialog(props) {
|
|
6
|
+
var open = props.open,
|
|
7
|
+
onClose = props.onClose,
|
|
8
|
+
children = props.children;
|
|
9
|
+
|
|
10
|
+
// return <MuiDialog open={open}>
|
|
11
|
+
// {children}
|
|
12
|
+
// </MuiDialog>
|
|
13
|
+
return /*#__PURE__*/React.createElement(Drawer, {
|
|
14
|
+
anchor: "bottom",
|
|
15
|
+
open: open,
|
|
16
|
+
onClose: onClose,
|
|
17
|
+
height: 650,
|
|
18
|
+
autoFocus: true,
|
|
19
|
+
className: window.innerWidth > 800 ? 'date-picker-paid-drawer' : 'date-picker-custom-drawer'
|
|
20
|
+
}, children);
|
|
21
|
+
};
|
|
22
|
+
export default Dialog;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import "./index.less";
|
|
3
|
+
interface DrawerProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
className?: string;
|
|
6
|
+
height?: number;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
}
|
|
10
|
+
declare const Drawer: (props: DrawerProps) => JSX.Element | null;
|
|
11
|
+
export default Drawer;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import "./index.less";
|
|
4
|
+
var Drawer = function Drawer(props) {
|
|
5
|
+
var open = props.open,
|
|
6
|
+
className = props.className,
|
|
7
|
+
onClose = props.onClose,
|
|
8
|
+
children = props.children,
|
|
9
|
+
_props$height = props.height,
|
|
10
|
+
height = _props$height === void 0 ? 375 : _props$height;
|
|
11
|
+
|
|
12
|
+
// return ReactDOM.createPortal(
|
|
13
|
+
// drawerElement,
|
|
14
|
+
// document.body
|
|
15
|
+
// );
|
|
16
|
+
|
|
17
|
+
if (!open) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, open && /*#__PURE__*/React.createElement("div", {
|
|
21
|
+
className: "date-picker-drawer-overlay",
|
|
22
|
+
onClick: onClose
|
|
23
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
24
|
+
className: classNames("date-picker-drawer", className, {
|
|
25
|
+
open: open
|
|
26
|
+
}),
|
|
27
|
+
onClick: function onClick() {}
|
|
28
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
className: "date-picker-drawer-content",
|
|
30
|
+
style: {
|
|
31
|
+
height: height
|
|
32
|
+
}
|
|
33
|
+
}, children)));
|
|
34
|
+
};
|
|
35
|
+
export default Drawer;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.date-picker-drawer {
|
|
2
|
+
position: fixed;
|
|
3
|
+
bottom: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100%;
|
|
6
|
+
background-color: white;
|
|
7
|
+
box-shadow: 0px -2px 10px rgba(0, 0, 0, 0.1);
|
|
8
|
+
transform: translateY(100%);
|
|
9
|
+
transition: transform 0.3s ease-out;
|
|
10
|
+
z-index: 1000;
|
|
11
|
+
border-radius: 8px 8px 0 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.date-picker-drawer-content {
|
|
15
|
+
//transform: translateY(100%);
|
|
16
|
+
//transition: transform 0.3s ease-out;
|
|
17
|
+
//position: absolute;
|
|
18
|
+
//padding: 20px;
|
|
19
|
+
//bottom: 0;
|
|
20
|
+
//width: 100vw;
|
|
21
|
+
//background-color: #fff;
|
|
22
|
+
//z-index: 1000;
|
|
23
|
+
//box-shadow: 0px -2px 10px rgba(0, 0, 0, 0.1);
|
|
24
|
+
//border-radius: 8px 8px 0px 0px;
|
|
25
|
+
//height: 650px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.date-picker-drawer.open {
|
|
29
|
+
transform: translateY(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.date-picker-drawer-overlay {
|
|
33
|
+
position: fixed;
|
|
34
|
+
top: 0;
|
|
35
|
+
left: 0;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 100%;
|
|
38
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
39
|
+
z-index: 999;
|
|
40
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Dayjs } from "dayjs";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ButtonProps } from "antd";
|
|
4
|
+
import { PopperPlacementType } from "@mui/base/Popper/Popper.types";
|
|
5
|
+
import { PresetType } from "../Shortcuts";
|
|
6
|
+
import "dayjs/locale/zh-cn";
|
|
7
|
+
import "dayjs/locale/en";
|
|
8
|
+
import "dayjs/locale/zh-tw";
|
|
9
|
+
import "./index.less";
|
|
10
|
+
export interface PisellDateRangePickerProps {
|
|
11
|
+
/** 再次选择日期时是否清除结束时间 */
|
|
12
|
+
clearEndOnSelection?: boolean;
|
|
13
|
+
/** 日期选择确认回调 */
|
|
14
|
+
onChange?: (day: (Dayjs | null)[] | string) => void;
|
|
15
|
+
/** 日期改变回调 此处只为了组件外拿到当前日期项进行状态操作 通常情况下只使用onChange来拿value */
|
|
16
|
+
onDateChange?: (day: (Dayjs | null)[]) => void;
|
|
17
|
+
/** 日期选择值 */
|
|
18
|
+
value?: Dayjs[] | string;
|
|
19
|
+
/** 日期选择默认值 */
|
|
20
|
+
defaultValue?: Dayjs[];
|
|
21
|
+
/** 快捷选择项 */
|
|
22
|
+
presets?: PresetType[];
|
|
23
|
+
/** 类名 */
|
|
24
|
+
className?: string;
|
|
25
|
+
/** 是否显示时间选择 这里参数为antd TimePickerProps */
|
|
26
|
+
showTime?: boolean | {
|
|
27
|
+
defaultValue: Dayjs;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}[];
|
|
30
|
+
/** 占位符 */
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
/** 是否禁用日期 */
|
|
33
|
+
disabledDate?: (day: Dayjs, position: "start" | "end", value: Dayjs[]) => boolean;
|
|
34
|
+
/** 日期格式 */
|
|
35
|
+
format?: string;
|
|
36
|
+
/** 后缀图标 */
|
|
37
|
+
suffixIcon?: React.ReactNode;
|
|
38
|
+
/** 是否显示边框 */
|
|
39
|
+
bordered?: boolean;
|
|
40
|
+
/** 是否打开日期选择 */
|
|
41
|
+
open?: boolean;
|
|
42
|
+
/** 关闭回调 */
|
|
43
|
+
onClose?: () => void;
|
|
44
|
+
/** 打开回调 */
|
|
45
|
+
onOpen?: () => void;
|
|
46
|
+
/** 弹窗宽度 */
|
|
47
|
+
popupWidth?: number;
|
|
48
|
+
/** 最小日期 */
|
|
49
|
+
minDate?: Dayjs;
|
|
50
|
+
/** 最大日期 */
|
|
51
|
+
maxDate?: Dayjs;
|
|
52
|
+
/** 月份切换事件 */
|
|
53
|
+
onMonthChange?: (value: Dayjs) => void;
|
|
54
|
+
/** 额外的弹出日历 className */
|
|
55
|
+
popupClassName?: string;
|
|
56
|
+
/** 默认显示月份 */
|
|
57
|
+
defaultCalendarMonth?: Dayjs;
|
|
58
|
+
/** ok 按钮 props */
|
|
59
|
+
okButtonProps?: ButtonProps;
|
|
60
|
+
/** cancel 按钮 props */
|
|
61
|
+
cancelButtonProps?: ButtonProps;
|
|
62
|
+
/**
|
|
63
|
+
* CSS media query when `Mobile` mode will be changed to `Desktop`.
|
|
64
|
+
* @default '@media (pointer: fine)'
|
|
65
|
+
* @example '@media (min-width: 720px)' or theme.breakpoints.up("sm")
|
|
66
|
+
*/
|
|
67
|
+
desktopModeMediaQuery?: string;
|
|
68
|
+
style?: React.CSSProperties;
|
|
69
|
+
/** 是否展示清除按钮 */
|
|
70
|
+
allowClear?: boolean;
|
|
71
|
+
/** true 将弹窗当前DOM层次结构下 false 追加到body */
|
|
72
|
+
disablePortal?: boolean;
|
|
73
|
+
/** 弹窗放置位置 */
|
|
74
|
+
placement?: PopperPlacementType;
|
|
75
|
+
/** 输入框只读 */
|
|
76
|
+
inputReadOnly: boolean;
|
|
77
|
+
/** 使用快捷筛选时返回快捷字符串 */
|
|
78
|
+
returnShortcutString?: boolean;
|
|
79
|
+
}
|
|
80
|
+
declare const PisellDateRangePicker: (props: PisellDateRangePickerProps) => JSX.Element;
|
|
81
|
+
export default PisellDateRangePicker;
|
|
@@ -10,24 +10,31 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
11
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import React, { useState, useEffect, useMemo, useContext } from "react";
|
|
13
|
+
import React, { useState, useEffect, useMemo, useContext, useRef } from "react";
|
|
14
14
|
import { DateRangePicker } from "../DateRangePicker";
|
|
15
15
|
import ActionBar from "../ActionBar";
|
|
16
16
|
import Shortcuts from "../Shortcuts";
|
|
17
17
|
import { SingleInputDateRangeField } from "../SingleInputDateRangeField";
|
|
18
18
|
import classNames from "classnames";
|
|
19
|
-
import { isArr, isBoolean } from "@pisell/utils";
|
|
19
|
+
import { isArr, isBoolean, isString } from "@pisell/utils";
|
|
20
20
|
import useCssVariables from "./useCssVariables";
|
|
21
|
-
import CloseCircle from "
|
|
21
|
+
import CloseCircle from "../icon/CloseCircle";
|
|
22
22
|
import "dayjs/locale/zh-cn";
|
|
23
23
|
import "dayjs/locale/en";
|
|
24
24
|
import "dayjs/locale/zh-tw";
|
|
25
25
|
import "./index.less";
|
|
26
|
-
import { getCurrentLocale,
|
|
26
|
+
import { formatPresets, getCurrentLocale, getPresetLabel, getShortcutValue } from "../utils";
|
|
27
27
|
import { LocaleContext } from "./LocaleContext";
|
|
28
28
|
import { pLocaleMap } from "../locales";
|
|
29
|
-
|
|
29
|
+
import Dialog from "../Dialog";
|
|
30
|
+
import Toolbar from "../Toolbar";
|
|
31
|
+
import useNextDay from "../hooks/useNextDay";
|
|
32
|
+
import { defaultPresets } from "../constants";
|
|
33
|
+
var transDayjsArr = function transDayjsArr(dayjsArr, defaultValue, _presets) {
|
|
30
34
|
var _newArr;
|
|
35
|
+
if (isString(dayjsArr)) {
|
|
36
|
+
return getShortcutValue(dayjsArr, _presets);
|
|
37
|
+
}
|
|
31
38
|
var newArr = dayjsArr || defaultValue || [null, null];
|
|
32
39
|
if ((dayjsArr === null || dayjsArr === void 0 ? void 0 : dayjsArr.length) === 0) {
|
|
33
40
|
newArr = defaultValue || [null, null];
|
|
@@ -41,8 +48,7 @@ var transDayjsArr = function transDayjsArr(dayjsArr, defaultValue) {
|
|
|
41
48
|
var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
42
49
|
var propsOnChange = props.onChange,
|
|
43
50
|
propsValue = props.value,
|
|
44
|
-
|
|
45
|
-
presets = _props$presets === void 0 ? [] : _props$presets,
|
|
51
|
+
presets = props.presets,
|
|
46
52
|
className = props.className,
|
|
47
53
|
showTime = props.showTime,
|
|
48
54
|
placeholder = props.placeholder,
|
|
@@ -72,25 +78,52 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
72
78
|
disablePortal = props.disablePortal,
|
|
73
79
|
_props$placement = props.placement,
|
|
74
80
|
placement = _props$placement === void 0 ? "auto" : _props$placement,
|
|
75
|
-
inputReadOnly = props.inputReadOnly
|
|
81
|
+
_props$inputReadOnly = props.inputReadOnly,
|
|
82
|
+
inputReadOnly = _props$inputReadOnly === void 0 ? true : _props$inputReadOnly,
|
|
83
|
+
_props$returnShortcut = props.returnShortcutString,
|
|
84
|
+
returnShortcutString = _props$returnShortcut === void 0 ? false : _props$returnShortcut;
|
|
76
85
|
var _useState = useState(propsOpen !== null && propsOpen !== void 0 ? propsOpen : false),
|
|
77
86
|
_useState2 = _slicedToArray(_useState, 2),
|
|
78
87
|
open = _useState2[0],
|
|
79
88
|
setOpen = _useState2[1];
|
|
80
89
|
var _ref = useContext(LocaleContext) || {},
|
|
81
90
|
locale = _ref.locale;
|
|
91
|
+
var _useState3 = useState(""),
|
|
92
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
93
|
+
currentShortcut = _useState4[0],
|
|
94
|
+
setCurrentShortcut = _useState4[1];
|
|
95
|
+
var lastConfirmShortcut = useRef(isString(propsValue) ? propsValue : null);
|
|
82
96
|
useEffect(function () {
|
|
83
97
|
isBoolean(propsOpen) && setOpen(propsOpen);
|
|
84
98
|
}, [propsOpen]);
|
|
85
|
-
var
|
|
86
|
-
|
|
99
|
+
var _presets = useMemo(function () {
|
|
100
|
+
return formatPresets(presets || defaultPresets);
|
|
101
|
+
}, [presets]);
|
|
102
|
+
var _useState5 = useState(function () {
|
|
103
|
+
return transDayjsArr(propsValue, defaultValue, _presets);
|
|
87
104
|
}),
|
|
88
|
-
|
|
89
|
-
_value =
|
|
90
|
-
setValue =
|
|
105
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
106
|
+
_value = _useState6[0],
|
|
107
|
+
setValue = _useState6[1];
|
|
91
108
|
useEffect(function () {
|
|
92
|
-
setValue(transDayjsArr(propsValue, defaultValue));
|
|
109
|
+
setValue(transDayjsArr(propsValue, defaultValue, _presets));
|
|
110
|
+
if (isString(propsValue)) {
|
|
111
|
+
setCurrentShortcut(propsValue);
|
|
112
|
+
}
|
|
93
113
|
}, [propsValue]);
|
|
114
|
+
var getVal = function getVal() {
|
|
115
|
+
var val = _value;
|
|
116
|
+
if (returnShortcutString) {
|
|
117
|
+
val = currentShortcut;
|
|
118
|
+
} else if (currentShortcut) {
|
|
119
|
+
val = getShortcutValue(currentShortcut, _presets);
|
|
120
|
+
}
|
|
121
|
+
return val;
|
|
122
|
+
};
|
|
123
|
+
useNextDay(function () {
|
|
124
|
+
setValue(getVal());
|
|
125
|
+
setTimeout(handleOk);
|
|
126
|
+
});
|
|
94
127
|
var handleOpen = function handleOpen() {
|
|
95
128
|
setOpen(true);
|
|
96
129
|
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
@@ -98,31 +131,24 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
98
131
|
var handleClose = function handleClose() {
|
|
99
132
|
setOpen(false);
|
|
100
133
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
101
|
-
|
|
102
|
-
|
|
134
|
+
var v = transDayjsArr(propsValue, defaultValue, _presets);
|
|
135
|
+
onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(v);
|
|
136
|
+
setValue(v);
|
|
137
|
+
setCurrentShortcut(lastConfirmShortcut.current);
|
|
103
138
|
};
|
|
104
139
|
var handleOk = function handleOk() {
|
|
105
140
|
setOpen(false);
|
|
106
141
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
107
|
-
propsOnChange === null || propsOnChange === void 0 ? void 0 : propsOnChange(
|
|
142
|
+
propsOnChange === null || propsOnChange === void 0 ? void 0 : propsOnChange(getVal());
|
|
143
|
+
lastConfirmShortcut.current = currentShortcut;
|
|
108
144
|
};
|
|
109
|
-
var
|
|
110
|
-
if (isMobile()) return [];
|
|
111
|
-
return presets.map(function (item) {
|
|
112
|
-
var getValue = function getValue() {
|
|
113
|
-
if (typeof item.getValue === "function") {
|
|
114
|
-
return item.getValue();
|
|
115
|
-
}
|
|
116
|
-
return item === null || item === void 0 ? void 0 : item.value;
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
label: item.label,
|
|
120
|
-
getValue: getValue
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
}, [presets]);
|
|
124
|
-
var handleChange = function handleChange(val, type) {
|
|
145
|
+
var handleChange = function handleChange(val, type, shortcutValue) {
|
|
125
146
|
var newVal = val;
|
|
147
|
+
if (isString(shortcutValue) && type === "shortcuts") {
|
|
148
|
+
setCurrentShortcut(shortcutValue);
|
|
149
|
+
} else {
|
|
150
|
+
setCurrentShortcut(null);
|
|
151
|
+
}
|
|
126
152
|
if (isArr(showTime) && type !== "time") {
|
|
127
153
|
newVal = newVal.map(function (item, index) {
|
|
128
154
|
var _showTime$index;
|
|
@@ -133,16 +159,22 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
133
159
|
return item || null;
|
|
134
160
|
});
|
|
135
161
|
}
|
|
162
|
+
if (!clearEndOnSelection) {
|
|
163
|
+
if (newVal[0] && !newVal[1]) {
|
|
164
|
+
newVal[1] = newVal[0];
|
|
165
|
+
} else if (newVal[1] && !newVal[0]) {
|
|
166
|
+
newVal[0] = newVal[1];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
136
169
|
if (clearEndOnSelection && type !== "set" && _value.filter(Boolean).length === 2) {
|
|
137
170
|
newVal = [newVal[0], null];
|
|
138
171
|
}
|
|
139
172
|
onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(newVal);
|
|
140
173
|
setValue(newVal);
|
|
141
174
|
};
|
|
142
|
-
var hasPreset = (_presets === null || _presets === void 0 ? void 0 : _presets.length) > 0;
|
|
143
175
|
useCssVariables({
|
|
144
176
|
variables: {
|
|
145
|
-
"--pisell-date-range-picker-popup-width": "".concat(
|
|
177
|
+
"--pisell-date-range-picker-popup-width": "".concat(popupWidth, "px")
|
|
146
178
|
},
|
|
147
179
|
dom: document.body
|
|
148
180
|
});
|
|
@@ -152,6 +184,8 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
152
184
|
setOpen(false);
|
|
153
185
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
154
186
|
propsOnChange === null || propsOnChange === void 0 ? void 0 : propsOnChange([null, null]);
|
|
187
|
+
setCurrentShortcut(null);
|
|
188
|
+
lastConfirmShortcut.current = null;
|
|
155
189
|
};
|
|
156
190
|
var endAdornment = useMemo(function () {
|
|
157
191
|
if (!allowClear) {
|
|
@@ -185,6 +219,18 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
185
219
|
}
|
|
186
220
|
return localeValue === "en" || localeValue === "en-US" ? "DD/MM/YYYY" : "YYYY/MM/DD";
|
|
187
221
|
}, [propsFormat, locale]);
|
|
222
|
+
var inputPropsObj = useMemo(function () {
|
|
223
|
+
var _value$every;
|
|
224
|
+
var obj = {
|
|
225
|
+
endAdornment: endAdornment
|
|
226
|
+
};
|
|
227
|
+
if (_value !== null && _value !== void 0 && (_value$every = _value.every) !== null && _value$every !== void 0 && _value$every.call(_value, Boolean) && getPresetLabel(currentShortcut, _presets)) {
|
|
228
|
+
obj = _objectSpread(_objectSpread({}, obj), {}, {
|
|
229
|
+
value: getPresetLabel(currentShortcut, _presets)
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return obj;
|
|
233
|
+
}, [_value, endAdornment, returnShortcutString, currentShortcut]);
|
|
188
234
|
return /*#__PURE__*/React.createElement("span", {
|
|
189
235
|
className: classNames(className, "pisell-date-range-picker", {
|
|
190
236
|
"pisell-date-range-picker-no-border": !bordered
|
|
@@ -208,7 +254,18 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
208
254
|
onClose: handleClose,
|
|
209
255
|
onChange: handleChange,
|
|
210
256
|
onOpen: handleOpen,
|
|
211
|
-
open: open
|
|
257
|
+
open: open
|
|
258
|
+
// onRangePositionChange={(rp) => {
|
|
259
|
+
// console.log(rp, "rangePosition");
|
|
260
|
+
// // if (_value.every(item => !Boolean(item))) {
|
|
261
|
+
// // return
|
|
262
|
+
// // } else {
|
|
263
|
+
// setRangePosition(rp)
|
|
264
|
+
// // }
|
|
265
|
+
// }}
|
|
266
|
+
// // defaultRangePosition="start"
|
|
267
|
+
// rangePosition={_value.every((item) => Boolean(item)) ? "start" : undefined}
|
|
268
|
+
,
|
|
212
269
|
defaultCalendarMonth: defaultCalendarMonth,
|
|
213
270
|
shouldDisableDate: function shouldDisableDate(current, position) {
|
|
214
271
|
return disabledDate === null || disabledDate === void 0 ? void 0 : disabledDate(current, position, _value);
|
|
@@ -216,14 +273,18 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
216
273
|
slots: {
|
|
217
274
|
actionBar: ActionBar,
|
|
218
275
|
shortcuts: Shortcuts,
|
|
219
|
-
field: SingleInputDateRangeField
|
|
276
|
+
field: SingleInputDateRangeField,
|
|
277
|
+
dialog: Dialog,
|
|
278
|
+
// calendarHeader: CustomCalendarHeader,
|
|
279
|
+
// calendarHeader: <div>12312</div> ,
|
|
280
|
+
toolbar: Toolbar
|
|
220
281
|
},
|
|
221
282
|
dayOfWeekFormatter: function dayOfWeekFormatter(day) {
|
|
222
283
|
return day;
|
|
223
284
|
},
|
|
224
285
|
slotProps: {
|
|
225
286
|
shortcuts: {
|
|
226
|
-
items:
|
|
287
|
+
items: [],
|
|
227
288
|
changeImportance: "set",
|
|
228
289
|
onChange: handleChange
|
|
229
290
|
},
|
|
@@ -236,15 +297,25 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
236
297
|
okButtonProps: okButtonProps,
|
|
237
298
|
cancelButtonProps: cancelButtonProps
|
|
238
299
|
},
|
|
300
|
+
toolbar: {
|
|
301
|
+
hidden: false,
|
|
302
|
+
presetItems: _presets,
|
|
303
|
+
format: format,
|
|
304
|
+
locale: locale,
|
|
305
|
+
onChange: handleChange,
|
|
306
|
+
currentShortcut: currentShortcut,
|
|
307
|
+
setCurrentShortcut: setCurrentShortcut
|
|
308
|
+
},
|
|
309
|
+
layout: {
|
|
310
|
+
orientation: "portrait"
|
|
311
|
+
},
|
|
239
312
|
field: _objectSpread({
|
|
240
313
|
value: _value,
|
|
241
314
|
size: "small",
|
|
242
315
|
fullWidth: true,
|
|
243
316
|
// variant: "standard",
|
|
244
317
|
// hiddenLabel: true,
|
|
245
|
-
InputProps:
|
|
246
|
-
endAdornment: endAdornment
|
|
247
|
-
}
|
|
318
|
+
InputProps: inputPropsObj
|
|
248
319
|
}, readOnlyProps),
|
|
249
320
|
popper: {
|
|
250
321
|
className: popupClassName,
|