@pisell/date-picker 1.0.86 → 1.0.88
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.less +1 -1
- package/es/OldActionBar/index.d.ts +18 -0
- package/es/OldActionBar/index.js +113 -0
- package/es/OldActionBar/index.less +18 -0
- package/es/OldPisellDateRangePicker/index.d.ts +79 -0
- package/es/OldPisellDateRangePicker/index.js +264 -0
- package/es/OldPisellDateRangePicker/index.less +102 -0
- package/es/PisellDateRangePicker/index.js +8 -8
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/lib/ActionBar/index.less +1 -1
- package/lib/OldActionBar/index.d.ts +18 -0
- package/lib/OldActionBar/index.js +129 -0
- package/lib/OldActionBar/index.less +18 -0
- package/lib/OldPisellDateRangePicker/index.d.ts +79 -0
- package/lib/OldPisellDateRangePicker/index.js +281 -0
- package/lib/OldPisellDateRangePicker/index.less +102 -0
- package/lib/PisellDateRangePicker/index.js +8 -8
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -0
- package/package.json +2 -2
package/es/ActionBar/index.less
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ButtonProps } from "antd";
|
|
2
|
+
import { Dayjs } from "dayjs";
|
|
3
|
+
import "./index.less";
|
|
4
|
+
interface ActionBarProps {
|
|
5
|
+
ownerState: any;
|
|
6
|
+
onCancel: () => void;
|
|
7
|
+
onChange: (val: any[], type?: "time") => void;
|
|
8
|
+
onOk: () => void;
|
|
9
|
+
value: any[];
|
|
10
|
+
showTime?: boolean | {
|
|
11
|
+
defaultValue: Dayjs;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}[];
|
|
14
|
+
okButtonProps?: ButtonProps;
|
|
15
|
+
cancelButtonProps?: ButtonProps;
|
|
16
|
+
}
|
|
17
|
+
declare const ActionBar: (props: ActionBarProps) => JSX.Element;
|
|
18
|
+
export default ActionBar;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
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
|
+
import React, { useMemo, useContext } from "react";
|
|
15
|
+
import classNames from "classnames";
|
|
16
|
+
import { Button, Space, TimePicker } from "antd";
|
|
17
|
+
import { MuiPickersAdapterContext } from "@mui/x-date-pickers";
|
|
18
|
+
import { isArr, isMobile } from "@pisell/utils";
|
|
19
|
+
import dayjs from "dayjs";
|
|
20
|
+
import { getText, pLocaleMap } from "../locales";
|
|
21
|
+
import "./index.less";
|
|
22
|
+
var ActionBar = function ActionBar(props) {
|
|
23
|
+
var ownerState = props.ownerState,
|
|
24
|
+
onCancel = props.onCancel,
|
|
25
|
+
onOk = props.onOk,
|
|
26
|
+
onChange = props.onChange,
|
|
27
|
+
showTime = props.showTime,
|
|
28
|
+
_props$value = props.value,
|
|
29
|
+
value = _props$value === void 0 ? [] : _props$value,
|
|
30
|
+
okButtonProps = props.okButtonProps,
|
|
31
|
+
cancelButtonProps = props.cancelButtonProps;
|
|
32
|
+
var local = useContext(MuiPickersAdapterContext);
|
|
33
|
+
var locale = useMemo(function () {
|
|
34
|
+
return local.utils.locale || "en";
|
|
35
|
+
}, [local.utils.locale]);
|
|
36
|
+
var slotProps = ownerState.slotProps;
|
|
37
|
+
var _ref = (slotProps === null || slotProps === void 0 ? void 0 : slotProps.shortcuts) || {},
|
|
38
|
+
items = _ref.items;
|
|
39
|
+
var hasShortcuts = !!items.length;
|
|
40
|
+
var handleStartChange = function handleStartChange(val) {
|
|
41
|
+
var _start$set, _start$set$set;
|
|
42
|
+
var newValue = _toConsumableArray(value);
|
|
43
|
+
var start = newValue[0] || dayjs();
|
|
44
|
+
newValue[0] = (start === null || start === void 0 ? void 0 : (_start$set = start.set("hour", (val === null || val === void 0 ? void 0 : val.get("hour")) || 0)) === null || _start$set === void 0 ? void 0 : (_start$set$set = _start$set.set("minute", (val === null || val === void 0 ? void 0 : val.get("minute")) || 0)) === null || _start$set$set === void 0 ? void 0 : _start$set$set.set("second", (val === null || val === void 0 ? void 0 : val.get("second")) || 0)) || null;
|
|
45
|
+
onChange(newValue, "time");
|
|
46
|
+
};
|
|
47
|
+
var handleEndChange = function handleEndChange(val) {
|
|
48
|
+
var _end$set, _end$set$set;
|
|
49
|
+
var newValue = _toConsumableArray(value);
|
|
50
|
+
var end = newValue[1] || dayjs();
|
|
51
|
+
newValue[1] = (end === null || end === void 0 ? void 0 : (_end$set = end.set("hour", (val === null || val === void 0 ? void 0 : val.get("hour")) || 0)) === null || _end$set === void 0 ? void 0 : (_end$set$set = _end$set.set("minute", (val === null || val === void 0 ? void 0 : val.get("minute")) || 0)) === null || _end$set$set === void 0 ? void 0 : _end$set$set.set("second", (val === null || val === void 0 ? void 0 : val.get("second")) || 0)) || null;
|
|
52
|
+
onChange(newValue, "time");
|
|
53
|
+
};
|
|
54
|
+
var spaceStyle = useMemo(function () {
|
|
55
|
+
return isMobile() ? {
|
|
56
|
+
display: "flex",
|
|
57
|
+
justifyContent: "end",
|
|
58
|
+
marginBottom: 12
|
|
59
|
+
} : {
|
|
60
|
+
display: "flex"
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
var startTimeProps = useMemo(function () {
|
|
64
|
+
if (isArr(showTime) && showTime[0]) {
|
|
65
|
+
return showTime[0];
|
|
66
|
+
}
|
|
67
|
+
return {};
|
|
68
|
+
}, [showTime]);
|
|
69
|
+
var endTimeProps = useMemo(function () {
|
|
70
|
+
if (isArr(showTime) && showTime[1]) {
|
|
71
|
+
return showTime[1];
|
|
72
|
+
}
|
|
73
|
+
return {};
|
|
74
|
+
}, [showTime]);
|
|
75
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
76
|
+
className: classNames(props.className, "date-picker-action-bar")
|
|
77
|
+
}, hasShortcuts && /*#__PURE__*/React.createElement("div", {
|
|
78
|
+
className: "date-picker-action-bar-left"
|
|
79
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
80
|
+
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
|
+
style: _objectSpread(_objectSpread({}, spaceStyle), {}, {
|
|
103
|
+
margin: 0
|
|
104
|
+
})
|
|
105
|
+
}, /*#__PURE__*/React.createElement(Button, _extends({}, cancelButtonProps || {}, {
|
|
106
|
+
onClick: onCancel
|
|
107
|
+
}), getText("action-bar-cancel", pLocaleMap[locale])), /*#__PURE__*/React.createElement(Button, _extends({
|
|
108
|
+
type: "primary"
|
|
109
|
+
}, okButtonProps || {}, {
|
|
110
|
+
onClick: onOk
|
|
111
|
+
}), getText("action-bar-apply", pLocaleMap[locale])))));
|
|
112
|
+
};
|
|
113
|
+
export default ActionBar;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.date-picker-action-bar {
|
|
2
|
+
display: flex;
|
|
3
|
+
.date-picker-action-bar-left {
|
|
4
|
+
width: 192px;
|
|
5
|
+
border-right: 1px solid rgba(0, 0, 0, 0.12);
|
|
6
|
+
}
|
|
7
|
+
.date-picker-action-bar-right {
|
|
8
|
+
flex: 1;
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-content: space-between;
|
|
11
|
+
padding: 16px;
|
|
12
|
+
border-top: 1px solid rgba(0, 0, 0, 0.12);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.date-picker-action-bar-time-picker-popup {
|
|
17
|
+
z-index: 1400;
|
|
18
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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)[]) => void;
|
|
15
|
+
/** 日期改变回调 此处只为了组件外拿到当前日期项进行状态操作 通常情况下只使用onChange来拿value */
|
|
16
|
+
onDateChange?: (day: (Dayjs | null)[]) => void;
|
|
17
|
+
/** 日期选择值 */
|
|
18
|
+
value?: Dayjs[];
|
|
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
|
+
declare const PisellDateRangePicker: (props: PisellDateRangePickerProps) => JSX.Element;
|
|
79
|
+
export default PisellDateRangePicker;
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
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
|
+
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
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
import React, { useState, useEffect, useMemo, useContext } from 'react';
|
|
14
|
+
import { DateRangePicker } from "../DateRangePicker";
|
|
15
|
+
import ActionBar from "../OldActionBar";
|
|
16
|
+
import Shortcuts from "../Shortcuts";
|
|
17
|
+
import { SingleInputDateRangeField } from "../SingleInputDateRangeField";
|
|
18
|
+
import classNames from 'classnames';
|
|
19
|
+
import { isArr, isBoolean } from '@pisell/utils';
|
|
20
|
+
import useCssVariables from "../PisellDateRangePicker/useCssVariables";
|
|
21
|
+
import CloseCircle from "../icon/CloseCircle";
|
|
22
|
+
import 'dayjs/locale/zh-cn';
|
|
23
|
+
import 'dayjs/locale/en';
|
|
24
|
+
import 'dayjs/locale/zh-tw';
|
|
25
|
+
import { getCurrentLocale, isMobile } from "../utils";
|
|
26
|
+
import { LocaleContext } from "../PisellDateRangePicker/LocaleContext";
|
|
27
|
+
import { pLocaleMap } from "../locales";
|
|
28
|
+
import "./index.less";
|
|
29
|
+
var transDayjsArr = function transDayjsArr(dayjsArr, defaultValue) {
|
|
30
|
+
var _newArr;
|
|
31
|
+
var newArr = dayjsArr || defaultValue || [null, null];
|
|
32
|
+
if ((dayjsArr === null || dayjsArr === void 0 ? void 0 : dayjsArr.length) === 0) {
|
|
33
|
+
newArr = defaultValue || [null, null];
|
|
34
|
+
}
|
|
35
|
+
return (_newArr = newArr) === null || _newArr === void 0 ? void 0 : _newArr.map(function (item) {
|
|
36
|
+
return item ? item : null;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
// api详情
|
|
40
|
+
// https://mui.com/x/api/date-pickers/date-range-picker/
|
|
41
|
+
var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
42
|
+
var propsOnChange = props.onChange,
|
|
43
|
+
propsValue = props.value,
|
|
44
|
+
_props$presets = props.presets,
|
|
45
|
+
presets = _props$presets === void 0 ? [] : _props$presets,
|
|
46
|
+
className = props.className,
|
|
47
|
+
showTime = props.showTime,
|
|
48
|
+
placeholder = props.placeholder,
|
|
49
|
+
disabledDate = props.disabledDate,
|
|
50
|
+
propsFormat = props.format,
|
|
51
|
+
defaultValue = props.defaultValue,
|
|
52
|
+
suffixIcon = props.suffixIcon,
|
|
53
|
+
_props$bordered = props.bordered,
|
|
54
|
+
bordered = _props$bordered === void 0 ? true : _props$bordered,
|
|
55
|
+
propsOpen = props.open,
|
|
56
|
+
onClose = props.onClose,
|
|
57
|
+
_props$popupWidth = props.popupWidth,
|
|
58
|
+
popupWidth = _props$popupWidth === void 0 ? 625 : _props$popupWidth,
|
|
59
|
+
clearEndOnSelection = props.clearEndOnSelection,
|
|
60
|
+
minDate = props.minDate,
|
|
61
|
+
maxDate = props.maxDate,
|
|
62
|
+
onOpen = props.onOpen,
|
|
63
|
+
onMonthChange = props.onMonthChange,
|
|
64
|
+
popupClassName = props.popupClassName,
|
|
65
|
+
defaultCalendarMonth = props.defaultCalendarMonth,
|
|
66
|
+
okButtonProps = props.okButtonProps,
|
|
67
|
+
cancelButtonProps = props.cancelButtonProps,
|
|
68
|
+
onDateChange = props.onDateChange,
|
|
69
|
+
desktopModeMediaQuery = props.desktopModeMediaQuery,
|
|
70
|
+
style = props.style,
|
|
71
|
+
allowClear = props.allowClear,
|
|
72
|
+
disablePortal = props.disablePortal,
|
|
73
|
+
_props$placement = props.placement,
|
|
74
|
+
placement = _props$placement === void 0 ? 'auto' : _props$placement,
|
|
75
|
+
inputReadOnly = props.inputReadOnly;
|
|
76
|
+
var _useState = useState(propsOpen !== null && propsOpen !== void 0 ? propsOpen : false),
|
|
77
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
78
|
+
open = _useState2[0],
|
|
79
|
+
setOpen = _useState2[1];
|
|
80
|
+
var _ref = useContext(LocaleContext) || {},
|
|
81
|
+
locale = _ref.locale;
|
|
82
|
+
useEffect(function () {
|
|
83
|
+
isBoolean(propsOpen) && setOpen(propsOpen);
|
|
84
|
+
}, [propsOpen]);
|
|
85
|
+
var _useState3 = useState(function () {
|
|
86
|
+
return transDayjsArr(propsValue, defaultValue);
|
|
87
|
+
}),
|
|
88
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
89
|
+
_value = _useState4[0],
|
|
90
|
+
setValue = _useState4[1];
|
|
91
|
+
useEffect(function () {
|
|
92
|
+
setValue(transDayjsArr(propsValue, defaultValue));
|
|
93
|
+
}, [propsValue]);
|
|
94
|
+
var handleOpen = function handleOpen() {
|
|
95
|
+
setOpen(true);
|
|
96
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
97
|
+
};
|
|
98
|
+
var handleClose = function handleClose() {
|
|
99
|
+
setOpen(false);
|
|
100
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
101
|
+
onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(transDayjsArr(propsValue, defaultValue));
|
|
102
|
+
setValue(transDayjsArr(propsValue, defaultValue));
|
|
103
|
+
};
|
|
104
|
+
var handleOk = function handleOk() {
|
|
105
|
+
setOpen(false);
|
|
106
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
107
|
+
propsOnChange === null || propsOnChange === void 0 ? void 0 : propsOnChange(_value);
|
|
108
|
+
};
|
|
109
|
+
var _presets = useMemo(function () {
|
|
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) {
|
|
125
|
+
var newVal = val;
|
|
126
|
+
if (isArr(showTime) && type !== 'time') {
|
|
127
|
+
newVal = newVal.map(function (item, index) {
|
|
128
|
+
var _showTime$index;
|
|
129
|
+
if (showTime !== null && showTime !== void 0 && (_showTime$index = showTime[index]) !== null && _showTime$index !== void 0 && _showTime$index.defaultValue) {
|
|
130
|
+
var _showTime$index2, _showTime$index2$defa, _showTime$index3, _showTime$index3$defa, _showTime$index4, _showTime$index4$defa;
|
|
131
|
+
return (item === null || item === void 0 ? void 0 : item.set('hour', (_showTime$index2 = showTime[index]) === null || _showTime$index2 === void 0 ? void 0 : (_showTime$index2$defa = _showTime$index2.defaultValue) === null || _showTime$index2$defa === void 0 ? void 0 : _showTime$index2$defa.get('hour')).set('minute', (_showTime$index3 = showTime[index]) === null || _showTime$index3 === void 0 ? void 0 : (_showTime$index3$defa = _showTime$index3.defaultValue) === null || _showTime$index3$defa === void 0 ? void 0 : _showTime$index3$defa.get('minute')).set('second', (_showTime$index4 = showTime[index]) === null || _showTime$index4 === void 0 ? void 0 : (_showTime$index4$defa = _showTime$index4.defaultValue) === null || _showTime$index4$defa === void 0 ? void 0 : _showTime$index4$defa.get('second'))) || null;
|
|
132
|
+
}
|
|
133
|
+
return item || null;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (clearEndOnSelection && type !== 'set' && _value.filter(Boolean).length === 2) {
|
|
137
|
+
newVal = [newVal[0], null];
|
|
138
|
+
}
|
|
139
|
+
onDateChange === null || onDateChange === void 0 ? void 0 : onDateChange(newVal);
|
|
140
|
+
setValue(newVal);
|
|
141
|
+
};
|
|
142
|
+
var hasPreset = (_presets === null || _presets === void 0 ? void 0 : _presets.length) > 0;
|
|
143
|
+
useCssVariables({
|
|
144
|
+
variables: {
|
|
145
|
+
'--pisell-date-range-picker-popup-width': "".concat(hasPreset ? popupWidth + 192 : popupWidth, "px")
|
|
146
|
+
},
|
|
147
|
+
dom: document.body
|
|
148
|
+
});
|
|
149
|
+
var handleClear = function handleClear(e) {
|
|
150
|
+
e.stopPropagation();
|
|
151
|
+
setValue([null, null]);
|
|
152
|
+
setOpen(false);
|
|
153
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
154
|
+
propsOnChange === null || propsOnChange === void 0 ? void 0 : propsOnChange([null, null]);
|
|
155
|
+
};
|
|
156
|
+
var endAdornment = useMemo(function () {
|
|
157
|
+
if (!allowClear) {
|
|
158
|
+
return suffixIcon;
|
|
159
|
+
}
|
|
160
|
+
if (_value !== null && _value !== void 0 && _value.some(function (item) {
|
|
161
|
+
return !!item;
|
|
162
|
+
})) {
|
|
163
|
+
return /*#__PURE__*/React.createElement(CloseCircle, {
|
|
164
|
+
className: "pisell-date-range-picker-clear",
|
|
165
|
+
onClick: handleClear
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}, [suffixIcon, allowClear, _value]);
|
|
169
|
+
var readOnlyProps = useMemo(function () {
|
|
170
|
+
if (inputReadOnly) {
|
|
171
|
+
return {
|
|
172
|
+
readOnly: true,
|
|
173
|
+
selectedSections: null
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return {};
|
|
177
|
+
}, [inputReadOnly]);
|
|
178
|
+
var format = useMemo(function () {
|
|
179
|
+
if (propsFormat) {
|
|
180
|
+
return propsFormat;
|
|
181
|
+
}
|
|
182
|
+
var localeValue = locale;
|
|
183
|
+
if (!localeValue) {
|
|
184
|
+
localeValue = pLocaleMap[getCurrentLocale()];
|
|
185
|
+
}
|
|
186
|
+
return localeValue === 'en' || localeValue === 'en-US' ? 'DD/MM/YYYY' : 'YYYY/MM/DD';
|
|
187
|
+
}, [propsFormat, locale]);
|
|
188
|
+
console.log(_presets, presets, '_presets');
|
|
189
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
190
|
+
className: classNames(className, 'pisell-date-range-picker', 'pisell-date-range-picker-old', {
|
|
191
|
+
'pisell-date-range-picker-no-border': !bordered
|
|
192
|
+
}),
|
|
193
|
+
style: style,
|
|
194
|
+
onClick: function onClick(e) {
|
|
195
|
+
return e.stopPropagation();
|
|
196
|
+
}
|
|
197
|
+
}, /*#__PURE__*/React.createElement(DateRangePicker
|
|
198
|
+
// defaultValue={defaultValue}
|
|
199
|
+
// key={`${_value?.[0]?.valueOf()}-${_value?.[1]?.valueOf()}`}
|
|
200
|
+
, {
|
|
201
|
+
desktopModeMediaQuery: desktopModeMediaQuery,
|
|
202
|
+
onMonthChange: onMonthChange,
|
|
203
|
+
minDate: minDate,
|
|
204
|
+
maxDate: maxDate,
|
|
205
|
+
format: format,
|
|
206
|
+
label: placeholder,
|
|
207
|
+
value: _value,
|
|
208
|
+
closeOnSelect: false,
|
|
209
|
+
onClose: handleClose,
|
|
210
|
+
onChange: handleChange,
|
|
211
|
+
onOpen: handleOpen,
|
|
212
|
+
open: open,
|
|
213
|
+
defaultCalendarMonth: defaultCalendarMonth,
|
|
214
|
+
shouldDisableDate: function shouldDisableDate(current, position) {
|
|
215
|
+
return disabledDate === null || disabledDate === void 0 ? void 0 : disabledDate(current, position, _value);
|
|
216
|
+
},
|
|
217
|
+
slots: {
|
|
218
|
+
actionBar: ActionBar,
|
|
219
|
+
shortcuts: Shortcuts,
|
|
220
|
+
field: SingleInputDateRangeField
|
|
221
|
+
},
|
|
222
|
+
dayOfWeekFormatter: function dayOfWeekFormatter(day) {
|
|
223
|
+
return day;
|
|
224
|
+
},
|
|
225
|
+
slotProps: {
|
|
226
|
+
shortcuts: {
|
|
227
|
+
items: _presets,
|
|
228
|
+
changeImportance: 'set',
|
|
229
|
+
onChange: handleChange
|
|
230
|
+
},
|
|
231
|
+
actionBar: {
|
|
232
|
+
onOk: handleOk,
|
|
233
|
+
onCancel: handleClose,
|
|
234
|
+
showTime: showTime,
|
|
235
|
+
onChange: handleChange,
|
|
236
|
+
value: _value,
|
|
237
|
+
okButtonProps: okButtonProps,
|
|
238
|
+
cancelButtonProps: cancelButtonProps
|
|
239
|
+
},
|
|
240
|
+
field: _objectSpread({
|
|
241
|
+
value: _value,
|
|
242
|
+
size: 'small',
|
|
243
|
+
fullWidth: true,
|
|
244
|
+
// variant: "standard",
|
|
245
|
+
// hiddenLabel: true,
|
|
246
|
+
InputProps: {
|
|
247
|
+
endAdornment: endAdornment
|
|
248
|
+
}
|
|
249
|
+
}, readOnlyProps),
|
|
250
|
+
popper: {
|
|
251
|
+
className: classNames(popupClassName, "pisell-date-range-picker-popper-old"),
|
|
252
|
+
disablePortal: disablePortal,
|
|
253
|
+
placement: placement
|
|
254
|
+
},
|
|
255
|
+
dialog: {
|
|
256
|
+
disablePortal: disablePortal
|
|
257
|
+
},
|
|
258
|
+
mobilePaper: {
|
|
259
|
+
className: popupClassName
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}));
|
|
263
|
+
};
|
|
264
|
+
export default PisellDateRangePicker;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
.pisell-date-range-picker {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
width: 100%;
|
|
4
|
+
//width: 350px;
|
|
5
|
+
//.MuiInputBase-input {
|
|
6
|
+
// padding: 10px;
|
|
7
|
+
//}
|
|
8
|
+
label {
|
|
9
|
+
font-size: 14px;
|
|
10
|
+
}
|
|
11
|
+
.pisell-date-range-picker-clear {
|
|
12
|
+
color: rgba(0, 0, 0, 0.25);
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
display: none;
|
|
15
|
+
line-height: 0;
|
|
16
|
+
:hover {
|
|
17
|
+
color: rgba(0, 0, 0, 0.45);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
:hover {
|
|
21
|
+
.pisell-date-range-picker-clear {
|
|
22
|
+
display: block;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
.pisell-date-range-picker-no-border {
|
|
27
|
+
.MuiOutlinedInput-notchedOutline {
|
|
28
|
+
border: none;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
.MuiOutlinedInput-notchedOutline {
|
|
32
|
+
legend {
|
|
33
|
+
color: inherit !important;
|
|
34
|
+
width: auto !important;
|
|
35
|
+
margin-bottom: 0.5em !important;
|
|
36
|
+
font-size: 1.5em !important;
|
|
37
|
+
line-height: 11px !important;
|
|
38
|
+
border: none !important;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.MuiPickersPopper-root {
|
|
43
|
+
.MuiPickersLayout-root {
|
|
44
|
+
width: var(--pisell-date-range-picker-popup-width, 625px);
|
|
45
|
+
.MuiDateRangeCalendar-root {
|
|
46
|
+
width: 100%;
|
|
47
|
+
flex: 1;
|
|
48
|
+
.MuiDateRangeCalendar-monthContainer {
|
|
49
|
+
width: 50%;
|
|
50
|
+
.MuiDayCalendar-header {
|
|
51
|
+
padding: 0 20px;
|
|
52
|
+
.MuiDayCalendar-weekDayLabel {
|
|
53
|
+
flex: 1;
|
|
54
|
+
width: 100%;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
.MuiPickersSlideTransition-root {
|
|
58
|
+
min-width: 200px;
|
|
59
|
+
//min-height: auto;
|
|
60
|
+
&::before {
|
|
61
|
+
content: "";
|
|
62
|
+
display: block;
|
|
63
|
+
padding-top: 67%;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
.MuiDayCalendar-monthContainer {
|
|
67
|
+
padding: 0 20px;
|
|
68
|
+
}
|
|
69
|
+
.MuiDayCalendar-weekContainer {
|
|
70
|
+
.MuiDateRangePickerDay-root {
|
|
71
|
+
flex: 1;
|
|
72
|
+
.MuiDateRangePickerDay-day {
|
|
73
|
+
width: 100%;
|
|
74
|
+
height: auto;
|
|
75
|
+
&::before {
|
|
76
|
+
content: "";
|
|
77
|
+
display: block;
|
|
78
|
+
padding-top: 100%;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.MuiDialog-root {
|
|
89
|
+
.MuiPickersLayout-toolbar {
|
|
90
|
+
display: none;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.MuiPickersLayout-shortcuts {
|
|
95
|
+
grid-column: 1 !important;
|
|
96
|
+
grid-row: 1/3 !important;
|
|
97
|
+
}
|
|
98
|
+
.pisell-date-range-picker-popper-old {
|
|
99
|
+
.MuiPickersLayout-root {
|
|
100
|
+
display: grid !important;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -153,6 +153,14 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
153
153
|
} else {
|
|
154
154
|
setCurrentShortcut(null);
|
|
155
155
|
}
|
|
156
|
+
if (!clearEndOnSelection && type !== "shortcuts" && type !== "write") {
|
|
157
|
+
if (rangePosition === 'start') {
|
|
158
|
+
newVal = [newVal[0], newVal[0]];
|
|
159
|
+
}
|
|
160
|
+
if (!newVal[1]) {
|
|
161
|
+
newVal = [newVal[0], newVal[0]];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
156
164
|
if (isArr(showTime) && type !== "time") {
|
|
157
165
|
newVal = newVal.map(function (item, index) {
|
|
158
166
|
var _showTime$index;
|
|
@@ -163,14 +171,6 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
|
|
|
163
171
|
return item || null;
|
|
164
172
|
});
|
|
165
173
|
}
|
|
166
|
-
if (!clearEndOnSelection && type !== "shortcuts" && type !== "write") {
|
|
167
|
-
if (rangePosition === 'start') {
|
|
168
|
-
newVal = [newVal[0], newVal[0]];
|
|
169
|
-
}
|
|
170
|
-
if (!newVal[1]) {
|
|
171
|
-
newVal = [newVal[0], newVal[0]];
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
174
|
if (clearEndOnSelection && type !== "set" && _value.filter(Boolean).length === 2) {
|
|
175
175
|
newVal = [newVal[0], null];
|
|
176
176
|
}
|
package/es/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConfigProvider } from 'antd';
|
|
2
2
|
import PisellDateRangePicker from "./PisellDateRangePicker";
|
|
3
|
+
import OldPisellDateRangePicker from "./OldPisellDateRangePicker";
|
|
3
4
|
import { LocaleContext, LocaleProvider } from "./PisellDateRangePicker/LocaleContext";
|
|
4
5
|
export * from "@mui/x-date-pickers";
|
|
5
6
|
export * from "@mui/material/styles";
|
|
@@ -19,6 +20,7 @@ export * from "./dateRangeViewRenderers";
|
|
|
19
20
|
export type { DateRange, RangePosition } from "./internals/models/range";
|
|
20
21
|
export type { UseDateRangeFieldProps } from "./internals/models/dateRange";
|
|
21
22
|
export { PisellDateRangePicker as RangePicker };
|
|
23
|
+
export { OldPisellDateRangePicker };
|
|
22
24
|
export { LocaleContext, LocaleProvider, ConfigProvider };
|
|
23
25
|
export { getDatePickerValueByShortcut, formatPresets, getShortcutValue, getPresetLabel, getDatePickerValue, } from "./utils/index";
|
|
24
26
|
export * from "./models";
|
package/es/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConfigProvider } from 'antd';
|
|
2
2
|
import PisellDateRangePicker from "./PisellDateRangePicker";
|
|
3
|
+
import OldPisellDateRangePicker from "./OldPisellDateRangePicker";
|
|
3
4
|
import { LocaleContext, LocaleProvider } from "./PisellDateRangePicker/LocaleContext";
|
|
4
5
|
export * from "@mui/x-date-pickers";
|
|
5
6
|
export * from "@mui/material/styles";
|
|
@@ -24,6 +25,7 @@ export * from "./StaticDateRangePicker";
|
|
|
24
25
|
// View renderers
|
|
25
26
|
export * from "./dateRangeViewRenderers";
|
|
26
27
|
export { PisellDateRangePicker as RangePicker };
|
|
28
|
+
export { OldPisellDateRangePicker };
|
|
27
29
|
export { LocaleContext, LocaleProvider, ConfigProvider };
|
|
28
30
|
export { getDatePickerValueByShortcut, formatPresets, getShortcutValue, getPresetLabel, getDatePickerValue } from "./utils/index";
|
|
29
31
|
export * from "./models";
|